diff --git a/develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx b/develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx index f03cfcb071e34..7ba92aabbd9cd 100644 --- a/develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx +++ b/develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx @@ -103,6 +103,19 @@ Additional attributes on the span: | `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 + +Relay sets these attributes during ingestion: + +- `gen_ai.operation.type` is inferred from `gen_ai.operation.name` with a `sentry.op` fallback. +- `gen_ai.response.model` is set to `gen_ai.request.model` if not already present. +- `gen_ai.usage.total_tokens` is computed as `gen_ai.usage.input_tokens + gen_ai.usage.output_tokens`. +- `gen_ai.response.tokens_per_second` is computed as `gen_ai.usage.output_tokens` divided by the span duration. +- `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).