Add A365 telemetry correlation for WebSocket invocations - #48007
Add A365 telemetry correlation for WebSocket invocations#48007Yulin Li (yulin-li) wants to merge 20 commits into
Conversation
Propagate W3C context through WebSocket scopes and attach the hosted session ID as A365 baggage for the connection lifecycle. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 811a430b-62e7-49b3-b426-45d1f28b04ef
Use the cross-protocol azure.ai.agentserver.session_id field for invocations_ws close-event telemetry, matching REST invocations and A365 correlation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 811a430b-62e7-49b3-b426-45d1f28b04ef
Remove the duplicate WebSocket session attribute constant and use the core tracing key in both invocation transports. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 811a430b-62e7-49b3-b426-45d1f28b04ef
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 811a430b-62e7-49b3-b426-45d1f28b04ef
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 811a430b-62e7-49b3-b426-45d1f28b04ef
There was a problem hiding this comment.
Pull request overview
Aligns WebSocket telemetry with REST invocation tracing and Agent 365 correlation.
Changes:
- Propagates W3C context through WebSocket connections.
- Adds canonical session baggage to handler spans and close logs.
- Adds tracing tests and updates documentation.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
core/CHANGELOG.md |
Records WebSocket propagation support. |
core/_base.py |
Documents WebSocket middleware behavior. |
core/_tracing.py |
Enables context extraction for WebSockets. |
invocations/CHANGELOG.md |
Records Agent 365 correlation. |
invocations/README.md |
Updates WebSocket telemetry documentation. |
invocations/_constants.py |
Removes protocol-specific session key. |
invocations/_invocation.py |
Reuses the shared baggage constant. |
invocations/_invocation_ws.py |
Attaches session baggage throughout connections. |
tests/conftest.py |
Updates close-log filtering. |
tests/test_ws_close_event.py |
Checks the canonical session field. |
tests/test_ws_session_id.py |
Updates session-log assertions. |
tests/test_ws_tracing.py |
Tests baggage, parenting, and enrichment. |
Bump core to 2.0.0b8 and invocations to 1.0.0b7, and raise the invocations core dependency to >=2.0.0b8. The repo core was still 2.0.0b7, identical to the published PyPI 2.0.0b7 which lacks the new WebSocket scope handling, so CI resolved the constraint to the published wheel and the WS trace-context/baggage tests failed. The version bumps also align _version.py with the top CHANGELOG entries so Verify-ChangeLogs passes. Fix _FoundryEnrichmentSpanProcessor._on_ending for opentelemetry-sdk 1.43.0+, which now marks span attributes immutable before the on-ending hook; temporarily clear the flag so agent identity attributes are applied. Correct the invocations README to describe the actual per-connection telemetry (context/baggage propagation + close-event log) instead of a non-existent websocket_session span, and update the stale close-event comment to note the session-ID key comes from the shared _BAGGAGE_SESSION_ID in core. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 05a86c59-4ebd-4ec8-a42b-73b2e4ce94e0
…65-telemetry # Conflicts: # sdk/agentserver/azure-ai-agentserver-invocations/CHANGELOG.md
…65-telemetry # Conflicts: # sdk/agentserver/azure-ai-agentserver-core/azure/ai/agentserver/core/_tracing.py # sdk/agentserver/azure-ai-agentserver-invocations/pyproject.toml
…65-telemetry # Conflicts: # sdk/agentserver/azure-ai-agentserver-core/CHANGELOG.md
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
sdk/agentserver/azure-ai-agentserver-invocations/azure/ai/agentserver/invocations/_invocation_ws.py:398
- This replaces the previously documented
azure.ai.agentserver.invocations_ws.session_idclose-event field rather than adding the shared key alongside it. Existing structured-log queries and processors will therefore lose session correlation, which contradicts the PR's “no breaking changes” declaration (the old field is documented in the 1.0.0b4 changelog). Preserve compatibility by emitting both keys for a transition period, or explicitly classify and document the schema change as breaking.
_BAGGAGE_SESSION_ID: session_id,
…65-telemetry # Conflicts: # sdk/agentserver/azure-ai-agentserver-core/CHANGELOG.md
…65-telemetry # Conflicts: # sdk/agentserver/azure-ai-agentserver-invocations/CHANGELOG.md # sdk/agentserver/azure-ai-agentserver-invocations/pyproject.toml
…65-telemetry # Conflicts: # sdk/agentserver/azure-ai-agentserver-core/CHANGELOG.md # sdk/agentserver/azure-ai-agentserver-invocations/CHANGELOG.md
…65-telemetry # Conflicts: # sdk/agentserver/azure-ai-agentserver-core/CHANGELOG.md
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
sdk/agentserver/azure-ai-agentserver-core/azure/ai/agentserver/core/_tracing.py:485
- WebSocket upgrade requests may carry baggage or tracestate across multiple header fields, but the dict carrier below retains only the last value. With this scope now enabled, earlier caller baggage entries are silently dropped instead of being propagated. Combine repeated header values (comma-separated, as required by W3C list headers) before calling
extract; normalizing names also avoids relying on the ASGI server to lowercase them.
if scope["type"] not in ("http", "websocket"):
…65-telemetry # Conflicts: # sdk/agentserver/azure-ai-agentserver-invocations/CHANGELOG.md
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.
Suppressed comments (1)
sdk/agentserver/azure-ai-agentserver-invocations/azure/ai/agentserver/invocations/_invocation_ws.py:404
- Replacing the structured close-event field removes the
azure.ai.agentserver.invocations_ws.session_idcontract documented for the stable 1.0.0 release (CHANGELOG.md:77). Existing dashboards and log queries will stop correlating sessions after a patch upgrade, despite this PR declaring no breaking changes. Emit both the legacy and canonical keys for a deprecation window, or treat the removal as a breaking release.
_BAGGAGE_SESSION_ID: session_id,
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e
Description
invocations_wspreviously excluded WebSocket scopes from W3C trace propagation and did not attach the Agent 365 session baggage used to enrich spans created by customer handler code. This aligns WebSocket telemetry with the existing RESTinvocationsbehavior.The change propagates incoming
traceparent,tracestate, and baggage through the WebSocket lifecycle; attaches the canonicalazure.ai.agentserver.session_id; and maps that context onto exported child spans and close-event logs. REST and WebSocket now share the existing core session key instead of defining protocol-specific duplicates.Customer-code coverage creates and exports an explicit
customer.websocket.process_messagespan, verifying its remote parent, instrumentation scope, custom attributes, A365 session correlation, and Foundry project identity. A hosted dual-protocol E2E run also confirmed the customer-createdinvocations_ws_a365_e2espan in Application Insights with session, agent, blueprint, and project enrichment.The shared
microsoft-opentelemetryoptional OpenAI Agents instrumentation warning (ModuleNotFoundError: agents) reproduces for both REST and WebSocket and is intentionally unchanged.Validation:
customer-ws-span-20260711T153708ZAll SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines