diff --git a/develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx b/develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx index ae60466096767..41dfbdd89b7ac 100644 --- a/develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx +++ b/develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx @@ -77,7 +77,7 @@ Describes AI agent invocation. Agent invocations represent operations that can include multiple model calls, or some auxiliary work that goes beyond transforming the model input and output. - Span `op` is `"gen_ai.invoke_agent"`. -- Span `name` is `"invoke_agent {gen_ai.agent.name}"`. (e.g. `"invoke_agent Weather Agent"`) **[2]** +- Span `name` is `"invoke_agent {gen_ai.agent.name}"`. (e.g. `"invoke_agent Weather Agent"`) In some agent libraries, the agent name is optional, and some do not provide the user an option to name their agents. In these cases, the span name is `"invoke_agent {call_id}"`, where `call_id` is some user-provided identifier for the agent invocation. For example, `functionId` in Vercel AI. - Attribute `gen_ai.operation.name` is `"invoke_agent"`. - Attribute `gen_ai.agent.name` is the agent's name. (e.g. `"Weather Agent"`). As a fallback to `gen_ai.agent.name`, the product also interprets `gen_ai.function_id` as an agent name for libraries that let users set a tracing identifier on a per-invocation basis. - If relevant, the `gen_ai.pipeline.name` attribute is the name of the AI workflow, pipeline or chain within which the agent operates. (e.g. `"weather-pipeline"`) @@ -100,40 +100,46 @@ Additional attributes on the span: ### Request Data -| Attribute | Type | Description | Example | -| :--------------------------------- | :----- | :----------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------- | -| `gen_ai.input.messages` | string | List of dictionaries describing the messages (prompts) sent to the LLM. **[0]**, **[1]** | `'[{"role": "user", "parts": [{"type": "text", "content": "..."}]}]'` | -| `gen_ai.tool.definitions` | string | List of dictionaries describing the available tools. **[0]** | `'[{"name": "random_number", "description": "..."}, ...]'` | -| `gen_ai.system_instructions` | string | The system instructions passed to the model. | `"You are a helpful assistant."` | -| `gen_ai.request.max_tokens` | int | Model configuration parameter. | `500` | -| `gen_ai.request.seed` | string | Seed for reproducible outputs. | `"12345"` | -| `gen_ai.request.frequency_penalty` | float | Model configuration parameter. | `0.5` | -| `gen_ai.request.presence_penalty` | float | Model configuration parameter. | `0.5` | -| `gen_ai.request.temperature` | float | Model configuration parameter. | `0.1` | -| `gen_ai.request.top_p` | float | Model configuration parameter. | `0.7` | -| `gen_ai.request.top_k` | int | Limits model to K most likely next tokens. | `40` | -| `gen_ai.request.reasoning.level` | string | The reasoning or thinking effort level requested for a GenAI model. Supported values vary by provider. | `"medium"` | + ### Response Data -| Attribute | Type | Description | Example | -| :------------------------------------ | :------ | :------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------- | -| `gen_ai.output.messages` | string | Stringified array of message objects representing the model's output. **[0]**, **[1]** | `'[{"role": "assistant", "parts": [{"type": "text", "content": "..."}]}]'` | -| `gen_ai.response.finish_reasons` | string | The reason why the model stopped generating. | `"stop"` | -| `gen_ai.response.id` | string | Unique identifier for the completion. | `"chatcmpl-abc123"` | -| `gen_ai.response.streaming` | boolean | Whether response was streamed asynchronously. | `true` | -| `gen_ai.response.time_to_first_chunk` | double | Seconds until first response chunk in streaming. | `0.5` | + ### Token Usage Data -| Attribute | Type | Description | Example | -| :----------------------------------------- | :--- | :----------------------------------------------------------------------------------------------------------------------------- | :------ | -| `gen_ai.usage.input_tokens` | int | The number of tokens used in the AI input (prompt), including cached tokens. | `60` | -| `gen_ai.usage.cache_read.input_tokens` | int | The number of cached tokens used in the AI input (prompt). | `50` | -| `gen_ai.usage.cache_creation.input_tokens` | int | Tokens written to cache when processing input. | `20` | -| `gen_ai.usage.output_tokens` | int | The number of tokens used in the AI output, including reasoning tokens. | `130` | -| `gen_ai.usage.reasoning.output_tokens` | int | The number of tokens used for reasoning. | `30` | -| `gen_ai.usage.total_tokens` | int | The sum of `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`. | `190` | + ## Embedding Span @@ -148,10 +154,9 @@ This span represents a request to encode input into numeric vector embeddings. Additional attributes on the span: -| Attribute | Type | Description | Example | -| :-------------------------- | :----- | :-------------------------------------- | :-------------- | -| `gen_ai.embeddings.input` | string | Input to embed. | "Hello, world!" | -| `gen_ai.usage.input_tokens` | int | The number of tokens used in the input. | `60` | + ## Execute Tool Span @@ -165,12 +170,14 @@ Describes a tool execution. Additional attributes on the span: -| Attribute | Type | Description | Example | -| :--------------------------- | :----- | :------------------------------------------------------------------------------------------------------------- | :----------------------------------------- | -| `gen_ai.tool.name` | string | Name of the tool executed. | `"random_number"` | -| `gen_ai.tool.description` | string | Description of the tool executed. | `"Tool returning a random number"` | -| `gen_ai.tool.call.arguments` | string | Arguments of the tool call (stringified). | `'{"max":10}'` | -| `gen_ai.tool.call.result` | string | Result of the tool call (stringified). | `"7"` | + ## Derived by Relay @@ -183,17 +190,3 @@ Relay sets these attributes during ingestion: - `gen_ai.context.window_size` is looked up from the model metadata registry by `gen_ai.response.model`. - `gen_ai.context.utilization` is computed as `gen_ai.usage.total_tokens / gen_ai.context.window_size`. - `gen_ai.cost.input_tokens`, `gen_ai.cost.output_tokens`, and `gen_ai.cost.total_tokens` are calculated from token counts and per-token pricing in the model registry. - - -**[0]:** - -Span attributes only allow primitive data types (like `int`, `float`, `boolean`, `string`). This means you need to use a stringified version of a list of dictionaries. Do NOT set the object/array `[{"foo": "bar"}]` but rather the string `'[{"foo": "bar"}]'` (must be parsable JSON). - -**[1]:** - -Messages use the format `{role, parts}` where `parts` is an array of typed objects: `[{"role": "user", "parts": [{"type": "text", "content": "..."}]}]`. The `role` must be `"user"`, `"assistant"`, `"tool"`, or `"system"`. Each part has a `type`; common types include `"text"` (user-visible content), `"reasoning"` (internal thinking/chain-of-thought), `"tool_call"`, and `"tool_call_response"`. Use `{"type": "reasoning", "content": "..."}` for the model's thinking output — Sentry surfaces it separately and does not render it as a user-visible message in Conversations, so do not represent thinking content as a `"text"` part. For backwards compatibility, the legacy format `{role, content}` is also accepted. - -**[2]** - -In some agent libraries, the agent name is optional, and some do not provide the user an option to name their agents. -In these cases, the span name is `"invoke_agent {call_id}"`, where `call_id` is some user-provided identifier for the agent invocation. For example, `functionId` in Vercel AI. diff --git a/package.json b/package.json index e077145a96ce0..89e6c56a44837 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "@radix-ui/themes": "^3.1.3", "@sentry-internal/global-search": "^1.3.0", "@sentry/browser": "11.6.0", + "@sentry/conventions": "^0.33.0", "@sentry/nextjs": "11.6.0", "@types/mdx": "^2.0.9", "algoliasearch": "^4.23.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index be0bb14b16151..87d0e30b39657 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,6 +105,9 @@ importers: '@sentry/browser': specifier: 11.6.0 version: 11.6.0 + '@sentry/conventions': + specifier: ^0.33.0 + version: 0.33.0 '@sentry/nextjs': specifier: 11.6.0 version: 11.6.0(@babel/core@7.29.7)(next@15.5.24(@babel/core@7.29.7)(@opentelemetry/api@1.9.1)(@types/node@22.19.11)(babel-plugin-macros@3.1.0)(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(sass@1.98.0))(react@19.2.4)(webpack@5.105.2(esbuild@0.28.1)(postcss@8.5.23)) @@ -3115,6 +3118,10 @@ packages: resolution: {integrity: sha512-ttSRcoLf2kIENDIFzH12aJaVMdxnidMYLvVNwEX/JjXfXaQot8u5M47QmgAFOOhVJ4nQ2uU8wTCh+fwSPrrCfg==} engines: {node: '>=14'} + '@sentry/conventions@0.33.0': + resolution: {integrity: sha512-5aa3g/VOnMoL8yHbfkYIWBYC3BLgMudgRNBTKNMrcMEj1mE9aKIt/CYCG7sasijhiSU4nTcSEzyM2voIVzLCng==} + engines: {node: '>=14'} + '@sentry/core@11.6.0': resolution: {integrity: sha512-PbITT1kfJYKJiS9fH4ZtOcwIONKyt+tUsTZSPtcAjPdkUDOzMKT61MkUa1Ze07VzNtLALT24ZdUOc6d9K4YoKA==} engines: {node: '>=20.19.0 <22.0.0 || >=22.12.0 <23.0.0 || >=23.2.0'} @@ -10621,6 +10628,8 @@ snapshots: '@sentry/conventions@0.26.0': {} + '@sentry/conventions@0.33.0': {} + '@sentry/core@11.6.0': dependencies: '@sentry/conventions': 0.26.0 diff --git a/src/components/conventionAttributes/index.spec.tsx b/src/components/conventionAttributes/index.spec.tsx new file mode 100644 index 0000000000000..1904e6d1cd95b --- /dev/null +++ b/src/components/conventionAttributes/index.spec.tsx @@ -0,0 +1,61 @@ +import {ATTRIBUTE_METADATA} from '@sentry/conventions/attributes'; +import React from 'react'; +import {renderToStaticMarkup} from 'react-dom/server'; +import {describe, expect, it, vi} from 'vitest'; + +import {ConventionAttributes} from './index'; + +// Vitest compiles JSX with the classic runtime here (tsconfig `jsx: preserve`). +vi.stubGlobal('React', React); + +describe('ConventionAttributes', () => { + it('renders attributes from the conventions package', () => { + const html = renderToStaticMarkup( + + ); + + expect(html).toContain('gen_ai.tool.name'); + expect(html).toContain(ATTRIBUTE_METADATA['gen_ai.tool.name'].type); + expect(html).toContain(ATTRIBUTE_METADATA['gen_ai.tool.name'].brief); + }); + + it('appends page-specific notes to the description', () => { + const html = renderToStaticMarkup( + + ); + + expect(html).toContain('[2]'); + }); + + it('throws on unknown attributes so the build fails', () => { + expect(() => + renderToStaticMarkup() + ).toThrow('unknown attribute "gen_ai.not.a.thing"'); + }); + + it('throws on keys inherited from Object.prototype', () => { + expect(() => + renderToStaticMarkup() + ).toThrow('unknown attribute "constructor"'); + }); + + it('single-quotes stringified JSON examples', () => { + const html = renderToStaticMarkup( + + ); + + expect(html).toContain( + `'${ATTRIBUTE_METADATA['gen_ai.tool.call.arguments'].example}'`.replaceAll( + '"', + '"' + ) + ); + expect(html).toContain( + `"${ATTRIBUTE_METADATA['gen_ai.tool.name'].example}"` + ); + }); +}); diff --git a/src/components/conventionAttributes/index.tsx b/src/components/conventionAttributes/index.tsx new file mode 100644 index 0000000000000..77b4fa4a1d7f4 --- /dev/null +++ b/src/components/conventionAttributes/index.tsx @@ -0,0 +1,72 @@ +import { + ATTRIBUTE_METADATA, + type AttributeMetadata, + type AttributeValue, +} from '@sentry/conventions/attributes'; +import {micromark} from 'micromark'; + +type Props = { + attributes: (string | {key: string; notes?: string})[]; +}; + +const metadata: Record = ATTRIBUTE_METADATA; + +/** + * Renders attribute details from `@sentry/conventions`, so pages don't copy + * types, descriptions, and examples that drift from the source of truth. + */ +export function ConventionAttributes({attributes}: Props) { + const rows = attributes.map(row => { + const {key, notes} = typeof row === 'string' ? {key: row} : row; + // `Object.hasOwn` so keys like `constructor` don't pass as known attributes. + const attribute = Object.hasOwn(metadata, key) ? metadata[key] : undefined; + if (!attribute) { + throw new Error(`: unknown attribute "${key}"`); + } + const description = micromark([attribute.brief, notes].filter(Boolean).join(' ')) + .replace(/^

