mirror of
https://github.com/microsoft/autogen.git
synced 2025-06-26 22:30:10 +00:00
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:
parent
89927ca436
commit
c5b893d3f8
@ -98,6 +98,8 @@
|
||||
"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",
|
||||
"`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",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
|
@ -160,6 +160,7 @@ class SingleThreadedAgentRuntime(AgentRuntime):
|
||||
intervention_handlers (List[InterventionHandler], optional): A list of intervention
|
||||
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.
|
||||
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.
|
||||
|
||||
Examples:
|
||||
|
@ -1,4 +1,5 @@
|
||||
import contextlib
|
||||
import os
|
||||
from typing import Dict, Generic, Iterator, Optional
|
||||
|
||||
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,
|
||||
instrumentation_builder_config: TracingConfig[Operation, Destination, ExtraAttributes],
|
||||
) -> 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
|
||||
# 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 = self.tracer_provider.get_tracer(f"autogen {instrumentation_builder_config.name}")
|
||||
self.instrumentation_builder_config = instrumentation_builder_config
|
||||
|
||||
@contextlib.contextmanager
|
||||
def trace_block(
|
||||
|
Loading…
x
Reference in New Issue
Block a user