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
1 change: 1 addition & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 0 additions & 16 deletions packages/core/src/tracing/ai/gen-ai-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
17 changes: 5 additions & 12 deletions packages/core/src/tracing/langchain/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
}

Expand Down
Loading