Uh oh!
There was an error while loading. Please reload this page.
feat(server-utils): Emit low-cardinality gen_ai agent span names when streaming - #23582
Conversation
… streaming Fixes#23524 Co-Authored-By: Cursor <cursoragent@cursor.com>
size-limit report 📦
|
Streamed invoke_agent names should be derivable from attributes, not only from the span name. Co-Authored-By: Cursor <cursoragent@cursor.com>
…-gen_ai-agent-span-names
…09-emit-low-cardinality-gen_ai-agent-span-names # Conflicts: # docs/migration/v11-end-state.md # packages/server-utils/src/ai/langchain/index.ts
Lms24
left a comment
There was a problem hiding this comment.
Had one last question, otherwise LGTM!
| expect(span.data?.[GEN_AI_FUNCTION_ID]).toBe('weather_agent'); | ||
| }); | ||
| it('uses `invoke_agent` when span streaming is enabled', () => { |
There was a problem hiding this comment.
q: is gen_ai.function.id the same as gen_ai.agent.name? Just wondering if we can preserve the name here as well, similarly to the execute tool one.
There was a problem hiding this comment.
they're different, gen_ai.agent.name is the name of the agent but gen_ai.function.id is more of a tracing label. i guess we can treat it same as execute tool
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…t` span names Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…agent` names Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…eaming (#23573) When span streaming is enabled, gen_ai inference span names follow the inference templates: `{operation} {model}` when a model is known, `{operation}` when it is not. Instrumented methods always have an operation, so the convention fallback `Generative AI model operation` is not emitted today. `traceLifecycle: 'static'` keeps the previous names (`chat unknown`). Known models stay in the name in both lifecycles (`chat gpt-4`). The inference ops the SDK emits are `gen_ai.chat`, `gen_ai.embeddings`, `gen_ai.generate_content` and `gen_ai.rerank` — the last three were only added to the conventions' inference rule in [sentry-conventions#579](getsentry/sentry-conventions#579), but the naming here is derived from the operation rather than hardcoded per op, so they were already covered. The Vercel AI channel path never emitted an `unknown` model sentinel, so its names were already conformant; a test now locks that in. The SDK emits no `gen_ai.responses` or `gen_ai.text_completion` spans. `gen_ai.execute_tool` spans keep the tool name in their name (`execute_tool getWeather`) — the tool name is a bounded, resolved value, so it behaves like a known model rather than a high-cardinality identifier. Agent ops (`gen_ai.invoke_agent`, `gen_ai.create_agent`, `gen_ai.handoff`) are out of scope here and handled in #23582 (`JS-3409`). Fixes#23525
…09-emit-low-cardinality-gen_ai-agent-span-names # Conflicts: # MIGRATION.md
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Uh oh!
There was an error while loading. Please reload this page.
With span streaming enabled (the default),
gen_ai.invoke_agentnames follow the agent span name conventions:{operation} {name}fromgen_ai.agent.name,gen_ai.pipeline.nameorgen_ai.function_id, otherwise{operation}.In practice this only changes LangChain chain spans, and only their prefix. They were named
chain format_prompt, which does not lead with the operation like every other agent span; they are nowinvoke_agent format_prompt. The chain name itself is bounded, so it stays in the name. A chain the SDK cannot name falls back toinvoke_agentrather than carrying theunknown_chainsentinel, the same way a missing model is dropped in #23573.LangGraph agent names and Vercel AI
functionIds are unchanged in both lifecycles — both are bounded, low-cardinality values.The
pipeline.nameandfunction_idtemplates are added in getsentry/sentry-conventions#593. LangChain still emits its chain name onlangchain.chain.name; moving it togen_ai.pipeline.nameis tracked in JS-3452 and should land before v11 ships, so the emitted name matches a published template. Span names are unaffected by that move — they are built from the local chain name, not read back off the attribute.The other two ops in the agent rule need nothing: the SDK emits no
gen_ai.handoffspans, andgen_ai.create_agentwas dropped in v11. Neither is listed in the migration table.The migration entry lives in
MIGRATION.mdrather thandocs/migration/v11-end-state.md, which was removed by #23623.Fixes#23524