Skip to content

Add A365 telemetry correlation for WebSocket invocations - #48007

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

Yulin Li (yulin-li) wants to merge 57 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
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

Copilot review overview

🟡 Changes recommended

Unresolved critical and moderate fail-open regressions can abort Voice host construction and generic WebSocket connections.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)

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

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

Copilot review overview

🔵 Needs a closer look

Cross-package telemetry propagation changes warrant final human review despite no unresolved comments.

Review effort: Balanced
Findings: None

Resolved since last review (1)

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

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

Copilot review overview

🟡 Changes recommended

The core API metadata hash does not match the committed API snapshot.

Review effort: Balanced
Findings: 1 High severity

Open (1)

Comment thread sdk/agentserver/azure-ai-agentserver-core/api.metadata.yml Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

Copilot review overview

🟢 Approval recommended

The implementation, dependency versions, API metadata, documentation, and targeted regression coverage are consistent.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Resolve AgentServer release metadata against the active core 2.3.0b1 and invocations 1.3.0b1 preview lines.

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

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

🔵 Needs a closer look

Cross-package ASGI context propagation and Voice routing changes warrant final human validation.

0 open findings

🧠 Review effort: Balanced

Preserve the AgentServer telemetry changes alongside the new lifecycle APIs and record the normalized combined API snapshot.

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

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

🟢 Approval recommended

The implementation and focused regressions consistently cover generic and Voice WebSocket correlation, sanitization, and compatibility behavior.

0 open findings

🧠 Review effort: Balanced

Preserve the WebSocket telemetry changes alongside the latest Foundry tracing enrichment from main.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

🔵 Needs a closer look

Cross-package propagation and Voice telemetry privacy boundaries warrant human security review, particularly with incomplete privacy regression coverage.

1 open finding

🧠 Review effort: Balanced

Exercise callback export through an isolated Foundry enrichment processor so unsafe session baggage would fail the test if attached.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

🔵 Needs a closer look

Cross-package context propagation and security-sensitive Voice baggage filtering warrant final human review.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Preserve the WebSocket telemetry release note alongside the latest streaming and durable-task fixes.

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

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

🔵 Needs a closer look

Shared trace-context handling and Voice baggage privacy boundaries warrant final human review.

0 open findings

🧠 Review effort: Balanced

Move the core telemetry fix to unreleased 2.3.0b2 after the 2.3.0b1 release and align the invocations dependency floor.

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

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

🔵 Needs a closer look

Shared propagation and Voice baggage-isolation changes affect telemetry privacy boundaries and warrant human security review.

0 open findings

🧠 Review effort: Balanced

Preserve the core 2.3.0b2 changelog template and the WebSocket telemetry fix.

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

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

🔵 Needs a closer look

Cross-package propagation and Voice telemetry isolation warrant final human review.

0 open findings

🧠 Review effort: Balanced

Integrate the new Voice conversation-engine route with the existing propagation privacy boundary and preserve current API metadata and release notes.

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

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

🔵 Needs a closer look

Connection-wide propagation and Voice header filtering affect telemetry privacy boundaries and warrant final human security review.

No open issues 🎉

Review effort: Balanced

Integrate protocol-scoped task runtime changes with shared identifier sanitization and WebSocket telemetry propagation.

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

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

🟡 Changes recommended

Caller baggage can overwrite server-generated close-event attributes in exported WebSocket logs.

1 open issue

Review effort: Balanced

Prevent caller baggage from overwriting server-authored telemetry fields and cover exported WebSocket close records with colliding baggage.

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

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

🟡 Changes recommended

The new close-event regression selects both the handler-error and close-event logs, invalidating its single-record assertion.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread sdk/agentserver/azure-ai-agentserver-invocations/tests/test_ws_close_event.py Outdated
Filter the collision regression by the SDK close-event message so caller baggage on an earlier error log cannot select the wrong record.

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

Copilot-Session: b94aa89c-e288-46f2-8802-4f266ba8830e

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.

🔵 Needs a closer look

Caller-supplied session-alias baggage can still make exported WebSocket logs disagree with the SDK session used by handler spans.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Baggage alias overrides canonical WebSocket session correlation

sdk/​agentserver/​azure-ai-agentserver-core/​azure/​ai/​agentserver/​core/​_tracing.py:936

Incoming baggage: microsoft.session.id=caller-session still breaks A365 session correlation for generic WebSocket handlers. Close-event extras contain the canonical and legacy session keys, but not microsoft.session.id, so this loop inserts the caller's alias. The session-resolution block below then skips the canonical session because the alias already exists. Exported close logs consequently use caller-session while handler spans use the SDK session. Skip the baggage alias when canonical session baggage is present, while preserving genuinely pre-existing log attributes. Extend the exporter regression to inject this alias and assert that exported microsoft.session.id matches the canonical session.

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
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