fix(agno): propagate run identity to child spans#239
Conversation
ralf0131
left a comment
There was a problem hiding this comment.
Summary
Propagates Agno run identity (user/session) to child GenAI spans via a ContextVar, with ENTRY baggage taking per-key priority over framework-provided values. The streaming path correctly scopes identity between yields so caller code consuming stream chunks does not inherit the agent's run-local identity. Nested runs restore outer identity via token reset, and concurrent runs are isolated by ContextVar semantics.
The implementation is clean: identity is set before the wrapped call and always reset in finally (including the GeneratorExit path). Test coverage is thorough — sync, async, streaming, nested, concurrent, ENTRY priority, per-key fallback, tool propagation, and stream-yield scoping are all exercised. CI is green across all Python versions (3.9–3.13).
No issues found. LGTM.
Automated review by github-manager-bot
Description
This PR aligns Agno identity handling with ENTRY priority and propagates the effective Agno run identity to child GenAI spans.
Changes:
gen_ai.user.id/gen_ai.session.idover Agnorun()arguments or agent attributes, per key.ContextVarwhile an agent run is active.gen_ai.conversation.idfrom the effective session id when unset.Fixes # (not filed)
Type of change
How Has This Been Tested?
uvx tox -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-agno -- -quvx tox -c tox-loongsuite.ini -e py39-test-loongsuite-instrumentation-agno -- -quvx tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-agnoPRE_COMMIT_HOME="$(mktemp -d)" tox -e precommitfull=false,packages=|loongsuite-instrumentation-agno|.Validation Evidence
Spec and Scope
loongsuite-instrumentation-agnowrapper, Agno utility helpers, Agno tests, and package changelog.Local Checks
python "$PIPELINE_SKILL_DIR/scripts/check_loongsuite_pr_readiness.py" --repo .PRE_COMMIT_HOME="$(mktemp -d)" tox -e precommitgit diff --checkpassed after the run.uvx tox -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-agno -- -quvx tox -c tox-loongsuite.ini -e py39-test-loongsuite-instrumentation-agno -- -quvx tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-agnoGITHUB_EVENT_NAME=pull_request LOONGSUITE_CHANGED_FILES="$(git diff --name-only)" python .github/scripts/detect_loongsuite_changes.pyfull=false, `packages=Real E2E Matrix
AGNO_SMOKE_MODE=allAGNO_SMOKE_MODE=allAGNO_SMOKE_MODE=all; separate identity smoke with 2 concurrent callsget_weathertoolget_weatherandget_air_qualitytoolsTelemetry and Weaver
test_content_capture_mode_does_not_gate_span_creationplus NO_CONTENT Weaver sampletest_concurrent_runs_do_not_drop_spans; real DashScope identity smokeweaver registry live-check -r <loongsuite-semantic-conventions-registry> --advice-profile loongsuite-genai ...CI
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.