Skip to content

fix(qwen-agent): scope stream invocation context to execution - #919

Open
123liuziming wants to merge 2 commits into
open-telemetry:mainfrom
123liuziming:codex/fix-qwen-agent-stream-context
Open

123liuziming wants to merge 2 commits into
open-telemetry:mainfrom
123liuziming:codex/fix-qwen-agent-stream-context

Conversation

@123liuziming

Copy link
Copy Markdown
Contributor

Description

Addresses the Qwen-Agent portion of #872 by making agent spans current only during stream reads and cleanup, preserving caller context and nested spans across tasks. Local agent invocations no longer emit inference chunk timing metrics.

Type of change

  • Bug fix
  • Documentation update

Validation

  • Qwen-Agent oldest: 34 passed, 1 existing skip; latest: 35 passed.
  • Shared util: 652 passed, 13 subtests passed.
  • Pre-commit, typecheck, README rendering, changelog preview, and public API comparison against upstream main passed.
  • Independent review found no actionable regressions.
  • Conformance: 1 skipped because the Weaver binary was unavailable locally (download timed out).

Checklist

  • Followed project style guidelines
  • Added changelog fragments
  • Added regression tests
  • Updated documentation

Copilot AI balanced review requested due to automatic review settings October 19, 2026 03:11
@123liuziming
123liuziming requested a review from a team as a code owner October 19, 2026 03:11
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-10-20 02:02 UTC

Respond to 2 review items (e.g. link a commit, explain why not, ask a follow-up):

  • Inline threads: 1, 2
Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

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 focused changes follow the shared stream lifecycle and include targeted regression coverage, with no unresolved findings.

No open issues 🎉

What changed in this PR

Addresses the Qwen-Agent portion of #872 by limiting stream invocation context to execution and cleanup while preserving caller context.

Changes:

  • Uses the shared stream wrapper’s execution-scoped context.
  • Suppresses inference chunk-timing metrics for local agents.
  • Adds lifecycle regression tests and documents stream behavior.
File Description
util/​opentelemetry-util-genai/​tests/​test_handler_metrics.py Verifies agent-only duration metrics.
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​_agent_invocation.py Disables local-agent chunk timing.
util/​opentelemetry-util-genai/​.changelog/​0.fixed Records the metrics fix.
instrumentation/​opentelemetry-instrumentation-genai-qwen-agent/​tests/​test_agent.py Tests context isolation, cleanup, parenting, and metrics.
instrumentation/​opentelemetry-instrumentation-genai-qwen-agent/​src/​opentelemetry/​instrumentation/​genai/​qwen_agent/​patch.py Passes and suspends the stream invocation.
instrumentation/​opentelemetry-instrumentation-genai-qwen-agent/​README.rst Documents stream context and lifecycle.
instrumentation/​opentelemetry-instrumentation-genai-qwen-agent/​.changelog/​0.fixed Records the context fix.

Review effort: Balanced

@eternalcuriouslearner eternalcuriouslearner 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.

Thanks for this contribution!!

Comment on lines +235 to +236
def _on_stream_chunk(self, chunk_at: float) -> None:
"""Local agent streams scope context without inference chunk timing metrics."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

#880 fixes this generally in util: chunk timing is recorded only for InferenceInvocation. Could we drop this override and the util changelog/test here, and rebase on #880 once it merges?

Comment on lines +55 to +56
when stopping early. Agent streams record agent duration without LLM chunk
timing metrics.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: the metrics detail is an implementation note, not something users need to act on.

Suggested change
when stopping early. Agent streams record agent duration without LLM chunk
timing metrics.
when stopping early.

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

None yet

Development

Successfully merging this pull request may close these issues.

4 participants