Skip to content

feat(observability): identify agent spans#1978

Open
Ankcorn wants to merge 1 commit into
cloudflare:mainfrom
Ankcorn:tankcorn/group-agent-spans
Open

feat(observability): identify agent spans#1978
Ankcorn wants to merge 1 commit into
cloudflare:mainfrom
Ankcorn:tankcorn/group-agent-spans

Conversation

@Ankcorn

@Ankcorn Ankcorn commented Jul 23, 2026

Copy link
Copy Markdown
Member

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.name
  • instrumentation_scope.version
  • cloudflare.agents.session.id
  • cloudflare.agents.session.name
  • gen_ai.agent.name

Open in Devin Review

@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8d724ca

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
agents Patch
@cloudflare/agent-think Patch

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

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Open in Devin Review

// Compatibility representation of InstrumentationScope until the Workers
// tracing API exposes native scope metadata.
"instrumentation_scope.name": "agents",
"instrumentation_scope.version": "0.18.0",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Telemetry reports a frozen SDK version that no longer matches the actual release

The reported instrumentation version is written as a fixed string ("0.18.0" at packages/agents/src/observability/agent-span-attributes.ts:12) instead of being read from the package version, so it stops matching the real SDK version as soon as the package is bumped (this PR is already a version bump).
Impact: Anyone reading the traces sees a version label that is wrong, making it impossible to reliably tell which SDK version produced a span.

Version constant drifts from package.json on every release

The current packages/agents/package.json version is 0.18.0, matching the literal. However this PR ships a patch changeset (.changeset/curly-agents-trace.md), so the released version becomes 0.18.1 while instrumentation_scope.version stays 0.18.0. There is no build-time injection (scripts/build.ts performs no version substitution) and the accompanying test (packages/agents/src/tests/observability/agent-span-attributes.test.ts:14) hardcodes the same literal, so it cannot detect drift against package.json. Every future release requires a manual edit here or the emitted scope version silently diverges from the true SDK version.

Prompt for agents
The instrumentation_scope.version in packages/agents/src/observability/agent-span-attributes.ts is hardcoded to "0.18.0" and will drift from the real package version on every release (this PR itself is a patch bump to 0.18.x). There is no build-time version injection in packages/agents/scripts/build.ts. Consider deriving the version from packages/agents/package.json (e.g. an import of the version, or a build-time define/replace injected into the bundle) so the emitted instrumentation_scope.version always matches the shipped SDK version. Update the test in packages/agents/src/tests/observability/agent-span-attributes.test.ts accordingly so it validates against the single source of truth rather than duplicating the literal.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove this. froxen versions are not gonna be fun

@Ankcorn
Ankcorn force-pushed the tankcorn/group-agent-spans branch 2 times, most recently from abdb1fd to 28cd075 Compare July 23, 2026 15:42
@pkg-pr-new

pkg-pr-new Bot commented Jul 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1978

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1978

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1978

create-think

npm i https://pkg.pr.new/create-think@1978

hono-agents

npm i https://pkg.pr.new/hono-agents@1978

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1978

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1978

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1978

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1978

commit: 8d724ca

@Ankcorn
Ankcorn force-pushed the tankcorn/group-agent-spans branch 2 times, most recently from c46dfc7 to 4edca85 Compare July 24, 2026 11:57
@Ankcorn
Ankcorn force-pushed the tankcorn/group-agent-spans branch from 4edca85 to 8d724ca Compare July 24, 2026 12:05
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.

Unify Agent span identity and instrumentation metadata

2 participants