/, '') + .replace(/<\/p>$/, ''); + return {key, attribute, description}; + }); + + return ( + + + + + + + + + + + {rows.map(({key, attribute, description}) => ( + + + + {/* Briefs are long; override the site's nowrap rule for non-last columns. */} + + + ))} + +
AttributeTypeDescriptionExample
+ {key} + {attribute.type} + + {attribute.example !== undefined && ( + {formatExample(attribute.example)} + )} +
+ ); +} + +function formatExample(example: AttributeValue) { + if (typeof example !== 'string') { + return JSON.stringify(example); + } + // Single-quote stringified JSON so its inner double quotes stay readable. + return /^[[{]/.test(example) ? `'${example}'` : `"${example}"`; +} diff --git a/src/mdxComponents.ts b/src/mdxComponents.ts index 13d823b180d63..27d17c1f72fe1 100644 --- a/src/mdxComponents.ts +++ b/src/mdxComponents.ts @@ -12,6 +12,7 @@ import {CommunitySupportedPlatforms} from './components/communitySupportedPlatfo import {ConfigKey} from './components/configKey'; import {ConfigValue} from './components/configValue'; import {ContentSeparator} from './components/contentSeparator'; +import {ConventionAttributes} from './components/conventionAttributes'; import {CopyableCard} from './components/copyableCard'; import {CreateGitHubAppForm} from './components/createGitHubAppForm'; import {DefinitionList} from './components/definitionList'; @@ -82,6 +83,7 @@ export function mdxComponents( CliChecksumTable, CommunitySupportedPlatforms, ContentSeparator, + ConventionAttributes, DevDocsCardGrid, PlatformFilter, CodeBlock,