@sentry/core 10.39.0-alpha.0 → 10.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/attributes.js.map +1 -1
- package/build/cjs/client.js +6 -13
- package/build/cjs/client.js.map +1 -1
- package/build/cjs/envelope.js +7 -41
- package/build/cjs/envelope.js.map +1 -1
- package/build/cjs/index.js +0 -48
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/integration.js +0 -12
- package/build/cjs/integration.js.map +1 -1
- package/build/cjs/integrations/eventFilters.js +1 -1
- package/build/cjs/integrations/eventFilters.js.map +1 -1
- package/build/cjs/integrations/requestdata.js +6 -72
- package/build/cjs/integrations/requestdata.js.map +1 -1
- package/build/cjs/semanticAttributes.js +0 -84
- package/build/cjs/semanticAttributes.js.map +1 -1
- package/build/cjs/tracing/sentrySpan.js +0 -32
- package/build/cjs/tracing/sentrySpan.js.map +1 -1
- package/build/cjs/tracing/trace.js +0 -1
- package/build/cjs/tracing/trace.js.map +1 -1
- package/build/cjs/tracing/vercel-ai/index.js +0 -1
- package/build/cjs/tracing/vercel-ai/index.js.map +1 -1
- package/build/cjs/utils/featureFlags.js +0 -1
- package/build/cjs/utils/featureFlags.js.map +1 -1
- package/build/cjs/utils/scopeData.js +0 -4
- package/build/cjs/utils/scopeData.js.map +1 -1
- package/build/cjs/utils/should-ignore-span.js +9 -31
- package/build/cjs/utils/should-ignore-span.js.map +1 -1
- package/build/cjs/utils/spanUtils.js +2 -90
- package/build/cjs/utils/spanUtils.js.map +1 -1
- package/build/cjs/utils/version.js +1 -1
- package/build/cjs/utils/version.js.map +1 -1
- package/build/esm/attributes.js.map +1 -1
- package/build/esm/client.js +2 -9
- package/build/esm/client.js.map +1 -1
- package/build/esm/envelope.js +8 -41
- package/build/esm/envelope.js.map +1 -1
- package/build/esm/index.js +3 -10
- package/build/esm/index.js.map +1 -1
- package/build/esm/integration.js +1 -12
- package/build/esm/integration.js.map +1 -1
- package/build/esm/integrations/eventFilters.js +1 -1
- package/build/esm/integrations/eventFilters.js.map +1 -1
- package/build/esm/integrations/requestdata.js +6 -72
- package/build/esm/integrations/requestdata.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/semanticAttributes.js +1 -57
- package/build/esm/semanticAttributes.js.map +1 -1
- package/build/esm/tracing/sentrySpan.js +1 -33
- package/build/esm/tracing/sentrySpan.js.map +1 -1
- package/build/esm/tracing/trace.js +0 -1
- package/build/esm/tracing/trace.js.map +1 -1
- package/build/esm/tracing/vercel-ai/index.js +0 -1
- package/build/esm/tracing/vercel-ai/index.js.map +1 -1
- package/build/esm/utils/featureFlags.js +0 -1
- package/build/esm/utils/featureFlags.js.map +1 -1
- package/build/esm/utils/scopeData.js +0 -4
- package/build/esm/utils/scopeData.js.map +1 -1
- package/build/esm/utils/should-ignore-span.js +9 -31
- package/build/esm/utils/should-ignore-span.js.map +1 -1
- package/build/esm/utils/spanUtils.js +3 -87
- package/build/esm/utils/spanUtils.js.map +1 -1
- package/build/esm/utils/version.js +1 -1
- package/build/esm/utils/version.js.map +1 -1
- package/build/types/attributes.d.ts +1 -1
- package/build/types/attributes.d.ts.map +1 -1
- package/build/types/client.d.ts +2 -40
- package/build/types/client.d.ts.map +1 -1
- package/build/types/envelope.d.ts +1 -6
- package/build/types/envelope.d.ts.map +1 -1
- package/build/types/index.d.ts +4 -11
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integration.d.ts +0 -4
- package/build/types/integration.d.ts.map +1 -1
- package/build/types/integrations/requestdata.d.ts.map +1 -1
- package/build/types/semanticAttributes.d.ts +0 -38
- package/build/types/semanticAttributes.d.ts.map +1 -1
- package/build/types/tracing/sentrySpan.d.ts +1 -10
- package/build/types/tracing/sentrySpan.d.ts.map +1 -1
- package/build/types/tracing/vercel-ai/index.d.ts.map +1 -1
- package/build/types/types-hoist/envelope.d.ts +2 -22
- package/build/types/types-hoist/envelope.d.ts.map +1 -1
- package/build/types/types-hoist/integration.d.ts +0 -7
- package/build/types/types-hoist/integration.d.ts.map +1 -1
- package/build/types/types-hoist/link.d.ts +2 -2
- package/build/types/types-hoist/link.d.ts.map +1 -1
- package/build/types/types-hoist/options.d.ts +2 -18
- package/build/types/types-hoist/options.d.ts.map +1 -1
- package/build/types/types-hoist/span.d.ts +0 -27
- package/build/types/types-hoist/span.d.ts.map +1 -1
- package/build/types/utils/featureFlags.d.ts.map +1 -1
- package/build/types/utils/scopeData.d.ts.map +1 -1
- package/build/types/utils/should-ignore-span.d.ts +3 -3
- package/build/types/utils/should-ignore-span.d.ts.map +1 -1
- package/build/types/utils/spanUtils.d.ts +2 -22
- package/build/types/utils/spanUtils.d.ts.map +1 -1
- package/build/types-ts3.8/attributes.d.ts +1 -1
- package/build/types-ts3.8/client.d.ts +2 -40
- package/build/types-ts3.8/envelope.d.ts +1 -6
- package/build/types-ts3.8/index.d.ts +4 -11
- package/build/types-ts3.8/integration.d.ts +0 -4
- package/build/types-ts3.8/semanticAttributes.d.ts +0 -38
- package/build/types-ts3.8/tracing/sentrySpan.d.ts +1 -10
- package/build/types-ts3.8/types-hoist/envelope.d.ts +2 -22
- package/build/types-ts3.8/types-hoist/integration.d.ts +0 -7
- package/build/types-ts3.8/types-hoist/link.d.ts +2 -2
- package/build/types-ts3.8/types-hoist/options.d.ts +2 -18
- package/build/types-ts3.8/types-hoist/span.d.ts +0 -27
- package/build/types-ts3.8/utils/should-ignore-span.d.ts +3 -3
- package/build/types-ts3.8/utils/spanUtils.d.ts +2 -22
- package/package.json +1 -1
- package/build/cjs/integrations/spanStreaming.js +0 -54
- package/build/cjs/integrations/spanStreaming.js.map +0 -1
- package/build/cjs/spans/captureSpan.js +0 -104
- package/build/cjs/spans/captureSpan.js.map +0 -1
- package/build/cjs/spans/spanBuffer.js +0 -121
- package/build/cjs/spans/spanBuffer.js.map +0 -1
- package/build/cjs/spans/spanFirstUtils.js +0 -186
- package/build/cjs/spans/spanFirstUtils.js.map +0 -1
- package/build/cjs/utils/beforeSendSpan.js +0 -36
- package/build/cjs/utils/beforeSendSpan.js.map +0 -1
- package/build/cjs/utils/hasSpanStreamingEnabled.js +0 -21
- package/build/cjs/utils/hasSpanStreamingEnabled.js.map +0 -1
- package/build/esm/integrations/spanStreaming.js +0 -52
- package/build/esm/integrations/spanStreaming.js.map +0 -1
- package/build/esm/spans/captureSpan.js +0 -102
- package/build/esm/spans/captureSpan.js.map +0 -1
- package/build/esm/spans/spanBuffer.js +0 -119
- package/build/esm/spans/spanBuffer.js.map +0 -1
- package/build/esm/spans/spanFirstUtils.js +0 -182
- package/build/esm/spans/spanFirstUtils.js.map +0 -1
- package/build/esm/utils/beforeSendSpan.js +0 -33
- package/build/esm/utils/beforeSendSpan.js.map +0 -1
- package/build/esm/utils/hasSpanStreamingEnabled.js +0 -19
- package/build/esm/utils/hasSpanStreamingEnabled.js.map +0 -1
- package/build/types/integrations/spanStreaming.d.ts +0 -11
- package/build/types/integrations/spanStreaming.d.ts.map +0 -1
- package/build/types/spans/captureSpan.d.ts +0 -10
- package/build/types/spans/captureSpan.d.ts.map +0 -1
- package/build/types/spans/spanBuffer.d.ts +0 -35
- package/build/types/spans/spanBuffer.d.ts.map +0 -1
- package/build/types/spans/spanFirstUtils.d.ts +0 -20
- package/build/types/spans/spanFirstUtils.d.ts.map +0 -1
- package/build/types/types-hoist/attributes.d.ts +0 -19
- package/build/types/types-hoist/attributes.d.ts.map +0 -1
- package/build/types/utils/beforeSendSpan.d.ts +0 -22
- package/build/types/utils/beforeSendSpan.d.ts.map +0 -1
- package/build/types/utils/hasSpanStreamingEnabled.d.ts +0 -9
- package/build/types/utils/hasSpanStreamingEnabled.d.ts.map +0 -1
- package/build/types-ts3.8/integrations/spanStreaming.d.ts +0 -11
- package/build/types-ts3.8/spans/captureSpan.d.ts +0 -10
- package/build/types-ts3.8/spans/spanBuffer.d.ts +0 -35
- package/build/types-ts3.8/spans/spanFirstUtils.d.ts +0 -20
- package/build/types-ts3.8/types-hoist/attributes.d.ts +0 -19
- package/build/types-ts3.8/utils/beforeSendSpan.d.ts +0 -22
- package/build/types-ts3.8/utils/hasSpanStreamingEnabled.d.ts +0 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/tracing/vercel-ai/index.ts"],"sourcesContent":["import type { Client } from '../../client';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes';\nimport type { Event } from '../../types-hoist/event';\nimport type { Span, SpanAttributes, SpanAttributeValue, SpanJSON, SpanOrigin } from '../../types-hoist/span';\nimport { spanToJSON } from '../../utils/spanUtils';\nimport {\n GEN_AI_INPUT_MESSAGES_ATTRIBUTE,\n GEN_AI_OPERATION_NAME_ATTRIBUTE,\n GEN_AI_REQUEST_MODEL_ATTRIBUTE,\n GEN_AI_RESPONSE_MODEL_ATTRIBUTE,\n GEN_AI_TOOL_CALL_ID_ATTRIBUTE,\n GEN_AI_TOOL_INPUT_ATTRIBUTE,\n GEN_AI_TOOL_NAME_ATTRIBUTE,\n GEN_AI_TOOL_OUTPUT_ATTRIBUTE,\n GEN_AI_TOOL_TYPE_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS_CACHE_WRITE_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE,\n GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,\n} from '../ai/gen-ai-attributes';\nimport { EMBEDDINGS_OPS, GENERATE_CONTENT_OPS, INVOKE_AGENT_OPS, RERANK_OPS, toolCallSpanMap } from './constants';\nimport type { TokenSummary } from './types';\nimport {\n accumulateTokensForParent,\n applyAccumulatedTokens,\n convertAvailableToolsToJsonString,\n getSpanOpFromName,\n requestMessagesFromPrompt,\n} from './utils';\nimport type { OpenAiProviderMetadata, ProviderMetadata } from './vercel-ai-attributes';\nimport {\n AI_MODEL_ID_ATTRIBUTE,\n AI_OPERATION_ID_ATTRIBUTE,\n AI_PROMPT_MESSAGES_ATTRIBUTE,\n AI_PROMPT_TOOLS_ATTRIBUTE,\n AI_RESPONSE_OBJECT_ATTRIBUTE,\n AI_RESPONSE_PROVIDER_METADATA_ATTRIBUTE,\n AI_RESPONSE_TEXT_ATTRIBUTE,\n AI_RESPONSE_TOOL_CALLS_ATTRIBUTE,\n AI_SCHEMA_ATTRIBUTE,\n AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE,\n AI_TOOL_CALL_ARGS_ATTRIBUTE,\n AI_TOOL_CALL_ID_ATTRIBUTE,\n AI_TOOL_CALL_NAME_ATTRIBUTE,\n AI_TOOL_CALL_RESULT_ATTRIBUTE,\n AI_USAGE_CACHED_INPUT_TOKENS_ATTRIBUTE,\n AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE,\n AI_USAGE_PROMPT_TOKENS_ATTRIBUTE,\n OPERATION_NAME_ATTRIBUTE,\n} from './vercel-ai-attributes';\n\nfunction addOriginToSpan(span: Span, origin: SpanOrigin): void {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);\n}\n\n/**\n * Maps Vercel AI SDK operation names to OpenTelemetry semantic convention values\n * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/#llm-request-spans\n */\nfunction mapVercelAiOperationName(operationName: string): string {\n // Top-level pipeline operations map to invoke_agent\n if (INVOKE_AGENT_OPS.has(operationName)) {\n return 'invoke_agent';\n }\n // .do* operations are the actual LLM calls\n if (GENERATE_CONTENT_OPS.has(operationName)) {\n return 'generate_content';\n }\n if (EMBEDDINGS_OPS.has(operationName)) {\n return 'embeddings';\n }\n if (RERANK_OPS.has(operationName)) {\n return 'rerank';\n }\n if (operationName === 'ai.toolCall') {\n return 'execute_tool';\n }\n // Return the original value for unknown operations\n return operationName;\n}\n\n/**\n * Post-process spans emitted by the Vercel AI SDK.\n * This is supposed to be used in `client.on('spanStart', ...)\n */\nfunction onVercelAiSpanStart(span: Span): void {\n const { data: attributes, description: name } = spanToJSON(span);\n\n if (!name) {\n return;\n }\n\n // Tool call spans\n // https://ai-sdk.dev/docs/ai-sdk-core/telemetry#tool-call-spans\n if (attributes[AI_TOOL_CALL_NAME_ATTRIBUTE] && attributes[AI_TOOL_CALL_ID_ATTRIBUTE] && name === 'ai.toolCall') {\n processToolCallSpan(span, attributes);\n return;\n }\n\n // V6+ Check if this is a Vercel AI span by checking if the operation ID attribute is present.\n // V5+ Check if this is a Vercel AI span by name pattern.\n if (!attributes[AI_OPERATION_ID_ATTRIBUTE] && !name.startsWith('ai.')) {\n return;\n }\n\n processGenerateSpan(span, name, attributes);\n}\n\n// TODO (span-streaming): move to client hook. What to do about parent modifications?\nfunction vercelAiEventProcessor(event: Event): Event {\n if (event.type === 'transaction' && event.spans) {\n // Map to accumulate token data by parent span ID\n const tokenAccumulator: Map<string, TokenSummary> = new Map();\n\n // First pass: process all spans and accumulate token data\n for (const span of event.spans) {\n processEndedVercelAiSpan(span);\n\n // Accumulate token data for parent spans\n accumulateTokensForParent(span, tokenAccumulator);\n }\n\n // Second pass: apply accumulated token data to parent spans\n for (const span of event.spans) {\n if (span.op !== 'gen_ai.invoke_agent') {\n continue;\n }\n\n applyAccumulatedTokens(span, tokenAccumulator);\n }\n\n // Also apply to root when it is the invoke_agent pipeline\n const trace = event.contexts?.trace;\n if (trace && trace.op === 'gen_ai.invoke_agent') {\n applyAccumulatedTokens(trace, tokenAccumulator);\n }\n }\n\n return event;\n}\n/**\n * Post-process spans emitted by the Vercel AI SDK.\n */\nfunction processEndedVercelAiSpan(span: SpanJSON): void {\n const { data: attributes, origin } = span;\n\n if (origin !== 'auto.vercelai.otel') {\n return;\n }\n\n renameAttributeKey(attributes, AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE, GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE);\n renameAttributeKey(attributes, AI_USAGE_PROMPT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE);\n renameAttributeKey(attributes, AI_USAGE_CACHED_INPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE);\n\n // Parent spans (ai.streamText, ai.streamObject, etc.) use inputTokens/outputTokens instead of promptTokens/completionTokens\n renameAttributeKey(attributes, 'ai.usage.inputTokens', GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE);\n renameAttributeKey(attributes, 'ai.usage.outputTokens', GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE);\n\n // AI SDK uses avgOutputTokensPerSecond, map to our expected attribute name\n renameAttributeKey(attributes, 'ai.response.avgOutputTokensPerSecond', 'ai.response.avgCompletionTokensPerSecond');\n\n // Input tokens is the sum of prompt tokens and cached input tokens\n if (\n typeof attributes[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] === 'number' &&\n typeof attributes[GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE] === 'number'\n ) {\n attributes[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] =\n attributes[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] + attributes[GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE];\n }\n\n if (\n typeof attributes[GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE] === 'number' &&\n typeof attributes[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] === 'number'\n ) {\n attributes[GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE] =\n attributes[GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE] + attributes[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE];\n }\n\n // Convert the available tools array to a JSON string\n if (attributes[AI_PROMPT_TOOLS_ATTRIBUTE] && Array.isArray(attributes[AI_PROMPT_TOOLS_ATTRIBUTE])) {\n attributes[AI_PROMPT_TOOLS_ATTRIBUTE] = convertAvailableToolsToJsonString(\n attributes[AI_PROMPT_TOOLS_ATTRIBUTE] as unknown[],\n );\n }\n\n // Rename AI SDK attributes to standardized gen_ai attributes\n // Map operation.name to OpenTelemetry semantic convention values\n if (attributes[OPERATION_NAME_ATTRIBUTE]) {\n const operationName = mapVercelAiOperationName(attributes[OPERATION_NAME_ATTRIBUTE] as string);\n attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE] = operationName;\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete attributes[OPERATION_NAME_ATTRIBUTE];\n }\n renameAttributeKey(attributes, AI_PROMPT_MESSAGES_ATTRIBUTE, GEN_AI_INPUT_MESSAGES_ATTRIBUTE);\n renameAttributeKey(attributes, AI_RESPONSE_TEXT_ATTRIBUTE, 'gen_ai.response.text');\n renameAttributeKey(attributes, AI_RESPONSE_TOOL_CALLS_ATTRIBUTE, 'gen_ai.response.tool_calls');\n renameAttributeKey(attributes, AI_RESPONSE_OBJECT_ATTRIBUTE, 'gen_ai.response.object');\n renameAttributeKey(attributes, AI_PROMPT_TOOLS_ATTRIBUTE, 'gen_ai.request.available_tools');\n\n renameAttributeKey(attributes, AI_TOOL_CALL_ARGS_ATTRIBUTE, GEN_AI_TOOL_INPUT_ATTRIBUTE);\n renameAttributeKey(attributes, AI_TOOL_CALL_RESULT_ATTRIBUTE, GEN_AI_TOOL_OUTPUT_ATTRIBUTE);\n\n renameAttributeKey(attributes, AI_SCHEMA_ATTRIBUTE, 'gen_ai.request.schema');\n renameAttributeKey(attributes, AI_MODEL_ID_ATTRIBUTE, GEN_AI_REQUEST_MODEL_ATTRIBUTE);\n\n addProviderMetadataToAttributes(attributes);\n\n // Change attributes namespaced with `ai.X` to `vercel.ai.X`\n for (const key of Object.keys(attributes)) {\n if (key.startsWith('ai.')) {\n renameAttributeKey(attributes, key, `vercel.${key}`);\n }\n }\n}\n\n/**\n * Renames an attribute key in the provided attributes object if the old key exists.\n * This function safely handles null and undefined values.\n */\nfunction renameAttributeKey(attributes: Record<string, unknown>, oldKey: string, newKey: string): void {\n if (attributes[oldKey] != null) {\n attributes[newKey] = attributes[oldKey];\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete attributes[oldKey];\n }\n}\n\nfunction processToolCallSpan(span: Span, attributes: SpanAttributes): void {\n addOriginToSpan(span, 'auto.vercelai.otel');\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'gen_ai.execute_tool');\n span.setAttribute(GEN_AI_OPERATION_NAME_ATTRIBUTE, 'execute_tool');\n renameAttributeKey(attributes, AI_TOOL_CALL_NAME_ATTRIBUTE, GEN_AI_TOOL_NAME_ATTRIBUTE);\n renameAttributeKey(attributes, AI_TOOL_CALL_ID_ATTRIBUTE, GEN_AI_TOOL_CALL_ID_ATTRIBUTE);\n\n // Store the span in our global map using the tool call ID\n // This allows us to capture tool errors and link them to the correct span\n const toolCallId = attributes[GEN_AI_TOOL_CALL_ID_ATTRIBUTE];\n\n if (typeof toolCallId === 'string') {\n toolCallSpanMap.set(toolCallId, span);\n }\n\n // https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-tool-type\n if (!attributes[GEN_AI_TOOL_TYPE_ATTRIBUTE]) {\n span.setAttribute(GEN_AI_TOOL_TYPE_ATTRIBUTE, 'function');\n }\n const toolName = attributes[GEN_AI_TOOL_NAME_ATTRIBUTE];\n if (toolName) {\n span.updateName(`execute_tool ${toolName}`);\n }\n}\n\nfunction processGenerateSpan(span: Span, name: string, attributes: SpanAttributes): void {\n addOriginToSpan(span, 'auto.vercelai.otel');\n\n const nameWthoutAi = name.replace('ai.', '');\n span.setAttribute('ai.pipeline.name', nameWthoutAi);\n span.updateName(nameWthoutAi);\n\n // If a telemetry name is set and the span represents a pipeline, use it as the operation name.\n // This name can be set at the request level by adding `experimental_telemetry.functionId`.\n const functionId = attributes[AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE];\n if (functionId && typeof functionId === 'string') {\n span.updateName(`${nameWthoutAi} ${functionId}`);\n span.setAttribute('gen_ai.function_id', functionId);\n }\n\n requestMessagesFromPrompt(span, attributes);\n\n if (attributes[AI_MODEL_ID_ATTRIBUTE] && !attributes[GEN_AI_RESPONSE_MODEL_ATTRIBUTE]) {\n span.setAttribute(GEN_AI_RESPONSE_MODEL_ATTRIBUTE, attributes[AI_MODEL_ID_ATTRIBUTE]);\n }\n span.setAttribute('ai.streaming', name.includes('stream'));\n\n // Set the op based on the span name\n const op = getSpanOpFromName(name);\n if (op) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, op);\n }\n\n // Update span names for .do* spans to include the model ID (only if model ID exists)\n const modelId = attributes[AI_MODEL_ID_ATTRIBUTE];\n if (modelId) {\n switch (name) {\n case 'ai.generateText.doGenerate':\n span.updateName(`generate_text ${modelId}`);\n break;\n case 'ai.streamText.doStream':\n span.updateName(`stream_text ${modelId}`);\n break;\n case 'ai.generateObject.doGenerate':\n span.updateName(`generate_object ${modelId}`);\n break;\n case 'ai.streamObject.doStream':\n span.updateName(`stream_object ${modelId}`);\n break;\n case 'ai.embed.doEmbed':\n span.updateName(`embed ${modelId}`);\n break;\n case 'ai.embedMany.doEmbed':\n span.updateName(`embed_many ${modelId}`);\n break;\n case 'ai.rerank.doRerank':\n span.updateName(`rerank ${modelId}`);\n break;\n }\n }\n}\n\n/**\n * Add event processors to the given client to process Vercel AI spans.\n */\nexport function addVercelAiProcessors(client: Client): void {\n client.on('spanStart', onVercelAiSpanStart);\n // Note: We cannot do this on `spanEnd`, because the span cannot be mutated anymore at this point\n client.addEventProcessor(Object.assign(vercelAiEventProcessor, { id: 'VercelAiEventProcessor' }));\n}\n\nfunction addProviderMetadataToAttributes(attributes: SpanAttributes): void {\n const providerMetadata = attributes[AI_RESPONSE_PROVIDER_METADATA_ATTRIBUTE] as string | undefined;\n if (providerMetadata) {\n try {\n const providerMetadataObject = JSON.parse(providerMetadata) as ProviderMetadata;\n\n // Handle OpenAI metadata (v5 uses 'openai', v6 Azure Responses API uses 'azure')\n const openaiMetadata: OpenAiProviderMetadata | undefined =\n providerMetadataObject.openai ?? providerMetadataObject.azure;\n if (openaiMetadata) {\n setAttributeIfDefined(\n attributes,\n GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE,\n openaiMetadata.cachedPromptTokens,\n );\n setAttributeIfDefined(attributes, 'gen_ai.usage.output_tokens.reasoning', openaiMetadata.reasoningTokens);\n setAttributeIfDefined(\n attributes,\n 'gen_ai.usage.output_tokens.prediction_accepted',\n openaiMetadata.acceptedPredictionTokens,\n );\n setAttributeIfDefined(\n attributes,\n 'gen_ai.usage.output_tokens.prediction_rejected',\n openaiMetadata.rejectedPredictionTokens,\n );\n setAttributeIfDefined(attributes, 'gen_ai.conversation.id', openaiMetadata.responseId);\n }\n\n if (providerMetadataObject.anthropic) {\n const cachedInputTokens =\n providerMetadataObject.anthropic.usage?.cache_read_input_tokens ??\n providerMetadataObject.anthropic.cacheReadInputTokens;\n setAttributeIfDefined(attributes, GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE, cachedInputTokens);\n\n const cacheWriteInputTokens =\n providerMetadataObject.anthropic.usage?.cache_creation_input_tokens ??\n providerMetadataObject.anthropic.cacheCreationInputTokens;\n setAttributeIfDefined(attributes, GEN_AI_USAGE_INPUT_TOKENS_CACHE_WRITE_ATTRIBUTE, cacheWriteInputTokens);\n }\n\n if (providerMetadataObject.bedrock?.usage) {\n setAttributeIfDefined(\n attributes,\n GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE,\n providerMetadataObject.bedrock.usage.cacheReadInputTokens,\n );\n setAttributeIfDefined(\n attributes,\n GEN_AI_USAGE_INPUT_TOKENS_CACHE_WRITE_ATTRIBUTE,\n providerMetadataObject.bedrock.usage.cacheWriteInputTokens,\n );\n }\n\n if (providerMetadataObject.deepseek) {\n setAttributeIfDefined(\n attributes,\n GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE,\n providerMetadataObject.deepseek.promptCacheHitTokens,\n );\n setAttributeIfDefined(\n attributes,\n 'gen_ai.usage.input_tokens.cache_miss',\n providerMetadataObject.deepseek.promptCacheMissTokens,\n );\n }\n } catch {\n // Ignore\n }\n }\n}\n\n/**\n * Sets an attribute only if the value is not null or undefined.\n */\nfunction setAttributeIfDefined(attributes: SpanAttributes, key: string, value: SpanAttributeValue | undefined): void {\n if (value != null) {\n attributes[key] = value;\n }\n}\n"],"names":["SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","INVOKE_AGENT_OPS","GENERATE_CONTENT_OPS","EMBEDDINGS_OPS","RERANK_OPS","spanToJSON","AI_TOOL_CALL_NAME_ATTRIBUTE","AI_TOOL_CALL_ID_ATTRIBUTE","AI_OPERATION_ID_ATTRIBUTE","accumulateTokensForParent","applyAccumulatedTokens","AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE","GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE","AI_USAGE_PROMPT_TOKENS_ATTRIBUTE","GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE","AI_USAGE_CACHED_INPUT_TOKENS_ATTRIBUTE","GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE","GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE","AI_PROMPT_TOOLS_ATTRIBUTE","convertAvailableToolsToJsonString","OPERATION_NAME_ATTRIBUTE","GEN_AI_OPERATION_NAME_ATTRIBUTE","AI_PROMPT_MESSAGES_ATTRIBUTE","GEN_AI_INPUT_MESSAGES_ATTRIBUTE","AI_RESPONSE_TEXT_ATTRIBUTE","AI_RESPONSE_TOOL_CALLS_ATTRIBUTE","AI_RESPONSE_OBJECT_ATTRIBUTE","AI_TOOL_CALL_ARGS_ATTRIBUTE","GEN_AI_TOOL_INPUT_ATTRIBUTE","AI_TOOL_CALL_RESULT_ATTRIBUTE","GEN_AI_TOOL_OUTPUT_ATTRIBUTE","AI_SCHEMA_ATTRIBUTE","AI_MODEL_ID_ATTRIBUTE","GEN_AI_REQUEST_MODEL_ATTRIBUTE","SEMANTIC_ATTRIBUTE_SENTRY_OP","GEN_AI_TOOL_NAME_ATTRIBUTE","GEN_AI_TOOL_CALL_ID_ATTRIBUTE","toolCallSpanMap","GEN_AI_TOOL_TYPE_ATTRIBUTE","AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE","requestMessagesFromPrompt","GEN_AI_RESPONSE_MODEL_ATTRIBUTE","getSpanOpFromName","AI_RESPONSE_PROVIDER_METADATA_ATTRIBUTE","GEN_AI_USAGE_INPUT_TOKENS_CACHE_WRITE_ATTRIBUTE"],"mappings":";;;;;;;;;AAoDA,SAAS,eAAe,CAAC,IAAI,EAAQ,MAAM,EAAoB;AAC/D,EAAE,IAAI,CAAC,YAAY,CAACA,mDAAgC,EAAE,MAAM,CAAC;AAC7D;;AAEA;AACA;AACA;AACA;AACA,SAAS,wBAAwB,CAAC,aAAa,EAAkB;AACjE;AACA,EAAE,IAAIC,0BAAgB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;AAC3C,IAAI,OAAO,cAAc;AACzB,EAAE;AACF;AACA,EAAE,IAAIC,8BAAoB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;AAC/C,IAAI,OAAO,kBAAkB;AAC7B,EAAE;AACF,EAAE,IAAIC,wBAAc,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;AACzC,IAAI,OAAO,YAAY;AACvB,EAAE;AACF,EAAE,IAAIC,oBAAU,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;AACrC,IAAI,OAAO,QAAQ;AACnB,EAAE;AACF,EAAE,IAAI,aAAA,KAAkB,aAAa,EAAE;AACvC,IAAI,OAAO,cAAc;AACzB,EAAE;AACF;AACA,EAAE,OAAO,aAAa;AACtB;;AAEA;AACA;AACA;AACA;AACA,SAAS,mBAAmB,CAAC,IAAI,EAAc;AAC/C,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAA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QAAA,qBAAA;AACA,UAAA,UAAA;AACA,UAAA4B,+DAAA;AACA,UAAA,sBAAA,CAAA,OAAA,CAAA,KAAA,CAAA,qBAAA;AACA,SAAA;AACA,MAAA;;AAEA,MAAA,IAAA,sBAAA,CAAA,QAAA,EAAA;AACA,QAAA,qBAAA;AACA,UAAA,UAAA;AACA,UAAA5B,0DAAA;AACA,UAAA,sBAAA,CAAA,QAAA,CAAA,oBAAA;AACA,SAAA;AACA,QAAA,qBAAA;AACA,UAAA,UAAA;AACA,UAAA,sCAAA;AACA,UAAA,sBAAA,CAAA,QAAA,CAAA,qBAAA;AACA,SAAA;AACA,MAAA;AACA,IAAA,CAAA,CAAA,MAAA;AACA;AACA,IAAA;AACA,EAAA;AACA;;AAEA;AACA;AACA;AACA,SAAA,qBAAA,CAAA,UAAA,EAAA,GAAA,EAAA,KAAA,EAAA;AACA,EAAA,IAAA,KAAA,IAAA,IAAA,EAAA;AACA,IAAA,UAAA,CAAA,GAAA,CAAA,GAAA,KAAA;AACA,EAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/tracing/vercel-ai/index.ts"],"sourcesContent":["import type { Client } from '../../client';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes';\nimport type { Event } from '../../types-hoist/event';\nimport type { Span, SpanAttributes, SpanAttributeValue, SpanJSON, SpanOrigin } from '../../types-hoist/span';\nimport { spanToJSON } from '../../utils/spanUtils';\nimport {\n GEN_AI_INPUT_MESSAGES_ATTRIBUTE,\n GEN_AI_OPERATION_NAME_ATTRIBUTE,\n GEN_AI_REQUEST_MODEL_ATTRIBUTE,\n GEN_AI_RESPONSE_MODEL_ATTRIBUTE,\n GEN_AI_TOOL_CALL_ID_ATTRIBUTE,\n GEN_AI_TOOL_INPUT_ATTRIBUTE,\n GEN_AI_TOOL_NAME_ATTRIBUTE,\n GEN_AI_TOOL_OUTPUT_ATTRIBUTE,\n GEN_AI_TOOL_TYPE_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS_CACHE_WRITE_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE,\n GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,\n} from '../ai/gen-ai-attributes';\nimport { EMBEDDINGS_OPS, GENERATE_CONTENT_OPS, INVOKE_AGENT_OPS, RERANK_OPS, toolCallSpanMap } from './constants';\nimport type { TokenSummary } from './types';\nimport {\n accumulateTokensForParent,\n applyAccumulatedTokens,\n convertAvailableToolsToJsonString,\n getSpanOpFromName,\n requestMessagesFromPrompt,\n} from './utils';\nimport type { OpenAiProviderMetadata, ProviderMetadata } from './vercel-ai-attributes';\nimport {\n AI_MODEL_ID_ATTRIBUTE,\n AI_OPERATION_ID_ATTRIBUTE,\n AI_PROMPT_MESSAGES_ATTRIBUTE,\n AI_PROMPT_TOOLS_ATTRIBUTE,\n AI_RESPONSE_OBJECT_ATTRIBUTE,\n AI_RESPONSE_PROVIDER_METADATA_ATTRIBUTE,\n AI_RESPONSE_TEXT_ATTRIBUTE,\n AI_RESPONSE_TOOL_CALLS_ATTRIBUTE,\n AI_SCHEMA_ATTRIBUTE,\n AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE,\n AI_TOOL_CALL_ARGS_ATTRIBUTE,\n AI_TOOL_CALL_ID_ATTRIBUTE,\n AI_TOOL_CALL_NAME_ATTRIBUTE,\n AI_TOOL_CALL_RESULT_ATTRIBUTE,\n AI_USAGE_CACHED_INPUT_TOKENS_ATTRIBUTE,\n AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE,\n AI_USAGE_PROMPT_TOKENS_ATTRIBUTE,\n OPERATION_NAME_ATTRIBUTE,\n} from './vercel-ai-attributes';\n\nfunction addOriginToSpan(span: Span, origin: SpanOrigin): void {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);\n}\n\n/**\n * Maps Vercel AI SDK operation names to OpenTelemetry semantic convention values\n * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/#llm-request-spans\n */\nfunction mapVercelAiOperationName(operationName: string): string {\n // Top-level pipeline operations map to invoke_agent\n if (INVOKE_AGENT_OPS.has(operationName)) {\n return 'invoke_agent';\n }\n // .do* operations are the actual LLM calls\n if (GENERATE_CONTENT_OPS.has(operationName)) {\n return 'generate_content';\n }\n if (EMBEDDINGS_OPS.has(operationName)) {\n return 'embeddings';\n }\n if (RERANK_OPS.has(operationName)) {\n return 'rerank';\n }\n if (operationName === 'ai.toolCall') {\n return 'execute_tool';\n }\n // Return the original value for unknown operations\n return operationName;\n}\n\n/**\n * Post-process spans emitted by the Vercel AI SDK.\n * This is supposed to be used in `client.on('spanStart', ...)\n */\nfunction onVercelAiSpanStart(span: Span): void {\n const { data: attributes, description: name } = spanToJSON(span);\n\n if (!name) {\n return;\n }\n\n // Tool call spans\n // https://ai-sdk.dev/docs/ai-sdk-core/telemetry#tool-call-spans\n if (attributes[AI_TOOL_CALL_NAME_ATTRIBUTE] && attributes[AI_TOOL_CALL_ID_ATTRIBUTE] && name === 'ai.toolCall') {\n processToolCallSpan(span, attributes);\n return;\n }\n\n // V6+ Check if this is a Vercel AI span by checking if the operation ID attribute is present.\n // V5+ Check if this is a Vercel AI span by name pattern.\n if (!attributes[AI_OPERATION_ID_ATTRIBUTE] && !name.startsWith('ai.')) {\n return;\n }\n\n processGenerateSpan(span, name, attributes);\n}\n\nfunction vercelAiEventProcessor(event: Event): Event {\n if (event.type === 'transaction' && event.spans) {\n // Map to accumulate token data by parent span ID\n const tokenAccumulator: Map<string, TokenSummary> = new Map();\n\n // First pass: process all spans and accumulate token data\n for (const span of event.spans) {\n processEndedVercelAiSpan(span);\n\n // Accumulate token data for parent spans\n accumulateTokensForParent(span, tokenAccumulator);\n }\n\n // Second pass: apply accumulated token data to parent spans\n for (const span of event.spans) {\n if (span.op !== 'gen_ai.invoke_agent') {\n continue;\n }\n\n applyAccumulatedTokens(span, tokenAccumulator);\n }\n\n // Also apply to root when it is the invoke_agent pipeline\n const trace = event.contexts?.trace;\n if (trace && trace.op === 'gen_ai.invoke_agent') {\n applyAccumulatedTokens(trace, tokenAccumulator);\n }\n }\n\n return event;\n}\n/**\n * Post-process spans emitted by the Vercel AI SDK.\n */\nfunction processEndedVercelAiSpan(span: SpanJSON): void {\n const { data: attributes, origin } = span;\n\n if (origin !== 'auto.vercelai.otel') {\n return;\n }\n\n renameAttributeKey(attributes, AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE, GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE);\n renameAttributeKey(attributes, AI_USAGE_PROMPT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE);\n renameAttributeKey(attributes, AI_USAGE_CACHED_INPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE);\n\n // Parent spans (ai.streamText, ai.streamObject, etc.) use inputTokens/outputTokens instead of promptTokens/completionTokens\n renameAttributeKey(attributes, 'ai.usage.inputTokens', GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE);\n renameAttributeKey(attributes, 'ai.usage.outputTokens', GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE);\n\n // AI SDK uses avgOutputTokensPerSecond, map to our expected attribute name\n renameAttributeKey(attributes, 'ai.response.avgOutputTokensPerSecond', 'ai.response.avgCompletionTokensPerSecond');\n\n // Input tokens is the sum of prompt tokens and cached input tokens\n if (\n typeof attributes[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] === 'number' &&\n typeof attributes[GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE] === 'number'\n ) {\n attributes[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] =\n attributes[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] + attributes[GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE];\n }\n\n if (\n typeof attributes[GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE] === 'number' &&\n typeof attributes[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] === 'number'\n ) {\n attributes[GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE] =\n attributes[GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE] + attributes[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE];\n }\n\n // Convert the available tools array to a JSON string\n if (attributes[AI_PROMPT_TOOLS_ATTRIBUTE] && Array.isArray(attributes[AI_PROMPT_TOOLS_ATTRIBUTE])) {\n attributes[AI_PROMPT_TOOLS_ATTRIBUTE] = convertAvailableToolsToJsonString(\n attributes[AI_PROMPT_TOOLS_ATTRIBUTE] as unknown[],\n );\n }\n\n // Rename AI SDK attributes to standardized gen_ai attributes\n // Map operation.name to OpenTelemetry semantic convention values\n if (attributes[OPERATION_NAME_ATTRIBUTE]) {\n const operationName = mapVercelAiOperationName(attributes[OPERATION_NAME_ATTRIBUTE] as string);\n attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE] = operationName;\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete attributes[OPERATION_NAME_ATTRIBUTE];\n }\n renameAttributeKey(attributes, AI_PROMPT_MESSAGES_ATTRIBUTE, GEN_AI_INPUT_MESSAGES_ATTRIBUTE);\n renameAttributeKey(attributes, AI_RESPONSE_TEXT_ATTRIBUTE, 'gen_ai.response.text');\n renameAttributeKey(attributes, AI_RESPONSE_TOOL_CALLS_ATTRIBUTE, 'gen_ai.response.tool_calls');\n renameAttributeKey(attributes, AI_RESPONSE_OBJECT_ATTRIBUTE, 'gen_ai.response.object');\n renameAttributeKey(attributes, AI_PROMPT_TOOLS_ATTRIBUTE, 'gen_ai.request.available_tools');\n\n renameAttributeKey(attributes, AI_TOOL_CALL_ARGS_ATTRIBUTE, GEN_AI_TOOL_INPUT_ATTRIBUTE);\n renameAttributeKey(attributes, AI_TOOL_CALL_RESULT_ATTRIBUTE, GEN_AI_TOOL_OUTPUT_ATTRIBUTE);\n\n renameAttributeKey(attributes, AI_SCHEMA_ATTRIBUTE, 'gen_ai.request.schema');\n renameAttributeKey(attributes, AI_MODEL_ID_ATTRIBUTE, GEN_AI_REQUEST_MODEL_ATTRIBUTE);\n\n addProviderMetadataToAttributes(attributes);\n\n // Change attributes namespaced with `ai.X` to `vercel.ai.X`\n for (const key of Object.keys(attributes)) {\n if (key.startsWith('ai.')) {\n renameAttributeKey(attributes, key, `vercel.${key}`);\n }\n }\n}\n\n/**\n * Renames an attribute key in the provided attributes object if the old key exists.\n * This function safely handles null and undefined values.\n */\nfunction renameAttributeKey(attributes: Record<string, unknown>, oldKey: string, newKey: string): void {\n if (attributes[oldKey] != null) {\n attributes[newKey] = attributes[oldKey];\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete attributes[oldKey];\n }\n}\n\nfunction processToolCallSpan(span: Span, attributes: SpanAttributes): void {\n addOriginToSpan(span, 'auto.vercelai.otel');\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'gen_ai.execute_tool');\n span.setAttribute(GEN_AI_OPERATION_NAME_ATTRIBUTE, 'execute_tool');\n renameAttributeKey(attributes, AI_TOOL_CALL_NAME_ATTRIBUTE, GEN_AI_TOOL_NAME_ATTRIBUTE);\n renameAttributeKey(attributes, AI_TOOL_CALL_ID_ATTRIBUTE, GEN_AI_TOOL_CALL_ID_ATTRIBUTE);\n\n // Store the span in our global map using the tool call ID\n // This allows us to capture tool errors and link them to the correct span\n const toolCallId = attributes[GEN_AI_TOOL_CALL_ID_ATTRIBUTE];\n\n if (typeof toolCallId === 'string') {\n toolCallSpanMap.set(toolCallId, span);\n }\n\n // https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-tool-type\n if (!attributes[GEN_AI_TOOL_TYPE_ATTRIBUTE]) {\n span.setAttribute(GEN_AI_TOOL_TYPE_ATTRIBUTE, 'function');\n }\n const toolName = attributes[GEN_AI_TOOL_NAME_ATTRIBUTE];\n if (toolName) {\n span.updateName(`execute_tool ${toolName}`);\n }\n}\n\nfunction processGenerateSpan(span: Span, name: string, attributes: SpanAttributes): void {\n addOriginToSpan(span, 'auto.vercelai.otel');\n\n const nameWthoutAi = name.replace('ai.', '');\n span.setAttribute('ai.pipeline.name', nameWthoutAi);\n span.updateName(nameWthoutAi);\n\n // If a telemetry name is set and the span represents a pipeline, use it as the operation name.\n // This name can be set at the request level by adding `experimental_telemetry.functionId`.\n const functionId = attributes[AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE];\n if (functionId && typeof functionId === 'string') {\n span.updateName(`${nameWthoutAi} ${functionId}`);\n span.setAttribute('gen_ai.function_id', functionId);\n }\n\n requestMessagesFromPrompt(span, attributes);\n\n if (attributes[AI_MODEL_ID_ATTRIBUTE] && !attributes[GEN_AI_RESPONSE_MODEL_ATTRIBUTE]) {\n span.setAttribute(GEN_AI_RESPONSE_MODEL_ATTRIBUTE, attributes[AI_MODEL_ID_ATTRIBUTE]);\n }\n span.setAttribute('ai.streaming', name.includes('stream'));\n\n // Set the op based on the span name\n const op = getSpanOpFromName(name);\n if (op) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, op);\n }\n\n // Update span names for .do* spans to include the model ID (only if model ID exists)\n const modelId = attributes[AI_MODEL_ID_ATTRIBUTE];\n if (modelId) {\n switch (name) {\n case 'ai.generateText.doGenerate':\n span.updateName(`generate_text ${modelId}`);\n break;\n case 'ai.streamText.doStream':\n span.updateName(`stream_text ${modelId}`);\n break;\n case 'ai.generateObject.doGenerate':\n span.updateName(`generate_object ${modelId}`);\n break;\n case 'ai.streamObject.doStream':\n span.updateName(`stream_object ${modelId}`);\n break;\n case 'ai.embed.doEmbed':\n span.updateName(`embed ${modelId}`);\n break;\n case 'ai.embedMany.doEmbed':\n span.updateName(`embed_many ${modelId}`);\n break;\n case 'ai.rerank.doRerank':\n span.updateName(`rerank ${modelId}`);\n break;\n }\n }\n}\n\n/**\n * Add event processors to the given client to process Vercel AI spans.\n */\nexport function addVercelAiProcessors(client: Client): void {\n client.on('spanStart', onVercelAiSpanStart);\n // Note: We cannot do this on `spanEnd`, because the span cannot be mutated anymore at this point\n client.addEventProcessor(Object.assign(vercelAiEventProcessor, { id: 'VercelAiEventProcessor' }));\n}\n\nfunction addProviderMetadataToAttributes(attributes: SpanAttributes): void {\n const providerMetadata = attributes[AI_RESPONSE_PROVIDER_METADATA_ATTRIBUTE] as string | undefined;\n if (providerMetadata) {\n try {\n const providerMetadataObject = JSON.parse(providerMetadata) as ProviderMetadata;\n\n // Handle OpenAI metadata (v5 uses 'openai', v6 Azure Responses API uses 'azure')\n const openaiMetadata: OpenAiProviderMetadata | undefined =\n providerMetadataObject.openai ?? providerMetadataObject.azure;\n if (openaiMetadata) {\n setAttributeIfDefined(\n attributes,\n GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE,\n openaiMetadata.cachedPromptTokens,\n );\n setAttributeIfDefined(attributes, 'gen_ai.usage.output_tokens.reasoning', openaiMetadata.reasoningTokens);\n setAttributeIfDefined(\n attributes,\n 'gen_ai.usage.output_tokens.prediction_accepted',\n openaiMetadata.acceptedPredictionTokens,\n );\n setAttributeIfDefined(\n attributes,\n 'gen_ai.usage.output_tokens.prediction_rejected',\n openaiMetadata.rejectedPredictionTokens,\n );\n setAttributeIfDefined(attributes, 'gen_ai.conversation.id', openaiMetadata.responseId);\n }\n\n if (providerMetadataObject.anthropic) {\n const cachedInputTokens =\n providerMetadataObject.anthropic.usage?.cache_read_input_tokens ??\n providerMetadataObject.anthropic.cacheReadInputTokens;\n setAttributeIfDefined(attributes, GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE, cachedInputTokens);\n\n const cacheWriteInputTokens =\n providerMetadataObject.anthropic.usage?.cache_creation_input_tokens ??\n providerMetadataObject.anthropic.cacheCreationInputTokens;\n setAttributeIfDefined(attributes, GEN_AI_USAGE_INPUT_TOKENS_CACHE_WRITE_ATTRIBUTE, cacheWriteInputTokens);\n }\n\n if (providerMetadataObject.bedrock?.usage) {\n setAttributeIfDefined(\n attributes,\n GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE,\n providerMetadataObject.bedrock.usage.cacheReadInputTokens,\n );\n setAttributeIfDefined(\n attributes,\n GEN_AI_USAGE_INPUT_TOKENS_CACHE_WRITE_ATTRIBUTE,\n providerMetadataObject.bedrock.usage.cacheWriteInputTokens,\n );\n }\n\n if (providerMetadataObject.deepseek) {\n setAttributeIfDefined(\n attributes,\n GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE,\n providerMetadataObject.deepseek.promptCacheHitTokens,\n );\n setAttributeIfDefined(\n attributes,\n 'gen_ai.usage.input_tokens.cache_miss',\n providerMetadataObject.deepseek.promptCacheMissTokens,\n );\n }\n } catch {\n // Ignore\n }\n }\n}\n\n/**\n * Sets an attribute only if the value is not null or undefined.\n */\nfunction setAttributeIfDefined(attributes: SpanAttributes, key: string, value: SpanAttributeValue | undefined): void {\n if (value != null) {\n attributes[key] = value;\n }\n}\n"],"names":["SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","INVOKE_AGENT_OPS","GENERATE_CONTENT_OPS","EMBEDDINGS_OPS","RERANK_OPS","spanToJSON","AI_TOOL_CALL_NAME_ATTRIBUTE","AI_TOOL_CALL_ID_ATTRIBUTE","AI_OPERATION_ID_ATTRIBUTE","accumulateTokensForParent","applyAccumulatedTokens","AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE","GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE","AI_USAGE_PROMPT_TOKENS_ATTRIBUTE","GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE","AI_USAGE_CACHED_INPUT_TOKENS_ATTRIBUTE","GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE","GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE","AI_PROMPT_TOOLS_ATTRIBUTE","convertAvailableToolsToJsonString","OPERATION_NAME_ATTRIBUTE","GEN_AI_OPERATION_NAME_ATTRIBUTE","AI_PROMPT_MESSAGES_ATTRIBUTE","GEN_AI_INPUT_MESSAGES_ATTRIBUTE","AI_RESPONSE_TEXT_ATTRIBUTE","AI_RESPONSE_TOOL_CALLS_ATTRIBUTE","AI_RESPONSE_OBJECT_ATTRIBUTE","AI_TOOL_CALL_ARGS_ATTRIBUTE","GEN_AI_TOOL_INPUT_ATTRIBUTE","AI_TOOL_CALL_RESULT_ATTRIBUTE","GEN_AI_TOOL_OUTPUT_ATTRIBUTE","AI_SCHEMA_ATTRIBUTE","AI_MODEL_ID_ATTRIBUTE","GEN_AI_REQUEST_MODEL_ATTRIBUTE","SEMANTIC_ATTRIBUTE_SENTRY_OP","GEN_AI_TOOL_NAME_ATTRIBUTE","GEN_AI_TOOL_CALL_ID_ATTRIBUTE","toolCallSpanMap","GEN_AI_TOOL_TYPE_ATTRIBUTE","AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE","requestMessagesFromPrompt","GEN_AI_RESPONSE_MODEL_ATTRIBUTE","getSpanOpFromName","AI_RESPONSE_PROVIDER_METADATA_ATTRIBUTE","GEN_AI_USAGE_INPUT_TOKENS_CACHE_WRITE_ATTRIBUTE"],"mappings":";;;;;;;;;AAoDA,SAAS,eAAe,CAAC,IAAI,EAAQ,MAAM,EAAoB;AAC/D,EAAE,IAAI,CAAC,YAAY,CAACA,mDAAgC,EAAE,MAAM,CAAC;AAC7D;;AAEA;AACA;AACA;AACA;AACA,SAAS,wBAAwB,CAAC,aAAa,EAAkB;AACjE;AACA,EAAE,IAAIC,0BAAgB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;AAC3C,IAAI,OAAO,cAAc;AACzB,EAAE;AACF;AACA,EAAE,IAAIC,8BAAoB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/**
|
|
27
27
|
* Copies feature flags that are in current scope context to the event context
|
|
28
28
|
*/
|
|
29
|
-
// TODO (span-streaming): should flags be added to (segment) spans? If so, probably do this via globally applying context data to spans
|
|
30
29
|
function _INTERNAL_copyFlagsFromScopeToEvent(event) {
|
|
31
30
|
const scope = currentScopes.getCurrentScope();
|
|
32
31
|
const flagContext = scope.getScopeData().contexts.flags;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"featureFlags.js","sources":["../../../src/utils/featureFlags.ts"],"sourcesContent":["import { getCurrentScope } from '../currentScopes';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { type Event } from '../types-hoist/event';\nimport { debug } from './debug-logger';\nimport { getActiveSpan, spanToJSON } from './spanUtils';\n\n/**\n * Ordered LRU cache for storing feature flags in the scope context. The name\n * of each flag in the buffer is unique, and the output of getAll() is ordered\n * from oldest to newest.\n */\n\nexport type FeatureFlag = { readonly flag: string; readonly result: boolean };\n\n/**\n * Max size of the LRU flag buffer stored in Sentry scope and event contexts.\n */\nexport const _INTERNAL_FLAG_BUFFER_SIZE = 100;\n\n/**\n * Max number of flag evaluations to record per span.\n */\nexport const _INTERNAL_MAX_FLAGS_PER_SPAN = 10;\n\nconst SPAN_FLAG_ATTRIBUTE_PREFIX = 'flag.evaluation.';\n\n/**\n * Copies feature flags that are in current scope context to the event context\n */\
|
|
1
|
+
{"version":3,"file":"featureFlags.js","sources":["../../../src/utils/featureFlags.ts"],"sourcesContent":["import { getCurrentScope } from '../currentScopes';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { type Event } from '../types-hoist/event';\nimport { debug } from './debug-logger';\nimport { getActiveSpan, spanToJSON } from './spanUtils';\n\n/**\n * Ordered LRU cache for storing feature flags in the scope context. The name\n * of each flag in the buffer is unique, and the output of getAll() is ordered\n * from oldest to newest.\n */\n\nexport type FeatureFlag = { readonly flag: string; readonly result: boolean };\n\n/**\n * Max size of the LRU flag buffer stored in Sentry scope and event contexts.\n */\nexport const _INTERNAL_FLAG_BUFFER_SIZE = 100;\n\n/**\n * Max number of flag evaluations to record per span.\n */\nexport const _INTERNAL_MAX_FLAGS_PER_SPAN = 10;\n\nconst SPAN_FLAG_ATTRIBUTE_PREFIX = 'flag.evaluation.';\n\n/**\n * Copies feature flags that are in current scope context to the event context\n */\nexport function _INTERNAL_copyFlagsFromScopeToEvent(event: Event): Event {\n const scope = getCurrentScope();\n const flagContext = scope.getScopeData().contexts.flags;\n const flagBuffer = flagContext ? flagContext.values : [];\n\n if (!flagBuffer.length) {\n return event;\n }\n\n if (event.contexts === undefined) {\n event.contexts = {};\n }\n event.contexts.flags = { values: [...flagBuffer] };\n return event;\n}\n\n/**\n * Inserts a flag into the current scope's context while maintaining ordered LRU properties.\n * Not thread-safe. After inserting:\n * - The flag buffer is sorted in order of recency, with the newest evaluation at the end.\n * - The names in the buffer are always unique.\n * - The length of the buffer never exceeds `maxSize`.\n *\n * @param name Name of the feature flag to insert.\n * @param value Value of the feature flag.\n * @param maxSize Max number of flags the buffer should store. Default value should always be used in production.\n */\nexport function _INTERNAL_insertFlagToScope(\n name: string,\n value: unknown,\n maxSize: number = _INTERNAL_FLAG_BUFFER_SIZE,\n): void {\n const scopeContexts = getCurrentScope().getScopeData().contexts;\n if (!scopeContexts.flags) {\n scopeContexts.flags = { values: [] };\n }\n const flags = scopeContexts.flags.values;\n _INTERNAL_insertToFlagBuffer(flags, name, value, maxSize);\n}\n\n/**\n * Exported for tests only. Currently only accepts boolean values (otherwise no-op).\n * Inserts a flag into a FeatureFlag array while maintaining the following properties:\n * - Flags are sorted in order of recency, with the newest evaluation at the end.\n * - The flag names are always unique.\n * - The length of the array never exceeds `maxSize`.\n *\n * @param flags The buffer to insert the flag into.\n * @param name Name of the feature flag to insert.\n * @param value Value of the feature flag.\n * @param maxSize Max number of flags the buffer should store. Default value should always be used in production.\n */\nexport function _INTERNAL_insertToFlagBuffer(\n flags: FeatureFlag[],\n name: string,\n value: unknown,\n maxSize: number,\n): void {\n if (typeof value !== 'boolean') {\n return;\n }\n\n if (flags.length > maxSize) {\n DEBUG_BUILD && debug.error(`[Feature Flags] insertToFlagBuffer called on a buffer larger than maxSize=${maxSize}`);\n return;\n }\n\n // Check if the flag is already in the buffer - O(n)\n const index = flags.findIndex(f => f.flag === name);\n\n if (index !== -1) {\n // The flag was found, remove it from its current position - O(n)\n flags.splice(index, 1);\n }\n\n if (flags.length === maxSize) {\n // If at capacity, pop the earliest flag - O(n)\n flags.shift();\n }\n\n // Push the flag to the end - O(1)\n flags.push({\n flag: name,\n result: value,\n });\n}\n\n/**\n * Records a feature flag evaluation for the active span. This is a no-op for non-boolean values.\n * The flag and its value is stored in span attributes with the `flag.evaluation` prefix. Once the\n * unique flags for a span reaches maxFlagsPerSpan, subsequent flags are dropped.\n *\n * @param name Name of the feature flag.\n * @param value Value of the feature flag. Non-boolean values are ignored.\n * @param maxFlagsPerSpan Max number of flags a buffer should store. Default value should always be used in production.\n */\nexport function _INTERNAL_addFeatureFlagToActiveSpan(\n name: string,\n value: unknown,\n maxFlagsPerSpan: number = _INTERNAL_MAX_FLAGS_PER_SPAN,\n): void {\n if (typeof value !== 'boolean') {\n return;\n }\n\n const span = getActiveSpan();\n if (!span) {\n return;\n }\n\n const attributes = spanToJSON(span).data;\n\n // If the flag already exists, always update it\n if (`${SPAN_FLAG_ATTRIBUTE_PREFIX}${name}` in attributes) {\n span.setAttribute(`${SPAN_FLAG_ATTRIBUTE_PREFIX}${name}`, value);\n return;\n }\n\n // Else, add the flag to the span if we have not reached the max number of flags\n const numOfAddedFlags = Object.keys(attributes).filter(key => key.startsWith(SPAN_FLAG_ATTRIBUTE_PREFIX)).length;\n if (numOfAddedFlags < maxFlagsPerSpan) {\n span.setAttribute(`${SPAN_FLAG_ATTRIBUTE_PREFIX}${name}`, value);\n }\n}\n"],"names":["getCurrentScope","DEBUG_BUILD","debug","getActiveSpan","spanToJSON"],"mappings":";;;;;;;AAMA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACO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,EAAA,IAAA,CAAA,CAAA,IAAA,UAAA,EAAA;AACA,IAAA,IAAA,CAAA,YAAA,CAAA,CAAA,EAAA,0BAAA,CAAA,EAAA,IAAA,CAAA,CAAA,EAAA,KAAA,CAAA;AACA,IAAA;AACA,EAAA;;AAEA;AACA,EAAA,MAAA,eAAA,GAAA,MAAA,CAAA,IAAA,CAAA,UAAA,CAAA,CAAA,MAAA,CAAA,GAAA,IAAA,GAAA,CAAA,UAAA,CAAA,0BAAA,CAAA,CAAA,CAAA,MAAA;AACA,EAAA,IAAA,eAAA,GAAA,eAAA,EAAA;AACA,IAAA,IAAA,CAAA,YAAA,CAAA,CAAA,EAAA,0BAAA,CAAA,EAAA,IAAA,CAAA,CAAA,EAAA,KAAA,CAAA;AACA,EAAA;AACA;;;;;;;;;"}
|
|
@@ -81,10 +81,6 @@ function mergeScopeData(data, mergeData) {
|
|
|
81
81
|
data.attachments = [...data.attachments, ...attachments];
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
if (attributes) {
|
|
85
|
-
data.attributes = { ...data.attributes, ...attributes };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
84
|
data.propagationContext = { ...data.propagationContext, ...propagationContext };
|
|
89
85
|
}
|
|
90
86
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scopeData.js","sources":["../../../src/utils/scopeData.ts"],"sourcesContent":["import { getGlobalScope } from '../currentScopes';\nimport type { Scope, ScopeData } from '../scope';\nimport { getDynamicSamplingContextFromSpan } from '../tracing/dynamicSamplingContext';\nimport type { Breadcrumb } from '../types-hoist/breadcrumb';\nimport type { Event } from '../types-hoist/event';\nimport type { Span } from '../types-hoist/span';\nimport { merge } from './merge';\nimport { getRootSpan, spanToJSON, spanToTraceContext } from './spanUtils';\n\n/**\n * Applies data from the scope to the event and runs all event processors on it.\n */\nexport function applyScopeDataToEvent(event: Event, data: ScopeData): void {\n const { fingerprint, span, breadcrumbs, sdkProcessingMetadata } = data;\n\n // Apply general data\n applyDataToEvent(event, data);\n\n // We want to set the trace context for normal events only if there isn't already\n // a trace context on the event. There is a product feature in place where we link\n // errors with transaction and it relies on that.\n if (span) {\n applySpanToEvent(event, span);\n }\n\n applyFingerprintToEvent(event, fingerprint);\n applyBreadcrumbsToEvent(event, breadcrumbs);\n applySdkMetadataToEvent(event, sdkProcessingMetadata);\n}\n\n/** Merge data of two scopes together. */\nexport function mergeScopeData(data: ScopeData, mergeData: ScopeData): void {\n const {\n extra,\n tags,\n attributes,\n user,\n contexts,\n level,\n sdkProcessingMetadata,\n breadcrumbs,\n fingerprint,\n eventProcessors,\n attachments,\n propagationContext,\n transactionName,\n span,\n } = mergeData;\n\n mergeAndOverwriteScopeData(data, 'extra', extra);\n mergeAndOverwriteScopeData(data, 'tags', tags);\n mergeAndOverwriteScopeData(data, 'attributes', attributes);\n mergeAndOverwriteScopeData(data, 'user', user);\n mergeAndOverwriteScopeData(data, 'contexts', contexts);\n\n data.sdkProcessingMetadata = merge(data.sdkProcessingMetadata, sdkProcessingMetadata, 2);\n\n if (level) {\n data.level = level;\n }\n\n if (transactionName) {\n data.transactionName = transactionName;\n }\n\n if (span) {\n data.span = span;\n }\n\n if (breadcrumbs.length) {\n data.breadcrumbs = [...data.breadcrumbs, ...breadcrumbs];\n }\n\n if (fingerprint.length) {\n data.fingerprint = [...data.fingerprint, ...fingerprint];\n }\n\n if (eventProcessors.length) {\n data.eventProcessors = [...data.eventProcessors, ...eventProcessors];\n }\n\n if (attachments.length) {\n data.attachments = [...data.attachments, ...attachments];\n }\n\n if (attributes) {\n data.attributes = { ...data.attributes, ...attributes };\n }\n\n data.propagationContext = { ...data.propagationContext, ...propagationContext };\n}\n\n/**\n * Merges certain scope data. Undefined values will overwrite any existing values.\n * Exported only for tests.\n */\nexport function mergeAndOverwriteScopeData<\n Prop extends 'extra' | 'tags' | 'attributes' | 'user' | 'contexts' | 'sdkProcessingMetadata',\n Data extends ScopeData,\n>(data: Data, prop: Prop, mergeVal: Data[Prop]): void {\n data[prop] = merge(data[prop], mergeVal, 1);\n}\n\n/** Exported only for tests */\nexport function mergeArray<Prop extends 'breadcrumbs' | 'fingerprint'>(\n event: Event,\n prop: Prop,\n mergeVal: ScopeData[Prop],\n): void {\n const prevVal = event[prop];\n // If we are not merging any new values,\n // we only need to proceed if there was an empty array before (as we want to replace it with undefined)\n if (!mergeVal.length && (!prevVal || prevVal.length)) {\n return;\n }\n\n const merged = [...(prevVal || []), ...mergeVal] as ScopeData[Prop];\n event[prop] = merged.length ? merged : undefined;\n}\n\n/**\n * Get the scope data for the current scope after merging with the\n * global scope and isolation scope.\n *\n * @param currentScope - The current scope.\n * @returns The scope data.\n */\nexport function getCombinedScopeData(isolationScope: Scope | undefined, currentScope: Scope | undefined): ScopeData {\n const scopeData = getGlobalScope().getScopeData();\n isolationScope && mergeScopeData(scopeData, isolationScope.getScopeData());\n currentScope && mergeScopeData(scopeData, currentScope.getScopeData());\n return scopeData;\n}\n\nfunction applyDataToEvent(event: Event, data: ScopeData): void {\n const { extra, tags, user, contexts, level, transactionName } = data;\n\n if (Object.keys(extra).length) {\n event.extra = { ...extra, ...event.extra };\n }\n\n if (Object.keys(tags).length) {\n event.tags = { ...tags, ...event.tags };\n }\n\n if (Object.keys(user).length) {\n event.user = { ...user, ...event.user };\n }\n\n if (Object.keys(contexts).length) {\n event.contexts = { ...contexts, ...event.contexts };\n }\n\n if (level) {\n event.level = level;\n }\n\n // transaction events get their `transaction` from the root span name\n if (transactionName && event.type !== 'transaction') {\n event.transaction = transactionName;\n }\n}\n\nfunction applyBreadcrumbsToEvent(event: Event, breadcrumbs: Breadcrumb[]): void {\n const mergedBreadcrumbs = [...(event.breadcrumbs || []), ...breadcrumbs];\n event.breadcrumbs = mergedBreadcrumbs.length ? mergedBreadcrumbs : undefined;\n}\n\nfunction applySdkMetadataToEvent(event: Event, sdkProcessingMetadata: ScopeData['sdkProcessingMetadata']): void {\n event.sdkProcessingMetadata = {\n ...event.sdkProcessingMetadata,\n ...sdkProcessingMetadata,\n };\n}\n\nfunction applySpanToEvent(event: Event, span: Span): void {\n event.contexts = {\n trace: spanToTraceContext(span),\n ...event.contexts,\n };\n\n event.sdkProcessingMetadata = {\n dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),\n ...event.sdkProcessingMetadata,\n };\n\n const rootSpan = getRootSpan(span);\n const transactionName = spanToJSON(rootSpan).description;\n if (transactionName && !event.transaction && event.type === 'transaction') {\n event.transaction = transactionName;\n }\n}\n\n/**\n * Applies fingerprint from the scope to the event if there's one,\n * uses message if there's one instead or get rid of empty fingerprint\n */\nfunction applyFingerprintToEvent(event: Event, fingerprint: ScopeData['fingerprint'] | undefined): void {\n // Make sure it's an array first and we actually have something in place\n event.fingerprint = event.fingerprint\n ? Array.isArray(event.fingerprint)\n ? event.fingerprint\n : [event.fingerprint]\n : [];\n\n // If we have something on the scope, then merge it with event\n if (fingerprint) {\n event.fingerprint = event.fingerprint.concat(fingerprint);\n }\n\n // If we have no data at all, remove empty array default\n if (!event.fingerprint.length) {\n delete event.fingerprint;\n }\n}\n"],"names":["merge","getGlobalScope","spanToTraceContext","getDynamicSamplingContextFromSpan","getRootSpan","spanToJSON"],"mappings":";;;;;;;AASA;AACA;AACA;AACO,SAAS,qBAAqB,CAAC,KAAK,EAAS,IAAI,EAAmB;AAC3E,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,qBAAA,EAAsB,GAAI,IAAI;;AAExE;AACA,EAAE,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC;;AAE/B;AACA;AACA;AACA,EAAE,IAAI,IAAI,EAAE;AACZ,IAAI,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC;AACjC,EAAE;;AAEF,EAAE,uBAAuB,CAAC,KAAK,EAAE,WAAW,CAAC;AAC7C,EAAE,uBAAuB,CAAC,KAAK,EAAE,WAAW,CAAC;AAC7C,EAAE,uBAAuB,CAAC,KAAK,EAAE,qBAAqB,CAAC;AACvD;;AAEA;AAC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AACA,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE;AACjC,IAAI,OAAO,KAAK,CAAC,WAAW;AAC5B,EAAE;AACF;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"scopeData.js","sources":["../../../src/utils/scopeData.ts"],"sourcesContent":["import { getGlobalScope } from '../currentScopes';\nimport type { Scope, ScopeData } from '../scope';\nimport { getDynamicSamplingContextFromSpan } from '../tracing/dynamicSamplingContext';\nimport type { Breadcrumb } from '../types-hoist/breadcrumb';\nimport type { Event } from '../types-hoist/event';\nimport type { Span } from '../types-hoist/span';\nimport { merge } from './merge';\nimport { getRootSpan, spanToJSON, spanToTraceContext } from './spanUtils';\n\n/**\n * Applies data from the scope to the event and runs all event processors on it.\n */\nexport function applyScopeDataToEvent(event: Event, data: ScopeData): void {\n const { fingerprint, span, breadcrumbs, sdkProcessingMetadata } = data;\n\n // Apply general data\n applyDataToEvent(event, data);\n\n // We want to set the trace context for normal events only if there isn't already\n // a trace context on the event. There is a product feature in place where we link\n // errors with transaction and it relies on that.\n if (span) {\n applySpanToEvent(event, span);\n }\n\n applyFingerprintToEvent(event, fingerprint);\n applyBreadcrumbsToEvent(event, breadcrumbs);\n applySdkMetadataToEvent(event, sdkProcessingMetadata);\n}\n\n/** Merge data of two scopes together. */\nexport function mergeScopeData(data: ScopeData, mergeData: ScopeData): void {\n const {\n extra,\n tags,\n attributes,\n user,\n contexts,\n level,\n sdkProcessingMetadata,\n breadcrumbs,\n fingerprint,\n eventProcessors,\n attachments,\n propagationContext,\n transactionName,\n span,\n } = mergeData;\n\n mergeAndOverwriteScopeData(data, 'extra', extra);\n mergeAndOverwriteScopeData(data, 'tags', tags);\n mergeAndOverwriteScopeData(data, 'attributes', attributes);\n mergeAndOverwriteScopeData(data, 'user', user);\n mergeAndOverwriteScopeData(data, 'contexts', contexts);\n\n data.sdkProcessingMetadata = merge(data.sdkProcessingMetadata, sdkProcessingMetadata, 2);\n\n if (level) {\n data.level = level;\n }\n\n if (transactionName) {\n data.transactionName = transactionName;\n }\n\n if (span) {\n data.span = span;\n }\n\n if (breadcrumbs.length) {\n data.breadcrumbs = [...data.breadcrumbs, ...breadcrumbs];\n }\n\n if (fingerprint.length) {\n data.fingerprint = [...data.fingerprint, ...fingerprint];\n }\n\n if (eventProcessors.length) {\n data.eventProcessors = [...data.eventProcessors, ...eventProcessors];\n }\n\n if (attachments.length) {\n data.attachments = [...data.attachments, ...attachments];\n }\n\n data.propagationContext = { ...data.propagationContext, ...propagationContext };\n}\n\n/**\n * Merges certain scope data. Undefined values will overwrite any existing values.\n * Exported only for tests.\n */\nexport function mergeAndOverwriteScopeData<\n Prop extends 'extra' | 'tags' | 'attributes' | 'user' | 'contexts' | 'sdkProcessingMetadata',\n Data extends ScopeData,\n>(data: Data, prop: Prop, mergeVal: Data[Prop]): void {\n data[prop] = merge(data[prop], mergeVal, 1);\n}\n\n/** Exported only for tests */\nexport function mergeArray<Prop extends 'breadcrumbs' | 'fingerprint'>(\n event: Event,\n prop: Prop,\n mergeVal: ScopeData[Prop],\n): void {\n const prevVal = event[prop];\n // If we are not merging any new values,\n // we only need to proceed if there was an empty array before (as we want to replace it with undefined)\n if (!mergeVal.length && (!prevVal || prevVal.length)) {\n return;\n }\n\n const merged = [...(prevVal || []), ...mergeVal] as ScopeData[Prop];\n event[prop] = merged.length ? merged : undefined;\n}\n\n/**\n * Get the scope data for the current scope after merging with the\n * global scope and isolation scope.\n *\n * @param currentScope - The current scope.\n * @returns The scope data.\n */\nexport function getCombinedScopeData(isolationScope: Scope | undefined, currentScope: Scope | undefined): ScopeData {\n const scopeData = getGlobalScope().getScopeData();\n isolationScope && mergeScopeData(scopeData, isolationScope.getScopeData());\n currentScope && mergeScopeData(scopeData, currentScope.getScopeData());\n return scopeData;\n}\n\nfunction applyDataToEvent(event: Event, data: ScopeData): void {\n const { extra, tags, user, contexts, level, transactionName } = data;\n\n if (Object.keys(extra).length) {\n event.extra = { ...extra, ...event.extra };\n }\n\n if (Object.keys(tags).length) {\n event.tags = { ...tags, ...event.tags };\n }\n\n if (Object.keys(user).length) {\n event.user = { ...user, ...event.user };\n }\n\n if (Object.keys(contexts).length) {\n event.contexts = { ...contexts, ...event.contexts };\n }\n\n if (level) {\n event.level = level;\n }\n\n // transaction events get their `transaction` from the root span name\n if (transactionName && event.type !== 'transaction') {\n event.transaction = transactionName;\n }\n}\n\nfunction applyBreadcrumbsToEvent(event: Event, breadcrumbs: Breadcrumb[]): void {\n const mergedBreadcrumbs = [...(event.breadcrumbs || []), ...breadcrumbs];\n event.breadcrumbs = mergedBreadcrumbs.length ? mergedBreadcrumbs : undefined;\n}\n\nfunction applySdkMetadataToEvent(event: Event, sdkProcessingMetadata: ScopeData['sdkProcessingMetadata']): void {\n event.sdkProcessingMetadata = {\n ...event.sdkProcessingMetadata,\n ...sdkProcessingMetadata,\n };\n}\n\nfunction applySpanToEvent(event: Event, span: Span): void {\n event.contexts = {\n trace: spanToTraceContext(span),\n ...event.contexts,\n };\n\n event.sdkProcessingMetadata = {\n dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),\n ...event.sdkProcessingMetadata,\n };\n\n const rootSpan = getRootSpan(span);\n const transactionName = spanToJSON(rootSpan).description;\n if (transactionName && !event.transaction && event.type === 'transaction') {\n event.transaction = transactionName;\n }\n}\n\n/**\n * Applies fingerprint from the scope to the event if there's one,\n * uses message if there's one instead or get rid of empty fingerprint\n */\nfunction applyFingerprintToEvent(event: Event, fingerprint: ScopeData['fingerprint'] | undefined): void {\n // Make sure it's an array first and we actually have something in place\n event.fingerprint = event.fingerprint\n ? Array.isArray(event.fingerprint)\n ? event.fingerprint\n : [event.fingerprint]\n : [];\n\n // If we have something on the scope, then merge it with event\n if (fingerprint) {\n event.fingerprint = event.fingerprint.concat(fingerprint);\n }\n\n // If we have no data at all, remove empty array default\n if (!event.fingerprint.length) {\n delete event.fingerprint;\n }\n}\n"],"names":["merge","getGlobalScope","spanToTraceContext","getDynamicSamplingContextFromSpan","getR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ACA;AACA;AACA,SAAS,uBAAuB,CAAC,KAAK,EAAS,WAAW,EAA8C;AACxG;AACA,EAAE,KAAK,CAAC,WAAA,GAAc,KAAK,CAAC;AAC5B,MAAM,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW;AACrC,QAAQ,KAAK,CAAC;AACd,QAAQ,CAAC,KAAK,CAAC,WAAW;AAC1B,MAAM,EAAE;;AAER;AACA,EAAE,IAAI,WAAW,EAAE;AACnB,IAAI,KAAK,CAAC,WAAA,GAAc,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC;AAC7D,EAAE;;AAEF;AACA,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE;AACjC,IAAI,OAAO,KAAK,CAAC,WAAW;AAC5B,EAAE;AACF;;;;;;;"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
const debugBuild = require('../debug-build.js');
|
|
4
|
-
const semanticAttributes = require('../semanticAttributes.js');
|
|
5
4
|
const debugLogger = require('./debug-logger.js');
|
|
6
5
|
const string = require('./string.js');
|
|
7
6
|
|
|
8
|
-
function logIgnoredSpan(
|
|
9
|
-
debugLogger.debug.log(`Ignoring span ${
|
|
7
|
+
function logIgnoredSpan(droppedSpan) {
|
|
8
|
+
debugLogger.debug.log(`Ignoring span ${droppedSpan.op} - ${droppedSpan.description} because it matches \`ignoreSpans\`.`);
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
/**
|
|
@@ -16,32 +15,14 @@ function shouldIgnoreSpan(
|
|
|
16
15
|
span,
|
|
17
16
|
ignoreSpans,
|
|
18
17
|
) {
|
|
19
|
-
if (!ignoreSpans?.length) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const { spanName, spanOp: spanOpAttributeOrString } =
|
|
24
|
-
'description' in span
|
|
25
|
-
? { spanName: span.description, spanOp: span.op }
|
|
26
|
-
: 'name' in span
|
|
27
|
-
? { spanName: span.name, spanOp: span.attributes?.[semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_OP] }
|
|
28
|
-
: { spanName: '', spanOp: '' };
|
|
29
|
-
|
|
30
|
-
const spanOp =
|
|
31
|
-
typeof spanOpAttributeOrString === 'string'
|
|
32
|
-
? spanOpAttributeOrString
|
|
33
|
-
: spanOpAttributeOrString?.type === 'string'
|
|
34
|
-
? spanOpAttributeOrString.value
|
|
35
|
-
: undefined;
|
|
36
|
-
|
|
37
|
-
if (!spanName) {
|
|
18
|
+
if (!ignoreSpans?.length || !span.description) {
|
|
38
19
|
return false;
|
|
39
20
|
}
|
|
40
21
|
|
|
41
22
|
for (const pattern of ignoreSpans) {
|
|
42
23
|
if (isStringOrRegExp(pattern)) {
|
|
43
|
-
if (string.isMatchingPattern(
|
|
44
|
-
debugBuild.DEBUG_BUILD && logIgnoredSpan(
|
|
24
|
+
if (string.isMatchingPattern(span.description, pattern)) {
|
|
25
|
+
debugBuild.DEBUG_BUILD && logIgnoredSpan(span);
|
|
45
26
|
return true;
|
|
46
27
|
}
|
|
47
28
|
continue;
|
|
@@ -51,15 +32,15 @@ function shouldIgnoreSpan(
|
|
|
51
32
|
continue;
|
|
52
33
|
}
|
|
53
34
|
|
|
54
|
-
const nameMatches = pattern.name ? string.isMatchingPattern(
|
|
55
|
-
const opMatches = pattern.op ?
|
|
35
|
+
const nameMatches = pattern.name ? string.isMatchingPattern(span.description, pattern.name) : true;
|
|
36
|
+
const opMatches = pattern.op ? span.op && string.isMatchingPattern(span.op, pattern.op) : true;
|
|
56
37
|
|
|
57
38
|
// This check here is only correct because we can guarantee that we ran `isMatchingPattern`
|
|
58
39
|
// for at least one of `nameMatches` and `opMatches`. So in contrary to how this looks,
|
|
59
40
|
// not both op and name actually have to match. This is the most efficient way to check
|
|
60
41
|
// for all combinations of name and op patterns.
|
|
61
42
|
if (nameMatches && opMatches) {
|
|
62
|
-
debugBuild.DEBUG_BUILD && logIgnoredSpan(
|
|
43
|
+
debugBuild.DEBUG_BUILD && logIgnoredSpan(span);
|
|
63
44
|
return true;
|
|
64
45
|
}
|
|
65
46
|
}
|
|
@@ -71,10 +52,7 @@ function shouldIgnoreSpan(
|
|
|
71
52
|
* Takes a list of spans, and a span that was dropped, and re-parents the child spans of the dropped span to the parent of the dropped span, if possible.
|
|
72
53
|
* This mutates the spans array in place!
|
|
73
54
|
*/
|
|
74
|
-
function reparentChildSpans(
|
|
75
|
-
spans,
|
|
76
|
-
dropSpan,
|
|
77
|
-
) {
|
|
55
|
+
function reparentChildSpans(spans, dropSpan) {
|
|
78
56
|
const droppedSpanParentId = dropSpan.parent_span_id;
|
|
79
57
|
const droppedSpanId = dropSpan.span_id;
|
|
80
58
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"should-ignore-span.js","sources":["../../../src/utils/should-ignore-span.ts"],"sourcesContent":["import { DEBUG_BUILD } from '../debug-build';\nimport
|
|
1
|
+
{"version":3,"file":"should-ignore-span.js","sources":["../../../src/utils/should-ignore-span.ts"],"sourcesContent":["import { DEBUG_BUILD } from '../debug-build';\nimport type { ClientOptions } from '../types-hoist/options';\nimport type { SpanJSON } from '../types-hoist/span';\nimport { debug } from './debug-logger';\nimport { isMatchingPattern } from './string';\n\nfunction logIgnoredSpan(droppedSpan: Pick<SpanJSON, 'description' | 'op'>): void {\n debug.log(`Ignoring span ${droppedSpan.op} - ${droppedSpan.description} because it matches \\`ignoreSpans\\`.`);\n}\n\n/**\n * Check if a span should be ignored based on the ignoreSpans configuration.\n */\nexport function shouldIgnoreSpan(\n span: Pick<SpanJSON, 'description' | 'op'>,\n ignoreSpans: Required<ClientOptions>['ignoreSpans'],\n): boolean {\n if (!ignoreSpans?.length || !span.description) {\n return false;\n }\n\n for (const pattern of ignoreSpans) {\n if (isStringOrRegExp(pattern)) {\n if (isMatchingPattern(span.description, pattern)) {\n DEBUG_BUILD && logIgnoredSpan(span);\n return true;\n }\n continue;\n }\n\n if (!pattern.name && !pattern.op) {\n continue;\n }\n\n const nameMatches = pattern.name ? isMatchingPattern(span.description, pattern.name) : true;\n const opMatches = pattern.op ? span.op && isMatchingPattern(span.op, pattern.op) : true;\n\n // This check here is only correct because we can guarantee that we ran `isMatchingPattern`\n // for at least one of `nameMatches` and `opMatches`. So in contrary to how this looks,\n // not both op and name actually have to match. This is the most efficient way to check\n // for all combinations of name and op patterns.\n if (nameMatches && opMatches) {\n DEBUG_BUILD && logIgnoredSpan(span);\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Takes a list of spans, and a span that was dropped, and re-parents the child spans of the dropped span to the parent of the dropped span, if possible.\n * This mutates the spans array in place!\n */\nexport function reparentChildSpans(spans: SpanJSON[], dropSpan: SpanJSON): void {\n const droppedSpanParentId = dropSpan.parent_span_id;\n const droppedSpanId = dropSpan.span_id;\n\n // This should generally not happen, as we do not apply this on root spans\n // but to be safe, we just bail in this case\n if (!droppedSpanParentId) {\n return;\n }\n\n for (const span of spans) {\n if (span.parent_span_id === droppedSpanId) {\n span.parent_span_id = droppedSpanParentId;\n }\n }\n}\n\nfunction isStringOrRegExp(value: unknown): value is string | RegExp {\n return typeof value === 'string' || value instanceof RegExp;\n}\n"],"names":["debug","isMatchingPattern","DEBUG_BUILD"],"mappings":";;;;;;AAMA,SAAS,cAAc,CAAC,WAAW,EAA8C;AACjF,EAAEA,iBAAK,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,WAAW,CAAC,oCAAoC,CAAC,CAAC;AAC/G;;AAEA;AACA;AACA;AACO,SAAS,gBAAgB;AAChC,EAAE,IAAI;AACN,EAAE,WAAW;AACb,EAAW;AACX,EAAE,IAAI,CAAC,WAAW,EAAE,MAAA,IAAU,CAAC,IAAI,CAAC,WAAW,EAAE;AACjD,IAAI,OAAO,KAAK;AAChB,EAAE;;AAEF,EAAE,KAAK,MAAM,OAAA,I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AmB;AAC/C,IAAI;AACJ,EAAE;AACF;;AAEA,SAAS,gBAAgB,CAAC,KAAK,EAAqC;AACpE,EAAE,OAAO,OAAO,KAAA,KAAU,YAAY,KAAA,YAAiB,MAAM;AAC7D;;;;;"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
const index = require('../asyncContext/index.js');
|
|
4
|
-
const attributes = require('../attributes.js');
|
|
5
4
|
const carrier = require('../carrier.js');
|
|
6
5
|
const currentScopes = require('../currentScopes.js');
|
|
7
6
|
const semanticAttributes = require('../semanticAttributes.js');
|
|
@@ -85,7 +84,7 @@ function spanToTraceparentHeader(span) {
|
|
|
85
84
|
* If the links array is empty, it returns `undefined` so the empty value can be dropped before it's sent.
|
|
86
85
|
*/
|
|
87
86
|
function convertSpanLinksForEnvelope(links) {
|
|
88
|
-
if (links
|
|
87
|
+
if (links && links.length > 0) {
|
|
89
88
|
return links.map(({ context: { spanId, traceId, traceFlags, ...restContext }, attributes }) => ({
|
|
90
89
|
span_id: spanId,
|
|
91
90
|
trace_id: traceId,
|
|
@@ -97,24 +96,6 @@ function convertSpanLinksForEnvelope(links) {
|
|
|
97
96
|
return undefined;
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
* @param links
|
|
103
|
-
* @returns
|
|
104
|
-
*/
|
|
105
|
-
function getV2SpanLinks(links) {
|
|
106
|
-
if (links?.length) {
|
|
107
|
-
return links.map(({ context: { spanId, traceId, traceFlags, ...restContext }, attributes: attributes$1 }) => ({
|
|
108
|
-
span_id: spanId,
|
|
109
|
-
trace_id: traceId,
|
|
110
|
-
sampled: traceFlags === TRACE_FLAG_SAMPLED,
|
|
111
|
-
...(attributes$1 && { attributes: attributes.serializeAttributes(attributes$1) }),
|
|
112
|
-
...restContext,
|
|
113
|
-
}));
|
|
114
|
-
} else {
|
|
115
|
-
return undefined;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
99
|
|
|
119
100
|
/**
|
|
120
101
|
* Convert a span time input into a timestamp in seconds.
|
|
@@ -198,59 +179,6 @@ function spanToJSON(span) {
|
|
|
198
179
|
};
|
|
199
180
|
}
|
|
200
181
|
|
|
201
|
-
/**
|
|
202
|
-
* Convert a span to a SpanV2JSON representation.
|
|
203
|
-
* @returns
|
|
204
|
-
*/
|
|
205
|
-
function spanToV2JSON(span) {
|
|
206
|
-
if (spanIsSentrySpan(span)) {
|
|
207
|
-
return span.getSpanV2JSON();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const { spanId: span_id, traceId: trace_id } = span.spanContext();
|
|
211
|
-
|
|
212
|
-
// Handle a span from @opentelemetry/sdk-base-trace's `Span` class
|
|
213
|
-
if (spanIsOpenTelemetrySdkTraceBaseSpan(span)) {
|
|
214
|
-
const { attributes: attributes$1, startTime, name, endTime, status, links } = span;
|
|
215
|
-
|
|
216
|
-
// In preparation for the next major of OpenTelemetry, we want to support
|
|
217
|
-
// looking up the parent span id according to the new API
|
|
218
|
-
// In OTel v1, the parent span id is accessed as `parentSpanId`
|
|
219
|
-
// In OTel v2, the parent span id is accessed as `spanId` on the `parentSpanContext`
|
|
220
|
-
const parentSpanId =
|
|
221
|
-
'parentSpanId' in span
|
|
222
|
-
? span.parentSpanId
|
|
223
|
-
: 'parentSpanContext' in span
|
|
224
|
-
? (span.parentSpanContext )?.spanId
|
|
225
|
-
: undefined;
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
name,
|
|
229
|
-
span_id,
|
|
230
|
-
trace_id,
|
|
231
|
-
parent_span_id: parentSpanId,
|
|
232
|
-
start_timestamp: spanTimeInputToSeconds(startTime),
|
|
233
|
-
end_timestamp: spanTimeInputToSeconds(endTime),
|
|
234
|
-
is_segment: span === INTERNAL_getSegmentSpan(span),
|
|
235
|
-
status: getV2StatusMessage(status),
|
|
236
|
-
attributes: attributes.serializeAttributes(attributes$1),
|
|
237
|
-
links: getV2SpanLinks(links),
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// Finally, as a fallback, at least we have `spanContext()`....
|
|
242
|
-
// This should not actually happen in reality, but we need to handle it for type safety.
|
|
243
|
-
return {
|
|
244
|
-
span_id,
|
|
245
|
-
trace_id,
|
|
246
|
-
start_timestamp: 0,
|
|
247
|
-
name: '',
|
|
248
|
-
end_timestamp: 0,
|
|
249
|
-
status: 'ok',
|
|
250
|
-
is_segment: span === INTERNAL_getSegmentSpan(span),
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
182
|
function spanIsOpenTelemetrySdkTraceBaseSpan(span) {
|
|
255
183
|
const castSpan = span ;
|
|
256
184
|
return !!castSpan.attributes && !!castSpan.startTime && !!castSpan.name && !!castSpan.endTime && !!castSpan.status;
|
|
@@ -292,13 +220,6 @@ function getStatusMessage(status) {
|
|
|
292
220
|
return status.message || 'internal_error';
|
|
293
221
|
}
|
|
294
222
|
|
|
295
|
-
/**
|
|
296
|
-
* Convert the various statuses to the ones expected by Sentry ('ok' is default)
|
|
297
|
-
*/
|
|
298
|
-
function getV2StatusMessage(status) {
|
|
299
|
-
return !status || status.code === spanstatus.SPAN_STATUS_OK || status.code === spanstatus.SPAN_STATUS_UNSET ? 'ok' : 'error';
|
|
300
|
-
}
|
|
301
|
-
|
|
302
223
|
const CHILD_SPANS_FIELD = '_sentryChildSpans';
|
|
303
224
|
const ROOT_SPAN_FIELD = '_sentryRootSpan';
|
|
304
225
|
|
|
@@ -355,12 +276,7 @@ function getSpanDescendants(span) {
|
|
|
355
276
|
/**
|
|
356
277
|
* Returns the root span of a given span.
|
|
357
278
|
*/
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Returns the segment span of a given span.
|
|
362
|
-
*/
|
|
363
|
-
function INTERNAL_getSegmentSpan(span) {
|
|
279
|
+
function getRootSpan(span) {
|
|
364
280
|
return span[ROOT_SPAN_FIELD] || span;
|
|
365
281
|
}
|
|
366
282
|
|
|
@@ -416,7 +332,6 @@ function updateSpanName(span, name) {
|
|
|
416
332
|
});
|
|
417
333
|
}
|
|
418
334
|
|
|
419
|
-
exports.INTERNAL_getSegmentSpan = INTERNAL_getSegmentSpan;
|
|
420
335
|
exports.TRACE_FLAG_NONE = TRACE_FLAG_NONE;
|
|
421
336
|
exports.TRACE_FLAG_SAMPLED = TRACE_FLAG_SAMPLED;
|
|
422
337
|
exports.addChildSpanToSpan = addChildSpanToSpan;
|
|
@@ -425,8 +340,6 @@ exports.getActiveSpan = getActiveSpan;
|
|
|
425
340
|
exports.getRootSpan = getRootSpan;
|
|
426
341
|
exports.getSpanDescendants = getSpanDescendants;
|
|
427
342
|
exports.getStatusMessage = getStatusMessage;
|
|
428
|
-
exports.getV2SpanLinks = getV2SpanLinks;
|
|
429
|
-
exports.getV2StatusMessage = getV2StatusMessage;
|
|
430
343
|
exports.removeChildSpanFromSpan = removeChildSpanFromSpan;
|
|
431
344
|
exports.showSpanDropWarning = showSpanDropWarning;
|
|
432
345
|
exports.spanIsSampled = spanIsSampled;
|
|
@@ -436,6 +349,5 @@ exports.spanToTraceContext = spanToTraceContext;
|
|
|
436
349
|
exports.spanToTraceHeader = spanToTraceHeader;
|
|
437
350
|
exports.spanToTraceparentHeader = spanToTraceparentHeader;
|
|
438
351
|
exports.spanToTransactionTraceContext = spanToTransactionTraceContext;
|
|
439
|
-
exports.spanToV2JSON = spanToV2JSON;
|
|
440
352
|
exports.updateSpanName = updateSpanName;
|
|
441
353
|
//# sourceMappingURL=spanUtils.js.map
|