Skip to content

Enable A365 tracing and fix W3C baggage propagation in agentserver#46754

Open
singankit wants to merge 12 commits intomainfrom
feature/enable-a365-tracing
Open

Enable A365 tracing and fix W3C baggage propagation in agentserver#46754
singankit wants to merge 12 commits intomainfrom
feature/enable-a365-tracing

Conversation

@singankit
Copy link
Copy Markdown
Contributor

Summary

Enable Agent365 (A365) tracing in the agentserver packages and fix W3C baggage propagation so that incoming baggage entries (e.g. user.id) are visible to span processors on all spans.

Changes

A365 Tracing Enablement (agentserver-core)

  • Gate A365 export behind FOUNDRY_AGENT365_TRACING_ENABLED env var
  • Add agent identity resolvers (agent_id, blueprint_id, tenant_id) from env vars
  • Enable a365_enable_observability_exporter and a365_observability_scope_override
  • Wire through _FoundryEnrichmentSpanProcessor with span attributes

Streaming Context Fix (responses)

  • Capture full OTel context (span + baggage) at wrap time in _wrap_streaming_response
  • Re-attach during async iteration so baggage is available after the handler's finally block

W3C Baggage Propagation Fix (responses + invocations)

  • Use W3CBaggagePropagator().extract() to extract only baggage from incoming headers
  • Merge extracted baggage onto get_current() before adding server entries
  • This preserves span parent-child relationships while capturing incoming baggage like user.id

Tests

  • 3 baggage propagation tests for responses package
  • 3 baggage propagation tests for invocations package
  • Coverage: baggage merging, span parenting preserved, empty header safety

Root Cause

start_as_current_span(context=extracted_ctx) inside request_span makes the span current, but baggage from the extracted context does not survive through the contextmanager yield boundary to get_current() as seen by the endpoint handler. Only entries explicitly added after get_current() survive. The fix extracts baggage separately at the endpoint handler level.

singankit and others added 7 commits May 4, 2026 13:27
Conditionally enable A365 observability export via microsoft-opentelemetry
distro when both FOUNDRY_HOSTING_ENVIRONMENT and
FOUNDRY_AGENT365_TRACING_ENABLED env vars are set. Uses S2S endpoint
for token resolution in hosted environments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…hment

- Add resolve_agent_id() with FOUNDRY_AGENT_INSTANCE_CLIENT_ID env var
  (falls back to name:version or name)
- Add resolve_agent_blueprint_id() with FOUNDRY_AGENT_BLUEPRINT_CLIENT_ID
- Add resolve_agent_tenant_id() with FOUNDRY_AGENT_TENANT_ID
- Wire all three through _FoundryEnrichmentSpanProcessor
- Make processor __init__ keyword-only

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ator

The streaming async generator runs after the request handler's finally
block detaches baggage. Fix by capturing the full OTel context (including
baggage) at wrap time and re-attaching it during iteration, so child spans
created during streaming can see baggage entries like conversation_id.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extract incoming baggage (e.g. user.id) using W3CBaggagePropagator
without re-extracting traceparent, preserving parent-child span
relationships while making caller's baggage entries visible to
downstream span processors.

Also removes stale flask/sqlalchemy imports from prior attempts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…kages

- Apply same baggage extraction fix to invocations/_invocation.py
- Add 3 baggage propagation tests for invocations package
- Add 3 baggage propagation tests for responses package
- Tests verify: baggage merging, span parenting preserved, empty header safety

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@singankit singankit marked this pull request as ready for review May 6, 2026 14:51
@singankit singankit requested a review from ankitbko as a code owner May 6, 2026 14:51
Copilot AI review requested due to automatic review settings May 6, 2026 14:51
@github-actions github-actions Bot added the Hosted Agents sdk/agentserver/* label May 6, 2026
singankit and others added 5 commits May 6, 2026 09:50
Server-added entries (response_id) are set after span starts, so
on_start processor won't see them. Test should only verify incoming
baggage merging.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ponse'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…an start

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hosted Agents sdk/agentserver/*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant