Skip to content

Commit c5b893d

Browse files
EItanyaekzhu
andauthored
add env var to disable runtime tracing (#6681)
Recently a PR merged to enable GENAI semantic convention tracing, however, when using component loading it's not currently possible to disable the runtime tracing. --------- Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
1 parent 89927ca commit c5b893d

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tracing.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
"In turn, the runtime is already instrumented to log, see [Core Telemetry Guide](../core-user-guide/framework/telemetry.md).\n",
9999
"To disable the agent runtime telemetry, you can set the `trace_provider` to\n",
100100
"`opentelemetry.trace.NoOpTraceProvider` in the runtime constructor.\n",
101+
"\n",
102+
"Additionally, you can set the environment varibale `AUTOGEN_DISABLE_RUNTIME_TRACING` to `true` to disable the agent runtime telemetry if you don't have access to the runtime constructor. For example, if you are using `ComponentConfig`.\n",
101103
"```"
102104
]
103105
},

python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class SingleThreadedAgentRuntime(AgentRuntime):
160160
intervention_handlers (List[InterventionHandler], optional): A list of intervention
161161
handlers that can intercept messages before they are sent or published. Defaults to None.
162162
tracer_provider (TracerProvider, optional): The tracer provider to use for tracing. Defaults to None.
163+
Additionally, you can set environment variable `AUTOGEN_DISABLE_RUNTIME_TRACING` to `true` to disable the agent runtime telemetry if you don't have access to the runtime constructor. For example, if you are using `ComponentConfig`.
163164
ignore_unhandled_exceptions (bool, optional): Whether to ignore unhandled exceptions in that occur in agent event handlers. Any background exceptions will be raised on the next call to `process_next` or from an awaited `stop`, `stop_when_idle` or `stop_when`. Note, this does not apply to RPC handlers. Defaults to True.
164165
165166
Examples:

python/packages/autogen-core/src/autogen_core/_telemetry/_tracing.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import contextlib
2+
import os
23
from typing import Dict, Generic, Iterator, Optional
34

45
from opentelemetry.trace import NoOpTracerProvider, Span, SpanKind, TracerProvider, get_tracer_provider
@@ -22,11 +23,18 @@ def __init__(
2223
tracer_provider: TracerProvider | None,
2324
instrumentation_builder_config: TracingConfig[Operation, Destination, ExtraAttributes],
2425
) -> None:
26+
self.instrumentation_builder_config = instrumentation_builder_config
27+
28+
disable_runtime_tracing = os.environ.get("AUTOGEN_DISABLE_RUNTIME_TRACING") == "true"
29+
if disable_runtime_tracing:
30+
self.tracer_provider: TracerProvider = NoOpTracerProvider()
31+
self.tracer = self.tracer_provider.get_tracer(f"autogen {instrumentation_builder_config.name}")
32+
return
33+
2534
# Evaluate in order: first try tracer_provider param, then get_tracer_provider(), finally fallback to NoOp
2635
# This allows for nested tracing with a default tracer provided by the user
2736
self.tracer_provider = tracer_provider or get_tracer_provider() or NoOpTracerProvider()
2837
self.tracer = self.tracer_provider.get_tracer(f"autogen {instrumentation_builder_config.name}")
29-
self.instrumentation_builder_config = instrumentation_builder_config
3038

3139
@contextlib.contextmanager
3240
def trace_block(

0 commit comments

Comments
 (0)