diff --git a/MIGRATION.md b/MIGRATION.md index 129377ba8587..b55d7f2cce2d 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -251,6 +251,7 @@ Affected SDKs: All SDKs. - The `http.query` and `http.fragment` span attributes were renamed to `url.query` and `url.fragment`. - `network.*` span attributes were aligned across SDKs. - Legacy messaging (`messaging.*`) and database (`db.statement`, …) span attributes on the AMQP and Redis instrumentations were replaced by their current semantic-convention equivalents. +- The gen_ai cache token attributes `gen_ai.usage.cache_creation_input_tokens` and `gen_ai.usage.cache_read_input_tokens` were renamed to `gen_ai.usage.cache_creation.input_tokens` and `gen_ai.usage.cache_read.input_tokens`. - Span attributes now use the shared `@sentry/conventions` package under the hood. If you reference these attributes in custom instrumentation, `beforeSendSpan`, dashboards, or alerts, update them to the new names. diff --git a/packages/core/src/tracing/ai/gen-ai-attributes.ts b/packages/core/src/tracing/ai/gen-ai-attributes.ts index c6eecddefcdf..671dfd042165 100644 --- a/packages/core/src/tracing/ai/gen-ai-attributes.ts +++ b/packages/core/src/tracing/ai/gen-ai-attributes.ts @@ -30,22 +30,6 @@ export const GEN_AI_REQUEST_DIMENSIONS_ATTRIBUTE = 'gen_ai.request.dimensions'; */ export const GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE = 'gen_ai.response.stop_reason'; -/** - * The number of cache creation input tokens used - * - * Kept local: `@sentry/conventions` emits `gen_ai.usage.cache_creation.input_tokens` (dotted), which - * differs from the key we emit here. - */ -export const GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS_ATTRIBUTE = 'gen_ai.usage.cache_creation_input_tokens'; - -/** - * The number of cache read input tokens used - * - * Kept local: `@sentry/conventions` emits `gen_ai.usage.cache_read.input_tokens` (dotted), which - * differs from the key we emit here. - */ -export const GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS_ATTRIBUTE = 'gen_ai.usage.cache_read_input_tokens'; - /** * The span operation name for invoking an agent */ diff --git a/packages/core/src/tracing/langchain/utils.ts b/packages/core/src/tracing/langchain/utils.ts index 4683c02e7cf4..a48dc2a536be 100644 --- a/packages/core/src/tracing/langchain/utils.ts +++ b/packages/core/src/tracing/langchain/utils.ts @@ -19,16 +19,13 @@ import { GEN_AI_RESPONSE_TOOL_CALLS, GEN_AI_SYSTEM, GEN_AI_SYSTEM_INSTRUCTIONS, + GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS, + GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, GEN_AI_USAGE_INPUT_TOKENS, GEN_AI_USAGE_OUTPUT_TOKENS, GEN_AI_USAGE_TOTAL_TOKENS, } from '@sentry/conventions/attributes'; -import { - GEN_AI_REQUEST_STREAM_ATTRIBUTE, - GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE, - GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS_ATTRIBUTE, - GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS_ATTRIBUTE, -} from '../ai/gen-ai-attributes'; +import { GEN_AI_REQUEST_STREAM_ATTRIBUTE, GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE } from '../ai/gen-ai-attributes'; import { isContentMedia, stripInlineMediaFromSingleMessage } from '../ai/mediaStripping'; import { extractSystemInstructions, getTruncatedJsonString } from '../ai/utils'; import { LANGCHAIN_ORIGIN, ROLE_MAP } from './constants'; @@ -412,13 +409,9 @@ function addTokenUsageAttributes( // Extra Anthropic cache metrics (present only when caching is enabled) if (anthropicUsage.cache_creation_input_tokens !== undefined) - setNumberIfDefined( - attrs, - GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS_ATTRIBUTE, - anthropicUsage.cache_creation_input_tokens, - ); + setNumberIfDefined(attrs, GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS, anthropicUsage.cache_creation_input_tokens); if (anthropicUsage.cache_read_input_tokens !== undefined) - setNumberIfDefined(attrs, GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS_ATTRIBUTE, anthropicUsage.cache_read_input_tokens); + setNumberIfDefined(attrs, GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, anthropicUsage.cache_read_input_tokens); } }