fix(maf): preserve legacy streaming context#241
Merged
Conversation
ralf0131
approved these changes
Jul 9, 2026
ralf0131
left a comment
Collaborator
There was a problem hiding this comment.
Summary
Fixes legacy MAF streaming agent telemetry by backporting with_pull_context_manager to older ResponseStream versions and wrapping the agent trace invocation so the AGENT span is created before execute(), activated during stream resolution, and finalized with response/content capture during cleanup. This preserves AGENT → STEP → LLM/TOOL parent-child relationships for legacy streaming paths while leaving modern MAF behavior unchanged via feature detection.
Findings
No issues found. The implementation is clean:
- Feature detection (
hasattr) correctly gates the legacy path, leaving modern MAF untouched weakref.finalizeprovides a robust safety net for span cleanup if the stream is GC'd without proper teardown- Context var tracking (
INNER_RESPONSE_TELEMETRY_CAPTURED_FIELDS/INNER_ACCUMULATED_USAGE) prevents double-capture _finalize_streamproperly captures exceptions without re-raising (telemetry shouldn't break the stream)- Comprehensive test verifies parent-child span relationships, input/output capture, and proper revert
CI: all checks passing. Changelog updated.
Automated review by github-manager-bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes legacy Microsoft Agent Framework streaming agent telemetry for MAF versions whose
ResponseStreamdoes not providewith_pull_context_manager.The bridge now backports the per-pull context manager surface for legacy streams and wraps legacy streaming agent invocation so the AGENT span is created before
execute(), activated while the stream resolves and yields updates, and finalized with response/content capture during stream cleanup. This preservesAGENT -> STEP -> LLM/TOOLparent-child relationships and AGENT input/output capture for legacy streaming paths while leaving modern MAF behavior unchanged through feature detection.Fixes # (N/A)
Type of change
How Has This Been Tested?
uvx ruff check instrumentation-loongsuite/loongsuite-instrumentation-microsoft-agent-framework/src/opentelemetry/instrumentation/microsoft_agent_framework/util_genai_bridge.py instrumentation-loongsuite/loongsuite-instrumentation-microsoft-agent-framework/tests/test_util_genai_bridge.pyuvx tox -r -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-microsoft-agent-frameworkuvx tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-microsoft-agent-frameworkPRE_COMMIT_HOME="$(mktemp -d)" uvx tox -e precommitDoes This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.
Validation Evidence
Spec and Scope
loongsuite-instrumentation-microsoft-agent-frameworklegacy streaming bridge and focused tests.Local Checks
python "$PIPELINE_SKILL_DIR/scripts/check_loongsuite_pr_readiness.py" --repo .PRE_COMMIT_HOME="$(mktemp -d)" uvx tox -e precommituvx tox -r -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-microsoft-agent-frameworkuvx tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-microsoft-agent-frameworkqoder_team_review.py review . --backend deepopentelemetry-util-genai; no release artifact rename.Real E2E Matrix
stream=Truelegacy streams.agent-framework-core==1.0.0streaming smoke exported through OTLP.AGENT -> STEP -> LLM + TOOLtrace; private trace details omitted.Telemetry and Weaver
AGENT,STEP,LLM, andTOOLwere connected in one trace.weaver registry live-check -r <loongsuite-semantic-conventions>/model --advice-profile loongsuite-genai ...CI