feat(observability): identify agent spans - #1978
Conversation
🦋 Changeset detectedLatest commit: dc09000 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
abdb1fd to
28cd075
Compare
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
8d724ca to
ccb8821
Compare
ccb8821 to
57b9a68
Compare
| ...agentSpanAttributes({ | ||
| agentClassName: this._ParentClass.name, | ||
| sessionId: this.ctx.id.toString(), | ||
| sessionName: agentId | ||
| }), |
There was a problem hiding this comment.
🟡 Existing agent trace searches stop matching because two identity fields were renamed without notice
The identity labels that every agent trace used to carry are replaced with differently-named ones (agentSpanAttributes(...) at packages/agents/src/index.ts:1926-1930) while the published documentation and the release note still promise the old labels, so dashboards and saved searches built on them silently return nothing.
Impact: Users' existing observability queries and dashboards for agent traces quietly stop finding data after upgrading, with no changelog warning.
Renamed span attributes vs. documented contract
Before this PR _withAgentSpan emitted cloudflare.agents.agent.id (instance name) and cloudflare.agents.agent.name (agent class) on every SDK-created agent span (agent_initialization, initialize_agent_storage, agent_start, schedule_agent_alarm, etc.). The new code drops both and emits cloudflare.agents.session.id (the DO id), cloudflare.agents.session.name (the instance name) and gen_ai.agent.name (the class) instead.
docs/agents/observability.md:269-271 still documents cloudflare.agents.agent.name / cloudflare.agents.agent.id as the attributes on these spans, and the changeset (.changeset/curly-agents-trace.md) describes the change as purely additive ("Add ... attributes"), giving no signal that two attributes were removed/renamed. Note also that cloudflare.agents.session.id is the Durable Object id, not the previous agent.id value (the instance name), so it is not a drop-in replacement.
Prompt for agents
The agent span identity attributes were renamed: cloudflare.agents.agent.id and cloudflare.agents.agent.name are no longer emitted by Agent._withAgentSpan in packages/agents/src/index.ts; they are replaced by cloudflare.agents.session.id (the Durable Object id), cloudflare.agents.session.name (the instance name) and gen_ai.agent.name (the class name). docs/agents/observability.md around lines 267-272 still documents the old attribute names on the agent_initialization span, and .changeset/curly-agents-trace.md describes the change as additive only. Decide whether to keep emitting the old attributes for one release for backward compatibility, and in any case update the docs and the changeset text to call out the removal/rename so downstream dashboards and queries can be migrated.
Was this helpful? React with 👍 or 👎 to provide feedback.
Why
Users need to compare Agent token usage, cost, model preferences, latency, and errors without stitching together different identity fields.
Closes #1975
What
Add a consistent identity block to SDK-created Agent spans:
instrumentation_scope.nameinstrumentation_scope.versioncloudflare.agents.session.idcloudflare.agents.session.namegen_ai.agent.nameUsage (AI SDK v7)
Set agent identity in
runtimeContexton eachgenerateText/streamTextcall. The wrapper propagates it to theinvoke_agent,chat, andexecute_toolspans, so the Agents dashboard can aggregate sessions, runs, and tokens.agentNameandconversationIdare the minimum the dashboard needs;agentId/agentVersionare enrichment.experimental_telemetry.functionIdalso works as a fallback foragentName.