Skip to content

feat(util-genai): auto-propagate common GenAI attributes via baggage#57

Merged
fangxiu-wf merged 1 commit into
mainfrom
feat/util-genai-baggage-propagation
Jul 15, 2026
Merged

feat(util-genai): auto-propagate common GenAI attributes via baggage#57
fangxiu-wf merged 1 commit into
mainfrom
feat/util-genai-baggage-propagation

Conversation

@fangxiu-wf

Copy link
Copy Markdown
Collaborator

Summary

Adds automatic propagation of the ARMS GenAI common attributes (gen_ai.agent.name / gen_ai.user.id / gen_ai.session.id) via OpenTelemetry Baggage, matching the Python loongsuite-otel-util-genai 0.6.1 behavior.

  • startEntry / startInvokeAgent / startCreateAgent write the set common attributes into Baggage on the span's contextToken.
  • GenAI child spans (LLM / Tool / ReAct Step / Embedding / Retrieval / Rerank / Memory) created under that context automatically inherit the three attributes — no need to set them on every child invocation.
  • Fill-only: a child field is backfilled only when unset, so explicit values always win. Plain OTel SDK business spans are unaffected.
  • Downstream (probe-created) spans can also read the values from baggage.
  • New exported helpers setCommonBaggage / backfillCommonFromBaggage.
  • Cleans up a dead no-op context.with(...) in TelemetryHandler.startLlm.
  • Bumps to 0.1.0-beta.10.

Test plan

  • npm run build (tsc) — clean
  • npm test — 19 files / 207 tests passing (incl. new baggage-propagation.test.ts: child inheritance, explicit-wins, Entry propagation, no-baggage backward-compat)
  • End-to-end verified against a real model (qwen): STEP/LLM/TOOL spans inherit agent.name/user.id/session.id without being set explicitly; custom business spans correctly do NOT inherit

🤖 Generated with Claude Code

startEntry / startInvokeAgent / startCreateAgent now publish the set
gen_ai.agent.name / gen_ai.user.id / gen_ai.session.id into OpenTelemetry
Baggage. GenAI child spans (LLM / Tool / ReAct Step / Embedding / Retrieval /
Rerank / Memory) created under that Entry/Agent context automatically inherit
these three common attributes — no need to set them on every child invocation.

- Fill-only: a child field is backfilled only when unset, so explicit values win.
- Only affects util-created GenAI spans; plain OTel SDK business spans are untouched.
- Enables downstream (probe-created) spans to read the values from baggage.
- New exported helpers setCommonBaggage / backfillCommonFromBaggage.
- Remove a dead no-op context.with(...) in TelemetryHandler.startLlm.

Bump to 0.1.0-beta.10.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@fangxiu-wf fangxiu-wf merged commit d40f267 into main Jul 15, 2026
12 checks passed
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