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>
This commit is contained in:
Eitan Yarmush 2025-06-20 08:26:14 -04:00 committed by GitHub
parent 89927ca436
commit c5b893d3f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 1 deletions

View File

@ -98,6 +98,8 @@
"In turn, the runtime is already instrumented to log, see [Core Telemetry Guide](../core-user-guide/framework/telemetry.md).\n", "In turn, the runtime is already instrumented to log, see [Core Telemetry Guide](../core-user-guide/framework/telemetry.md).\n",
"To disable the agent runtime telemetry, you can set the `trace_provider` to\n", "To disable the agent runtime telemetry, you can set the `trace_provider` to\n",
"`opentelemetry.trace.NoOpTraceProvider` in the runtime constructor.\n", "`opentelemetry.trace.NoOpTraceProvider` in the runtime constructor.\n",
"\n",
"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",
"```" "```"
] ]
}, },

View File

@ -160,6 +160,7 @@ class SingleThreadedAgentRuntime(AgentRuntime):
intervention_handlers (List[InterventionHandler], optional): A list of intervention intervention_handlers (List[InterventionHandler], optional): A list of intervention
handlers that can intercept messages before they are sent or published. Defaults to None. handlers that can intercept messages before they are sent or published. Defaults to None.
tracer_provider (TracerProvider, optional): The tracer provider to use for tracing. Defaults to None. tracer_provider (TracerProvider, optional): The tracer provider to use for tracing. Defaults to None.
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`.
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. 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.
Examples: Examples:

View File

@ -1,4 +1,5 @@
import contextlib import contextlib
import os
from typing import Dict, Generic, Iterator, Optional from typing import Dict, Generic, Iterator, Optional
from opentelemetry.trace import NoOpTracerProvider, Span, SpanKind, TracerProvider, get_tracer_provider from opentelemetry.trace import NoOpTracerProvider, Span, SpanKind, TracerProvider, get_tracer_provider
@ -22,11 +23,18 @@ class TraceHelper(Generic[Operation, Destination, ExtraAttributes]):
tracer_provider: TracerProvider | None, tracer_provider: TracerProvider | None,
instrumentation_builder_config: TracingConfig[Operation, Destination, ExtraAttributes], instrumentation_builder_config: TracingConfig[Operation, Destination, ExtraAttributes],
) -> None: ) -> None:
self.instrumentation_builder_config = instrumentation_builder_config
disable_runtime_tracing = os.environ.get("AUTOGEN_DISABLE_RUNTIME_TRACING") == "true"
if disable_runtime_tracing:
self.tracer_provider: TracerProvider = NoOpTracerProvider()
self.tracer = self.tracer_provider.get_tracer(f"autogen {instrumentation_builder_config.name}")
return
# Evaluate in order: first try tracer_provider param, then get_tracer_provider(), finally fallback to NoOp # Evaluate in order: first try tracer_provider param, then get_tracer_provider(), finally fallback to NoOp
# This allows for nested tracing with a default tracer provided by the user # This allows for nested tracing with a default tracer provided by the user
self.tracer_provider = tracer_provider or get_tracer_provider() or NoOpTracerProvider() self.tracer_provider = tracer_provider or get_tracer_provider() or NoOpTracerProvider()
self.tracer = self.tracer_provider.get_tracer(f"autogen {instrumentation_builder_config.name}") self.tracer = self.tracer_provider.get_tracer(f"autogen {instrumentation_builder_config.name}")
self.instrumentation_builder_config = instrumentation_builder_config
@contextlib.contextmanager @contextlib.contextmanager
def trace_block( def trace_block(