Skip to content

Add A365 telemetry correlation for WebSocket invocations - #48007

Open
Yulin Li (yulin-li) wants to merge 20 commits into
Azure:mainfrom
yulin-li:yulin-li/verify-ws-a365-telemetry
Open

Add A365 telemetry correlation for WebSocket invocations#48007
Yulin Li (yulin-li) wants to merge 20 commits into
Azure:mainfrom
yulin-li:yulin-li/verify-ws-a365-telemetry

Conversation

@yulin-li

Copy link
Copy Markdown
Member

Description

invocations_ws previously 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 REST invocations behavior.

The change propagates incoming traceparent, tracestate, and baggage through the WebSocket lifecycle; attaches the canonical azure.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_message span, 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-created invocations_ws_a365_e2e span in Application Insights with session, agent, blueprint, and project enrichment.

The shared microsoft-opentelemetry optional OpenAI Agents instrumentation warning (ModuleNotFoundError: agents) reproduces for both REST and WebSocket and is intentionally unchanged.

Validation:

  • Invocations test suite: 190 passed, 2 skipped
  • Package pylint and pyright checks passed
  • Hosted Agent 365 E2E marker: customer-ws-span-20260711T153708Z

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Yulin Li added 4 commits July 11, 2026 22:44
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
@github-actions github-actions Bot added the Hosted Agents sdk/agentserver/* label Jul 11, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 811a430b-62e7-49b3-b426-45d1f28b04ef

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread sdk/agentserver/azure-ai-agentserver-invocations/CHANGELOG.md Outdated
Comment thread sdk/agentserver/azure-ai-agentserver-invocations/README.md Outdated
Yulin Li and others added 4 commits July 12, 2026 11:00
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 14 out of 14 changed files in this pull request and generated no new comments.

…65-telemetry

# Conflicts:
#	sdk/agentserver/azure-ai-agentserver-core/CHANGELOG.md
Copilot AI review requested due to automatic review settings July 22, 2026 07:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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_id close-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
Copilot AI review requested due to automatic review settings July 22, 2026 09:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 13 out of 13 changed files in this pull request and generated no new comments.

…65-telemetry

# Conflicts:
#	sdk/agentserver/azure-ai-agentserver-invocations/CHANGELOG.md
#	sdk/agentserver/azure-ai-agentserver-invocations/pyproject.toml

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 14 out of 14 changed files in this pull request and generated no new comments.

…65-telemetry

# Conflicts:
#	sdk/agentserver/azure-ai-agentserver-core/CHANGELOG.md
#	sdk/agentserver/azure-ai-agentserver-invocations/CHANGELOG.md
Copilot AI review requested due to automatic review settings July 29, 2026 12:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 14 out of 14 changed files in this pull request and generated no new comments.

…65-telemetry

# Conflicts:
#	sdk/agentserver/azure-ai-agentserver-core/CHANGELOG.md
Copilot AI review requested due to automatic review settings July 30, 2026 13:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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
Copilot AI review requested due to automatic review settings August 3, 2026 16:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 15 out of 15 changed files in this pull request and generated no new comments.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 5, 2026 13:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 14 out of 14 changed files in this pull request and generated no new comments.

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

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e
Copilot AI review requested due to automatic review settings August 7, 2026 15:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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_id contract 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
Copilot AI review requested due to automatic review settings August 7, 2026 16:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 14 out of 14 changed files in this pull request and generated no new comments.

Yulin Li added 2 commits August 8, 2026 07:45
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
Copilot AI review requested due to automatic review settings August 12, 2026 00:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 14 out of 14 changed files in this pull request and generated no new comments.

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.

2 participants