Skip to content

feat: add gen_ai.session.id to trace spans#1269

Open
fangxiu-wf wants to merge 1 commit intoagentscope-ai:mainfrom
fangxiu-wf:feat/add-session-id-to-trace-spans-v2
Open

feat: add gen_ai.session.id to trace spans#1269
fangxiu-wf wants to merge 1 commit intoagentscope-ai:mainfrom
fangxiu-wf:feat/add-session-id-to-trace-spans-v2

Conversation

@fangxiu-wf
Copy link
Copy Markdown
Contributor

Summary

  • Add gen_ai.session.id attribute to all trace spans (Agent/Model/Tool/Format) for session-level aggregation and analysis
  • Store currentSessionKey on AgentBase (set during loadFrom/loadIfExists) and propagate it through OTel Context to child spans in TelemetryTracer

Changes

  • AgentBase: add currentSessionKey field with getter/setter
  • ReActAgent: call setCurrentSessionKey(sessionKey) in loadFrom and loadIfExists
  • GenAiIncubatingAttributes: add GEN_AI_SESSION_ID attribute key
  • TelemetryTracer: resolve sessionId from AgentBase.getCurrentSessionKey() in callAgent, propagate via ContextKey to callModel/callTool/callFormat

Test plan

  • Verify mvn test passes for core and extensions-studio modules
  • Integration test: run ReActAgent with session, verify all spans carry gen_ai.session.id
  • Verify spans without session gracefully omit the attribute (no errors)

🤖 Generated with Claude Code

Store currentSessionKey on AgentBase (set during loadFrom/loadIfExists)
and propagate it through OTel Context to all child spans (Agent/Model/
Tool/Format) in TelemetryTracer, enabling session-level trace aggregation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fangxiu-wf fangxiu-wf requested a review from a team April 22, 2026 10:19
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.

1 participant