Skip to content

fix(agno): propagate run identity to child spans#239

Merged
sipercai merged 1 commit into
mainfrom
fix/agno-entry-identity-propagation
Jul 8, 2026
Merged

fix(agno): propagate run identity to child spans#239
sipercai merged 1 commit into
mainfrom
fix/agno-entry-identity-propagation

Conversation

@sipercai

@sipercai sipercai commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR aligns Agno identity handling with ENTRY priority and propagates the effective Agno run identity to child GenAI spans.

Changes:

  • Prefer ENTRY baggage gen_ai.user.id / gen_ai.session.id over Agno run() arguments or agent attributes, per key.
  • Store the effective Agno run identity in an Agno-local ContextVar while an agent run is active.
  • Apply the current identity to child LLM and TOOL invocations, setting LLM gen_ai.conversation.id from the effective session id when unset.
  • Scope streaming run identity so unrelated caller code between yielded stream chunks does not inherit the internal Agno run identity.
  • Add regression coverage for sync, async, streaming, nested runs, concurrent runs, ENTRY priority, per-key fallback, tool propagation, and stream-yield scoping.

Fixes # (not filed)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • uvx tox -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-agno -- -q
  • uvx tox -c tox-loongsuite.ini -e py39-test-loongsuite-instrumentation-agno -- -q
  • uvx tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-agno
  • Fresh-cache precommit gate: PRE_COMMIT_HOME="$(mktemp -d)" tox -e precommit
  • Static LoongSuite readiness checker passed.
  • LoongSuite detector simulation passed with full=false, packages=|loongsuite-instrumentation-agno|.
  • Weaver live-check passed against the regenerated Agno GenAI JSON sample.
  • Real DashScope smoke passed for non-streaming, streaming, and concurrent Agno calls.
  • Real DashScope identity smoke passed for 4 AGENT and 4 LLM spans with distinct user/session/conversation values.
  • Real DashScope tool-heavy smoke passed with two TOOL spans carrying the run user/session identity.

Validation Evidence

Spec and Scope

  • Linked issue/spec: N/A, direct user-requested Agno identity propagation fix.
  • Approved spec/comment: Direct implementation request in local maintainer thread.
  • Changed surface: loongsuite-instrumentation-agno wrapper, Agno utility helpers, Agno tests, and package changelog.

Local Checks

Check Command Result Notes
Static readiness python "$PIPELINE_SKILL_DIR/scripts/check_loongsuite_pr_readiness.py" --repo . pass No readiness blockers.
Precommit PRE_COMMIT_HOME="$(mktemp -d)" tox -e precommit pass Run with fresh hook cache; git diff --check passed after the run.
Focused tests uvx tox -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-agno -- -q pass 29 passed.
Focused tests uvx tox -c tox-loongsuite.ini -e py39-test-loongsuite-instrumentation-agno -- -q pass 29 passed.
Focused lint uvx tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-agno pass Ruff check passed.
Claude/Qoder review qoder deep review pass Final round: 0 blocking findings; remaining comments were P3 advisories.
Privacy scan Diff scan for local paths, bearer tokens, API keys, and secret-looking keys pass No matches.
Package detector GITHUB_EVENT_NAME=pull_request LOONGSUITE_CHANGED_FILES="$(git diff --name-only)" python .github/scripts/detect_loongsuite_changes.py pass full=false, `packages=

Real E2E Matrix

Scenario Status Command or Demo Evidence
non-streaming pass DashScope Agno smoke with AGNO_SMOKE_MODE=all Non-streaming call returned successfully.
streaming pass DashScope Agno smoke with AGNO_SMOKE_MODE=all Streaming call completed successfully.
concurrency pass DashScope Agno smoke with AGNO_SMOKE_MODE=all; separate identity smoke with 2 concurrent calls Concurrent calls completed; identity smoke verified distinct user/session values.
agent/tool/ReAct pass DashScope Agno smoke with local get_weather tool Tool-using agent path completed successfully.
tool-heavy pass DashScope identity smoke with get_weather and get_air_quality tools Two TOOL spans emitted and both carried the run user/session identity.
error path pass Focused Agno failure tests Model and tool wrapper failure tests passed without losing failure handling.

Telemetry and Weaver

Check Status Command or Artifact Notes
Span tree / span kinds pass Focused Agno tests and regenerated JSON sample AGENT, LLM, and TOOL span kinds verified.
Content capture modes pass test_content_capture_mode_does_not_gate_span_creation plus NO_CONTENT Weaver sample NO_CONTENT sample omitted message content while keeping required identity fields.
Concurrency isolation pass test_concurrent_runs_do_not_drop_spans; real DashScope identity smoke Per-run user/session values stayed isolated.
Weaver live-check pass weaver registry live-check -r <loongsuite-semantic-conventions-registry> --advice-profile loongsuite-genai ... Exit 0; only known stability / enum advisories.

CI

  • GitHub checks: Not run yet; PR branch has not been pushed.
  • Known unrelated failures: None known locally.
  • Follow-up needed: Inspect GitHub Actions after the PR is opened.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@ralf0131 ralf0131 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

@sipercai sipercai merged commit a92d031 into main Jul 8, 2026
24 of 25 checks passed
@sipercai sipercai deleted the fix/agno-entry-identity-propagation branch July 8, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants