Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk): support a "block-list" of things to not instrument #1958

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/traceloop-sdk/traceloop/sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def init(
api_key: str = None,
headers: Dict[str, str] = {},
disable_batch=False,
disable_requests_instrumentation: bool = True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

exporter: SpanExporter = None,
metrics_exporter: MetricExporter = None,
metrics_headers: Dict[str, str] = None,
Expand Down Expand Up @@ -125,6 +126,7 @@ def init(
)
Traceloop.__tracer_wrapper = TracerWrapper(
disable_batch=disable_batch,
disable_requests_instrumentation=disable_requests_instrumentation,
processor=processor,
propagator=propagator,
exporter=exporter,
Expand Down
9 changes: 6 additions & 3 deletions packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class TracerWrapper(object):
def __new__(
cls,
disable_batch=False,
disable_requests_instrumentation=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems highly specific, don't you think? I think I'd rather add something like the "instruments" parameter but that can be sort of a "block list" where any of the libraries in that parameter won't be instrumented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block list sounds like a better idea. The reason I went specific was because the tracer is normally expected to instrument GenAI-related packages, but has requests as a special additional scenario. Block list would be broad enough for future developments as well.

processor: SpanProcessor = None,
propagator: TextMapPropagator = None,
exporter: SpanExporter = None,
Expand Down Expand Up @@ -125,7 +126,7 @@ def __new__(

instrument_set = False
if instruments is None:
init_instrumentations(should_enrich_metrics)
init_instrumentations(should_enrich_metrics, disable_requests_instrumentation)
instrument_set = True
else:
for instrument in instruments:
Expand Down Expand Up @@ -525,7 +526,7 @@ def init_tracer_provider(resource: Resource) -> TracerProvider:
return provider


def init_instrumentations(should_enrich_metrics: bool):
def init_instrumentations(should_enrich_metrics: bool, disable_requests_instrumentation: bool):
init_openai_instrumentor(should_enrich_metrics)
init_anthropic_instrumentor(should_enrich_metrics)
init_cohere_instrumentor()
Expand All @@ -542,7 +543,6 @@ def init_instrumentations(should_enrich_metrics: bool):
init_transformers_instrumentor()
init_together_instrumentor()
init_redis_instrumentor()
init_requests_instrumentor()
init_urllib3_instrumentor()
init_pymysql_instrumentor()
init_bedrock_instrumentor(should_enrich_metrics)
Expand All @@ -555,6 +555,9 @@ def init_instrumentations(should_enrich_metrics: bool):
init_lancedb_instrumentor()
init_groq_instrumentor()

if not disable_requests_instrumentation:
init_requests_instrumentor()


def init_openai_instrumentor(should_enrich_metrics: bool):
try:
Expand Down