@sentry/core 10.49.0 → 10.50.0-alpha.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/client.js +9 -0
- package/build/cjs/client.js.map +1 -1
- package/build/cjs/fetch.js +5 -2
- package/build/cjs/fetch.js.map +1 -1
- package/build/cjs/integration.js +9 -0
- package/build/cjs/integration.js.map +1 -1
- package/build/cjs/integrations/mcp-server/transport.js +9 -9
- package/build/cjs/integrations/mcp-server/transport.js.map +1 -1
- package/build/cjs/integrations/requestdata.js.map +1 -1
- package/build/cjs/tracing/ai/utils.js +4 -4
- package/build/cjs/tracing/ai/utils.js.map +1 -1
- package/build/cjs/tracing/sentrySpan.js +5 -0
- package/build/cjs/tracing/sentrySpan.js.map +1 -1
- package/build/cjs/tracing/spans/captureSpan.js +3 -1
- package/build/cjs/tracing/spans/captureSpan.js.map +1 -1
- package/build/cjs/tracing/spans/extractGenAiSpans.js +50 -0
- package/build/cjs/tracing/spans/extractGenAiSpans.js.map +1 -0
- package/build/cjs/tracing/spans/spanJsonToStreamedSpan.js +26 -0
- package/build/cjs/tracing/spans/spanJsonToStreamedSpan.js.map +1 -0
- package/build/cjs/tracing/trace.js +17 -6
- package/build/cjs/tracing/trace.js.map +1 -1
- package/build/cjs/tracing/vercel-ai/index.js +9 -0
- package/build/cjs/tracing/vercel-ai/index.js.map +1 -1
- package/build/cjs/utils/version.js +1 -1
- package/build/cjs/utils/version.js.map +1 -1
- package/build/esm/client.js +9 -0
- package/build/esm/client.js.map +1 -1
- package/build/esm/fetch.js +5 -2
- package/build/esm/fetch.js.map +1 -1
- package/build/esm/integration.js +9 -0
- package/build/esm/integration.js.map +1 -1
- package/build/esm/integrations/mcp-server/transport.js +9 -9
- package/build/esm/integrations/mcp-server/transport.js.map +1 -1
- package/build/esm/integrations/requestdata.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/tracing/ai/utils.js +4 -4
- package/build/esm/tracing/ai/utils.js.map +1 -1
- package/build/esm/tracing/sentrySpan.js +5 -0
- package/build/esm/tracing/sentrySpan.js.map +1 -1
- package/build/esm/tracing/spans/captureSpan.js +3 -1
- package/build/esm/tracing/spans/captureSpan.js.map +1 -1
- package/build/esm/tracing/spans/extractGenAiSpans.js +48 -0
- package/build/esm/tracing/spans/extractGenAiSpans.js.map +1 -0
- package/build/esm/tracing/spans/spanJsonToStreamedSpan.js +24 -0
- package/build/esm/tracing/spans/spanJsonToStreamedSpan.js.map +1 -0
- package/build/esm/tracing/trace.js +17 -6
- package/build/esm/tracing/trace.js.map +1 -1
- package/build/esm/tracing/vercel-ai/index.js +9 -0
- package/build/esm/tracing/vercel-ai/index.js.map +1 -1
- package/build/esm/utils/version.js +1 -1
- package/build/esm/utils/version.js.map +1 -1
- package/build/types/client.d.ts +20 -0
- package/build/types/client.d.ts.map +1 -1
- package/build/types/fetch.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integration.d.ts.map +1 -1
- package/build/types/integrations/requestdata.d.ts.map +1 -1
- package/build/types/tracing/ai/utils.d.ts +3 -1
- package/build/types/tracing/ai/utils.d.ts.map +1 -1
- package/build/types/tracing/sentrySpan.d.ts.map +1 -1
- package/build/types/tracing/spans/captureSpan.d.ts.map +1 -1
- package/build/types/tracing/spans/extractGenAiSpans.d.ts +15 -0
- package/build/types/tracing/spans/extractGenAiSpans.d.ts.map +1 -0
- package/build/types/tracing/spans/spanJsonToStreamedSpan.d.ts +6 -0
- package/build/types/tracing/spans/spanJsonToStreamedSpan.d.ts.map +1 -0
- package/build/types/tracing/trace.d.ts.map +1 -1
- package/build/types/tracing/vercel-ai/index.d.ts.map +1 -1
- package/build/types/types-hoist/clientreport.d.ts +1 -1
- package/build/types/types-hoist/clientreport.d.ts.map +1 -1
- package/build/types/types-hoist/envelope.d.ts +1 -1
- package/build/types/types-hoist/envelope.d.ts.map +1 -1
- package/build/types/types-hoist/integration.d.ts +13 -0
- package/build/types/types-hoist/integration.d.ts.map +1 -1
- package/build/types/types-hoist/replay.d.ts +25 -0
- package/build/types/types-hoist/replay.d.ts.map +1 -1
- package/build/types-ts3.8/client.d.ts +20 -0
- package/build/types-ts3.8/index.d.ts +1 -1
- package/build/types-ts3.8/tracing/ai/utils.d.ts +3 -1
- package/build/types-ts3.8/tracing/spans/extractGenAiSpans.d.ts +15 -0
- package/build/types-ts3.8/tracing/spans/spanJsonToStreamedSpan.d.ts +6 -0
- package/build/types-ts3.8/types-hoist/clientreport.d.ts +1 -1
- package/build/types-ts3.8/types-hoist/envelope.d.ts +1 -1
- package/build/types-ts3.8/types-hoist/integration.d.ts +13 -0
- package/build/types-ts3.8/types-hoist/replay.d.ts +25 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.js","sources":["../../src/integration.ts"],"sourcesContent":["import type { Client } from './client';\nimport { getClient } from './currentScopes';\nimport { DEBUG_BUILD } from './debug-build';\nimport type { Event, EventHint } from './types-hoist/event';\nimport type { Integration, IntegrationFn } from './types-hoist/integration';\nimport type { CoreOptions } from './types-hoist/options';\nimport { debug } from './utils/debug-logger';\n\nexport const installedIntegrations: string[] = [];\n\n/** Map of integrations assigned to a client */\nexport type IntegrationIndex = {\n [key: string]: Integration;\n};\n\ntype IntegrationWithDefaultInstance = Integration & { isDefaultInstance?: true };\n\n/**\n * Remove duplicates from the given array, preferring the last instance of any duplicate. Not guaranteed to\n * preserve the order of integrations in the array.\n *\n * @private\n */\nfunction filterDuplicates(integrations: Integration[]): Integration[] {\n const integrationsByName: { [key: string]: Integration } = {};\n\n integrations.forEach((currentInstance: IntegrationWithDefaultInstance) => {\n const { name } = currentInstance;\n\n const existingInstance: IntegrationWithDefaultInstance | undefined = integrationsByName[name];\n\n // We want integrations later in the array to overwrite earlier ones of the same type, except that we never want a\n // default instance to overwrite an existing user instance\n if (existingInstance && !existingInstance.isDefaultInstance && currentInstance.isDefaultInstance) {\n return;\n }\n\n integrationsByName[name] = currentInstance;\n });\n\n return Object.values(integrationsByName);\n}\n\n/** Gets integrations to install */\nexport function getIntegrationsToSetup(\n options: Pick<CoreOptions, 'defaultIntegrations' | 'integrations'>,\n): Integration[] {\n const defaultIntegrations = options.defaultIntegrations || [];\n const userIntegrations = options.integrations;\n\n // We flag default instances, so that later we can tell them apart from any user-created instances of the same class\n defaultIntegrations.forEach((integration: IntegrationWithDefaultInstance) => {\n integration.isDefaultInstance = true;\n });\n\n let integrations: Integration[];\n\n if (Array.isArray(userIntegrations)) {\n integrations = [...defaultIntegrations, ...userIntegrations];\n } else if (typeof userIntegrations === 'function') {\n const resolvedUserIntegrations = userIntegrations(defaultIntegrations);\n integrations = Array.isArray(resolvedUserIntegrations) ? resolvedUserIntegrations : [resolvedUserIntegrations];\n } else {\n integrations = defaultIntegrations;\n }\n\n return filterDuplicates(integrations);\n}\n\n/**\n * Given a list of integration instances this installs them all. When `withDefaults` is set to `true` then all default\n * integrations are added unless they were already provided before.\n * @param integrations array of integration instances\n * @param withDefault should enable default integrations\n */\nexport function setupIntegrations(client: Client, integrations: Integration[]): IntegrationIndex {\n const integrationIndex: IntegrationIndex = {};\n\n integrations.forEach((integration: Integration | undefined) => {\n if (integration?.beforeSetup) {\n integration.beforeSetup(client);\n }\n });\n\n integrations.forEach((integration: Integration | undefined) => {\n // guard against empty provided integrations\n if (integration) {\n setupIntegration(client, integration, integrationIndex);\n }\n });\n\n return integrationIndex;\n}\n\n/**\n * Execute the `afterAllSetup` hooks of the given integrations.\n */\nexport function afterSetupIntegrations(client: Client, integrations: Integration[]): void {\n for (const integration of integrations) {\n // guard against empty provided integrations\n if (integration?.afterAllSetup) {\n integration.afterAllSetup(client);\n }\n }\n}\n\n/** Setup a single integration. */\nexport function setupIntegration(client: Client, integration: Integration, integrationIndex: IntegrationIndex): void {\n if (integrationIndex[integration.name]) {\n DEBUG_BUILD && debug.log(`Integration skipped because it was already installed: ${integration.name}`);\n return;\n }\n integrationIndex[integration.name] = integration;\n\n // `setupOnce` is only called the first time\n if (!installedIntegrations.includes(integration.name) && typeof integration.setupOnce === 'function') {\n integration.setupOnce();\n installedIntegrations.push(integration.name);\n }\n\n // `setup` is run for each client\n if (integration.setup && typeof integration.setup === 'function') {\n integration.setup(client);\n }\n\n if (typeof integration.preprocessEvent === 'function') {\n const callback = integration.preprocessEvent.bind(integration) as typeof integration.preprocessEvent;\n client.on('preprocessEvent', (event, hint) => callback(event, hint, client));\n }\n\n if (typeof integration.processEvent === 'function') {\n const callback = integration.processEvent.bind(integration) as typeof integration.processEvent;\n\n const processor = Object.assign((event: Event, hint: EventHint) => callback(event, hint, client), {\n id: integration.name,\n });\n\n client.addEventProcessor(processor);\n }\n\n DEBUG_BUILD && debug.log(`Integration installed: ${integration.name}`);\n}\n\n/** Add an integration to the current scope's client. */\nexport function addIntegration(integration: Integration): void {\n const client = getClient();\n\n if (!client) {\n DEBUG_BUILD && debug.warn(`Cannot add integration \"${integration.name}\" because no SDK Client is available.`);\n return;\n }\n\n client.addIntegration(integration);\n}\n\n/**\n * Define an integration function that can be used to create an integration instance.\n * Note that this by design hides the implementation details of the integration, as they are considered internal.\n */\nexport function defineIntegration<Fn extends IntegrationFn>(fn: Fn): (...args: Parameters<Fn>) => Integration {\n return fn;\n}\n"],"names":[],"mappings":";;;;AAQO,MAAM,qBAAqB,GAAa;;AAE/C;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,gBAAgB,CAAC,YAAY,EAAgC;AACtE,EAAE,MAAM,kBAAkB,GAAmC,EAAE;;AAE/D,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,eAAe,KAAqC;AAC5E,IAAI,MAAM,EAAE,IAAA,EAAK,GAAI,eAAe;;AAEpC,IAAI,MAAM,gBAAgB,GAA+C,kBAAkB,CAAC,IAAI,CAAC;;AAEjG;AACA;AACA,IAAI,IAAI,gBAAA,IAAoB,CAAC,gBAAgB,CAAC,iBAAA,IAAqB,eAAe,CAAC,iBAAiB,EAA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Content":["import type { Client } from './client';\nimport { getClient } from './currentScopes';\nimport { DEBUG_BUILD } from './debug-build';\nimport type { Event, EventHint } from './types-hoist/event';\nimport type { Integration, IntegrationFn } from './types-hoist/integration';\nimport type { CoreOptions } from './types-hoist/options';\nimport type { StreamedSpanJSON } from './types-hoist/span';\nimport { debug } from './utils/debug-logger';\n\nexport const installedIntegrations: string[] = [];\n\n/** Map of integrations assigned to a client */\nexport type IntegrationIndex = {\n [key: string]: Integration;\n};\n\ntype IntegrationWithDefaultInstance = Integration & { isDefaultInstance?: true };\n\n/**\n * Remove duplicates from the given array, preferring the last instance of any duplicate. Not guaranteed to\n * preserve the order of integrations in the array.\n *\n * @private\n */\nfunction filterDuplicates(integrations: Integration[]): Integration[] {\n const integrationsByName: { [key: string]: Integration } = {};\n\n integrations.forEach((currentInstance: IntegrationWithDefaultInstance) => {\n const { name } = currentInstance;\n\n const existingInstance: IntegrationWithDefaultInstance | undefined = integrationsByName[name];\n\n // We want integrations later in the array to overwrite earlier ones of the same type, except that we never want a\n // default instance to overwrite an existing user instance\n if (existingInstance && !existingInstance.isDefaultInstance && currentInstance.isDefaultInstance) {\n return;\n }\n\n integrationsByName[name] = currentInstance;\n });\n\n return Object.values(integrationsByName);\n}\n\n/** Gets integrations to install */\nexport function getIntegrationsToSetup(\n options: Pick<CoreOptions, 'defaultIntegrations' | 'integrations'>,\n): Integration[] {\n const defaultIntegrations = options.defaultIntegrations || [];\n const userIntegrations = options.integrations;\n\n // We flag default instances, so that later we can tell them apart from any user-created instances of the same class\n defaultIntegrations.forEach((integration: IntegrationWithDefaultInstance) => {\n integration.isDefaultInstance = true;\n });\n\n let integrations: Integration[];\n\n if (Array.isArray(userIntegrations)) {\n integrations = [...defaultIntegrations, ...userIntegrations];\n } else if (typeof userIntegrations === 'function') {\n const resolvedUserIntegrations = userIntegrations(defaultIntegrations);\n integrations = Array.isArray(resolvedUserIntegrations) ? resolvedUserIntegrations : [resolvedUserIntegrations];\n } else {\n integrations = defaultIntegrations;\n }\n\n return filterDuplicates(integrations);\n}\n\n/**\n * Given a list of integration instances this installs them all. When `withDefaults` is set to `true` then all default\n * integrations are added unless they were already provided before.\n * @param integrations array of integration instances\n * @param withDefault should enable default integrations\n */\nexport function setupIntegrations(client: Client, integrations: Integration[]): IntegrationIndex {\n const integrationIndex: IntegrationIndex = {};\n\n integrations.forEach((integration: Integration | undefined) => {\n if (integration?.beforeSetup) {\n integration.beforeSetup(client);\n }\n });\n\n integrations.forEach((integration: Integration | undefined) => {\n // guard against empty provided integrations\n if (integration) {\n setupIntegration(client, integration, integrationIndex);\n }\n });\n\n return integrationIndex;\n}\n\n/**\n * Execute the `afterAllSetup` hooks of the given integrations.\n */\nexport function afterSetupIntegrations(client: Client, integrations: Integration[]): void {\n for (const integration of integrations) {\n // guard against empty provided integrations\n if (integration?.afterAllSetup) {\n integration.afterAllSetup(client);\n }\n }\n}\n\n/** Setup a single integration. */\nexport function setupIntegration(client: Client, integration: Integration, integrationIndex: IntegrationIndex): void {\n if (integrationIndex[integration.name]) {\n DEBUG_BUILD && debug.log(`Integration skipped because it was already installed: ${integration.name}`);\n return;\n }\n integrationIndex[integration.name] = integration;\n\n // `setupOnce` is only called the first time\n if (!installedIntegrations.includes(integration.name) && typeof integration.setupOnce === 'function') {\n integration.setupOnce();\n installedIntegrations.push(integration.name);\n }\n\n // `setup` is run for each client\n if (integration.setup && typeof integration.setup === 'function') {\n integration.setup(client);\n }\n\n if (typeof integration.preprocessEvent === 'function') {\n const callback = integration.preprocessEvent.bind(integration) as typeof integration.preprocessEvent;\n client.on('preprocessEvent', (event, hint) => callback(event, hint, client));\n }\n\n if (typeof integration.processEvent === 'function') {\n const callback = integration.processEvent.bind(integration) as typeof integration.processEvent;\n\n const processor = Object.assign((event: Event, hint: EventHint) => callback(event, hint, client), {\n id: integration.name,\n });\n\n client.addEventProcessor(processor);\n }\n\n (['processSpan', 'processSegmentSpan'] as const).forEach(hook => {\n const callback = integration[hook];\n if (typeof callback === 'function') {\n // The cast is needed because TS can't resolve overloads when the discriminant is a union type.\n // Both overloads have the same callback signature so this is safe.\n client.on(hook as 'processSpan', (span: StreamedSpanJSON) => callback.call(integration, span, client));\n }\n });\n\n DEBUG_BUILD && debug.log(`Integration installed: ${integration.name}`);\n}\n\n/** Add an integration to the current scope's client. */\nexport function addIntegration(integration: Integration): void {\n const client = getClient();\n\n if (!client) {\n DEBUG_BUILD && debug.warn(`Cannot add integration \"${integration.name}\" because no SDK Client is available.`);\n return;\n }\n\n client.addIntegration(integration);\n}\n\n/**\n * Define an integration function that can be used to create an integration instance.\n * Note that this by design hides the implementation details of the integration, as they are considered internal.\n */\nexport function defineIntegration<Fn extends IntegrationFn>(fn: Fn): (...args: Parameters<Fn>) => Integration {\n return fn;\n}\n"],"names":[],"mappings":";;;;AASO,MAAM,qBAAqB,GAAa;;AAE/C;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,gBAAgB,CAAC,YAAY,EAAgC;AACtE,EAAE,MAAM,kBAAkB,GAAmC,EAAE;;AAE/D,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,eAAe,KAAqC;AAC5E,IAAI,MAAM,EAAE,IAAA,EAAK,GAAI,eAAe;;AAEpC,IAAI,MAAM,gBAAgB,GAA+C,kBAAkB,CAAC,IAAI,CAAC;;AAEjG;AACA;AACA,IAAI,IAAI,gBAAA,IAAoB,CAAC,gBAAgB,CAAC,iBAAA,IAAqB,eAAe,CAAC,iBAAiB,EAAE;AACtG,MAAM;AACN,IAAI;;AAEJ,IAAI,kBAAkB,CAAC,IAAI,CAAA,GAAI,eAAe;AAC9C,EAAE,CAAC,CAAC;;AAEJ,EAAE,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC;AAC1C;;AAEA;AACO,SAAS,sBAAsB;AACtC,EAAE,OAAO;AACT,EAAiB;AACjB,EAAE,MAAM,sBAAsB,OAAO,CAAC,mBAAA,IAAuB,EAAE;AAC/D,EAAE,MAAM,gBAAA,GAAmB,OAA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@ function wrapTransportOnMessage(transport, options) {
|
|
|
35
35
|
if (isInitialize) {
|
|
36
36
|
try {
|
|
37
37
|
initSessionData = extractSessionDataFromInitializeRequest(message);
|
|
38
|
-
storeSessionDataForTransport(
|
|
38
|
+
storeSessionDataForTransport(transport, initSessionData);
|
|
39
39
|
} catch {
|
|
40
40
|
// noop
|
|
41
41
|
}
|
|
@@ -44,7 +44,7 @@ function wrapTransportOnMessage(transport, options) {
|
|
|
44
44
|
const isolationScope = getIsolationScope().clone();
|
|
45
45
|
|
|
46
46
|
return withIsolationScope(isolationScope, () => {
|
|
47
|
-
const spanConfig = buildMcpServerSpanConfig(message,
|
|
47
|
+
const spanConfig = buildMcpServerSpanConfig(message, transport, extra , options);
|
|
48
48
|
const span = startInactiveSpan(spanConfig);
|
|
49
49
|
|
|
50
50
|
// For initialize requests, add client info directly to span (works even for stateless transports)
|
|
@@ -57,7 +57,7 @@ function wrapTransportOnMessage(transport, options) {
|
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
storeSpanForRequest(
|
|
60
|
+
storeSpanForRequest(transport, message.id, span, message.method);
|
|
61
61
|
|
|
62
62
|
return withActiveSpan(span, () => {
|
|
63
63
|
return (originalOnMessage ).call(this, message, extra);
|
|
@@ -66,7 +66,7 @@ function wrapTransportOnMessage(transport, options) {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
if (isJsonRpcNotification(message)) {
|
|
69
|
-
return createMcpNotificationSpan(message,
|
|
69
|
+
return createMcpNotificationSpan(message, transport, extra , options, () => {
|
|
70
70
|
return (originalOnMessage ).call(this, message, extra);
|
|
71
71
|
});
|
|
72
72
|
}
|
|
@@ -91,7 +91,7 @@ function wrapTransportSend(transport, options) {
|
|
|
91
91
|
const [message] = args;
|
|
92
92
|
|
|
93
93
|
if (isJsonRpcNotification(message)) {
|
|
94
|
-
return createMcpOutgoingNotificationSpan(message,
|
|
94
|
+
return createMcpOutgoingNotificationSpan(message, transport, options, () => {
|
|
95
95
|
return (originalSend ).call(this, ...args);
|
|
96
96
|
});
|
|
97
97
|
}
|
|
@@ -106,14 +106,14 @@ function wrapTransportSend(transport, options) {
|
|
|
106
106
|
if (message.result.protocolVersion || message.result.serverInfo) {
|
|
107
107
|
try {
|
|
108
108
|
const serverData = extractSessionDataFromInitializeResponse(message.result);
|
|
109
|
-
updateSessionDataForTransport(
|
|
109
|
+
updateSessionDataForTransport(transport, serverData);
|
|
110
110
|
} catch {
|
|
111
111
|
// noop
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
completeSpanWithResults(
|
|
116
|
+
completeSpanWithResults(transport, message.id, message.result, options, !!message.error);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -131,8 +131,8 @@ function wrapTransportOnClose(transport) {
|
|
|
131
131
|
if (transport.onclose) {
|
|
132
132
|
fill(transport, 'onclose', originalOnClose => {
|
|
133
133
|
return function ( ...args) {
|
|
134
|
-
cleanupPendingSpansForTransport(
|
|
135
|
-
cleanupSessionDataForTransport(
|
|
134
|
+
cleanupPendingSpansForTransport(transport);
|
|
135
|
+
cleanupSessionDataForTransport(transport);
|
|
136
136
|
return (originalOnClose ).call(this, ...args);
|
|
137
137
|
};
|
|
138
138
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sources":["../../../../src/integrations/mcp-server/transport.ts"],"sourcesContent":["/**\n * Transport layer instrumentation for MCP server\n *\n * Handles message interception and response correlation.\n * @see https://modelcontextprotocol.io/specification/2025-06-18/basic/transports\n */\n\nimport { getIsolationScope, withIsolationScope } from '../../currentScopes';\nimport { startInactiveSpan, withActiveSpan } from '../../tracing';\nimport { fill } from '../../utils/object';\nimport { MCP_PROTOCOL_VERSION_ATTRIBUTE } from './attributes';\nimport { cleanupPendingSpansForTransport, completeSpanWithResults, storeSpanForRequest } from './correlation';\nimport { captureError } from './errorCapture';\nimport {\n buildClientAttributesFromInfo,\n extractSessionDataFromInitializeRequest,\n extractSessionDataFromInitializeResponse,\n} from './sessionExtraction';\nimport {\n cleanupSessionDataForTransport,\n storeSessionDataForTransport,\n updateSessionDataForTransport,\n} from './sessionManagement';\nimport { buildMcpServerSpanConfig, createMcpNotificationSpan, createMcpOutgoingNotificationSpan } from './spans';\nimport type { ExtraHandlerData, MCPTransport, ResolvedMcpOptions, SessionData } from './types';\nimport { isJsonRpcNotification, isJsonRpcRequest, isJsonRpcResponse, isValidContentItem } from './validation';\n\n/**\n * Wraps transport.onmessage to create spans for incoming messages.\n * For \"initialize\" requests, extracts and stores client info and protocol version\n * in the session data for the transport.\n * @param transport - MCP transport instance to wrap\n * @param options - Resolved MCP options\n */\nexport function wrapTransportOnMessage(transport: MCPTransport, options: ResolvedMcpOptions): void {\n if (transport.onmessage) {\n fill(transport, 'onmessage', originalOnMessage => {\n return function (this: MCPTransport, message: unknown, extra?: unknown) {\n if (isJsonRpcRequest(message)) {\n const isInitialize = message.method === 'initialize';\n let initSessionData: SessionData | undefined;\n\n if (isInitialize) {\n try {\n initSessionData = extractSessionDataFromInitializeRequest(message);\n storeSessionDataForTransport(this, initSessionData);\n } catch {\n // noop\n }\n }\n\n const isolationScope = getIsolationScope().clone();\n\n return withIsolationScope(isolationScope, () => {\n const spanConfig = buildMcpServerSpanConfig(message, this, extra as ExtraHandlerData, options);\n const span = startInactiveSpan(spanConfig);\n\n // For initialize requests, add client info directly to span (works even for stateless transports)\n if (isInitialize && initSessionData) {\n span.setAttributes({\n ...buildClientAttributesFromInfo(initSessionData.clientInfo),\n ...(initSessionData.protocolVersion && {\n [MCP_PROTOCOL_VERSION_ATTRIBUTE]: initSessionData.protocolVersion,\n }),\n });\n }\n\n storeSpanForRequest(this, message.id, span, message.method);\n\n return withActiveSpan(span, () => {\n return (originalOnMessage as (...args: unknown[]) => unknown).call(this, message, extra);\n });\n });\n }\n\n if (isJsonRpcNotification(message)) {\n return createMcpNotificationSpan(message, this, extra as ExtraHandlerData, options, () => {\n return (originalOnMessage as (...args: unknown[]) => unknown).call(this, message, extra);\n });\n }\n\n return (originalOnMessage as (...args: unknown[]) => unknown).call(this, message, extra);\n };\n });\n }\n}\n\n/**\n * Wraps transport.send to handle outgoing messages and response correlation.\n * For \"initialize\" responses, extracts and stores protocol version and server info\n * in the session data for the transport.\n * @param transport - MCP transport instance to wrap\n * @param options - Resolved MCP options\n */\nexport function wrapTransportSend(transport: MCPTransport, options: ResolvedMcpOptions): void {\n if (transport.send) {\n fill(transport, 'send', originalSend => {\n return async function (this: MCPTransport, ...args: unknown[]) {\n const [message] = args;\n\n if (isJsonRpcNotification(message)) {\n return createMcpOutgoingNotificationSpan(message, this, options, () => {\n return (originalSend as (...args: unknown[]) => unknown).call(this, ...args);\n });\n }\n\n if (isJsonRpcResponse(message)) {\n if (message.id !== null && message.id !== undefined) {\n if (message.error) {\n captureJsonRpcErrorResponse(message.error);\n }\n\n if (isValidContentItem(message.result)) {\n if (message.result.protocolVersion || message.result.serverInfo) {\n try {\n const serverData = extractSessionDataFromInitializeResponse(message.result);\n updateSessionDataForTransport(this, serverData);\n } catch {\n // noop\n }\n }\n }\n\n completeSpanWithResults(this, message.id, message.result, options, !!message.error);\n }\n }\n\n return (originalSend as (...args: unknown[]) => unknown).call(this, ...args);\n };\n });\n }\n}\n\n/**\n * Wraps transport.onclose to clean up pending spans for this transport only\n * @param transport - MCP transport instance to wrap\n */\nexport function wrapTransportOnClose(transport: MCPTransport): void {\n if (transport.onclose) {\n fill(transport, 'onclose', originalOnClose => {\n return function (this: MCPTransport, ...args: unknown[]) {\n cleanupPendingSpansForTransport(this);\n cleanupSessionDataForTransport(this);\n return (originalOnClose as (...args: unknown[]) => unknown).call(this, ...args);\n };\n });\n }\n}\n\n/**\n * Wraps transport error handlers to capture connection errors\n * @param transport - MCP transport instance to wrap\n */\nexport function wrapTransportError(transport: MCPTransport): void {\n if (transport.onerror) {\n fill(transport, 'onerror', (originalOnError: (error: Error) => void) => {\n return function (this: MCPTransport, error: Error) {\n captureTransportError(error);\n return originalOnError.call(this, error);\n };\n });\n }\n}\n\n/**\n * Captures JSON-RPC error responses for server-side errors.\n * @see https://www.jsonrpc.org/specification#error_object\n * @internal\n * @param errorResponse - JSON-RPC error response\n */\nfunction captureJsonRpcErrorResponse(errorResponse: unknown): void {\n try {\n if (errorResponse && typeof errorResponse === 'object' && 'code' in errorResponse && 'message' in errorResponse) {\n const jsonRpcError = errorResponse as { code: number; message: string; data?: unknown };\n\n const isServerError =\n jsonRpcError.code === -32603 || (jsonRpcError.code >= -32099 && jsonRpcError.code <= -32000);\n\n if (isServerError) {\n const error = new Error(jsonRpcError.message);\n error.name = `JsonRpcError_${jsonRpcError.code}`;\n\n captureError(error, 'protocol');\n }\n }\n } catch {\n // noop\n }\n}\n\n/**\n * Captures transport connection errors\n * @internal\n * @param error - Transport error\n */\nfunction captureTransportError(error: Error): void {\n try {\n captureError(error, 'transport');\n } catch {\n // noop\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;;AAsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,sBAAsB,CAAC,SAAS,EAAgB,OAAO,EAA4B;AACnG,EAAE,IAAI,SAAS,CAAC,SAAS,EAAE;AAC3B,IAAI,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,qBAAqB;AACtD,MAAM,OAAO,WAA8B,OAAO,EAAW,KAAK,EAAY;AAC9E,QAAQ,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE;AACvC,UAAU,MAAM,YAAA,GAAe,OAAO,CAAC,MAAA,KAAW,YAAY;AAC9D,UAAU,IAAI,eAAe;;AAE7B,UAAU,IAAI,YAAY,EAAE;AAC5B,YAAY,IAAI;AAChB,cAAc,eAAA,GAAkB,uCAAuC,CAAC,OAAO,CAAC;AAChF,cAAc,4BAA4B,CAAC,IAAI,EAAE,eAAe,CAAC;AACjE,YAAY,EAAE,MAAM;AACpB;AACA,YAAY;AACZ,U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,EAAE;AACrH,MAAM,MAAM,YAAA,GAAe,aAAA;;AAE3B,MAAM,MAAM,aAAA;AACZ,QAAQ,YAAY,CAAC,IAAA,KAAS,CAAC,KAAA,KAAU,YAAY,CAAC,QAAQ,CAAC,SAAS,YAAY,CAAC,IAAA,IAAQ,CAAC,KAAK,CAAC;;AAEpG,MAAM,IAAI,aAAa,EAAE;AACzB,QAAQ,MAAM,QAAQ,IAAI,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC;AACrD,QAAQ,KAAK,CAAC,IAAA,GAAO,CAAC,aAAa,EAAE,YAAY,CAAC,IAAI,CAAC,CAAA;;AAEA,QAAA,YAAA,CAAA,KAAA,EAAA,UAAA,CAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA,CAAA,CAAA,MAAA;AACA;AACA,EAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAA,qBAAA,CAAA,KAAA,EAAA;AACA,EAAA,IAAA;AACA,IAAA,YAAA,CAAA,KAAA,EAAA,WAAA,CAAA;AACA,EAAA,CAAA,CAAA,MAAA;AACA;AACA,EAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"transport.js","sources":["../../../../src/integrations/mcp-server/transport.ts"],"sourcesContent":["/**\n * Transport layer instrumentation for MCP server\n *\n * Handles message interception and response correlation.\n * @see https://modelcontextprotocol.io/specification/2025-06-18/basic/transports\n */\n\nimport { getIsolationScope, withIsolationScope } from '../../currentScopes';\nimport { startInactiveSpan, withActiveSpan } from '../../tracing';\nimport { fill } from '../../utils/object';\nimport { MCP_PROTOCOL_VERSION_ATTRIBUTE } from './attributes';\nimport { cleanupPendingSpansForTransport, completeSpanWithResults, storeSpanForRequest } from './correlation';\nimport { captureError } from './errorCapture';\nimport {\n buildClientAttributesFromInfo,\n extractSessionDataFromInitializeRequest,\n extractSessionDataFromInitializeResponse,\n} from './sessionExtraction';\nimport {\n cleanupSessionDataForTransport,\n storeSessionDataForTransport,\n updateSessionDataForTransport,\n} from './sessionManagement';\nimport { buildMcpServerSpanConfig, createMcpNotificationSpan, createMcpOutgoingNotificationSpan } from './spans';\nimport type { ExtraHandlerData, MCPTransport, ResolvedMcpOptions, SessionData } from './types';\nimport { isJsonRpcNotification, isJsonRpcRequest, isJsonRpcResponse, isValidContentItem } from './validation';\n\n/**\n * Wraps transport.onmessage to create spans for incoming messages.\n * For \"initialize\" requests, extracts and stores client info and protocol version\n * in the session data for the transport.\n * @param transport - MCP transport instance to wrap\n * @param options - Resolved MCP options\n */\nexport function wrapTransportOnMessage(transport: MCPTransport, options: ResolvedMcpOptions): void {\n if (transport.onmessage) {\n fill(transport, 'onmessage', originalOnMessage => {\n return function (this: MCPTransport, message: unknown, extra?: unknown) {\n if (isJsonRpcRequest(message)) {\n const isInitialize = message.method === 'initialize';\n let initSessionData: SessionData | undefined;\n\n if (isInitialize) {\n try {\n initSessionData = extractSessionDataFromInitializeRequest(message);\n storeSessionDataForTransport(transport, initSessionData);\n } catch {\n // noop\n }\n }\n\n const isolationScope = getIsolationScope().clone();\n\n return withIsolationScope(isolationScope, () => {\n const spanConfig = buildMcpServerSpanConfig(message, transport, extra as ExtraHandlerData, options);\n const span = startInactiveSpan(spanConfig);\n\n // For initialize requests, add client info directly to span (works even for stateless transports)\n if (isInitialize && initSessionData) {\n span.setAttributes({\n ...buildClientAttributesFromInfo(initSessionData.clientInfo),\n ...(initSessionData.protocolVersion && {\n [MCP_PROTOCOL_VERSION_ATTRIBUTE]: initSessionData.protocolVersion,\n }),\n });\n }\n\n storeSpanForRequest(transport, message.id, span, message.method);\n\n return withActiveSpan(span, () => {\n return (originalOnMessage as (...args: unknown[]) => unknown).call(this, message, extra);\n });\n });\n }\n\n if (isJsonRpcNotification(message)) {\n return createMcpNotificationSpan(message, transport, extra as ExtraHandlerData, options, () => {\n return (originalOnMessage as (...args: unknown[]) => unknown).call(this, message, extra);\n });\n }\n\n return (originalOnMessage as (...args: unknown[]) => unknown).call(this, message, extra);\n };\n });\n }\n}\n\n/**\n * Wraps transport.send to handle outgoing messages and response correlation.\n * For \"initialize\" responses, extracts and stores protocol version and server info\n * in the session data for the transport.\n * @param transport - MCP transport instance to wrap\n * @param options - Resolved MCP options\n */\nexport function wrapTransportSend(transport: MCPTransport, options: ResolvedMcpOptions): void {\n if (transport.send) {\n fill(transport, 'send', originalSend => {\n return async function (this: MCPTransport, ...args: unknown[]) {\n const [message] = args;\n\n if (isJsonRpcNotification(message)) {\n return createMcpOutgoingNotificationSpan(message, transport, options, () => {\n return (originalSend as (...args: unknown[]) => unknown).call(this, ...args);\n });\n }\n\n if (isJsonRpcResponse(message)) {\n if (message.id !== null && message.id !== undefined) {\n if (message.error) {\n captureJsonRpcErrorResponse(message.error);\n }\n\n if (isValidContentItem(message.result)) {\n if (message.result.protocolVersion || message.result.serverInfo) {\n try {\n const serverData = extractSessionDataFromInitializeResponse(message.result);\n updateSessionDataForTransport(transport, serverData);\n } catch {\n // noop\n }\n }\n }\n\n completeSpanWithResults(transport, message.id, message.result, options, !!message.error);\n }\n }\n\n return (originalSend as (...args: unknown[]) => unknown).call(this, ...args);\n };\n });\n }\n}\n\n/**\n * Wraps transport.onclose to clean up pending spans for this transport only\n * @param transport - MCP transport instance to wrap\n */\nexport function wrapTransportOnClose(transport: MCPTransport): void {\n if (transport.onclose) {\n fill(transport, 'onclose', originalOnClose => {\n return function (this: MCPTransport, ...args: unknown[]) {\n cleanupPendingSpansForTransport(transport);\n cleanupSessionDataForTransport(transport);\n return (originalOnClose as (...args: unknown[]) => unknown).call(this, ...args);\n };\n });\n }\n}\n\n/**\n * Wraps transport error handlers to capture connection errors\n * @param transport - MCP transport instance to wrap\n */\nexport function wrapTransportError(transport: MCPTransport): void {\n if (transport.onerror) {\n fill(transport, 'onerror', (originalOnError: (error: Error) => void) => {\n return function (this: MCPTransport, error: Error) {\n captureTransportError(error);\n return originalOnError.call(this, error);\n };\n });\n }\n}\n\n/**\n * Captures JSON-RPC error responses for server-side errors.\n * @see https://www.jsonrpc.org/specification#error_object\n * @internal\n * @param errorResponse - JSON-RPC error response\n */\nfunction captureJsonRpcErrorResponse(errorResponse: unknown): void {\n try {\n if (errorResponse && typeof errorResponse === 'object' && 'code' in errorResponse && 'message' in errorResponse) {\n const jsonRpcError = errorResponse as { code: number; message: string; data?: unknown };\n\n const isServerError =\n jsonRpcError.code === -32603 || (jsonRpcError.code >= -32099 && jsonRpcError.code <= -32000);\n\n if (isServerError) {\n const error = new Error(jsonRpcError.message);\n error.name = `JsonRpcError_${jsonRpcError.code}`;\n\n captureError(error, 'protocol');\n }\n }\n } catch {\n // noop\n }\n}\n\n/**\n * Captures transport connection errors\n * @internal\n * @param error - Transport error\n */\nfunction captureTransportError(error: Error): void {\n try {\n captureError(error, 'transport');\n } catch {\n // noop\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;;AAsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,sBAAsB,CAAC,SAAS,EAAgB,OAAO,EAA4B;AACnG,EAAE,IAAI,SAAS,CAAC,SAAS,EAAE;AAC3B,IAAI,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,qBAAqB;AACtD,MAAM,OAAO,WAA8B,OAAO,EAAW,KAAK,EAAY;AAC9E,QAAQ,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE;AACvC,UAAU,MAAM,YAAA,GAAe,OAAO,CAAC,MAAA,KAAW,YAAY;AAC9D,UAAU,IAAI,eAAe;;AAE7B,UAAU,IAAI,YAAY,EAAE;AAC5B,YAAY,IAAI;AAChB,cAAc,eAAA,GAAkB,uCAAuC,CAAC,OAAO,CAAC;AAChF,cAAc,4BAA4B,CAAC,SAAS,EAAE,eAAe,CAAC;AACtE,YAAY,EAAE,MAAM;AACpB;AACA,YAAY;AACZ,UAAU;;AAEV,UAAU,MAAM,iBAAiB,iBAAiB,EAAE,CAAC,KAAK,EAAE;;AAE5D,UAAU,OAAO,kBAAkB,CAAC,cAAc,EAAE,MAAM;AAC1D,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Y,CAAC,QAAQ,CAAC,SAAS,YAAY,CAAC,IAAA,IAAQ,CAAC,KAAK,CAAC;;AAEpG,MAAM,IAAI,aAAa,EAAE;AACzB,QAAQ,MAAM,QAAQ,IAAI,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC;AACrD,QAAQ,KAAK,CAAC,IAAA,GAAO,CAAC,aAAa,EAAE,YAAY,CAAC,IAAI,CAAC,CAAA;;AAEA,QAAA,YAAA,CAAA,KAAA,EAAA,UAAA,CAAA;AACA,MAAA;AACA,IAAA;AACA,EAAA,CAAA,CAAA,MAAA;AACA;AACA,EAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAA,qBAAA,CAAA,KAAA,EAAA;AACA,EAAA,IAAA;AACA,IAAA,YAAA,CAAA,KAAA,EAAA,WAAA,CAAA;AACA,EAAA,CAAA,CAAA,MAAA;AACA;AACA,EAAA;AACA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestdata.js","sources":["../../../src/integrations/requestdata.ts"],"sourcesContent":["import { defineIntegration } from '../integration';\nimport
|
|
1
|
+
{"version":3,"file":"requestdata.js","sources":["../../../src/integrations/requestdata.ts"],"sourcesContent":["import { defineIntegration } from '../integration';\nimport type { Event } from '../types-hoist/event';\nimport type { IntegrationFn } from '../types-hoist/integration';\nimport type { RequestEventData } from '../types-hoist/request';\nimport { parseCookie } from '../utils/cookie';\nimport { getClientIPAddress, ipHeaderNames } from '../vendor/getIpAddress';\n\ninterface RequestDataIncludeOptions {\n cookies?: boolean;\n data?: boolean;\n headers?: boolean;\n ip?: boolean;\n query_string?: boolean;\n url?: boolean;\n}\n\ntype RequestDataIntegrationOptions = {\n /**\n * Controls what data is pulled from the request and added to the event.\n */\n include?: RequestDataIncludeOptions;\n};\n\n// TODO(v11): Change defaults based on `sendDefaultPii`\nconst DEFAULT_INCLUDE: RequestDataIncludeOptions = {\n cookies: true,\n data: true,\n headers: true,\n query_string: true,\n url: true,\n};\n\nconst INTEGRATION_NAME = 'RequestData';\n\nconst _requestDataIntegration = ((options: RequestDataIntegrationOptions = {}) => {\n const include = {\n ...DEFAULT_INCLUDE,\n ...options.include,\n };\n\n return {\n name: INTEGRATION_NAME,\n processEvent(event, _hint, client) {\n const { sdkProcessingMetadata = {} } = event;\n const { normalizedRequest, ipAddress } = sdkProcessingMetadata;\n\n const includeWithDefaultPiiApplied: RequestDataIncludeOptions = {\n ...include,\n ip: include.ip ?? client.getOptions().sendDefaultPii,\n };\n\n if (normalizedRequest) {\n addNormalizedRequestDataToEvent(event, normalizedRequest, { ipAddress }, includeWithDefaultPiiApplied);\n }\n\n return event;\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Add data about a request to an event. Primarily for use in Node-based SDKs, but included in `@sentry/core`\n * so it can be used in cross-platform SDKs like `@sentry/nextjs`.\n */\nexport const requestDataIntegration = defineIntegration(_requestDataIntegration);\n\n/**\n * Add already normalized request data to an event.\n * This mutates the passed in event.\n */\nfunction addNormalizedRequestDataToEvent(\n event: Event,\n req: RequestEventData,\n // Data that should not go into `event.request` but is somehow related to requests\n additionalData: { ipAddress?: string },\n include: RequestDataIncludeOptions,\n): void {\n event.request = {\n ...event.request,\n ...extractNormalizedRequestData(req, include),\n };\n\n if (include.ip) {\n const ip = (req.headers && getClientIPAddress(req.headers)) || additionalData.ipAddress;\n if (ip) {\n event.user = {\n ...event.user,\n ip_address: ip,\n };\n }\n }\n}\n\nfunction extractNormalizedRequestData(\n normalizedRequest: RequestEventData,\n include: RequestDataIncludeOptions,\n): RequestEventData {\n const requestData: RequestEventData = {};\n const headers = { ...normalizedRequest.headers };\n\n if (include.headers) {\n requestData.headers = headers;\n\n // Remove the Cookie header in case cookie data should not be included in the event\n if (!include.cookies) {\n delete (headers as { cookie?: string }).cookie;\n }\n\n // Remove IP headers in case IP data should not be included in the event\n if (!include.ip) {\n ipHeaderNames.forEach(ipHeaderName => {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete (headers as Record<string, unknown>)[ipHeaderName];\n });\n }\n }\n\n requestData.method = normalizedRequest.method;\n\n if (include.url) {\n requestData.url = normalizedRequest.url;\n }\n\n if (include.cookies) {\n const cookies = normalizedRequest.cookies || (headers?.cookie ? parseCookie(headers.cookie) : undefined);\n requestData.cookies = cookies || {};\n }\n\n if (include.query_string) {\n requestData.query_string = normalizedRequest.query_string;\n }\n\n if (include.data) {\n requestData.data = normalizedRequest.data;\n }\n\n return requestData;\n}\n"],"names":[],"mappings":";;;;AAuBA;AACA,MAAM,eAAe,GAA8B;AACnD,EAAE,OAAO,EAAE,IAAI;AACf,EAAE,IAAI,EAAE,IAAI;AACZ,EAAE,OAAO,EAAE,IAAI;AACf,EAAE,YAAY,EAAE,IAAI;AACpB,EAAE,GAAG,EAAE,IAAI;AACX,CAAC;;AAED,MAAM,gBAAA,GAAmB,aAAa;;AAEtC,MAAM,uBAAA,IAA2B,CAAC,OAAO,GAAkC,EAAE,KAAK;AAClF,EAAE,MAAM,UAAU;AAClB,IAAI,GAAG,eAAe;AACtB,IAAI,GAAG,OAAO,CAAC,OAAO;AACtB,GAAG;;AAEH,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE;AACvC,MAAM,MAAM,EAAE,qBAAA,GAAwB,EAAC,EAAE,GAAI,KAAK;AAClD,MAAM,MAAM,EAAE,iBAAiB,EAAE,SAAA,EAAU,GAAI,qBAAqB;;AAEpE,MAAM,MAAM,4BAA4B,GAA8B;AACtE,QAAQ,GAAG,OAAO;AAClB,QAAQ,EAAE,EAAE,OAAO,CAAC,EAAA,IAAM,MAAM,CAAC,UAAU,EAAE,CAAC,cAAc;AAC5D,OAAO;;AAEP,MAAM,IAAI,iBAAiB,EAAE;AAC7B,QAAQ,+BAA+B,CAAC,KAAK,EAAE,iBAAiB,EAAE,EAAE,SAAA,EAAW,EAAE,4BAA4B,CAAC;AAC9G,MAAM;;AAEN,M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AAoC,YAAY,CAAC;AACjE,MAAM,CAAC,CAAC;AACR,IAAI;AACJ,EAAE;;AAEF,EAAE,WAAW,CAAC,MAAA,GAAS,iBAAiB,CAAC,MAAM;;AAE/C,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE;AACnB,IAAI,WAAW,CAAC,GAAA,GAAM,iBAAiB,CAAC,GAAG;AAC3C,EAAE;;AAEF,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE;AACvB,IAAI,MAAM,UAAU,iBAAiB,CAAC,OAAA,KAAY,OAAO,EAAE,SAAS,WAAW,CAAC,OAAO,CAAC,MAAM,CAAA,GAAI,SAAS,CAAC;AAC5G,IAAI,WAAW,CAAC,OAAA,GAAU,OAAA,IAAW,EAAE;AACvC,EAAE;;AAEF,EAAE,IAAI,OAAO,CAAC,YAAY,EAAE;AAC5B,IAAI,WAAW,CAAC,YAAA,GAAe,iBAAiB,CAAC,YAAY;AAC7D,EAAE;;AAEF,EAAE,IAAI,OAAO,CAAC,IAAI,EAAE;AACpB,IAAI,WAAW,CAAC,IAAA,GAAO,iBAAiB,CAAC,IAAI;AAC7C,EAAE;;AAEF,EAAE,OAAO,WAAW;AACpB;;;;"}
|
package/build/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"10.
|
|
1
|
+
{"type":"module","version":"10.50.0-alpha.0","sideEffects":false}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { captureException } from '../../exports.js';
|
|
2
2
|
import { getClient } from '../../currentScopes.js';
|
|
3
|
-
import { hasSpanStreamingEnabled } from '../spans/hasSpanStreamingEnabled.js';
|
|
4
3
|
import { isThenable } from '../../utils/is.js';
|
|
5
4
|
import { GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE, GEN_AI_RESPONSE_STREAMING_ATTRIBUTE, GEN_AI_RESPONSE_ID_ATTRIBUTE, GEN_AI_RESPONSE_MODEL_ATTRIBUTE, GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE, GEN_AI_RESPONSE_TEXT_ATTRIBUTE, GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE } from './gen-ai-attributes.js';
|
|
6
5
|
import { truncateGenAiStringInput, truncateGenAiMessages } from './messageTruncation.js';
|
|
@@ -25,11 +24,12 @@ function resolveAIRecordingOptions(options) {
|
|
|
25
24
|
/**
|
|
26
25
|
* Resolves whether truncation should be enabled.
|
|
27
26
|
* If the user explicitly set `enableTruncation`, that value is used.
|
|
28
|
-
* Otherwise, truncation
|
|
27
|
+
* Otherwise, truncation defaults to off: gen_ai spans always travel as v2
|
|
28
|
+
* spans (either via span streaming or extraction from the legacy transaction),
|
|
29
|
+
* so the legacy transaction size cap that motivated truncation no longer applies.
|
|
29
30
|
*/
|
|
30
31
|
function shouldEnableTruncation(enableTruncation) {
|
|
31
|
-
|
|
32
|
-
return enableTruncation ?? !(client && hasSpanStreamingEnabled(client));
|
|
32
|
+
return enableTruncation ?? false;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../src/tracing/ai/utils.ts"],"sourcesContent":["/**\n * Shared utils for AI integrations (OpenAI, Anthropic, Verce.AI, etc.)\n */\nimport { captureException } from '../../exports';\nimport { getClient } from '../../currentScopes';\nimport { hasSpanStreamingEnabled } from '../spans/hasSpanStreamingEnabled';\nimport type { Span } from '../../types-hoist/span';\nimport { isThenable } from '../../utils/is';\nimport {\n GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE,\n GEN_AI_RESPONSE_ID_ATTRIBUTE,\n GEN_AI_RESPONSE_MODEL_ATTRIBUTE,\n GEN_AI_RESPONSE_STREAMING_ATTRIBUTE,\n GEN_AI_RESPONSE_TEXT_ATTRIBUTE,\n GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,\n} from './gen-ai-attributes';\nimport { truncateGenAiMessages, truncateGenAiStringInput } from './messageTruncation';\n\nexport interface AIRecordingOptions {\n recordInputs?: boolean;\n recordOutputs?: boolean;\n}\n\n/**\n * A method registry entry describes a single instrumented method:\n * which gen_ai operation it maps to and whether it is intrinsically streaming.\n */\nexport interface InstrumentedMethodEntry {\n /** Operation name (e.g. 'chat', 'embeddings', 'generate_content'). Omit for factory methods that only need result proxying. */\n operation?: string;\n /** True if the method itself is always streaming (not param-based) */\n streaming?: boolean;\n /** When set, the method's return value is re-proxied with this as the base path */\n proxyResultPath?: string;\n}\n\n/**\n * Maps method paths to their registry entries.\n * Used by proxy-based AI client instrumentations to determine which methods\n * to instrument, what operation name to use, and whether they stream.\n */\nexport type InstrumentedMethodRegistry = Record<string, InstrumentedMethodEntry>;\n\n/**\n * Resolves AI recording options by falling back to the client's `sendDefaultPii` setting.\n * Precedence: explicit option > sendDefaultPii > false\n */\nexport function resolveAIRecordingOptions<T extends AIRecordingOptions>(options?: T): T & Required<AIRecordingOptions> {\n const sendDefaultPii = Boolean(getClient()?.getOptions().sendDefaultPii);\n return {\n ...options,\n recordInputs: options?.recordInputs ?? sendDefaultPii,\n recordOutputs: options?.recordOutputs ?? sendDefaultPii,\n } as T & Required<AIRecordingOptions>;\n}\n\n/**\n * Resolves whether truncation should be enabled.\n * If the user explicitly set `enableTruncation`, that value is used.\n * Otherwise, truncation is disabled when span streaming is active.\n */\nexport function shouldEnableTruncation(enableTruncation: boolean | undefined): boolean {\n const client = getClient();\n return enableTruncation ?? !(client && hasSpanStreamingEnabled(client));\n}\n\n/**\n * Build method path from current traversal\n */\nexport function buildMethodPath(currentPath: string, prop: string): string {\n return currentPath ? `${currentPath}.${prop}` : prop;\n}\n\n/**\n * Set token usage attributes\n * @param span - The span to add attributes to\n * @param promptTokens - The number of prompt tokens\n * @param completionTokens - The number of completion tokens\n * @param cachedInputTokens - The number of cached input tokens\n * @param cachedOutputTokens - The number of cached output tokens\n */\nexport function setTokenUsageAttributes(\n span: Span,\n promptTokens?: number,\n completionTokens?: number,\n cachedInputTokens?: number,\n cachedOutputTokens?: number,\n): void {\n if (promptTokens !== undefined) {\n span.setAttributes({\n [GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE]: promptTokens,\n });\n }\n if (completionTokens !== undefined) {\n span.setAttributes({\n [GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE]: completionTokens,\n });\n }\n if (\n promptTokens !== undefined ||\n completionTokens !== undefined ||\n cachedInputTokens !== undefined ||\n cachedOutputTokens !== undefined\n ) {\n /**\n * Total input tokens in a request is the summation of `input_tokens`,\n * `cache_creation_input_tokens`, and `cache_read_input_tokens`.\n */\n const totalTokens =\n (promptTokens ?? 0) + (completionTokens ?? 0) + (cachedInputTokens ?? 0) + (cachedOutputTokens ?? 0);\n\n span.setAttributes({\n [GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE]: totalTokens,\n });\n }\n}\n\nexport interface StreamResponseState {\n responseId?: string;\n responseModel?: string;\n finishReasons: string[];\n responseTexts: string[];\n toolCalls: unknown[];\n promptTokens?: number;\n completionTokens?: number;\n totalTokens?: number;\n cacheCreationInputTokens?: number;\n cacheReadInputTokens?: number;\n}\n\n/**\n * Ends a streaming span by setting all accumulated response attributes and ending the span.\n * Shared across OpenAI, Anthropic, and Google GenAI streaming implementations.\n */\nexport function endStreamSpan(span: Span, state: StreamResponseState, recordOutputs: boolean): void {\n if (!span.isRecording()) {\n return;\n }\n\n const attrs: Record<string, string | number | boolean> = {\n [GEN_AI_RESPONSE_STREAMING_ATTRIBUTE]: true,\n };\n\n if (state.responseId) attrs[GEN_AI_RESPONSE_ID_ATTRIBUTE] = state.responseId;\n if (state.responseModel) attrs[GEN_AI_RESPONSE_MODEL_ATTRIBUTE] = state.responseModel;\n\n if (state.promptTokens !== undefined) attrs[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] = state.promptTokens;\n if (state.completionTokens !== undefined) attrs[GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE] = state.completionTokens;\n\n // Use explicit total if provided (OpenAI, Google), otherwise compute from cache tokens (Anthropic)\n if (state.totalTokens !== undefined) {\n attrs[GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE] = state.totalTokens;\n } else if (\n state.promptTokens !== undefined ||\n state.completionTokens !== undefined ||\n state.cacheCreationInputTokens !== undefined ||\n state.cacheReadInputTokens !== undefined\n ) {\n attrs[GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE] =\n (state.promptTokens ?? 0) +\n (state.completionTokens ?? 0) +\n (state.cacheCreationInputTokens ?? 0) +\n (state.cacheReadInputTokens ?? 0);\n }\n\n if (state.finishReasons.length) {\n attrs[GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE] = JSON.stringify(state.finishReasons);\n }\n if (recordOutputs && state.responseTexts.length) {\n attrs[GEN_AI_RESPONSE_TEXT_ATTRIBUTE] = state.responseTexts.join('');\n }\n if (recordOutputs && state.toolCalls.length) {\n attrs[GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE] = JSON.stringify(state.toolCalls);\n }\n\n span.setAttributes(attrs);\n span.end();\n}\n\n/**\n * Serialize a value to a JSON string without truncation.\n * Strings are returned as-is, arrays and objects are JSON-stringified.\n */\nexport function getJsonString<T>(value: T | T[]): string {\n if (typeof value === 'string') {\n return value;\n }\n return JSON.stringify(value);\n}\n\n/**\n * Get the truncated JSON string for a string or array of strings.\n *\n * @param value - The string or array of strings to truncate\n * @returns The truncated JSON string\n */\nexport function getTruncatedJsonString<T>(value: T | T[]): string {\n if (typeof value === 'string') {\n // Some values are already JSON strings, so we don't need to duplicate the JSON parsing\n return truncateGenAiStringInput(value);\n }\n if (Array.isArray(value)) {\n // truncateGenAiMessages returns an array of strings, so we need to stringify it\n const truncatedMessages = truncateGenAiMessages(value);\n return JSON.stringify(truncatedMessages);\n }\n // value is an object, so we need to stringify it\n return JSON.stringify(value);\n}\n\n/**\n * Extract system instructions from messages array.\n * Finds the first system message and formats it according to OpenTelemetry semantic conventions.\n *\n * @param messages - Array of messages to extract system instructions from\n * @returns systemInstructions (JSON string) and filteredMessages (without system message)\n */\nexport function extractSystemInstructions(messages: unknown[] | unknown): {\n systemInstructions: string | undefined;\n filteredMessages: unknown[] | unknown;\n} {\n if (!Array.isArray(messages)) {\n return { systemInstructions: undefined, filteredMessages: messages };\n }\n\n const systemMessageIndex = messages.findIndex(\n msg => msg && typeof msg === 'object' && 'role' in msg && (msg as { role: string }).role === 'system',\n );\n\n if (systemMessageIndex === -1) {\n return { systemInstructions: undefined, filteredMessages: messages };\n }\n\n const systemMessage = messages[systemMessageIndex] as { role: string; content?: string | unknown };\n const systemContent =\n typeof systemMessage.content === 'string'\n ? systemMessage.content\n : systemMessage.content !== undefined\n ? JSON.stringify(systemMessage.content)\n : undefined;\n\n if (!systemContent) {\n return { systemInstructions: undefined, filteredMessages: messages };\n }\n\n const systemInstructions = JSON.stringify([{ type: 'text', content: systemContent }]);\n const filteredMessages = [...messages.slice(0, systemMessageIndex), ...messages.slice(systemMessageIndex + 1)];\n\n return { systemInstructions, filteredMessages };\n}\n\n/**\n * Creates a wrapped version of .withResponse() that replaces the data field\n * with the instrumented result while preserving metadata (response, request_id).\n */\nasync function createWithResponseWrapper<T>(\n originalWithResponse: Promise<unknown>,\n instrumentedPromise: Promise<T>,\n mechanismType: string,\n): Promise<unknown> {\n // Attach catch handler to originalWithResponse immediately to prevent unhandled rejection\n // If instrumentedPromise rejects first, we still need this handled\n const safeOriginalWithResponse = originalWithResponse.catch(error => {\n captureException(error, {\n mechanism: {\n handled: false,\n type: mechanismType,\n },\n });\n throw error;\n });\n\n const instrumentedResult = await instrumentedPromise;\n const originalWrapper = await safeOriginalWithResponse;\n\n // Combine instrumented result with original metadata\n if (originalWrapper && typeof originalWrapper === 'object' && 'data' in originalWrapper) {\n return {\n ...originalWrapper,\n data: instrumentedResult,\n };\n }\n return instrumentedResult;\n}\n\n/**\n * Wraps a promise-like object to preserve additional methods (like .withResponse())\n * that AI SDK clients (OpenAI, Anthropic) attach to their APIPromise return values.\n *\n * Standard Promise methods (.then, .catch, .finally) are routed to the instrumented\n * promise to preserve Sentry's span instrumentation, while custom SDK methods are\n * forwarded to the original promise to maintain the SDK's API surface.\n */\nexport function wrapPromiseWithMethods<R>(\n originalPromiseLike: Promise<R>,\n instrumentedPromise: Promise<R>,\n mechanismType: string,\n): Promise<R> {\n // If the original result is not thenable, return the instrumented promise\n if (!isThenable(originalPromiseLike)) {\n return instrumentedPromise;\n }\n\n // Create a proxy that forwards Promise methods to instrumentedPromise\n // and preserves additional methods from the original result\n return new Proxy(originalPromiseLike, {\n get(target: object, prop: string | symbol): unknown {\n // For standard Promise methods (.then, .catch, .finally, Symbol.toStringTag),\n // use instrumentedPromise to preserve Sentry instrumentation.\n // For custom methods (like .withResponse()), use the original target.\n const useInstrumentedPromise = prop in Promise.prototype || prop === Symbol.toStringTag;\n const source = useInstrumentedPromise ? instrumentedPromise : target;\n\n const value = Reflect.get(source, prop) as unknown;\n\n // Special handling for .withResponse() to preserve instrumentation\n // .withResponse() returns { data: T, response: Response, request_id: string }\n if (prop === 'withResponse' && typeof value === 'function') {\n return function wrappedWithResponse(this: unknown): unknown {\n const originalWithResponse = (value as (...args: unknown[]) => unknown).call(target);\n return createWithResponseWrapper(originalWithResponse, instrumentedPromise, mechanismType);\n };\n }\n\n return typeof value === 'function' ? value.bind(source) : value;\n },\n }) as Promise<R>;\n}\n"],"names":[],"mappings":";;;;;;;AAAA;AACA;AACA;;AA4CA;AACA;AACA;AACA;AACO,SAAS,yBAAyB,CAA+B,OAAO,EAAwC;AACvH,EAAE,MAAM,cAAA,GAAiB,OAAO,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,CA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A,sBAAA,GAAA,mBAAA,GAAA,MAAA;;AAEA,MAAA,MAAA,KAAA,GAAA,OAAA,CAAA,GAAA,CAAA,MAAA,EAAA,IAAA,CAAA;;AAEA;AACA;AACA,MAAA,IAAA,IAAA,KAAA,cAAA,IAAA,OAAA,KAAA,KAAA,UAAA,EAAA;AACA,QAAA,OAAA,SAAA,mBAAA,GAAA;AACA,UAAA,MAAA,oBAAA,GAAA,CAAA,KAAA,GAAA,IAAA,CAAA,MAAA,CAAA;AACA,UAAA,OAAA,yBAAA,CAAA,oBAAA,EAAA,mBAAA,EAAA,aAAA,CAAA;AACA,QAAA,CAAA;AACA,MAAA;;AAEA,MAAA,OAAA,OAAA,KAAA,KAAA,UAAA,GAAA,KAAA,CAAA,IAAA,CAAA,MAAA,CAAA,GAAA,KAAA;AACA,IAAA,CAAA;AACA,GAAA,CAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/tracing/ai/utils.ts"],"sourcesContent":["/**\n * Shared utils for AI integrations (OpenAI, Anthropic, Verce.AI, etc.)\n */\nimport { captureException } from '../../exports';\nimport { getClient } from '../../currentScopes';\nimport type { Span } from '../../types-hoist/span';\nimport { isThenable } from '../../utils/is';\nimport {\n GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE,\n GEN_AI_RESPONSE_ID_ATTRIBUTE,\n GEN_AI_RESPONSE_MODEL_ATTRIBUTE,\n GEN_AI_RESPONSE_STREAMING_ATTRIBUTE,\n GEN_AI_RESPONSE_TEXT_ATTRIBUTE,\n GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,\n} from './gen-ai-attributes';\nimport { truncateGenAiMessages, truncateGenAiStringInput } from './messageTruncation';\n\nexport interface AIRecordingOptions {\n recordInputs?: boolean;\n recordOutputs?: boolean;\n}\n\n/**\n * A method registry entry describes a single instrumented method:\n * which gen_ai operation it maps to and whether it is intrinsically streaming.\n */\nexport interface InstrumentedMethodEntry {\n /** Operation name (e.g. 'chat', 'embeddings', 'generate_content'). Omit for factory methods that only need result proxying. */\n operation?: string;\n /** True if the method itself is always streaming (not param-based) */\n streaming?: boolean;\n /** When set, the method's return value is re-proxied with this as the base path */\n proxyResultPath?: string;\n}\n\n/**\n * Maps method paths to their registry entries.\n * Used by proxy-based AI client instrumentations to determine which methods\n * to instrument, what operation name to use, and whether they stream.\n */\nexport type InstrumentedMethodRegistry = Record<string, InstrumentedMethodEntry>;\n\n/**\n * Resolves AI recording options by falling back to the client's `sendDefaultPii` setting.\n * Precedence: explicit option > sendDefaultPii > false\n */\nexport function resolveAIRecordingOptions<T extends AIRecordingOptions>(options?: T): T & Required<AIRecordingOptions> {\n const sendDefaultPii = Boolean(getClient()?.getOptions().sendDefaultPii);\n return {\n ...options,\n recordInputs: options?.recordInputs ?? sendDefaultPii,\n recordOutputs: options?.recordOutputs ?? sendDefaultPii,\n } as T & Required<AIRecordingOptions>;\n}\n\n/**\n * Resolves whether truncation should be enabled.\n * If the user explicitly set `enableTruncation`, that value is used.\n * Otherwise, truncation defaults to off: gen_ai spans always travel as v2\n * spans (either via span streaming or extraction from the legacy transaction),\n * so the legacy transaction size cap that motivated truncation no longer applies.\n */\nexport function shouldEnableTruncation(enableTruncation: boolean | undefined): boolean {\n return enableTruncation ?? false;\n}\n\n/**\n * Build method path from current traversal\n */\nexport function buildMethodPath(currentPath: string, prop: string): string {\n return currentPath ? `${currentPath}.${prop}` : prop;\n}\n\n/**\n * Set token usage attributes\n * @param span - The span to add attributes to\n * @param promptTokens - The number of prompt tokens\n * @param completionTokens - The number of completion tokens\n * @param cachedInputTokens - The number of cached input tokens\n * @param cachedOutputTokens - The number of cached output tokens\n */\nexport function setTokenUsageAttributes(\n span: Span,\n promptTokens?: number,\n completionTokens?: number,\n cachedInputTokens?: number,\n cachedOutputTokens?: number,\n): void {\n if (promptTokens !== undefined) {\n span.setAttributes({\n [GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE]: promptTokens,\n });\n }\n if (completionTokens !== undefined) {\n span.setAttributes({\n [GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE]: completionTokens,\n });\n }\n if (\n promptTokens !== undefined ||\n completionTokens !== undefined ||\n cachedInputTokens !== undefined ||\n cachedOutputTokens !== undefined\n ) {\n /**\n * Total input tokens in a request is the summation of `input_tokens`,\n * `cache_creation_input_tokens`, and `cache_read_input_tokens`.\n */\n const totalTokens =\n (promptTokens ?? 0) + (completionTokens ?? 0) + (cachedInputTokens ?? 0) + (cachedOutputTokens ?? 0);\n\n span.setAttributes({\n [GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE]: totalTokens,\n });\n }\n}\n\nexport interface StreamResponseState {\n responseId?: string;\n responseModel?: string;\n finishReasons: string[];\n responseTexts: string[];\n toolCalls: unknown[];\n promptTokens?: number;\n completionTokens?: number;\n totalTokens?: number;\n cacheCreationInputTokens?: number;\n cacheReadInputTokens?: number;\n}\n\n/**\n * Ends a streaming span by setting all accumulated response attributes and ending the span.\n * Shared across OpenAI, Anthropic, and Google GenAI streaming implementations.\n */\nexport function endStreamSpan(span: Span, state: StreamResponseState, recordOutputs: boolean): void {\n if (!span.isRecording()) {\n return;\n }\n\n const attrs: Record<string, string | number | boolean> = {\n [GEN_AI_RESPONSE_STREAMING_ATTRIBUTE]: true,\n };\n\n if (state.responseId) attrs[GEN_AI_RESPONSE_ID_ATTRIBUTE] = state.responseId;\n if (state.responseModel) attrs[GEN_AI_RESPONSE_MODEL_ATTRIBUTE] = state.responseModel;\n\n if (state.promptTokens !== undefined) attrs[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] = state.promptTokens;\n if (state.completionTokens !== undefined) attrs[GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE] = state.completionTokens;\n\n // Use explicit total if provided (OpenAI, Google), otherwise compute from cache tokens (Anthropic)\n if (state.totalTokens !== undefined) {\n attrs[GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE] = state.totalTokens;\n } else if (\n state.promptTokens !== undefined ||\n state.completionTokens !== undefined ||\n state.cacheCreationInputTokens !== undefined ||\n state.cacheReadInputTokens !== undefined\n ) {\n attrs[GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE] =\n (state.promptTokens ?? 0) +\n (state.completionTokens ?? 0) +\n (state.cacheCreationInputTokens ?? 0) +\n (state.cacheReadInputTokens ?? 0);\n }\n\n if (state.finishReasons.length) {\n attrs[GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE] = JSON.stringify(state.finishReasons);\n }\n if (recordOutputs && state.responseTexts.length) {\n attrs[GEN_AI_RESPONSE_TEXT_ATTRIBUTE] = state.responseTexts.join('');\n }\n if (recordOutputs && state.toolCalls.length) {\n attrs[GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE] = JSON.stringify(state.toolCalls);\n }\n\n span.setAttributes(attrs);\n span.end();\n}\n\n/**\n * Serialize a value to a JSON string without truncation.\n * Strings are returned as-is, arrays and objects are JSON-stringified.\n */\nexport function getJsonString<T>(value: T | T[]): string {\n if (typeof value === 'string') {\n return value;\n }\n return JSON.stringify(value);\n}\n\n/**\n * Get the truncated JSON string for a string or array of strings.\n *\n * @param value - The string or array of strings to truncate\n * @returns The truncated JSON string\n */\nexport function getTruncatedJsonString<T>(value: T | T[]): string {\n if (typeof value === 'string') {\n // Some values are already JSON strings, so we don't need to duplicate the JSON parsing\n return truncateGenAiStringInput(value);\n }\n if (Array.isArray(value)) {\n // truncateGenAiMessages returns an array of strings, so we need to stringify it\n const truncatedMessages = truncateGenAiMessages(value);\n return JSON.stringify(truncatedMessages);\n }\n // value is an object, so we need to stringify it\n return JSON.stringify(value);\n}\n\n/**\n * Extract system instructions from messages array.\n * Finds the first system message and formats it according to OpenTelemetry semantic conventions.\n *\n * @param messages - Array of messages to extract system instructions from\n * @returns systemInstructions (JSON string) and filteredMessages (without system message)\n */\nexport function extractSystemInstructions(messages: unknown[] | unknown): {\n systemInstructions: string | undefined;\n filteredMessages: unknown[] | unknown;\n} {\n if (!Array.isArray(messages)) {\n return { systemInstructions: undefined, filteredMessages: messages };\n }\n\n const systemMessageIndex = messages.findIndex(\n msg => msg && typeof msg === 'object' && 'role' in msg && (msg as { role: string }).role === 'system',\n );\n\n if (systemMessageIndex === -1) {\n return { systemInstructions: undefined, filteredMessages: messages };\n }\n\n const systemMessage = messages[systemMessageIndex] as { role: string; content?: string | unknown };\n const systemContent =\n typeof systemMessage.content === 'string'\n ? systemMessage.content\n : systemMessage.content !== undefined\n ? JSON.stringify(systemMessage.content)\n : undefined;\n\n if (!systemContent) {\n return { systemInstructions: undefined, filteredMessages: messages };\n }\n\n const systemInstructions = JSON.stringify([{ type: 'text', content: systemContent }]);\n const filteredMessages = [...messages.slice(0, systemMessageIndex), ...messages.slice(systemMessageIndex + 1)];\n\n return { systemInstructions, filteredMessages };\n}\n\n/**\n * Creates a wrapped version of .withResponse() that replaces the data field\n * with the instrumented result while preserving metadata (response, request_id).\n */\nasync function createWithResponseWrapper<T>(\n originalWithResponse: Promise<unknown>,\n instrumentedPromise: Promise<T>,\n mechanismType: string,\n): Promise<unknown> {\n // Attach catch handler to originalWithResponse immediately to prevent unhandled rejection\n // If instrumentedPromise rejects first, we still need this handled\n const safeOriginalWithResponse = originalWithResponse.catch(error => {\n captureException(error, {\n mechanism: {\n handled: false,\n type: mechanismType,\n },\n });\n throw error;\n });\n\n const instrumentedResult = await instrumentedPromise;\n const originalWrapper = await safeOriginalWithResponse;\n\n // Combine instrumented result with original metadata\n if (originalWrapper && typeof originalWrapper === 'object' && 'data' in originalWrapper) {\n return {\n ...originalWrapper,\n data: instrumentedResult,\n };\n }\n return instrumentedResult;\n}\n\n/**\n * Wraps a promise-like object to preserve additional methods (like .withResponse())\n * that AI SDK clients (OpenAI, Anthropic) attach to their APIPromise return values.\n *\n * Standard Promise methods (.then, .catch, .finally) are routed to the instrumented\n * promise to preserve Sentry's span instrumentation, while custom SDK methods are\n * forwarded to the original promise to maintain the SDK's API surface.\n */\nexport function wrapPromiseWithMethods<R>(\n originalPromiseLike: Promise<R>,\n instrumentedPromise: Promise<R>,\n mechanismType: string,\n): Promise<R> {\n // If the original result is not thenable, return the instrumented promise\n if (!isThenable(originalPromiseLike)) {\n return instrumentedPromise;\n }\n\n // Create a proxy that forwards Promise methods to instrumentedPromise\n // and preserves additional methods from the original result\n return new Proxy(originalPromiseLike, {\n get(target: object, prop: string | symbol): unknown {\n // For standard Promise methods (.then, .catch, .finally, Symbol.toStringTag),\n // use instrumentedPromise to preserve Sentry instrumentation.\n // For custom methods (like .withResponse()), use the original target.\n const useInstrumentedPromise = prop in Promise.prototype || prop === Symbol.toStringTag;\n const source = useInstrumentedPromise ? instrumentedPromise : target;\n\n const value = Reflect.get(source, prop) as unknown;\n\n // Special handling for .withResponse() to preserve instrumentation\n // .withResponse() returns { data: T, response: Response, request_id: string }\n if (prop === 'withResponse' && typeof value === 'function') {\n return function wrappedWithResponse(this: unknown): unknown {\n const originalWithResponse = (value as (...args: unknown[]) => unknown).call(target);\n return createWithResponseWrapper(originalWithResponse, instrumentedPromise, mechanismType);\n };\n }\n\n return typeof value === 'function' ? value.bind(source) : value;\n },\n }) as Promise<R>;\n}\n"],"names":[],"mappings":";;;;;;AAAA;AACA;AACA;;AA2CA;AACA;AACA;AACA;AACO,SAAS,yBAAyB,CAA+B,OAAO,EAAwC;AACvH,EAAE,MAAM,cAAA,GAAiB,OAAO,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,CAAC,cAAc,CAAC;AAC1E,EAAE,OAAO;AACT,IAAI,GAAG,OAAO;AACd,IAAI,YAAY,EAAE,OAAO,EAAE,YAAA,IAAgB,cAAc;AACzD,IAAI,aAAa,EAAE,OAAO,EAAE,aAAA,IAAiB,cAAc;AAC3D,GAAE;AACF;;AAEA;AACA;AACA;AACA;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A,CAAA,MAAA,CAAA;AACA,UAAA,OAAA,yBAAA,CAAA,oBAAA,EAAA,mBAAA,EAAA,aAAA,CAAA;AACA,QAAA,CAAA;AACA,MAAA;;AAEA,MAAA,OAAA,OAAA,KAAA,KAAA,UAAA,GAAA,KAAA,CAAA,IAAA,CAAA,MAAA,CAAA,GAAA,KAAA;AACA,IAAA,CAAA;AACA,GAAA,CAAA;AACA;;;;"}
|
|
@@ -350,8 +350,12 @@ class SentrySpan {
|
|
|
350
350
|
// remove internal root span attributes we don't need to send.
|
|
351
351
|
/* eslint-disable @typescript-eslint/no-dynamic-delete */
|
|
352
352
|
delete this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];
|
|
353
|
+
let hasGenAiSpans = false;
|
|
353
354
|
spans.forEach(span => {
|
|
354
355
|
delete span.data[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];
|
|
356
|
+
if (span.op?.startsWith('gen_ai.')) {
|
|
357
|
+
hasGenAiSpans = true;
|
|
358
|
+
}
|
|
355
359
|
});
|
|
356
360
|
// eslint-enabled-next-line @typescript-eslint/no-dynamic-delete
|
|
357
361
|
|
|
@@ -373,6 +377,7 @@ class SentrySpan {
|
|
|
373
377
|
capturedSpanScope,
|
|
374
378
|
capturedSpanIsolationScope,
|
|
375
379
|
dynamicSamplingContext: getDynamicSamplingContextFromSpan(this),
|
|
380
|
+
hasGenAiSpans,
|
|
376
381
|
},
|
|
377
382
|
request: normalizedRequest,
|
|
378
383
|
...(source && {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentrySpan.js","sources":["../../../src/tracing/sentrySpan.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport { getClient, getCurrentScope } from '../currentScopes';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { createSpanEnvelope } from '../envelope';\nimport {\n SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME,\n SEMANTIC_ATTRIBUTE_PROFILE_ID,\n SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n} from '../semanticAttributes';\nimport type { SpanEnvelope } from '../types-hoist/envelope';\nimport type { TransactionEvent } from '../types-hoist/event';\nimport type { SpanLink } from '../types-hoist/link';\nimport type {\n SentrySpanArguments,\n Span,\n SpanAttributes,\n SpanAttributeValue,\n SpanContextData,\n SpanJSON,\n SpanOrigin,\n SpanTimeInput,\n StreamedSpanJSON,\n} from '../types-hoist/span';\nimport type { SpanStatus } from '../types-hoist/spanStatus';\nimport type { TimedEvent } from '../types-hoist/timedEvent';\nimport { debug } from '../utils/debug-logger';\nimport { generateSpanId, generateTraceId } from '../utils/propagationContext';\nimport {\n convertSpanLinksForEnvelope,\n getRootSpan,\n getSimpleStatusMessage,\n getSpanDescendants,\n getStatusMessage,\n getStreamedSpanLinks,\n spanTimeInputToSeconds,\n spanToJSON,\n spanToTransactionTraceContext,\n TRACE_FLAG_NONE,\n TRACE_FLAG_SAMPLED,\n} from '../utils/spanUtils';\nimport { timestampInSeconds } from '../utils/time';\nimport { getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';\nimport { logSpanEnd } from './logSpans';\nimport { timedEventsToMeasurements } from './measurement';\nimport { hasSpanStreamingEnabled } from './spans/hasSpanStreamingEnabled';\nimport { getCapturedScopesOnSpan } from './utils';\n\nconst MAX_SPAN_COUNT = 1000;\n\n/**\n * Span contains all data about a span\n */\nexport class SentrySpan implements Span {\n protected _traceId: string;\n protected _spanId: string;\n protected _parentSpanId?: string | undefined;\n protected _sampled: boolean | undefined;\n protected _name?: string | undefined;\n protected _attributes: SpanAttributes;\n protected _links?: SpanLink[];\n /** Epoch timestamp in seconds when the span started. */\n protected _startTime: number;\n /** Epoch timestamp in seconds when the span ended. */\n protected _endTime?: number | undefined;\n /** Internal keeper of the status */\n protected _status?: SpanStatus;\n /** The timed events added to this span. */\n protected _events: TimedEvent[];\n\n /** if true, treat span as a standalone span (not part of a transaction) */\n private _isStandaloneSpan?: boolean;\n\n /**\n * You should never call the constructor manually, always use `Sentry.startSpan()`\n * or other span methods.\n * @internal\n * @hideconstructor\n * @hidden\n */\n public constructor(spanContext: SentrySpanArguments = {}) {\n this._traceId = spanContext.traceId || generateTraceId();\n this._spanId = spanContext.spanId || generateSpanId();\n this._startTime = spanContext.startTimestamp || timestampInSeconds();\n this._links = spanContext.links;\n\n this._attributes = {};\n this.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'manual',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: spanContext.op,\n ...spanContext.attributes,\n });\n\n this._name = spanContext.name;\n\n if (spanContext.parentSpanId) {\n this._parentSpanId = spanContext.parentSpanId;\n }\n // We want to include booleans as well here\n if ('sampled' in spanContext) {\n this._sampled = spanContext.sampled;\n }\n if (spanContext.endTimestamp) {\n this._endTime = spanContext.endTimestamp;\n }\n\n this._events = [];\n\n this._isStandaloneSpan = spanContext.isStandalone;\n\n // If the span is already ended, ensure we finalize the span immediately\n if (this._endTime) {\n this._onSpanEnded();\n }\n }\n\n /** @inheritDoc */\n public addLink(link: SpanLink): this {\n if (this._links) {\n this._links.push(link);\n } else {\n this._links = [link];\n }\n return this;\n }\n\n /** @inheritDoc */\n public addLinks(links: SpanLink[]): this {\n if (this._links) {\n this._links.push(...links);\n } else {\n this._links = links;\n }\n return this;\n }\n\n /**\n * This should generally not be used,\n * but it is needed for being compliant with the OTEL Span interface.\n *\n * @hidden\n * @internal\n */\n public recordException(_exception: unknown, _time?: number | undefined): void {\n // noop\n }\n\n /** @inheritdoc */\n public spanContext(): SpanContextData {\n const { _spanId: spanId, _traceId: traceId, _sampled: sampled } = this;\n return {\n spanId,\n traceId,\n traceFlags: sampled ? TRACE_FLAG_SAMPLED : TRACE_FLAG_NONE,\n };\n }\n\n /** @inheritdoc */\n public setAttribute(key: string, value: SpanAttributeValue | undefined): this {\n if (value === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._attributes[key];\n } else {\n this._attributes[key] = value;\n }\n\n return this;\n }\n\n /** @inheritdoc */\n public setAttributes(attributes: SpanAttributes): this {\n Object.keys(attributes).forEach(key => this.setAttribute(key, attributes[key]));\n return this;\n }\n\n /**\n * This should generally not be used,\n * but we need it for browser tracing where we want to adjust the start time afterwards.\n * USE THIS WITH CAUTION!\n *\n * @hidden\n * @internal\n */\n public updateStartTime(timeInput: SpanTimeInput): void {\n this._startTime = spanTimeInputToSeconds(timeInput);\n }\n\n /**\n * @inheritDoc\n */\n public setStatus(value: SpanStatus): this {\n this._status = value;\n return this;\n }\n\n /**\n * @inheritDoc\n */\n public updateName(name: string): this {\n this._name = name;\n this.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'custom');\n return this;\n }\n\n /** @inheritdoc */\n public end(endTimestamp?: SpanTimeInput): void {\n // If already ended, skip\n if (this._endTime) {\n return;\n }\n\n this._endTime = spanTimeInputToSeconds(endTimestamp);\n logSpanEnd(this);\n\n this._onSpanEnded();\n }\n\n /**\n * Get JSON representation of this span.\n *\n * @hidden\n * @internal This method is purely for internal purposes and should not be used outside\n * of SDK code. If you need to get a JSON representation of a span,\n * use `spanToJSON(span)` instead.\n */\n public getSpanJSON(): SpanJSON {\n return {\n data: this._attributes,\n description: this._name,\n op: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP],\n parent_span_id: this._parentSpanId,\n span_id: this._spanId,\n start_timestamp: this._startTime,\n status: getStatusMessage(this._status),\n timestamp: this._endTime,\n trace_id: this._traceId,\n origin: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined,\n profile_id: this._attributes[SEMANTIC_ATTRIBUTE_PROFILE_ID] as string | undefined,\n exclusive_time: this._attributes[SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME] as number | undefined,\n measurements: timedEventsToMeasurements(this._events),\n is_segment: (this._isStandaloneSpan && getRootSpan(this) === this) || undefined,\n segment_id: this._isStandaloneSpan ? getRootSpan(this).spanContext().spanId : undefined,\n links: convertSpanLinksForEnvelope(this._links),\n };\n }\n\n /**\n * Get {@link StreamedSpanJSON} representation of this span.\n *\n * @hidden\n * @internal This method is purely for internal purposes and should not be used outside\n * of SDK code. If you need to get a JSON representation of a span,\n * use `spanToStreamedSpanJSON(span)` instead.\n */\n public getStreamedSpanJSON(): StreamedSpanJSON {\n return {\n name: this._name ?? '',\n span_id: this._spanId,\n trace_id: this._traceId,\n parent_span_id: this._parentSpanId,\n start_timestamp: this._startTime,\n // just in case _endTime is not set, we use the start time (i.e. duration 0)\n end_timestamp: this._endTime ?? this._startTime,\n is_segment: this._isStandaloneSpan || this === getRootSpan(this),\n status: getSimpleStatusMessage(this._status),\n attributes: this._attributes,\n links: getStreamedSpanLinks(this._links),\n };\n }\n\n /** @inheritdoc */\n public isRecording(): boolean {\n return !this._endTime && !!this._sampled;\n }\n\n /**\n * @inheritdoc\n */\n public addEvent(\n name: string,\n attributesOrStartTime?: SpanAttributes | SpanTimeInput,\n startTime?: SpanTimeInput,\n ): this {\n DEBUG_BUILD && debug.log('[Tracing] Adding an event to span:', name);\n\n const time = isSpanTimeInput(attributesOrStartTime) ? attributesOrStartTime : startTime || timestampInSeconds();\n const attributes = isSpanTimeInput(attributesOrStartTime) ? {} : attributesOrStartTime || {};\n\n const event: TimedEvent = {\n name,\n time: spanTimeInputToSeconds(time),\n attributes,\n };\n\n this._events.push(event);\n\n return this;\n }\n\n /**\n * This method should generally not be used,\n * but for now we need a way to publicly check if the `_isStandaloneSpan` flag is set.\n * USE THIS WITH CAUTION!\n * @internal\n * @hidden\n * @experimental\n */\n public isStandaloneSpan(): boolean {\n return !!this._isStandaloneSpan;\n }\n\n /** Emit `spanEnd` when the span is ended. */\n private _onSpanEnded(): void {\n const client = getClient();\n if (client) {\n client.emit('spanEnd', this);\n // Guarding sending standalone v1 spans as v2 streamed spans for now.\n // Otherwise they'd be sent once as v1 spans and again as streamed spans.\n // We'll migrate CLS and LCP spans to streamed spans in a later PR and\n // INP spans in the next major of the SDK. At that point, we can fully remove\n // standalone v1 spans <3\n if (!this._isStandaloneSpan) {\n client.emit('afterSpanEnd', this);\n }\n }\n\n // A segment span is basically the root span of a local span tree.\n // So for now, this is either what we previously refer to as the root span,\n // or a standalone span.\n const isSegmentSpan = this._isStandaloneSpan || this === getRootSpan(this);\n\n if (!isSegmentSpan) {\n return;\n }\n\n // if this is a standalone span, we send it immediately\n if (this._isStandaloneSpan) {\n if (this._sampled) {\n sendSpanEnvelope(createSpanEnvelope([this], client));\n } else {\n DEBUG_BUILD &&\n debug.log('[Tracing] Discarding standalone span because its trace was not chosen to be sampled.');\n if (client) {\n client.recordDroppedEvent('sample_rate', 'span');\n }\n }\n return;\n } else if (client && hasSpanStreamingEnabled(client)) {\n // TODO (spans): Remove standalone span custom logic in favor of sending simple v2 web vital spans\n client.emit('afterSegmentSpanEnd', this);\n return;\n }\n\n const transactionEvent = this._convertSpanToTransaction();\n if (transactionEvent) {\n const scope = getCapturedScopesOnSpan(this).scope || getCurrentScope();\n scope.captureEvent(transactionEvent);\n }\n }\n\n /**\n * Finish the transaction & prepare the event to send to Sentry.\n */\n private _convertSpanToTransaction(): TransactionEvent | undefined {\n // We can only convert finished spans\n if (!isFullFinishedSpan(spanToJSON(this))) {\n return undefined;\n }\n\n if (!this._name) {\n DEBUG_BUILD && debug.warn('Transaction has no name, falling back to `<unlabeled transaction>`.');\n this._name = '<unlabeled transaction>';\n }\n\n const { scope: capturedSpanScope, isolationScope: capturedSpanIsolationScope } = getCapturedScopesOnSpan(this);\n\n const normalizedRequest = capturedSpanScope?.getScopeData().sdkProcessingMetadata?.normalizedRequest;\n\n if (this._sampled !== true) {\n return undefined;\n }\n\n // The transaction span itself as well as any potential standalone spans should be filtered out\n const finishedSpans = getSpanDescendants(this).filter(span => span !== this && !isStandaloneSpan(span));\n\n const spans = finishedSpans.map(span => spanToJSON(span)).filter(isFullFinishedSpan);\n\n const source = this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];\n\n // remove internal root span attributes we don't need to send.\n /* eslint-disable @typescript-eslint/no-dynamic-delete */\n delete this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];\n spans.forEach(span => {\n delete span.data[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];\n });\n // eslint-enabled-next-line @typescript-eslint/no-dynamic-delete\n\n const transaction: TransactionEvent = {\n contexts: {\n trace: spanToTransactionTraceContext(this),\n },\n spans:\n // spans.sort() mutates the array, but `spans` is already a copy so we can safely do this here\n // we do not use spans anymore after this point\n spans.length > MAX_SPAN_COUNT\n ? spans.sort((a, b) => a.start_timestamp - b.start_timestamp).slice(0, MAX_SPAN_COUNT)\n : spans,\n start_timestamp: this._startTime,\n timestamp: this._endTime,\n transaction: this._name,\n type: 'transaction',\n sdkProcessingMetadata: {\n capturedSpanScope,\n capturedSpanIsolationScope,\n dynamicSamplingContext: getDynamicSamplingContextFromSpan(this),\n },\n request: normalizedRequest,\n ...(source && {\n transaction_info: {\n source,\n },\n }),\n };\n\n const measurements = timedEventsToMeasurements(this._events);\n const hasMeasurements = measurements && Object.keys(measurements).length;\n\n if (hasMeasurements) {\n DEBUG_BUILD &&\n debug.log(\n '[Measurements] Adding measurements to transaction event',\n JSON.stringify(measurements, undefined, 2),\n );\n transaction.measurements = measurements;\n }\n\n return transaction;\n }\n}\n\nfunction isSpanTimeInput(value: undefined | SpanAttributes | SpanTimeInput): value is SpanTimeInput {\n return (value && typeof value === 'number') || value instanceof Date || Array.isArray(value);\n}\n\n// We want to filter out any incomplete SpanJSON objects\nfunction isFullFinishedSpan(input: Partial<SpanJSON>): input is SpanJSON {\n return !!input.start_timestamp && !!input.timestamp && !!input.span_id && !!input.trace_id;\n}\n\n/** `SentrySpan`s can be sent as a standalone span rather than belonging to a transaction */\nfunction isStandaloneSpan(span: Span): boolean {\n return span instanceof SentrySpan && span.isStandaloneSpan();\n}\n\n/**\n * Sends a `SpanEnvelope`.\n *\n * Note: If the envelope's spans are dropped, e.g. via `beforeSendSpan`,\n * the envelope will not be sent either.\n */\nfunction sendSpanEnvelope(envelope: SpanEnvelope): void {\n const client = getClient();\n if (!client) {\n return;\n }\n\n const spanItems = envelope[1];\n if (!spanItems || spanItems.length === 0) {\n client.recordDroppedEvent('before_send', 'span');\n return;\n }\n\n // sendEnvelope should not throw\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n client.sendEnvelope(envelope);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA;;AAkDA,MAAM,cAAA,GAAiB,IAAI;;AAE3B;AACA;AACA;AACO,MAAM,YAA2B;;AAQxC;;AAEA;;AAEA;;AAEA;;AAGA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAS,WAAW,CAAC,WAAW,GAAwB,EAAE,EAAE;AAC5D,IAAI,IAAI,CAAC,QAAA,GAAW,WAAW,CAAC,OAAA,IAAW,eAAe,EAAE;AAC5D,IAAI,IAAI,CAAC,OAAA,GAAU,WAAW,CAAC,MAAA,IAAU,cAAc,EAAE;AACzD,IAAI,IAAI,CAAC,UAAA,GAAa,WAAW,CAAC,cAAA,IAAkB,kBAAkB,EAAE;AACxE,IAAI,IAAI,CAAC,MAAA,GAAS,WAAW,CAAC,KAAK;;AAEnC,IAAI,IAAI,CAAC,WAAA,GAAc,EAAE;AACzB,IAAI,IAAI,CAAC,aAAa,CAAC;AACvB,MAAM,CAAC,gCAAgC,GAAG,QAAQ;AAClD,MAAM,CAAC,4BAA4B,GAAG,WAAW,CAAC,EAAE;AACpD,MAAM,GAAG,WAAW,CAAC,UAAU;AAC/B,KAAK,CAAC;;AAEN,IAAI,IAAI,CAAC,KAAA,GAAQ,WAAW,CAAC,IAAI;;AAEjC,IAAI,IAAI,WAAW,CAAC,YAAY,EAAE;AAClC,MA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ACA,EAAE,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC;AAC/B;;;;"}
|
|
1
|
+
{"version":3,"file":"sentrySpan.js","sources":["../../../src/tracing/sentrySpan.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport { getClient, getCurrentScope } from '../currentScopes';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { createSpanEnvelope } from '../envelope';\nimport {\n SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME,\n SEMANTIC_ATTRIBUTE_PROFILE_ID,\n SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n} from '../semanticAttributes';\nimport type { SpanEnvelope } from '../types-hoist/envelope';\nimport type { TransactionEvent } from '../types-hoist/event';\nimport type { SpanLink } from '../types-hoist/link';\nimport type {\n SentrySpanArguments,\n Span,\n SpanAttributes,\n SpanAttributeValue,\n SpanContextData,\n SpanJSON,\n SpanOrigin,\n SpanTimeInput,\n StreamedSpanJSON,\n} from '../types-hoist/span';\nimport type { SpanStatus } from '../types-hoist/spanStatus';\nimport type { TimedEvent } from '../types-hoist/timedEvent';\nimport { debug } from '../utils/debug-logger';\nimport { generateSpanId, generateTraceId } from '../utils/propagationContext';\nimport {\n convertSpanLinksForEnvelope,\n getRootSpan,\n getSimpleStatusMessage,\n getSpanDescendants,\n getStatusMessage,\n getStreamedSpanLinks,\n spanTimeInputToSeconds,\n spanToJSON,\n spanToTransactionTraceContext,\n TRACE_FLAG_NONE,\n TRACE_FLAG_SAMPLED,\n} from '../utils/spanUtils';\nimport { timestampInSeconds } from '../utils/time';\nimport { getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';\nimport { logSpanEnd } from './logSpans';\nimport { timedEventsToMeasurements } from './measurement';\nimport { hasSpanStreamingEnabled } from './spans/hasSpanStreamingEnabled';\nimport { getCapturedScopesOnSpan } from './utils';\n\nconst MAX_SPAN_COUNT = 1000;\n\n/**\n * Span contains all data about a span\n */\nexport class SentrySpan implements Span {\n protected _traceId: string;\n protected _spanId: string;\n protected _parentSpanId?: string | undefined;\n protected _sampled: boolean | undefined;\n protected _name?: string | undefined;\n protected _attributes: SpanAttributes;\n protected _links?: SpanLink[];\n /** Epoch timestamp in seconds when the span started. */\n protected _startTime: number;\n /** Epoch timestamp in seconds when the span ended. */\n protected _endTime?: number | undefined;\n /** Internal keeper of the status */\n protected _status?: SpanStatus;\n /** The timed events added to this span. */\n protected _events: TimedEvent[];\n\n /** if true, treat span as a standalone span (not part of a transaction) */\n private _isStandaloneSpan?: boolean;\n\n /**\n * You should never call the constructor manually, always use `Sentry.startSpan()`\n * or other span methods.\n * @internal\n * @hideconstructor\n * @hidden\n */\n public constructor(spanContext: SentrySpanArguments = {}) {\n this._traceId = spanContext.traceId || generateTraceId();\n this._spanId = spanContext.spanId || generateSpanId();\n this._startTime = spanContext.startTimestamp || timestampInSeconds();\n this._links = spanContext.links;\n\n this._attributes = {};\n this.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'manual',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: spanContext.op,\n ...spanContext.attributes,\n });\n\n this._name = spanContext.name;\n\n if (spanContext.parentSpanId) {\n this._parentSpanId = spanContext.parentSpanId;\n }\n // We want to include booleans as well here\n if ('sampled' in spanContext) {\n this._sampled = spanContext.sampled;\n }\n if (spanContext.endTimestamp) {\n this._endTime = spanContext.endTimestamp;\n }\n\n this._events = [];\n\n this._isStandaloneSpan = spanContext.isStandalone;\n\n // If the span is already ended, ensure we finalize the span immediately\n if (this._endTime) {\n this._onSpanEnded();\n }\n }\n\n /** @inheritDoc */\n public addLink(link: SpanLink): this {\n if (this._links) {\n this._links.push(link);\n } else {\n this._links = [link];\n }\n return this;\n }\n\n /** @inheritDoc */\n public addLinks(links: SpanLink[]): this {\n if (this._links) {\n this._links.push(...links);\n } else {\n this._links = links;\n }\n return this;\n }\n\n /**\n * This should generally not be used,\n * but it is needed for being compliant with the OTEL Span interface.\n *\n * @hidden\n * @internal\n */\n public recordException(_exception: unknown, _time?: number | undefined): void {\n // noop\n }\n\n /** @inheritdoc */\n public spanContext(): SpanContextData {\n const { _spanId: spanId, _traceId: traceId, _sampled: sampled } = this;\n return {\n spanId,\n traceId,\n traceFlags: sampled ? TRACE_FLAG_SAMPLED : TRACE_FLAG_NONE,\n };\n }\n\n /** @inheritdoc */\n public setAttribute(key: string, value: SpanAttributeValue | undefined): this {\n if (value === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this._attributes[key];\n } else {\n this._attributes[key] = value;\n }\n\n return this;\n }\n\n /** @inheritdoc */\n public setAttributes(attributes: SpanAttributes): this {\n Object.keys(attributes).forEach(key => this.setAttribute(key, attributes[key]));\n return this;\n }\n\n /**\n * This should generally not be used,\n * but we need it for browser tracing where we want to adjust the start time afterwards.\n * USE THIS WITH CAUTION!\n *\n * @hidden\n * @internal\n */\n public updateStartTime(timeInput: SpanTimeInput): void {\n this._startTime = spanTimeInputToSeconds(timeInput);\n }\n\n /**\n * @inheritDoc\n */\n public setStatus(value: SpanStatus): this {\n this._status = value;\n return this;\n }\n\n /**\n * @inheritDoc\n */\n public updateName(name: string): this {\n this._name = name;\n this.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'custom');\n return this;\n }\n\n /** @inheritdoc */\n public end(endTimestamp?: SpanTimeInput): void {\n // If already ended, skip\n if (this._endTime) {\n return;\n }\n\n this._endTime = spanTimeInputToSeconds(endTimestamp);\n logSpanEnd(this);\n\n this._onSpanEnded();\n }\n\n /**\n * Get JSON representation of this span.\n *\n * @hidden\n * @internal This method is purely for internal purposes and should not be used outside\n * of SDK code. If you need to get a JSON representation of a span,\n * use `spanToJSON(span)` instead.\n */\n public getSpanJSON(): SpanJSON {\n return {\n data: this._attributes,\n description: this._name,\n op: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP],\n parent_span_id: this._parentSpanId,\n span_id: this._spanId,\n start_timestamp: this._startTime,\n status: getStatusMessage(this._status),\n timestamp: this._endTime,\n trace_id: this._traceId,\n origin: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined,\n profile_id: this._attributes[SEMANTIC_ATTRIBUTE_PROFILE_ID] as string | undefined,\n exclusive_time: this._attributes[SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME] as number | undefined,\n measurements: timedEventsToMeasurements(this._events),\n is_segment: (this._isStandaloneSpan && getRootSpan(this) === this) || undefined,\n segment_id: this._isStandaloneSpan ? getRootSpan(this).spanContext().spanId : undefined,\n links: convertSpanLinksForEnvelope(this._links),\n };\n }\n\n /**\n * Get {@link StreamedSpanJSON} representation of this span.\n *\n * @hidden\n * @internal This method is purely for internal purposes and should not be used outside\n * of SDK code. If you need to get a JSON representation of a span,\n * use `spanToStreamedSpanJSON(span)` instead.\n */\n public getStreamedSpanJSON(): StreamedSpanJSON {\n return {\n name: this._name ?? '',\n span_id: this._spanId,\n trace_id: this._traceId,\n parent_span_id: this._parentSpanId,\n start_timestamp: this._startTime,\n // just in case _endTime is not set, we use the start time (i.e. duration 0)\n end_timestamp: this._endTime ?? this._startTime,\n is_segment: this._isStandaloneSpan || this === getRootSpan(this),\n status: getSimpleStatusMessage(this._status),\n attributes: this._attributes,\n links: getStreamedSpanLinks(this._links),\n };\n }\n\n /** @inheritdoc */\n public isRecording(): boolean {\n return !this._endTime && !!this._sampled;\n }\n\n /**\n * @inheritdoc\n */\n public addEvent(\n name: string,\n attributesOrStartTime?: SpanAttributes | SpanTimeInput,\n startTime?: SpanTimeInput,\n ): this {\n DEBUG_BUILD && debug.log('[Tracing] Adding an event to span:', name);\n\n const time = isSpanTimeInput(attributesOrStartTime) ? attributesOrStartTime : startTime || timestampInSeconds();\n const attributes = isSpanTimeInput(attributesOrStartTime) ? {} : attributesOrStartTime || {};\n\n const event: TimedEvent = {\n name,\n time: spanTimeInputToSeconds(time),\n attributes,\n };\n\n this._events.push(event);\n\n return this;\n }\n\n /**\n * This method should generally not be used,\n * but for now we need a way to publicly check if the `_isStandaloneSpan` flag is set.\n * USE THIS WITH CAUTION!\n * @internal\n * @hidden\n * @experimental\n */\n public isStandaloneSpan(): boolean {\n return !!this._isStandaloneSpan;\n }\n\n /** Emit `spanEnd` when the span is ended. */\n private _onSpanEnded(): void {\n const client = getClient();\n if (client) {\n client.emit('spanEnd', this);\n // Guarding sending standalone v1 spans as v2 streamed spans for now.\n // Otherwise they'd be sent once as v1 spans and again as streamed spans.\n // We'll migrate CLS and LCP spans to streamed spans in a later PR and\n // INP spans in the next major of the SDK. At that point, we can fully remove\n // standalone v1 spans <3\n if (!this._isStandaloneSpan) {\n client.emit('afterSpanEnd', this);\n }\n }\n\n // A segment span is basically the root span of a local span tree.\n // So for now, this is either what we previously refer to as the root span,\n // or a standalone span.\n const isSegmentSpan = this._isStandaloneSpan || this === getRootSpan(this);\n\n if (!isSegmentSpan) {\n return;\n }\n\n // if this is a standalone span, we send it immediately\n if (this._isStandaloneSpan) {\n if (this._sampled) {\n sendSpanEnvelope(createSpanEnvelope([this], client));\n } else {\n DEBUG_BUILD &&\n debug.log('[Tracing] Discarding standalone span because its trace was not chosen to be sampled.');\n if (client) {\n client.recordDroppedEvent('sample_rate', 'span');\n }\n }\n return;\n } else if (client && hasSpanStreamingEnabled(client)) {\n // TODO (spans): Remove standalone span custom logic in favor of sending simple v2 web vital spans\n client.emit('afterSegmentSpanEnd', this);\n return;\n }\n\n const transactionEvent = this._convertSpanToTransaction();\n if (transactionEvent) {\n const scope = getCapturedScopesOnSpan(this).scope || getCurrentScope();\n scope.captureEvent(transactionEvent);\n }\n }\n\n /**\n * Finish the transaction & prepare the event to send to Sentry.\n */\n private _convertSpanToTransaction(): TransactionEvent | undefined {\n // We can only convert finished spans\n if (!isFullFinishedSpan(spanToJSON(this))) {\n return undefined;\n }\n\n if (!this._name) {\n DEBUG_BUILD && debug.warn('Transaction has no name, falling back to `<unlabeled transaction>`.');\n this._name = '<unlabeled transaction>';\n }\n\n const { scope: capturedSpanScope, isolationScope: capturedSpanIsolationScope } = getCapturedScopesOnSpan(this);\n\n const normalizedRequest = capturedSpanScope?.getScopeData().sdkProcessingMetadata?.normalizedRequest;\n\n if (this._sampled !== true) {\n return undefined;\n }\n\n // The transaction span itself as well as any potential standalone spans should be filtered out\n const finishedSpans = getSpanDescendants(this).filter(span => span !== this && !isStandaloneSpan(span));\n\n const spans = finishedSpans.map(span => spanToJSON(span)).filter(isFullFinishedSpan);\n\n const source = this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];\n\n // remove internal root span attributes we don't need to send.\n /* eslint-disable @typescript-eslint/no-dynamic-delete */\n delete this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];\n let hasGenAiSpans = false;\n spans.forEach(span => {\n delete span.data[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];\n if (span.op?.startsWith('gen_ai.')) {\n hasGenAiSpans = true;\n }\n });\n // eslint-enabled-next-line @typescript-eslint/no-dynamic-delete\n\n const transaction: TransactionEvent = {\n contexts: {\n trace: spanToTransactionTraceContext(this),\n },\n spans:\n // spans.sort() mutates the array, but `spans` is already a copy so we can safely do this here\n // we do not use spans anymore after this point\n spans.length > MAX_SPAN_COUNT\n ? spans.sort((a, b) => a.start_timestamp - b.start_timestamp).slice(0, MAX_SPAN_COUNT)\n : spans,\n start_timestamp: this._startTime,\n timestamp: this._endTime,\n transaction: this._name,\n type: 'transaction',\n sdkProcessingMetadata: {\n capturedSpanScope,\n capturedSpanIsolationScope,\n dynamicSamplingContext: getDynamicSamplingContextFromSpan(this),\n hasGenAiSpans,\n },\n request: normalizedRequest,\n ...(source && {\n transaction_info: {\n source,\n },\n }),\n };\n\n const measurements = timedEventsToMeasurements(this._events);\n const hasMeasurements = measurements && Object.keys(measurements).length;\n\n if (hasMeasurements) {\n DEBUG_BUILD &&\n debug.log(\n '[Measurements] Adding measurements to transaction event',\n JSON.stringify(measurements, undefined, 2),\n );\n transaction.measurements = measurements;\n }\n\n return transaction;\n }\n}\n\nfunction isSpanTimeInput(value: undefined | SpanAttributes | SpanTimeInput): value is SpanTimeInput {\n return (value && typeof value === 'number') || value instanceof Date || Array.isArray(value);\n}\n\n// We want to filter out any incomplete SpanJSON objects\nfunction isFullFinishedSpan(input: Partial<SpanJSON>): input is SpanJSON {\n return !!input.start_timestamp && !!input.timestamp && !!input.span_id && !!input.trace_id;\n}\n\n/** `SentrySpan`s can be sent as a standalone span rather than belonging to a transaction */\nfunction isStandaloneSpan(span: Span): boolean {\n return span instanceof SentrySpan && span.isStandaloneSpan();\n}\n\n/**\n * Sends a `SpanEnvelope`.\n *\n * Note: If the envelope's spans are dropped, e.g. via `beforeSendSpan`,\n * the envelope will not be sent either.\n */\nfunction sendSpanEnvelope(envelope: SpanEnvelope): void {\n const client = getClient();\n if (!client) {\n return;\n }\n\n const spanItems = envelope[1];\n if (!spanItems || spanItems.length === 0) {\n client.recordDroppedEvent('before_send', 'span');\n return;\n }\n\n // sendEnvelope should not throw\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n client.sendEnvelope(envelope);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA;;AAkDA,MAAM,cAAA,GAAiB,IAAI;;AAE3B;AACA;AACA;AACO,MAAM,YAA2B;;AAQxC;;AAEA;;AAEA;;AAEA;;AAGA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAS,WAAW,CAAC,WAAW,GAAwB,EAAE,EAAE;AAC5D,IAAI,IAAI,CAAC,QAAA,GAAW,WAAW,CAAC,OAAA,IAAW,eAAe,EAAE;AAC5D,IAAI,IAAI,CAAC,OAAA,GAAU,WAAW,CAAC,MAAA,IAAU,cAAc,EAAE;AACzD,IAAI,IAAI,CAAC,UAAA,GAAa,WAAW,CAAC,cAAA,IAAkB,kB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AC,OAAA,IAAW,CAAC,CAAC,KAAK,CAAC,QAAQ;AAC5F;;AAEA;AACA,SAAS,gBAAgB,CAAC,IAAI,EAAiB;AAC/C,EAAE,OAAO,gBAAgB,UAAA,IAAc,IAAI,CAAC,gBAAgB,EAAE;AAC9D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,gBAAgB,CAAC,QAAQ,EAAsB;AACxD,EAAE,MAAM,MAAA,GAAS,SAAS,EAAE;AAC5B,EAAE,IAAI,CAAC,MAAM,EAAE;AACf,IAAI;AACJ,EAAE;;AAEF,EAAE,MAAM,SAAA,GAAY,QAAQ,CAAC,CAAC,CAAC;AAC/B,EAAE,IAAI,CAAC,SAAA,IAAa,SAAS,CAAC,MAAA,KAAW,CAAC,EAAE;AAC5C,IAAI,MAAM,CAAC,kBAAkB,CAAC,aAAa,EAAE,MAAM,CAAC;AACpD,IAAI;AACJ,EAAE;;AAEF;AACA;AACA,EAAE,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC;AAC/B;;;;"}
|
|
@@ -28,10 +28,12 @@ function captureSpan(span, client) {
|
|
|
28
28
|
|
|
29
29
|
if (spanJSON.is_segment) {
|
|
30
30
|
// Allow hook subscribers to mutate the segment span JSON
|
|
31
|
+
// This also invokes the `processSegmentSpan` hook of all integrations
|
|
31
32
|
client.emit('processSegmentSpan', spanJSON);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
//
|
|
35
|
+
// This allows hook subscribers to mutate the span JSON
|
|
36
|
+
// This also invokes the `processSpan` hook of all integrations
|
|
35
37
|
client.emit('processSpan', spanJSON);
|
|
36
38
|
|
|
37
39
|
const { beforeSendSpan } = client.getOptions();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"captureSpan.js","sources":["../../../../src/tracing/spans/captureSpan.ts"],"sourcesContent":["import type { RawAttributes } from '../../attributes';\nimport type { Client } from '../../client';\nimport type { ScopeData } from '../../scope';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT,\n SEMANTIC_ATTRIBUTE_SENTRY_RELEASE,\n SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION,\n SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID,\n SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n SEMANTIC_ATTRIBUTE_USER_EMAIL,\n SEMANTIC_ATTRIBUTE_USER_ID,\n SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS,\n SEMANTIC_ATTRIBUTE_USER_USERNAME,\n} from '../../semanticAttributes';\nimport type { SerializedStreamedSpan, Span, StreamedSpanJSON } from '../../types-hoist/span';\nimport { getCombinedScopeData } from '../../utils/scopeData';\nimport {\n INTERNAL_getSegmentSpan,\n showSpanDropWarning,\n spanToStreamedSpanJSON,\n streamedSpanJsonToSerializedSpan,\n} from '../../utils/spanUtils';\nimport { getCapturedScopesOnSpan } from '../utils';\nimport { isStreamedBeforeSendSpanCallback } from './beforeSendSpan';\n\nexport type SerializedStreamedSpanWithSegmentSpan = SerializedStreamedSpan & {\n _segmentSpan: Span;\n};\n\n/**\n * Captures a span and returns a JSON representation to be enqueued for sending.\n *\n * IMPORTANT: This function converts the span to JSON immediately to avoid writing\n * to an already-ended OTel span instance (which is blocked by the OTel Span class).\n *\n * @returns the final serialized span with a reference to its segment span. This reference\n * is needed later on to compute the DSC for the span envelope.\n */\nexport function captureSpan(span: Span, client: Client): SerializedStreamedSpanWithSegmentSpan {\n // Convert to JSON FIRST - we cannot write to an already-ended span\n const spanJSON = spanToStreamedSpanJSON(span);\n\n const segmentSpan = INTERNAL_getSegmentSpan(span);\n const serializedSegmentSpan = spanToStreamedSpanJSON(segmentSpan);\n\n const { isolationScope: spanIsolationScope, scope: spanScope } = getCapturedScopesOnSpan(span);\n\n const finalScopeData = getCombinedScopeData(spanIsolationScope, spanScope);\n\n applyCommonSpanAttributes(spanJSON, serializedSegmentSpan, client, finalScopeData);\n\n if (spanJSON.is_segment) {\n applyScopeToSegmentSpan(spanJSON, finalScopeData);\n // Allow hook subscribers to mutate the segment span JSON\n client.emit('processSegmentSpan', spanJSON);\n }\n\n //
|
|
1
|
+
{"version":3,"file":"captureSpan.js","sources":["../../../../src/tracing/spans/captureSpan.ts"],"sourcesContent":["import type { RawAttributes } from '../../attributes';\nimport type { Client } from '../../client';\nimport type { ScopeData } from '../../scope';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT,\n SEMANTIC_ATTRIBUTE_SENTRY_RELEASE,\n SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION,\n SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID,\n SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n SEMANTIC_ATTRIBUTE_USER_EMAIL,\n SEMANTIC_ATTRIBUTE_USER_ID,\n SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS,\n SEMANTIC_ATTRIBUTE_USER_USERNAME,\n} from '../../semanticAttributes';\nimport type { SerializedStreamedSpan, Span, StreamedSpanJSON } from '../../types-hoist/span';\nimport { getCombinedScopeData } from '../../utils/scopeData';\nimport {\n INTERNAL_getSegmentSpan,\n showSpanDropWarning,\n spanToStreamedSpanJSON,\n streamedSpanJsonToSerializedSpan,\n} from '../../utils/spanUtils';\nimport { getCapturedScopesOnSpan } from '../utils';\nimport { isStreamedBeforeSendSpanCallback } from './beforeSendSpan';\n\nexport type SerializedStreamedSpanWithSegmentSpan = SerializedStreamedSpan & {\n _segmentSpan: Span;\n};\n\n/**\n * Captures a span and returns a JSON representation to be enqueued for sending.\n *\n * IMPORTANT: This function converts the span to JSON immediately to avoid writing\n * to an already-ended OTel span instance (which is blocked by the OTel Span class).\n *\n * @returns the final serialized span with a reference to its segment span. This reference\n * is needed later on to compute the DSC for the span envelope.\n */\nexport function captureSpan(span: Span, client: Client): SerializedStreamedSpanWithSegmentSpan {\n // Convert to JSON FIRST - we cannot write to an already-ended span\n const spanJSON = spanToStreamedSpanJSON(span);\n\n const segmentSpan = INTERNAL_getSegmentSpan(span);\n const serializedSegmentSpan = spanToStreamedSpanJSON(segmentSpan);\n\n const { isolationScope: spanIsolationScope, scope: spanScope } = getCapturedScopesOnSpan(span);\n\n const finalScopeData = getCombinedScopeData(spanIsolationScope, spanScope);\n\n applyCommonSpanAttributes(spanJSON, serializedSegmentSpan, client, finalScopeData);\n\n if (spanJSON.is_segment) {\n applyScopeToSegmentSpan(spanJSON, finalScopeData);\n // Allow hook subscribers to mutate the segment span JSON\n // This also invokes the `processSegmentSpan` hook of all integrations\n client.emit('processSegmentSpan', spanJSON);\n }\n\n // This allows hook subscribers to mutate the span JSON\n // This also invokes the `processSpan` hook of all integrations\n client.emit('processSpan', spanJSON);\n\n const { beforeSendSpan } = client.getOptions();\n const processedSpan =\n beforeSendSpan && isStreamedBeforeSendSpanCallback(beforeSendSpan)\n ? applyBeforeSendSpanCallback(spanJSON, beforeSendSpan)\n : spanJSON;\n\n // Backfill sentry.span.source from sentry.source. Only `sentry.span.source` is respected by Sentry.\n // TODO(v11): Remove this backfill once we renamed SEMANTIC_ATTRIBUTE_SENTRY_SOURCE to sentry.span.source\n const spanNameSource = processedSpan.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];\n if (spanNameSource) {\n safeSetSpanJSONAttributes(processedSpan, {\n // Purposefully not using a constant defined here like in other attributes:\n // This will be the name for SEMANTIC_ATTRIBUTE_SENTRY_SOURCE in v11\n 'sentry.span.source': spanNameSource,\n });\n }\n\n return {\n ...streamedSpanJsonToSerializedSpan(processedSpan),\n _segmentSpan: segmentSpan,\n };\n}\n\nfunction applyScopeToSegmentSpan(_segmentSpanJSON: StreamedSpanJSON, _scopeData: ScopeData): void {\n // TODO: Apply all scope and request data from auto instrumentation (contexts, request) to segment span\n // This will follow in a separate PR\n}\n\nfunction applyCommonSpanAttributes(\n spanJSON: StreamedSpanJSON,\n serializedSegmentSpan: StreamedSpanJSON,\n client: Client,\n scopeData: ScopeData,\n): void {\n const sdk = client.getSdkMetadata();\n const { release, environment, sendDefaultPii } = client.getOptions();\n\n // avoid overwriting any previously set attributes (from users or potentially our SDK instrumentation)\n safeSetSpanJSONAttributes(spanJSON, {\n [SEMANTIC_ATTRIBUTE_SENTRY_RELEASE]: release,\n [SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT]: environment,\n [SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME]: serializedSegmentSpan.name,\n [SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID]: serializedSegmentSpan.span_id,\n [SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME]: sdk?.sdk?.name,\n [SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION]: sdk?.sdk?.version,\n ...(sendDefaultPii\n ? {\n [SEMANTIC_ATTRIBUTE_USER_ID]: scopeData.user?.id,\n [SEMANTIC_ATTRIBUTE_USER_EMAIL]: scopeData.user?.email,\n [SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: scopeData.user?.ip_address,\n [SEMANTIC_ATTRIBUTE_USER_USERNAME]: scopeData.user?.username,\n }\n : {}),\n ...scopeData.attributes,\n });\n}\n\n/**\n * Apply a user-provided beforeSendSpan callback to a span JSON.\n */\nexport function applyBeforeSendSpanCallback(\n span: StreamedSpanJSON,\n beforeSendSpan: (span: StreamedSpanJSON) => StreamedSpanJSON,\n): StreamedSpanJSON {\n const modifedSpan = beforeSendSpan(span);\n if (!modifedSpan) {\n showSpanDropWarning();\n return span;\n }\n return modifedSpan;\n}\n\n/**\n * Safely set attributes on a span JSON.\n * If an attribute already exists, it will not be overwritten.\n */\nexport function safeSetSpanJSONAttributes(\n spanJSON: StreamedSpanJSON,\n newAttributes: RawAttributes<Record<string, unknown>>,\n): void {\n const originalAttributes = spanJSON.attributes ?? (spanJSON.attributes = {});\n\n Object.entries(newAttributes).forEach(([key, value]) => {\n if (value != null && !(key in originalAttributes)) {\n originalAttributes[key] = value;\n }\n });\n}\n"],"names":[],"mappings":";;;;;;AA+BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,WAAW,CAAC,IAAI,EAAQ,MAAM,EAAiD;AAC/F;AACA,EAAE,MAAM,QAAA,GAAW,sBAAsB,CAAC,IAAI,CAAC;;AAE/C,EAAE,MAAM,WAAA,GAAc,uBAAuB,CAAC,IAAI,CAAC;AACnD,EAAE,MAAM,qBAAA,GAAwB,sBAAsB,CAAC,WAAW,CAAC;;AAEnE,EAAE,MAAM,EAAE,cAAc,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAA,EAAU,GAAI,uBAAuB,CAAC,IAAI,CAAC;;AAEhG,EAAE,MAAM,iBAAiB,oBAAoB,CAAC,kBAAkB,EAAE,SAAS,CAAC;;AAE5E,EAAE,yBAAyB,CAAC,QAAQ,EAAE,qBAAqB,EAAE,MAAM,EAAE,cAAc,CAAC;;AAEpF,EAAE,IAAI,QAAQ,CAAC,UAAU,EAAE;AAE3B;AACA;AACA,IAAI,MAAM,CAAC,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC;AAC/C,EAAE;;AAEF;AACA;AACA,EAAE,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC;;AAEtC,EAAE,MAAM,EAAE,cAAA,EAAe,GAAI,MAAM,CAAC,UAAU,EAAE;AAChD,EAAE,MAAM,aAAA;AACR,IAAI,cAAA,IAAkB,gCAAgC,CAAC,cAAc;AACrE,QAAQ,2BAA2B,CAAC,QAAQ,EAAE,cAAc;AAC5D,QAAQ,QAAQ;;AAEhB;AACA;AACA,EAAE,MAAM,iBAAiB,aAAa,CAAC,UAAU,GAAG,gCAAgC,CAAC;AACrF,EAAE,IAAI,cAAc,EAAE;AACtB,IAAI,yBAAyB,CAAC,aA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,EAAE,cAAc;AAChB,EAAoB;AACpB,EAAE,MAAM,WAAA,GAAc,cAAc,CAAC,IAAI,CAAC;AAC1C,EAAE,IAAI,CAAC,WAAW,EAAE;AACpB,IAAI,mBAAmB,EAAE;AACzB,IAAI,OAAO,IAAI;AACf,EAAE;AACF,EAAE,OAAO,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACO,SAAS,yBAAyB;AACzC,EAAE,QAAQ;AACV,EAAE,aAAa;AACf,EAAQ;AACR,EAAE,MAAM,kBAAA,GAAqB,QAAQ,CAAC,UAAA,KAAe,QAAQ,CAAC,UAAA,GAAa,EAAE,CAAC;;AAE9E,EAAE,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;AAC1D,IAAI,IAAI,KAAA,IAAS,IAAA,IAAQ,EAAE,GAAA,IAAO,kBAAkB,CAAC,EAAE;AACvD,MAAM,kBAAkB,CAAC,GAAG,CAAA,GAAI,KAAK;AACrC,IAAI;AACJ,EAAE,CAAC,CAAC;AACJ;;;;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { hasSpanStreamingEnabled } from './hasSpanStreamingEnabled.js';
|
|
2
|
+
import { spanJsonToSerializedStreamedSpan } from './spanJsonToStreamedSpan.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extracts gen_ai spans from a transaction event, converts them to span v2 format,
|
|
6
|
+
* and returns them as a SpanContainerItem.
|
|
7
|
+
*
|
|
8
|
+
* Only applies to static mode (non-streaming) transactions.
|
|
9
|
+
*
|
|
10
|
+
* WARNING: This function mutates `event.spans` by removing the extracted gen_ai spans
|
|
11
|
+
* from the array. Call this before creating the event envelope so the transaction
|
|
12
|
+
* item does not include the extracted spans.
|
|
13
|
+
*/
|
|
14
|
+
function extractGenAiSpansFromEvent(event, client) {
|
|
15
|
+
if (
|
|
16
|
+
event.type !== 'transaction' ||
|
|
17
|
+
!event.spans?.length ||
|
|
18
|
+
!event.sdkProcessingMetadata?.hasGenAiSpans ||
|
|
19
|
+
hasSpanStreamingEnabled(client)
|
|
20
|
+
) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const genAiSpans = [];
|
|
25
|
+
const remainingSpans = [];
|
|
26
|
+
|
|
27
|
+
for (const span of event.spans) {
|
|
28
|
+
if (span.op?.startsWith('gen_ai.')) {
|
|
29
|
+
genAiSpans.push(spanJsonToSerializedStreamedSpan(span));
|
|
30
|
+
} else {
|
|
31
|
+
remainingSpans.push(span);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (genAiSpans.length === 0) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
event.spans = remainingSpans;
|
|
40
|
+
|
|
41
|
+
return [
|
|
42
|
+
{ type: 'span', item_count: genAiSpans.length, content_type: 'application/vnd.sentry.items.span.v2+json' },
|
|
43
|
+
{ items: genAiSpans },
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { extractGenAiSpansFromEvent };
|
|
48
|
+
//# sourceMappingURL=extractGenAiSpans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractGenAiSpans.js","sources":["../../../../src/tracing/spans/extractGenAiSpans.ts"],"sourcesContent":["import type { Client } from '../../client';\nimport type { SpanContainerItem } from '../../types-hoist/envelope';\nimport type { Event } from '../../types-hoist/event';\nimport { hasSpanStreamingEnabled } from './hasSpanStreamingEnabled';\nimport { spanJsonToSerializedStreamedSpan } from './spanJsonToStreamedSpan';\n\n/**\n * Extracts gen_ai spans from a transaction event, converts them to span v2 format,\n * and returns them as a SpanContainerItem.\n *\n * Only applies to static mode (non-streaming) transactions.\n *\n * WARNING: This function mutates `event.spans` by removing the extracted gen_ai spans\n * from the array. Call this before creating the event envelope so the transaction\n * item does not include the extracted spans.\n */\nexport function extractGenAiSpansFromEvent(event: Event, client: Client): SpanContainerItem | undefined {\n if (\n event.type !== 'transaction' ||\n !event.spans?.length ||\n !event.sdkProcessingMetadata?.hasGenAiSpans ||\n hasSpanStreamingEnabled(client)\n ) {\n return undefined;\n }\n\n const genAiSpans = [];\n const remainingSpans = [];\n\n for (const span of event.spans) {\n if (span.op?.startsWith('gen_ai.')) {\n genAiSpans.push(spanJsonToSerializedStreamedSpan(span));\n } else {\n remainingSpans.push(span);\n }\n }\n\n if (genAiSpans.length === 0) {\n return undefined;\n }\n\n event.spans = remainingSpans;\n\n return [\n { type: 'span', item_count: genAiSpans.length, content_type: 'application/vnd.sentry.items.span.v2+json' },\n { items: genAiSpans },\n ];\n}\n"],"names":[],"mappings":";;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,0BAA0B,CAAC,KAAK,EAAS,MAAM,EAAyC;AACxG,EAAE;AACF,IAAI,KAAK,CAAC,IAAA,KAAS,aAAA;AACnB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,MAAA;AAClB,IAAI,CAAC,KAAK,CAAC,qBAAqB,EAAE,aAAA;AAClC,IAAI,uBAAuB,CAAC,MAAM;AAClC,IAAI;AACJ,IAAI,OAAO,SAAS;AACpB,EAAE;;AAEF,EAAE,MAAM,UAAA,GAAa,EAAE;AACvB,EAAE,MAAM,cAAA,GAAiB,EAAE;;AAE3B,EAAE,KAAK,MAAM,IAAA,IAAQ,KAAK,CAAC,KAAK,EAAE;AAClC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,SAAS,CAAC,EAAE;AACxC,MAAM,UAAU,CAAC,IAAI,CAAC,gCAAgC,CAAC,IAAI,CAAC,CAAC;AAC7D,IAAI,OAAO;AACX,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;AAC/B,IAAI;AACJ,EAAE;;AAEF,EAAE,IAAI,UAAU,CAAC,MAAA,KAAW,CAAC,EAAE;AAC/B,IAAI,OAAO,SAAS;AACpB,EAAE;;AAEF,EAAE,KAAK,CAAC,KAAA,GAAQ,cAAc;;AAE9B,EAAE,OAAO;AACT,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,YAAY,EAAE,6CAA6C;AAC9G,IAAI,EAAE,KAAK,EAAE,UAAA,EAAY;AACzB,GAAG;AACH;;;;"}
|