Skip to content

Enhance AzureAIOpenTelemetryTracer initialization in LangGraphAdapter#45633

Open
nagkumar91 wants to merge 1 commit intoAzure:mainfrom
nagkumar91:fix/enhance-tracer-initialization
Open

Enhance AzureAIOpenTelemetryTracer initialization in LangGraphAdapter#45633
nagkumar91 wants to merge 1 commit intoAzure:mainfrom
nagkumar91:fix/enhance-tracer-initialization

Conversation

@nagkumar91
Copy link
Member

Summary

Updates the AzureAIOpenTelemetryTracer initialization in LangGraphAdapter.init_tracing_internal to use all available tracer fields for richer telemetry:

Changes

  • project_endpoint: Read from AZURE_AI_PROJECT_ENDPOINT env var for project-level correlation
  • credential: DefaultAzureCredential() when project_endpoint is set, enabling authenticated telemetry export
  • agent_id: Read from AGENT_ID env var for agent identity tracking
  • trace_all_langgraph_nodes: Set to True since this is a LangGraph adapter, enabling tracing of all graph nodes by default

Motivation

The previous initialization only used connection_string, enable_content_recording, and name. The AzureAIOpenTelemetryTracer supports additional fields that provide richer observability, particularly for Foundry-hosted LangGraph agents where project endpoint and agent identity are available via well-known environment variables.

No Breaking Changes

All new parameters are optional and sourced from environment variables that are already populated in the Foundry hosted agent runtime. If the env vars are not set, the values default to None/are skipped gracefully.

Copilot AI review requested due to automatic review settings March 10, 2026 22:56
@nagkumar91 nagkumar91 requested review from a team, JC-386 and lusu-msft as code owners March 10, 2026 22:56
@github-actions github-actions bot added Evaluation Issues related to the client library for Azure AI Evaluation Hosted Agents sdk/agentserver/* labels Mar 10, 2026

This comment was marked as outdated.

@nagkumar91 nagkumar91 force-pushed the fix/enhance-tracer-initialization branch 2 times, most recently from d74da59 to 356fd64 Compare March 10, 2026 23:05
…ode tracing

Update the tracer creation in LangGraphAdapter.init_tracing_internal to use
additional available parameters:
- agent_id: from AGENT_ID env var for agent identity tracking
- trace_all_langgraph_nodes: True (since this is a LangGraph adapter)

This provides richer telemetry data including agent identity and full
LangGraph node tracing by default.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +70 to 78
agent_id = os.environ.get(Constants.AGENT_ID)

self.azure_ai_tracer = AzureAIOpenTelemetryTracer(
connection_string=app_insights_conn_str,
enable_content_recording=True,
name=self.get_agent_identifier(),
agent_id=agent_id,
trace_all_langgraph_nodes=True,
)
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description claims LangGraphAdapter will also populate AzureAIOpenTelemetryTracer with project-level fields (e.g., project_endpoint from AZURE_AI_PROJECT_ENDPOINT and DefaultAzureCredential when set), but the implementation here only adds agent_id and trace_all_langgraph_nodes. Either update the PR description to match the actual change, or extend the tracer initialization to include the described parameters so the behavior aligns with the motivation section.

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +77

self.azure_ai_tracer = AzureAIOpenTelemetryTracer(
connection_string=app_insights_conn_str,
enable_content_recording=True,
name=self.get_agent_identifier(),
agent_id=agent_id,
trace_all_langgraph_nodes=True,
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting trace_all_langgraph_nodes=True changes the default telemetry volume for all LangGraphAdapter users and can significantly increase span counts/costs for larger graphs. Consider making this configurable (e.g., via a well-known env var or adapter option) with a conservative default, so production deployments can opt in intentionally.

Suggested change
self.azure_ai_tracer = AzureAIOpenTelemetryTracer(
connection_string=app_insights_conn_str,
enable_content_recording=True,
name=self.get_agent_identifier(),
agent_id=agent_id,
trace_all_langgraph_nodes=True,
# Control LangGraph node tracing via environment variable with a conservative default.
# AZURE_AI_LANGGRAPH_TRACE_ALL_LANGGRAPH_NODES can be set to "true", "1", "yes", "y", or "on"
# to enable tracing for all LangGraph nodes.
trace_all_nodes_env = os.environ.get("AZURE_AI_LANGGRAPH_TRACE_ALL_LANGGRAPH_NODES", "false")
trace_all_nodes = trace_all_nodes_env.lower() in ("1", "true", "yes", "y", "on")
self.azure_ai_tracer = AzureAIOpenTelemetryTracer(
connection_string=app_insights_conn_str,
enable_content_recording=True,
name=self.get_agent_identifier(),
agent_id=agent_id,
trace_all_langgraph_nodes=trace_all_nodes,

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Evaluation Issues related to the client library for Azure AI Evaluation Hosted Agents sdk/agentserver/*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants