Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 46 additions & 53 deletions develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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"`)
Expand All @@ -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"` |
<ConventionAttributes
attributes={[
'gen_ai.input.messages',
'gen_ai.tool.definitions',
'gen_ai.system_instructions',
'gen_ai.request.max_tokens',
'gen_ai.request.seed',
'gen_ai.request.frequency_penalty',
'gen_ai.request.presence_penalty',
'gen_ai.request.temperature',
'gen_ai.request.top_p',
'gen_ai.request.top_k',
'gen_ai.request.reasoning.level',
]}
/>

### 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` |
<ConventionAttributes
attributes={[
'gen_ai.output.messages',
'gen_ai.response.finish_reasons',
'gen_ai.response.id',
'gen_ai.response.streaming',
'gen_ai.response.time_to_first_chunk',
]}
/>

### 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` |
<ConventionAttributes
attributes={[
'gen_ai.usage.input_tokens',
'gen_ai.usage.cache_read.input_tokens',
'gen_ai.usage.cache_creation.input_tokens',
'gen_ai.usage.output_tokens',
'gen_ai.usage.reasoning.output_tokens',
'gen_ai.usage.total_tokens',
]}
/>

## Embedding Span

Expand All @@ -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` |
<ConventionAttributes
attributes={['gen_ai.embeddings.input', 'gen_ai.usage.input_tokens']}
/>

## Execute Tool Span

Expand All @@ -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"` |
<ConventionAttributes
attributes={[
'gen_ai.tool.name',
'gen_ai.tool.description',
'gen_ai.tool.call.arguments',
'gen_ai.tool.call.result',
]}
/>

## Derived by Relay

Expand All @@ -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.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions src/components/conventionAttributes/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -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(
<ConventionAttributes attributes={['gen_ai.tool.name']} />
);

expect(html).toContain('<code>gen_ai.tool.name</code>');
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(
<ConventionAttributes
attributes={[{key: 'gen_ai.usage.input_tokens', notes: '**[2]**'}]}
/>
);

expect(html).toContain('<strong>[2]</strong>');
});

it('throws on unknown attributes so the build fails', () => {
expect(() =>
renderToStaticMarkup(<ConventionAttributes attributes={['gen_ai.not.a.thing']} />)
).toThrow('unknown attribute "gen_ai.not.a.thing"');
});

it('throws on keys inherited from Object.prototype', () => {
expect(() =>
renderToStaticMarkup(<ConventionAttributes attributes={['constructor']} />)
).toThrow('unknown attribute "constructor"');
});

it('single-quotes stringified JSON examples', () => {
const html = renderToStaticMarkup(
<ConventionAttributes
attributes={['gen_ai.tool.call.arguments', 'gen_ai.tool.name']}
/>
);

expect(html).toContain(
`<code>&#x27;${ATTRIBUTE_METADATA['gen_ai.tool.call.arguments'].example}&#x27;</code>`.replaceAll(
'"',
'&quot;'
)
);
expect(html).toContain(
`<code>&quot;${ATTRIBUTE_METADATA['gen_ai.tool.name'].example}&quot;</code>`
);
});
});
72 changes: 72 additions & 0 deletions src/components/conventionAttributes/index.tsx
Original file line number Diff line number Diff line change
@@ -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<string, AttributeMetadata> = 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(`<ConventionAttributes>: unknown attribute "${key}"`);
}
const description = micromark([attribute.brief, notes].filter(Boolean).join(' '))
.replace(/^<p>/, '')
.replace(/<\/p>$/, '');

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.

Paragraph unwrap breaks multi-block briefs

Medium Severity

micromark output is unwrapped by stripping a leading <p> and a trailing </p> independently. That only works for a single paragraph. Multi-paragraph brief text, or brief plus notes that form more than one block, leaves mismatched tags inside the cell via dangerouslySetInnerHTML, so later paragraphs pick up prose margins and the description renders inconsistently.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8c164b3. Configure here.

return {key, attribute, description};
});

return (
<table>
<thead>
<tr>
<th>Attribute</th>
<th>Type</th>
<th>Description</th>
<th>Example</th>
</tr>
</thead>
<tbody>
{rows.map(({key, attribute, description}) => (
<tr key={key}>
<td>
<code>{key}</code>
</td>
<td>{attribute.type}</td>
{/* Briefs are long; override the site's nowrap rule for non-last columns. */}
<td
style={{whiteSpace: 'normal', minWidth: '300px'}}
dangerouslySetInnerHTML={{__html: description}}
/>
<td>
{attribute.example !== undefined && (
<code>{formatExample(attribute.example)}</code>
)}
</td>
</tr>
))}
</tbody>
</table>
);
}

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}"`;
}
2 changes: 2 additions & 0 deletions src/mdxComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -82,6 +83,7 @@ export function mdxComponents(
CliChecksumTable,
CommunitySupportedPlatforms,
ContentSeparator,
ConventionAttributes,
DevDocsCardGrid,
PlatformFilter,
CodeBlock,
Expand Down
Loading