Python: [BREAKING] Observability updates (#2782)

* fixes Python: Add env_file_path parameter to setup_observability() similar to AzureOpenAIChatClient
Fixes #2186

* WIP on updates using configure_azure_monitor

* improved setup and clarity

* fixed root .env.example

* revert changes

* updated files

* updated sample

* updated zero code

* test fixes and fixed links

* fix devui

* removed planning docs

* added enable method and updated readme and samples

* clarified docstring

* add return annotation

* updated naming

* update capatilized version

* updated readme and some fixes

* updated decorator name inline with the rest

* feedback from comments addressed
This commit is contained in:
Eduard van Valkenburg
2025-12-16 07:56:30 +01:00
committed by GitHub
Unverified
parent 3c379718e9
commit 3139347526
46 changed files with 5823 additions and 4615 deletions
@@ -30,7 +30,6 @@ class GAIATelemetryConfig:
self,
enable_tracing: bool = False,
otlp_endpoint: str | None = None,
applicationinsights_connection_string: str | None = None,
trace_to_file: bool = False,
file_path: str | None = None,
):
@@ -39,24 +38,27 @@ class GAIATelemetryConfig:
Args:
enable_tracing: Whether to enable OpenTelemetry tracing
otlp_endpoint: OTLP endpoint for trace export
applicationinsights_connection_string: Azure Monitor connection string
trace_to_file: Whether to export traces to local file
file_path: Path for local file export (defaults to gaia_traces.json)
Note:
For Azure Monitor integration, configure using environment variables
(OTEL_EXPORTER_OTLP_ENDPOINT, etc.) or use AzureAIClient.configure_azure_monitor()
before creating the GAIA instance.
"""
self.enable_tracing = enable_tracing
self.otlp_endpoint = otlp_endpoint
self.applicationinsights_connection_string = applicationinsights_connection_string
self.trace_to_file = trace_to_file
self.file_path = file_path or "gaia_traces.json"
def setup_observability(self) -> None:
def configure_otel_providers(self) -> None:
"""Set up OpenTelemetry based on configuration."""
if not self.enable_tracing:
return
# If only file tracing is requested (no OTLP or Application Insights),
# skip the default setup_observability which adds console exporter
if self.trace_to_file and not self.otlp_endpoint and not self.applicationinsights_connection_string:
# If only file tracing is requested (no OTLP),
# skip the default configure_otel_providers which adds console exporter
if self.trace_to_file and not self.otlp_endpoint:
# Set up minimal tracing with only file export
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.trace import set_tracer_provider
@@ -65,13 +67,17 @@ class GAIATelemetryConfig:
set_tracer_provider(tracer_provider)
self._setup_file_export()
else:
# Use full observability setup for OTLP/AppInsights
from agent_framework.observability import setup_observability
# Use full observability setup for OTLP
from agent_framework.observability import configure_otel_providers
setup_observability(
# Set OTLP endpoint env var if provided
if self.otlp_endpoint:
import os
os.environ.setdefault("OTEL_EXPORTER_OTLP_ENDPOINT", self.otlp_endpoint)
configure_otel_providers(
enable_sensitive_data=True, # Enable for detailed task traces
otlp_endpoint=self.otlp_endpoint,
applicationinsights_connection_string=self.applicationinsights_connection_string,
)
# Set up local file export if requested
@@ -333,7 +339,7 @@ class GAIA:
self.telemetry_config = telemetry_config or GAIATelemetryConfig()
# Set up telemetry
self.telemetry_config.setup_observability()
self.telemetry_config.configure_otel_providers()
# Initialize tracer
if self.telemetry_config.enable_tracing:
@@ -22,13 +22,13 @@ class AgentFrameworkTracer(AgentOpsTracer): # type: ignore
def init(self) -> None:
"""Initialize the agent-framework-lab-lightning for training."""
OBSERVABILITY_SETTINGS.enable_otel = True
OBSERVABILITY_SETTINGS.enable_instrumentation = True
super().init()
def teardown(self) -> None:
"""Teardown the agent-framework-lab-lightning for training."""
super().teardown()
OBSERVABILITY_SETTINGS.enable_otel = False
OBSERVABILITY_SETTINGS.enable_instrumentation = False
__all__: list[str] = ["AgentFrameworkTracer"]