Skip to content

Fix exception tracing for streaming responses in invocations protocol#47455

Merged
harsheet-shah merged 10 commits into
mainfrom
anksing/fix-streaming-exception-tracing
Jun 12, 2026
Merged

Fix exception tracing for streaming responses in invocations protocol#47455
harsheet-shah merged 10 commits into
mainfrom
anksing/fix-streaming-exception-tracing

Conversation

@singankit

Copy link
Copy Markdown
Contributor

When an invoke handler returns a StreamingResponse, exceptions thrown during body iteration (e.g. in async generators) were not being recorded on the OTel trace span. This wraps the streaming body iterator to catch exceptions, log them with the invocation ID, and record them on the current span so they appear correctly in App Insights traces.

Description

Please add an informative description that covers that changes made by the pull request and link all relevant issues.

If an SDK is being regenerated based on a new API spec, a link to the pull request containing these API spec changes should be included above.

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.

When an invoke handler returns a StreamingResponse, exceptions thrown
during body iteration (e.g. in async generators) were not being recorded
on the OTel trace span. This wraps the streaming body iterator to catch
exceptions, log them with the invocation ID, and record them on the
current span so they appear correctly in App Insights traces.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the Hosted Agents sdk/agentserver/* label Jun 11, 2026
@ankitbko ankitbko marked this pull request as ready for review June 12, 2026 06:02
Copilot AI review requested due to automatic review settings June 12, 2026 06:02
@ankitbko ankitbko requested a review from RaviPidaparthi as a code owner June 12, 2026 06:02

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

This PR addresses observability gaps for invocation handlers that return StreamingResponse: exceptions raised during streaming body iteration are now caught, logged with the invocation ID, and recorded on the active OpenTelemetry span so they show up in traces (e.g., Application Insights).

Changes:

  • Add a wrapper around StreamingResponse.body_iterator to catch iteration-time exceptions and record them on the current OTel span.
  • Extend imports to support streaming and async-iterator typing.

Harsheet Shah and others added 6 commits June 12, 2026 11:49
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>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@harsheet-shah harsheet-shah enabled auto-merge (squash) June 12, 2026 07:08
@harsheet-shah harsheet-shah merged commit 843ab8b into main Jun 12, 2026
18 checks passed
@harsheet-shah harsheet-shah deleted the anksing/fix-streaming-exception-tracing branch June 12, 2026 08:20
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.

4 participants