Skip to content

feat: mirror the agent name onto gen_ai.agent.name on LLM spans - #127

Open
johndemic wants to merge 1 commit into
DEVtheOPS:mainfrom
johndemic:feat/gen-ai-agent-name
Open

johndemic wants to merge 1 commit into
DEVtheOPS:mainfrom
johndemic:feat/gen-ai-agent-name

Conversation

@johndemic

Copy link
Copy Markdown

Closes #126.

Problem

LLM spans carry the agent under the OpenInference key only:

agent.name = build        # opencode's internal agent (build / plan / a subagent name)
agent.type = primary

A consumer reading the OpenTelemetry GenAI conventions therefore sees the
provider, model and token usage but no agent attribution — it cannot tell a
build request from a plan request, or from a named subagent.

Change

Mirror the value onto gen_ai.agent.name, using ATTR_GEN_AI_AGENT_NAME from
@opentelemetry/semantic-conventions (already a dependency). Nothing is
renamed or removed, so OpenInference consumers are unaffected.

agent.type has no GenAI equivalent and is left as-is.

Scope

LLM spans only — startMessageSpan and the completion path in
handleMessageUpdated — matching the issue. Tool, subtask and session spans
also set the OpenInference key and could follow if that is wanted; happy to
extend this PR or send a second one.

A distinction worth preserving

Some backends use a field called agent for the coding assistant itself
(claude-code, gemini-cli, …) rather than an agent within it. This value is
not that — it is opencode's internal agent — so it deliberately is not mapped
onto a bare agent key.

That identity already travels correctly on the resource as
service.name = opencode. Anyone whose backend keys on a bare agent
attribute can set it today with no code change:

"spanAttributes": "agent=opencode"

Tests

Two added to tests/handlers/spans.test.ts; both fail against unpatched
source. They assert the literal attribute string rather than the imported
constant, since that string is the wire format consumers match on — a rename
upstream should fail the suite rather than silently change the payload.

baseline main: 326 pass
this branch:   328 pass, 0 fail

bun run lint, bun run check:jsdoc-coverage, bun run typecheck all pass.

Relationship to #125

Independent — this branches from main and can merge in either order. Both
touch adjacent lines in message.ts, so whichever lands second may need a
trivial rebase.

LLM spans carry the agent under the OpenInference key only, so a consumer
reading the OpenTelemetry GenAI conventions sees the provider, model and
token usage but no agent attribution — it cannot tell a build request from a
plan request, or from a named subagent.

Mirror the value onto gen_ai.agent.name, taken from the semantic-conventions
package already in the dependency tree. Nothing is renamed or removed, so
OpenInference consumers are unaffected. agent.type has no GenAI equivalent
and is left as-is.

Scoped to LLM spans, matching the issue. Tool, subtask and session spans also
set the OpenInference key and could follow if that is wanted.

The tests assert the literal attribute string rather than the constant the
source imports: that string is the wire format consumers match on, so a
constant renamed upstream should fail the suite rather than silently change
what goes over the wire.

Closes DEVtheOPS#126

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

Emit gen_ai.agent.name alongside agent.name on LLM spans

1 participant