From 1a1dcea6b7821badad764d8726d69a021dbffdd3 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Thu, 23 Apr 2026 18:39:09 -0700 Subject: [PATCH] feat(python): use microsoft-opentelemetry distro for observability Replace legacy microsoft_agents_a365.observability.core.config.configure() with use_microsoft_opentelemetry() from the Microsoft OpenTelemetry distro. - Add microsoft-opentelemetry >= 0.1.0a3 dependency - Remove microsoft_agents_a365_observability_extensions_agent_framework (auto-instrumented by the distro) - Remove disabled AgentFrameworkInstrumentor code - Update AGENT-CODE-WALKTHROUGH.md Ref: https://github.com/microsoft/opentelemetry-distro-python --- .../sample-agent/AGENT-CODE-WALKTHROUGH.md | 4 +++- python/agent-framework/sample-agent/agent.py | 15 ++------------- .../sample-agent/host_agent_server.py | 18 +++++++++++++----- .../sample-agent/pyproject.toml | 2 +- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/python/agent-framework/sample-agent/AGENT-CODE-WALKTHROUGH.md b/python/agent-framework/sample-agent/AGENT-CODE-WALKTHROUGH.md index ec9cf48b..8f1997b3 100644 --- a/python/agent-framework/sample-agent/AGENT-CODE-WALKTHROUGH.md +++ b/python/agent-framework/sample-agent/AGENT-CODE-WALKTHROUGH.md @@ -48,7 +48,9 @@ from microsoft_agents.hosting.core import Authorization, TurnContext from microsoft_agents_a365.notifications.agent_notification import NotificationTypes # Observability Components -from microsoft_agents_a365.observability.core.config import configure +# Observability is initialized by the Microsoft OpenTelemetry distro in +# host_agent_server.py via use_microsoft_opentelemetry(). +# See: https://github.com/microsoft/opentelemetry-distro-python # MCP Tooling from microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service import ( diff --git a/python/agent-framework/sample-agent/agent.py b/python/agent-framework/sample-agent/agent.py index 8f9fcb7b..04974e8b 100644 --- a/python/agent-framework/sample-agent/agent.py +++ b/python/agent-framework/sample-agent/agent.py @@ -52,10 +52,8 @@ from microsoft_agents_a365.notifications.agent_notification import NotificationTypes # Observability Components -# TEMPORARILY DISABLED - OpenTelemetry compatibility issue -# from microsoft_agents_a365.observability.extensions.agentframework.trace_instrumentor import ( -# AgentFrameworkInstrumentor, -# ) +# AgentFramework auto-instrumentation is handled by the microsoft-opentelemetry +# distro (see host_agent_server.py). No manual instrumentor setup is needed. # MCP Tooling from microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service import ( @@ -94,10 +92,6 @@ def __init__(self): """Initialize the AgentFramework agent.""" self.logger = logging.getLogger(self.__class__.__name__) - # Initialize auto instrumentation with Agent 365 Observability SDK - # TEMPORARILY DISABLED - OpenTelemetry compatibility issue - # self._enable_agentframework_instrumentation() - # Initialize authentication options self.auth_options = LocalAuthenticationOptions.from_environment() @@ -184,11 +178,6 @@ def token_resolver(self, agent_id: str, tenant_id: str) -> str | None: logger.error(f"Error resolving token: {e}") return None - def _enable_agentframework_instrumentation(self): - """Enable AgentFramework instrumentation""" - # TEMPORARILY DISABLED - OpenTelemetry compatibility issue - logger.warning("⚠️ AgentFramework instrumentation disabled due to OpenTelemetry version mismatch") - # # ========================================================================= diff --git a/python/agent-framework/sample-agent/host_agent_server.py b/python/agent-framework/sample-agent/host_agent_server.py index b9f96a9c..d2ba2050 100644 --- a/python/agent-framework/sample-agent/host_agent_server.py +++ b/python/agent-framework/sample-agent/host_agent_server.py @@ -39,14 +39,14 @@ ) from microsoft_agents_a365.notifications import EmailResponse -from microsoft_agents_a365.observability.core.config import configure +from microsoft.opentelemetry import use_microsoft_opentelemetry from microsoft_agents_a365.observability.core.middleware.baggage_builder import ( BaggageBuilder, ) from microsoft_agents_a365.runtime.environment_utils import ( get_observability_authentication_scope, ) -from token_cache import cache_agentic_token +from token_cache import cache_agentic_token, get_cached_agentic_token # --- Configuration --- ms_agents_logger = logging.getLogger("microsoft_agents") @@ -72,9 +72,17 @@ def create_and_run_host( f"Agent class {agent_class.__name__} must inherit from AgentInterface" ) - configure( - service_name="AgentFrameworkTracingWithAzureOpenAI", - service_namespace="AgentFrameworkTesting", + # Initialize Microsoft OpenTelemetry distro for observability. + # Replaces the legacy configure() call with a single entrypoint that sets up + # tracing, metrics, and logging pipelines including A365 telemetry export. + # See: https://github.com/microsoft/opentelemetry-distro-python + use_microsoft_opentelemetry( + enable_a365=True, + enable_azure_monitor=False, + a365_token_resolver=lambda agent_id, tenant_id: get_cached_agentic_token( + tenant_id, agent_id + ) + or "", ) host = GenericAgentHost(agent_class, *agent_args, **agent_kwargs) diff --git a/python/agent-framework/sample-agent/pyproject.toml b/python/agent-framework/sample-agent/pyproject.toml index 97aaa010..8cd7ab32 100644 --- a/python/agent-framework/sample-agent/pyproject.toml +++ b/python/agent-framework/sample-agent/pyproject.toml @@ -43,7 +43,7 @@ dependencies = [ "microsoft_agents_a365_tooling >= 0.1.0", "microsoft_agents_a365_tooling_extensions_agentframework >= 0.1.0", "microsoft_agents_a365_observability_core >= 0.1.0", - "microsoft_agents_a365_observability_extensions_agent_framework >= 0.1.0", + "microsoft-opentelemetry >= 0.1.0a3", "microsoft_agents_a365_runtime >= 0.1.0", "microsoft_agents_a365_notifications >= 0.1.0" ]