@sentry/server-utils 10.60.0 → 10.62.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.
Files changed (42) hide show
  1. package/build/cjs/index.js +4 -0
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/cjs/integrations/tracing-channel/mysql.js +12 -5
  4. package/build/cjs/integrations/tracing-channel/mysql.js.map +1 -1
  5. package/build/cjs/redis/redis-dc-subscriber.js +47 -82
  6. package/build/cjs/redis/redis-dc-subscriber.js.map +1 -1
  7. package/build/cjs/tracing-channel.js +94 -0
  8. package/build/cjs/tracing-channel.js.map +1 -0
  9. package/build/cjs/vercel-ai/index.js +21 -0
  10. package/build/cjs/vercel-ai/index.js.map +1 -0
  11. package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js +362 -0
  12. package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -0
  13. package/build/esm/index.js +2 -0
  14. package/build/esm/index.js.map +1 -1
  15. package/build/esm/integrations/tracing-channel/mysql.js +13 -6
  16. package/build/esm/integrations/tracing-channel/mysql.js.map +1 -1
  17. package/build/esm/package.json +1 -1
  18. package/build/esm/redis/redis-dc-subscriber.js +45 -80
  19. package/build/esm/redis/redis-dc-subscriber.js.map +1 -1
  20. package/build/esm/tracing-channel.js +92 -0
  21. package/build/esm/tracing-channel.js.map +1 -0
  22. package/build/esm/vercel-ai/index.js +19 -0
  23. package/build/esm/vercel-ai/index.js.map +1 -0
  24. package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js +357 -0
  25. package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -0
  26. package/build/types/index.d.ts +4 -1
  27. package/build/types/index.d.ts.map +1 -1
  28. package/build/types/integrations/tracing-channel/mysql.d.ts.map +1 -1
  29. package/build/types/redis/redis-dc-subscriber.d.ts +7 -32
  30. package/build/types/redis/redis-dc-subscriber.d.ts.map +1 -1
  31. package/build/types/tracing-channel.d.ts +46 -0
  32. package/build/types/tracing-channel.d.ts.map +1 -0
  33. package/build/types/vercel-ai/index.d.ts +25 -0
  34. package/build/types/vercel-ai/index.d.ts.map +1 -0
  35. package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts +62 -0
  36. package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -0
  37. package/build/types-ts3.8/index.d.ts +4 -1
  38. package/build/types-ts3.8/redis/redis-dc-subscriber.d.ts +7 -32
  39. package/build/types-ts3.8/tracing-channel.d.ts +46 -0
  40. package/build/types-ts3.8/vercel-ai/index.d.ts +25 -0
  41. package/build/types-ts3.8/vercel-ai/vercel-ai-dc-subscriber.d.ts +62 -0
  42. package/package.json +2 -2
@@ -0,0 +1,357 @@
1
+ import { GEN_AI_EMBEDDINGS_INPUT, GEN_AI_OPERATION_NAME, GEN_AI_FUNCTION_ID, GEN_AI_RESPONSE_STREAMING, GEN_AI_REQUEST_AVAILABLE_TOOLS, GEN_AI_TOOL_INPUT, GEN_AI_TOOL_NAME, GEN_AI_TOOL_TYPE, GEN_AI_TOOL_OUTPUT, GEN_AI_USAGE_INPUT_TOKENS, GEN_AI_USAGE_OUTPUT_TOKENS, GEN_AI_USAGE_TOTAL_TOKENS, GEN_AI_RESPONSE_FINISH_REASONS, GEN_AI_RESPONSE_ID, GEN_AI_RESPONSE_MODEL, GEN_AI_OUTPUT_MESSAGES, GEN_AI_INPUT_MESSAGES, GEN_AI_REQUEST_MODEL, GEN_AI_SYSTEM } from '@sentry/conventions/attributes';
2
+ import { GEN_AI_INVOKE_AGENT_SPAN_OP, GEN_AI_EXECUTE_TOOL_SPAN_OP } from '@sentry/conventions/op';
3
+ import { startInactiveSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getProviderMetadataAttributes, GEN_AI_CONVERSATION_ID_ATTRIBUTE, spanToJSON, SPAN_STATUS_ERROR, withScope, spanToTraceContext, captureException, getClient, shouldEnableTruncation, getTruncatedJsonString, GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE, GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE } from '@sentry/core';
4
+ import { bindTracingChannelToSpan } from '../tracing-channel.js';
5
+
6
+ const AI_SDK_TELEMETRY_TRACING_CHANNEL = "ai:telemetry";
7
+ const ORIGIN = "auto.vercelai.channel";
8
+ const GEN_AI_TOOL_CALL_ID_ATTRIBUTE = "gen_ai.tool.call.id";
9
+ const GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE = "gen_ai.tool.description";
10
+ const GEN_AI_EMBEDDINGS_OPERATION = "embeddings";
11
+ const GEN_AI_RERANK_OPERATION = "rerank";
12
+ const GEN_AI_GENERATE_CONTENT_OPERATION = "generate_content";
13
+ const VERCEL_AI_OPERATION_ID_ATTRIBUTE = "vercel.ai.operationId";
14
+ const VERCEL_AI_MODEL_PROVIDER_ATTRIBUTE = "vercel.ai.model.provider";
15
+ const VERCEL_AI_SETTINGS_MAX_RETRIES_ATTRIBUTE = "vercel.ai.settings.maxRetries";
16
+ const operationIdByCallId = /* @__PURE__ */ new Map();
17
+ const toolDescriptionsByCallId = /* @__PURE__ */ new Map();
18
+ const ROOT_OPERATION_TYPES = /* @__PURE__ */ new Set(["generateText", "streamText", "embed", "rerank"]);
19
+ function clearOperationId(data) {
20
+ if (!ROOT_OPERATION_TYPES.has(data.type)) {
21
+ return;
22
+ }
23
+ const callId = asString(data.event.callId);
24
+ if (callId) {
25
+ operationIdByCallId.delete(callId);
26
+ toolDescriptionsByCallId.delete(callId);
27
+ }
28
+ }
29
+ function recordToolDescriptions(callId, tools) {
30
+ if (!callId || !Array.isArray(tools)) {
31
+ return;
32
+ }
33
+ let descriptions = toolDescriptionsByCallId.get(callId);
34
+ for (const tool of tools) {
35
+ if (isRecord(tool) && typeof tool.name === "string" && typeof tool.description === "string") {
36
+ descriptions = descriptions ?? /* @__PURE__ */ new Map();
37
+ if (!descriptions.has(tool.name)) {
38
+ descriptions.set(tool.name, tool.description);
39
+ }
40
+ }
41
+ }
42
+ if (descriptions) {
43
+ toolDescriptionsByCallId.set(callId, descriptions);
44
+ }
45
+ }
46
+ function resolveToolDescription(callId, toolName, tools) {
47
+ const fromMap = callId ? toolDescriptionsByCallId.get(callId)?.get(toolName) : void 0;
48
+ if (fromMap) {
49
+ return fromMap;
50
+ }
51
+ if (Array.isArray(tools)) {
52
+ const match = tools.find((tool) => isRecord(tool) && tool.name === toolName);
53
+ return isRecord(match) ? asString(match.description) : void 0;
54
+ }
55
+ if (isRecord(tools)) {
56
+ const tool = tools[toolName];
57
+ return isRecord(tool) ? asString(tool.description) : void 0;
58
+ }
59
+ return void 0;
60
+ }
61
+ let subscribed = false;
62
+ function subscribeVercelAiTracingChannel(tracingChannel, options = {}) {
63
+ if (subscribed) {
64
+ return;
65
+ }
66
+ subscribed = true;
67
+ bindTracingChannelToSpan(
68
+ tracingChannel(AI_SDK_TELEMETRY_TRACING_CHANNEL),
69
+ (data) => createSpanFromMessage(data, options),
70
+ {
71
+ // The helper ends the span; we enrich it from the settled result first (tokens, output messages,
72
+ // finish reasons, response model/id, provider metadata) and drop the per-operation `callId` maps.
73
+ beforeSpanEnd: (span, data) => {
74
+ enrichSpanOnEnd(span, data, options);
75
+ clearOperationId(data);
76
+ }
77
+ }
78
+ );
79
+ }
80
+ function createSpanFromMessage(data, channelOptions) {
81
+ const { type, event } = data;
82
+ if (type === "step" || !event || typeof event !== "object") {
83
+ return void 0;
84
+ }
85
+ const { recordInputs, enableTruncation } = getRecordingOptions(event, channelOptions);
86
+ const provider = asString(event.provider);
87
+ const modelId = asString(event.modelId);
88
+ const callId = asString(event.callId);
89
+ const maxRetries = asNumber(event.maxRetries);
90
+ if (recordInputs) {
91
+ recordToolDescriptions(callId, event.tools);
92
+ }
93
+ const baseAttributes = {
94
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
95
+ ...provider ? { [GEN_AI_SYSTEM]: provider, [VERCEL_AI_MODEL_PROVIDER_ATTRIBUTE]: provider } : {},
96
+ ...modelId ? { [GEN_AI_REQUEST_MODEL]: modelId } : {},
97
+ ...maxRetries !== void 0 ? { [VERCEL_AI_SETTINGS_MAX_RETRIES_ATTRIBUTE]: maxRetries } : {}
98
+ };
99
+ switch (type) {
100
+ case "generateText":
101
+ case "streamText":
102
+ return buildInvokeAgentSpan(event, baseAttributes, recordInputs, enableTruncation, callId, type === "streamText");
103
+ case "languageModelCall":
104
+ return buildModelCallSpan(event, baseAttributes, recordInputs, enableTruncation, callId, modelId);
105
+ case "executeTool":
106
+ return buildToolSpan(event, recordInputs);
107
+ case "embed":
108
+ return startGenAiSpan(GEN_AI_EMBEDDINGS_OPERATION, modelId, {
109
+ ...baseAttributes,
110
+ ...recordInputs && event.value !== void 0 ? { [GEN_AI_EMBEDDINGS_INPUT]: safeStringify(event.value) } : {}
111
+ });
112
+ case "rerank":
113
+ return startGenAiSpan(GEN_AI_RERANK_OPERATION, modelId, baseAttributes);
114
+ default:
115
+ return void 0;
116
+ }
117
+ }
118
+ function startGenAiSpan(operation, suffix, attributes) {
119
+ return startInactiveSpan({
120
+ name: suffix ? `${operation} ${suffix}` : operation,
121
+ op: `gen_ai.${operation}`,
122
+ attributes: { [GEN_AI_OPERATION_NAME]: operation, ...attributes }
123
+ });
124
+ }
125
+ function buildInvokeAgentSpan(event, baseAttributes, recordInputs, enableTruncation, callId, isStream) {
126
+ const functionId = asString(event.functionId);
127
+ const operationId = asString(event.operationId) ?? (isStream ? "ai.streamText" : "ai.generateText");
128
+ if (callId) {
129
+ operationIdByCallId.set(callId, { operationId, isStream });
130
+ }
131
+ return startGenAiSpan(GEN_AI_INVOKE_AGENT_SPAN_OP, functionId, {
132
+ ...baseAttributes,
133
+ [VERCEL_AI_OPERATION_ID_ATTRIBUTE]: operationId,
134
+ [GEN_AI_RESPONSE_STREAMING]: isStream,
135
+ ...functionId ? { [GEN_AI_FUNCTION_ID]: functionId } : {},
136
+ ...recordInputs ? buildInputMessageAttributes(event, enableTruncation) : {}
137
+ });
138
+ }
139
+ function buildModelCallSpan(event, baseAttributes, recordInputs, enableTruncation, callId, modelId) {
140
+ const parent = callId ? operationIdByCallId.get(callId) : void 0;
141
+ const operationId = parent ? `${parent.operationId}.${parent.isStream ? "doStream" : "doGenerate"}` : "ai.generateText.doGenerate";
142
+ return startGenAiSpan(GEN_AI_GENERATE_CONTENT_OPERATION, modelId, {
143
+ ...baseAttributes,
144
+ [VERCEL_AI_OPERATION_ID_ATTRIBUTE]: operationId,
145
+ ...recordInputs ? buildInputMessageAttributes(event, enableTruncation) : {},
146
+ ...recordInputs && Array.isArray(event.tools) ? { [GEN_AI_REQUEST_AVAILABLE_TOOLS]: safeStringify(event.tools) } : {}
147
+ });
148
+ }
149
+ function buildToolSpan(event, recordInputs) {
150
+ const toolCall = isRecord(event.toolCall) ? event.toolCall : {};
151
+ const toolName = asString(toolCall.toolName);
152
+ const toolCallId = asString(event.toolCallId) ?? asString(toolCall.toolCallId);
153
+ const toolInput = toolCall.input ?? toolCall.args;
154
+ const description = recordInputs && toolName ? resolveToolDescription(asString(event.callId), toolName, event.tools) : void 0;
155
+ return startGenAiSpan(GEN_AI_EXECUTE_TOOL_SPAN_OP, toolName, {
156
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
157
+ [GEN_AI_TOOL_TYPE]: "function",
158
+ ...toolName ? { [GEN_AI_TOOL_NAME]: toolName } : {},
159
+ ...toolCallId ? { [GEN_AI_TOOL_CALL_ID_ATTRIBUTE]: toolCallId } : {},
160
+ ...description ? { [GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE]: description } : {},
161
+ ...recordInputs && toolInput !== void 0 ? { [GEN_AI_TOOL_INPUT]: safeStringify(toolInput) } : {}
162
+ });
163
+ }
164
+ function enrichSpanOnEnd(span, data, channelOptions) {
165
+ const { type, result } = data;
166
+ if (!isRecord(result)) {
167
+ return;
168
+ }
169
+ const { recordOutputs } = getRecordingOptions(data.event, channelOptions);
170
+ if (type === "executeTool") {
171
+ if (recordOutputs) {
172
+ span.setAttribute(GEN_AI_TOOL_OUTPUT, safeStringify(result.output ?? result));
173
+ }
174
+ const output = isRecord(result.output) ? result.output : void 0;
175
+ if (output?.type === "tool-error") {
176
+ captureToolError(span, data, output.error);
177
+ }
178
+ return;
179
+ }
180
+ const usage = isRecord(result.usage) ? result.usage : void 0;
181
+ if (usage) {
182
+ const inputTokens = tokenCount(usage.inputTokens) ?? tokenCount(usage.tokens);
183
+ const outputTokens = tokenCount(usage.outputTokens);
184
+ const totalTokens = tokenCount(usage.totalTokens) ?? sum(inputTokens, outputTokens);
185
+ if (inputTokens !== void 0) {
186
+ span.setAttribute(GEN_AI_USAGE_INPUT_TOKENS, inputTokens);
187
+ }
188
+ if (outputTokens !== void 0) {
189
+ span.setAttribute(GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);
190
+ }
191
+ if (totalTokens !== void 0) {
192
+ span.setAttribute(GEN_AI_USAGE_TOTAL_TOKENS, totalTokens);
193
+ }
194
+ }
195
+ const finishReason = getFinishReason(result);
196
+ if (finishReason && type === "languageModelCall") {
197
+ span.setAttribute(GEN_AI_RESPONSE_FINISH_REASONS, safeStringify([finishReason]));
198
+ }
199
+ const response = isRecord(result.response) ? result.response : void 0;
200
+ const responseId = asString(response?.id) ?? asString(result.responseId);
201
+ if (responseId) {
202
+ span.setAttribute(GEN_AI_RESPONSE_ID, responseId);
203
+ }
204
+ const responseModel = asString(response?.modelId) ?? asString(data.event.modelId);
205
+ if (responseModel) {
206
+ span.setAttribute(GEN_AI_RESPONSE_MODEL, responseModel);
207
+ }
208
+ const providerMetadata = result.providerMetadata;
209
+ const providerAttributes = getProviderMetadataAttributes(providerMetadata);
210
+ if (GEN_AI_CONVERSATION_ID_ATTRIBUTE in providerAttributes && spanToJSON(span).data[GEN_AI_CONVERSATION_ID_ATTRIBUTE]) {
211
+ delete providerAttributes[GEN_AI_CONVERSATION_ID_ATTRIBUTE];
212
+ }
213
+ span.setAttributes(providerAttributes);
214
+ if (recordOutputs) {
215
+ const parts = type === "languageModelCall" && Array.isArray(result.content) ? partsFromContent(result.content) : partsFromTextAndToolCalls(result.text, result.toolCalls);
216
+ const outputMessages = buildOutputMessages(parts, finishReason);
217
+ if (outputMessages) {
218
+ span.setAttribute(GEN_AI_OUTPUT_MESSAGES, outputMessages);
219
+ }
220
+ }
221
+ }
222
+ function normalizeFinishReason(finishReason) {
223
+ return finishReason === "tool-calls" ? "tool_call" : finishReason ?? "stop";
224
+ }
225
+ function getFinishReason(result) {
226
+ const finishReason = result.finishReason;
227
+ if (typeof finishReason === "string") {
228
+ return finishReason;
229
+ }
230
+ return isRecord(finishReason) ? asString(finishReason.unified) : void 0;
231
+ }
232
+ function tokenCount(value) {
233
+ return asNumber(value) ?? (isRecord(value) ? asNumber(value.total) : void 0);
234
+ }
235
+ function buildOutputMessages(parts, finishReason) {
236
+ if (!parts.length) {
237
+ return void 0;
238
+ }
239
+ return safeStringify([{ role: "assistant", parts, finish_reason: normalizeFinishReason(finishReason) }]);
240
+ }
241
+ function toolCallPart(toolCall) {
242
+ const args = toolCall.input ?? toolCall.args;
243
+ return {
244
+ type: "tool_call",
245
+ id: asString(toolCall.toolCallId),
246
+ name: asString(toolCall.toolName),
247
+ arguments: typeof args === "string" ? args : safeStringify(args ?? {})
248
+ };
249
+ }
250
+ function partsFromContent(content) {
251
+ const parts = [];
252
+ for (const item of content) {
253
+ if (!isRecord(item)) {
254
+ continue;
255
+ }
256
+ if (item.type === "text" && typeof item.text === "string") {
257
+ parts.push({ type: "text", content: item.text });
258
+ } else if (item.type === "tool-call") {
259
+ parts.push(toolCallPart(item));
260
+ }
261
+ }
262
+ return parts;
263
+ }
264
+ function partsFromTextAndToolCalls(text, toolCalls) {
265
+ const parts = [];
266
+ if (typeof text === "string" && text.length) {
267
+ parts.push({ type: "text", content: text });
268
+ }
269
+ if (Array.isArray(toolCalls)) {
270
+ for (const toolCall of toolCalls) {
271
+ if (isRecord(toolCall)) {
272
+ parts.push(toolCallPart(toolCall));
273
+ }
274
+ }
275
+ }
276
+ return parts;
277
+ }
278
+ function captureToolError(span, data, error) {
279
+ span.setStatus({
280
+ code: SPAN_STATUS_ERROR,
281
+ message: error instanceof Error ? error.message : "tool_error"
282
+ });
283
+ const toolCall = isRecord(data.event.toolCall) ? data.event.toolCall : {};
284
+ const toolName = asString(toolCall.toolName);
285
+ const toolCallId = asString(data.event.toolCallId) ?? asString(toolCall.toolCallId);
286
+ withScope((scope) => {
287
+ scope.setContext("trace", spanToTraceContext(span));
288
+ if (toolName) {
289
+ scope.setTag("vercel.ai.tool.name", toolName);
290
+ }
291
+ if (toolCallId) {
292
+ scope.setTag("vercel.ai.tool.callId", toolCallId);
293
+ }
294
+ scope.setLevel("error");
295
+ captureException(
296
+ error instanceof Error ? error : new Error(typeof error === "string" ? error : "Tool execution failed"),
297
+ {
298
+ mechanism: { type: "auto.vercelai.channel", handled: false }
299
+ }
300
+ );
301
+ });
302
+ }
303
+ function getRecordingOptions(event, channelOptions) {
304
+ const genAI = getClient()?.getDataCollectionOptions().genAI;
305
+ return {
306
+ recordInputs: resolveRecording(channelOptions.recordInputs, event.recordInputs, genAI?.inputs),
307
+ recordOutputs: resolveRecording(channelOptions.recordOutputs, event.recordOutputs, genAI?.outputs),
308
+ enableTruncation: shouldEnableTruncation(channelOptions.enableTruncation)
309
+ };
310
+ }
311
+ function resolveRecording(integrationOption, perCallOption, globalDefault) {
312
+ if (typeof integrationOption === "boolean") {
313
+ return integrationOption;
314
+ }
315
+ if (typeof perCallOption === "boolean") {
316
+ return perCallOption;
317
+ }
318
+ return globalDefault === true;
319
+ }
320
+ function buildInputMessageAttributes(event, enableTruncation) {
321
+ const attributes = {};
322
+ const instructions = asString(event.instructions);
323
+ if (instructions) {
324
+ attributes[GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE] = safeStringify([{ type: "text", content: instructions }]);
325
+ }
326
+ const messages = event.messages ?? event.prompt;
327
+ if (messages !== void 0) {
328
+ attributes[GEN_AI_INPUT_MESSAGES] = enableTruncation ? getTruncatedJsonString(messages) : safeStringify(messages);
329
+ attributes[GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE] = Array.isArray(messages) ? messages.length : 1;
330
+ }
331
+ return attributes;
332
+ }
333
+ function asString(value) {
334
+ return typeof value === "string" ? value : void 0;
335
+ }
336
+ function asNumber(value) {
337
+ return typeof value === "number" && !isNaN(value) ? value : void 0;
338
+ }
339
+ function sum(a, b) {
340
+ return a === void 0 && b === void 0 ? void 0 : (a ?? 0) + (b ?? 0);
341
+ }
342
+ function isRecord(value) {
343
+ return typeof value === "object" && value !== null;
344
+ }
345
+ function safeStringify(value) {
346
+ if (typeof value === "string") {
347
+ return value;
348
+ }
349
+ try {
350
+ return JSON.stringify(value);
351
+ } catch {
352
+ return "[unserializable]";
353
+ }
354
+ }
355
+
356
+ export { clearOperationId, createSpanFromMessage, enrichSpanOnEnd, subscribeVercelAiTracingChannel };
357
+ //# sourceMappingURL=vercel-ai-dc-subscriber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vercel-ai-dc-subscriber.js","sources":["../../../src/vercel-ai/vercel-ai-dc-subscriber.ts"],"sourcesContent":["/* eslint-disable max-lines */\n// `@sentry/conventions` marks several gen_ai attributes (e.g. `GEN_AI_SYSTEM`, `GEN_AI_TOOL_*`,\n// `GEN_AI_REQUEST_AVAILABLE_TOOLS`) as deprecated in favour of newer semconv names. We intentionally\n// keep emitting the current names so these spans match the OTel-based (v6) integration and what the\n// Sentry product consumes today; migrating to the new names is a separate, coordinated change.\n/* eslint-disable typescript-eslint/no-deprecated */\nimport {\n GEN_AI_EMBEDDINGS_INPUT,\n GEN_AI_FUNCTION_ID,\n GEN_AI_INPUT_MESSAGES,\n GEN_AI_OPERATION_NAME,\n GEN_AI_OUTPUT_MESSAGES,\n GEN_AI_REQUEST_AVAILABLE_TOOLS,\n GEN_AI_REQUEST_MODEL,\n GEN_AI_RESPONSE_FINISH_REASONS,\n GEN_AI_RESPONSE_ID,\n GEN_AI_RESPONSE_MODEL,\n GEN_AI_RESPONSE_STREAMING,\n GEN_AI_SYSTEM,\n GEN_AI_TOOL_INPUT,\n GEN_AI_TOOL_NAME,\n GEN_AI_TOOL_OUTPUT,\n GEN_AI_TOOL_TYPE,\n GEN_AI_USAGE_INPUT_TOKENS,\n GEN_AI_USAGE_OUTPUT_TOKENS,\n GEN_AI_USAGE_TOTAL_TOKENS,\n} from '@sentry/conventions/attributes';\nimport { GEN_AI_EXECUTE_TOOL_SPAN_OP, GEN_AI_INVOKE_AGENT_SPAN_OP } from '@sentry/conventions/op';\nimport type { Span } from '@sentry/core';\nimport {\n captureException,\n GEN_AI_CONVERSATION_ID_ATTRIBUTE,\n GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE,\n GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE,\n getClient,\n getProviderMetadataAttributes,\n getTruncatedJsonString,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n shouldEnableTruncation,\n SPAN_STATUS_ERROR,\n spanToJSON,\n spanToTraceContext,\n startInactiveSpan,\n withScope,\n} from '@sentry/core';\nimport type { TracingChannel } from 'node:diagnostics_channel';\nimport { bindTracingChannelToSpan } from '../tracing-channel';\n\n/**\n * The single tracing channel the `ai` package (>= 7) publishes all telemetry lifecycle events to\n * via `node:diagnostics_channel`. Events are discriminated by their `type` field.\n * @see https://github.com/vercel/ai/pull/15660\n */\nconst AI_SDK_TELEMETRY_TRACING_CHANNEL = 'ai:telemetry';\n\nconst ORIGIN = 'auto.vercelai.channel';\n\n// `@sentry/conventions` does not expose these yet, so we keep the literals here.\nconst GEN_AI_TOOL_CALL_ID_ATTRIBUTE = 'gen_ai.tool.call.id';\nconst GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE = 'gen_ai.tool.description';\nconst GEN_AI_EMBEDDINGS_OPERATION = 'embeddings';\nconst GEN_AI_RERANK_OPERATION = 'rerank';\n// The model-call op matches the Vercel AI OTel integration (`gen_ai.generate_content`) rather than\n// the generic `gen_ai.chat`, so v6 (OTel) and v7 (channel) produce the same spans.\nconst GEN_AI_GENERATE_CONTENT_OPERATION = 'generate_content';\n\n// Subset of the `vercel.ai.*` passthrough attributes the OTel integration emits that we reproduce.\nconst VERCEL_AI_OPERATION_ID_ATTRIBUTE = 'vercel.ai.operationId';\nconst VERCEL_AI_MODEL_PROVIDER_ATTRIBUTE = 'vercel.ai.model.provider';\nconst VERCEL_AI_SETTINGS_MAX_RETRIES_ATTRIBUTE = 'vercel.ai.settings.maxRetries';\n\n// Tracks the top-level operationId (and whether it streams) per `callId` so a model-call span can\n// name its `doGenerate`/`doStream` operation the same way the OTel integration does. `isStream` is\n// the authoritative event-type signal rather than a substring check on the (possibly custom)\n// operationId. Cleared when the top-level span ends.\nconst operationIdByCallId = new Map<string, { operationId: string; isStream: boolean }>();\n\n// Per-operation map of tool name → description, harvested from a model-call /\n// top-level event's `tools` (keyed by the shared `callId`). The AI SDK's\n// `executeTool` event doesn't carry the tool's description, so we backfill it\n// onto the tool span here — without relying on the OTel `vercelAiEventProcessor`\n// (which isn't registered in channel/orchestrion mode). Cleared with the\n// operation. Only populated when inputs are recorded, matching the OTel path\n// (which sources descriptions from the recorded `available_tools`).\nconst toolDescriptionsByCallId = new Map<string, Map<string, string>>();\n\n// Only top-level operations own the `callId` → operationId mapping; `step`/`languageModelCall`/\n// `executeTool` share the parent's `callId`, so they must not clear it.\nconst ROOT_OPERATION_TYPES = new Set<ChannelEventType>(['generateText', 'streamText', 'embed', 'rerank']);\n\n/** Drop the per-operation `callId` maps once the owning top-level operation settles (success or error). */\nexport function clearOperationId(data: VercelAiChannelMessage): void {\n if (!ROOT_OPERATION_TYPES.has(data.type)) {\n return;\n }\n const callId = asString(data.event.callId);\n if (callId) {\n operationIdByCallId.delete(callId);\n toolDescriptionsByCallId.delete(callId);\n }\n}\n\n/** Record tool name → description from an event's `tools`, so tool spans can backfill the description. */\nfunction recordToolDescriptions(callId: string | undefined, tools: unknown): void {\n if (!callId || !Array.isArray(tools)) {\n return;\n }\n let descriptions = toolDescriptionsByCallId.get(callId);\n for (const tool of tools) {\n if (isRecord(tool) && typeof tool.name === 'string' && typeof tool.description === 'string') {\n descriptions = descriptions ?? new Map();\n if (!descriptions.has(tool.name)) {\n descriptions.set(tool.name, tool.description);\n }\n }\n }\n if (descriptions) {\n toolDescriptionsByCallId.set(callId, descriptions);\n }\n}\n\n/**\n * Resolve a tool's description, preferring the per-operation map (populated from the model-call /\n * top-level event's `tools`, v7) and falling back to a `tools` collection on the event itself —\n * which may be an array of `{ name, description }` or a record keyed by tool name (v6).\n */\nfunction resolveToolDescription(callId: string | undefined, toolName: string, tools: unknown): string | undefined {\n const fromMap = callId ? toolDescriptionsByCallId.get(callId)?.get(toolName) : undefined;\n if (fromMap) {\n return fromMap;\n }\n if (Array.isArray(tools)) {\n const match = tools.find(tool => isRecord(tool) && tool.name === toolName);\n return isRecord(match) ? asString(match.description) : undefined;\n }\n if (isRecord(tools)) {\n const tool = tools[toolName];\n return isRecord(tool) ? asString(tool.description) : undefined;\n }\n return undefined;\n}\n\n/** The lifecycle event types the `ai:telemetry` channel can carry. */\nexport type ChannelEventType =\n | 'generateText'\n | 'streamText'\n | 'step'\n | 'languageModelCall'\n | 'executeTool'\n | 'embed'\n | 'rerank';\n\n/**\n * The context object the AI SDK passes through one tracing-channel call. It is the same object\n * identity across `start`/`end`/`asyncEnd`/`error`, and Node's `tracingChannel` attaches\n * `result`/`error` to it as the traced promise settles.\n */\nexport interface VercelAiChannelMessage {\n type: ChannelEventType;\n event: Record<string, unknown>;\n result?: unknown;\n error?: unknown;\n}\n\n/**\n * Platform-provided factory that returns a tracing channel for the given channel name. The factory\n * is responsible for, when `start` fires, calling `transformStart(data)` and storing the returned\n * span on `data._sentrySpan` so the subscriber's `asyncEnd`/`error` handlers can read it.\n *\n * Node passes `@sentry/opentelemetry/tracing-channel`, which uses `bindStore` to additionally make\n * the span the active OTel context for the duration of the traced operation. That is what makes\n * nested AI SDK operations (model calls, tool calls) become children of the enclosing span without\n * any manual parent bookkeeping here.\n */\ntype VercelAiTracingChannelFactory = <T extends object>(name: string) => TracingChannel<T, T>;\n\n/** Integration-level recording options, pinned at subscribe time so we never look the integration up per event. */\ninterface VercelAiChannelOptions {\n recordInputs?: boolean;\n recordOutputs?: boolean;\n enableTruncation?: boolean;\n}\n\nlet subscribed = false;\n\n/**\n * Subscribe Sentry span handlers to the `ai` SDK's native telemetry tracing channel (`ai:telemetry`,\n * available in `ai` >= 7) and emit fully-formed `gen_ai.*` spans directly — no OpenTelemetry span\n * post-processing involved.\n *\n * The integration passes its options in directly (rather than us looking the integration up on every\n * event); the global `dataCollection.genAI` default is still read from the client per event.\n *\n * Safe to always call: on `ai` versions that don't publish to the channel (e.g. < 7) nothing is\n * ever emitted and this is inert, so there is no double-instrumentation against the OTel-based\n * patcher. Idempotent.\n */\nexport function subscribeVercelAiTracingChannel(\n tracingChannel: VercelAiTracingChannelFactory,\n options: VercelAiChannelOptions = {},\n): void {\n if (subscribed) {\n return;\n }\n subscribed = true;\n\n bindTracingChannelToSpan(\n tracingChannel<VercelAiChannelMessage>(AI_SDK_TELEMETRY_TRACING_CHANNEL),\n data => createSpanFromMessage(data, options),\n {\n // The helper ends the span; we enrich it from the settled result first (tokens, output messages,\n // finish reasons, response model/id, provider metadata) and drop the per-operation `callId` maps.\n beforeSpanEnd: (span, data) => {\n enrichSpanOnEnd(span, data, options);\n clearOperationId(data);\n },\n },\n );\n}\n\n/**\n * Transform a channel `start` payload into the span that should be active for the operation. For\n * `step` we deliberately don't open a span (model calls and tool calls are siblings under the\n * invoke_agent span, matching the OTel-based output), so we reuse the active span and mark the\n * payload to skip ending it.\n */\nexport function createSpanFromMessage(\n data: VercelAiChannelMessage,\n channelOptions: VercelAiChannelOptions,\n): Span | undefined {\n const { type, event } = data;\n\n if (type === 'step' || !event || typeof event !== 'object') {\n // Opt out: returning `undefined` leaves the enclosing `invoke_agent` span as the active context\n // (model-call and tool-call events nest under it) without opening — or ending — a span of its own.\n return undefined;\n }\n\n const { recordInputs, enableTruncation } = getRecordingOptions(event, channelOptions);\n const provider = asString(event.provider);\n const modelId = asString(event.modelId);\n const callId = asString(event.callId);\n const maxRetries = asNumber(event.maxRetries);\n\n // Harvest tool descriptions from the operation/model-call `tools` so tool spans can backfill them.\n // Gated on `recordInputs` to match the OTel path, which only records `available_tools` then.\n if (recordInputs) {\n recordToolDescriptions(callId, event.tools);\n }\n\n const baseAttributes: Record<string, string | number | boolean> = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n ...(provider ? { [GEN_AI_SYSTEM]: provider, [VERCEL_AI_MODEL_PROVIDER_ATTRIBUTE]: provider } : {}),\n ...(modelId ? { [GEN_AI_REQUEST_MODEL]: modelId } : {}),\n ...(maxRetries !== undefined ? { [VERCEL_AI_SETTINGS_MAX_RETRIES_ATTRIBUTE]: maxRetries } : {}),\n };\n\n switch (type) {\n case 'generateText':\n case 'streamText':\n return buildInvokeAgentSpan(event, baseAttributes, recordInputs, enableTruncation, callId, type === 'streamText');\n case 'languageModelCall':\n return buildModelCallSpan(event, baseAttributes, recordInputs, enableTruncation, callId, modelId);\n case 'executeTool':\n return buildToolSpan(event, recordInputs);\n case 'embed':\n return startGenAiSpan(GEN_AI_EMBEDDINGS_OPERATION, modelId, {\n ...baseAttributes,\n ...(recordInputs && event.value !== undefined ? { [GEN_AI_EMBEDDINGS_INPUT]: safeStringify(event.value) } : {}),\n });\n case 'rerank':\n return startGenAiSpan(GEN_AI_RERANK_OPERATION, modelId, baseAttributes);\n default:\n // Unknown event type: opt out rather than open a span we can't shape correctly.\n return undefined;\n }\n}\n\ntype Attributes = Record<string, string | number | boolean>;\n\n/** Start a `gen_ai.<operation>` span named `<operation> <suffix>` (or just `<operation>` when no suffix). */\nfunction startGenAiSpan(operation: string, suffix: string | undefined, attributes: Attributes): Span {\n return startInactiveSpan({\n name: suffix ? `${operation} ${suffix}` : operation,\n op: `gen_ai.${operation}`,\n attributes: { [GEN_AI_OPERATION_NAME]: operation, ...attributes },\n });\n}\n\nfunction buildInvokeAgentSpan(\n event: Record<string, unknown>,\n baseAttributes: Attributes,\n recordInputs: boolean,\n enableTruncation: boolean,\n callId: string | undefined,\n isStream: boolean,\n): Span {\n const functionId = asString(event.functionId);\n const operationId = asString(event.operationId) ?? (isStream ? 'ai.streamText' : 'ai.generateText');\n if (callId) {\n operationIdByCallId.set(callId, { operationId, isStream });\n }\n return startGenAiSpan(GEN_AI_INVOKE_AGENT_SPAN_OP, functionId, {\n ...baseAttributes,\n [VERCEL_AI_OPERATION_ID_ATTRIBUTE]: operationId,\n [GEN_AI_RESPONSE_STREAMING]: isStream,\n ...(functionId ? { [GEN_AI_FUNCTION_ID]: functionId } : {}),\n ...(recordInputs ? buildInputMessageAttributes(event, enableTruncation) : {}),\n });\n}\n\nfunction buildModelCallSpan(\n event: Record<string, unknown>,\n baseAttributes: Attributes,\n recordInputs: boolean,\n enableTruncation: boolean,\n callId: string | undefined,\n modelId: string | undefined,\n): Span {\n const parent = callId ? operationIdByCallId.get(callId) : undefined;\n const operationId = parent\n ? `${parent.operationId}.${parent.isStream ? 'doStream' : 'doGenerate'}`\n : 'ai.generateText.doGenerate';\n return startGenAiSpan(GEN_AI_GENERATE_CONTENT_OPERATION, modelId, {\n ...baseAttributes,\n [VERCEL_AI_OPERATION_ID_ATTRIBUTE]: operationId,\n ...(recordInputs ? buildInputMessageAttributes(event, enableTruncation) : {}),\n ...(recordInputs && Array.isArray(event.tools)\n ? { [GEN_AI_REQUEST_AVAILABLE_TOOLS]: safeStringify(event.tools) }\n : {}),\n });\n}\n\nfunction buildToolSpan(event: Record<string, unknown>, recordInputs: boolean): Span {\n const toolCall = isRecord(event.toolCall) ? event.toolCall : {};\n const toolName = asString(toolCall.toolName);\n const toolCallId = asString(event.toolCallId) ?? asString(toolCall.toolCallId);\n const toolInput = toolCall.input ?? toolCall.args;\n // The `executeTool` event has no description; backfill it from the operation's recorded tools.\n // Gated on `recordInputs` to match the OTel path (descriptions come from the recorded tools list).\n const description =\n recordInputs && toolName ? resolveToolDescription(asString(event.callId), toolName, event.tools) : undefined;\n return startGenAiSpan(GEN_AI_EXECUTE_TOOL_SPAN_OP, toolName, {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [GEN_AI_TOOL_TYPE]: 'function',\n ...(toolName ? { [GEN_AI_TOOL_NAME]: toolName } : {}),\n ...(toolCallId ? { [GEN_AI_TOOL_CALL_ID_ATTRIBUTE]: toolCallId } : {}),\n ...(description ? { [GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE]: description } : {}),\n ...(recordInputs && toolInput !== undefined ? { [GEN_AI_TOOL_INPUT]: safeStringify(toolInput) } : {}),\n });\n}\n\n/**\n * Best-effort enrichment from the resolved value the AI SDK attaches to the channel context.\n * Everything here is guarded: when a field is missing or the shape differs across `ai` versions,\n * we simply don't set the attribute rather than emit a malformed span.\n */\nexport function enrichSpanOnEnd(\n span: Span,\n data: VercelAiChannelMessage,\n channelOptions: VercelAiChannelOptions,\n): void {\n const { type, result } = data;\n if (!isRecord(result)) {\n return;\n }\n\n const { recordOutputs } = getRecordingOptions(data.event, channelOptions);\n\n if (type === 'executeTool') {\n if (recordOutputs) {\n span.setAttribute(GEN_AI_TOOL_OUTPUT, safeStringify(result.output ?? result));\n }\n // From V5 on, tool errors are not rejected (so the `error` channel verb never fires) — they\n // surface as `tool-error` content on the resolved result. Mirror the OTel path by marking the\n // span and capturing the error.\n const output = isRecord(result.output) ? result.output : undefined;\n if (output?.type === 'tool-error') {\n captureToolError(span, data, output.error);\n }\n return;\n }\n\n // `languageModelCall` results report usage as `{ total }` objects; top-level/step results report\n // flat numbers. `tokenCount` handles both.\n const usage = isRecord(result.usage) ? result.usage : undefined;\n if (usage) {\n const inputTokens = tokenCount(usage.inputTokens) ?? tokenCount(usage.tokens);\n const outputTokens = tokenCount(usage.outputTokens);\n const totalTokens = tokenCount(usage.totalTokens) ?? sum(inputTokens, outputTokens);\n if (inputTokens !== undefined) {\n span.setAttribute(GEN_AI_USAGE_INPUT_TOKENS, inputTokens);\n }\n if (outputTokens !== undefined) {\n span.setAttribute(GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);\n }\n if (totalTokens !== undefined) {\n span.setAttribute(GEN_AI_USAGE_TOTAL_TOKENS, totalTokens);\n }\n }\n\n // Match the OTel integration: finish reasons live on the model-call (`generate_content`) span, not\n // on the top-level `invoke_agent` span.\n const finishReason = getFinishReason(result);\n if (finishReason && type === 'languageModelCall') {\n span.setAttribute(GEN_AI_RESPONSE_FINISH_REASONS, safeStringify([finishReason]));\n }\n\n const response = isRecord(result.response) ? result.response : undefined;\n const responseId = asString(response?.id) ?? asString(result.responseId);\n if (responseId) {\n span.setAttribute(GEN_AI_RESPONSE_ID, responseId);\n }\n const responseModel = asString(response?.modelId) ?? asString(data.event.modelId);\n if (responseModel) {\n span.setAttribute(GEN_AI_RESPONSE_MODEL, responseModel);\n }\n\n // Provider-specific cache/reasoning/prediction token breakdowns and `gen_ai.conversation.id`.\n // The channel exposes `providerMetadata` as an object (the OTel path parses it from a string);\n // both share `getProviderMetadataAttributes` so the emitted shape is identical.\n const providerMetadata = (result as { providerMetadata?: unknown }).providerMetadata;\n const providerAttributes = getProviderMetadataAttributes(providerMetadata);\n // Don't overwrite a conversation id already set on span start (e.g. by `conversationIdIntegration`\n // from a user-set scope value); the provider-derived id is only a fallback. Matches the OTel path.\n if (\n GEN_AI_CONVERSATION_ID_ATTRIBUTE in providerAttributes &&\n spanToJSON(span).data[GEN_AI_CONVERSATION_ID_ATTRIBUTE]\n ) {\n // oxlint-disable-next-line typescript/no-dynamic-delete\n delete providerAttributes[GEN_AI_CONVERSATION_ID_ATTRIBUTE];\n }\n span.setAttributes(providerAttributes);\n\n if (recordOutputs) {\n // `languageModelCall` exposes the response as a `content` parts array; top-level results expose\n // `text` + `toolCalls`. Both normalize into the OTel `gen_ai.output.messages` assistant message.\n const parts =\n type === 'languageModelCall' && Array.isArray(result.content)\n ? partsFromContent(result.content)\n : partsFromTextAndToolCalls(result.text, result.toolCalls);\n const outputMessages = buildOutputMessages(parts, finishReason);\n if (outputMessages) {\n span.setAttribute(GEN_AI_OUTPUT_MESSAGES, outputMessages);\n }\n }\n}\n\n/** Maps a Vercel AI finish reason to the OTel `gen_ai.output.messages` form (`tool-calls` → `tool_call`). */\nfunction normalizeFinishReason(finishReason: string | undefined): string {\n return finishReason === 'tool-calls' ? 'tool_call' : (finishReason ?? 'stop');\n}\n\n/** Reads the finish reason from a result — a string on top-level results, `{ unified }` on model calls. */\nfunction getFinishReason(result: Record<string, unknown>): string | undefined {\n const finishReason = result.finishReason;\n if (typeof finishReason === 'string') {\n return finishReason;\n }\n return isRecord(finishReason) ? asString(finishReason.unified) : undefined;\n}\n\n/** Reads a token count that may be a plain number or a `{ total }` object (model-call usage). */\nfunction tokenCount(value: unknown): number | undefined {\n return asNumber(value) ?? (isRecord(value) ? asNumber(value.total) : undefined);\n}\n\nfunction buildOutputMessages(\n parts: Array<Record<string, unknown>>,\n finishReason: string | undefined,\n): string | undefined {\n if (!parts.length) {\n return undefined;\n }\n return safeStringify([{ role: 'assistant', parts, finish_reason: normalizeFinishReason(finishReason) }]);\n}\n\nfunction toolCallPart(toolCall: Record<string, unknown>): Record<string, unknown> {\n const args = toolCall.input ?? toolCall.args;\n return {\n type: 'tool_call',\n id: asString(toolCall.toolCallId),\n name: asString(toolCall.toolName),\n arguments: typeof args === 'string' ? args : safeStringify(args ?? {}),\n };\n}\n\nfunction partsFromContent(content: unknown[]): Array<Record<string, unknown>> {\n const parts: Array<Record<string, unknown>> = [];\n for (const item of content) {\n if (!isRecord(item)) {\n continue;\n }\n if (item.type === 'text' && typeof item.text === 'string') {\n parts.push({ type: 'text', content: item.text });\n } else if (item.type === 'tool-call') {\n parts.push(toolCallPart(item));\n }\n }\n return parts;\n}\n\nfunction partsFromTextAndToolCalls(text: unknown, toolCalls: unknown): Array<Record<string, unknown>> {\n const parts: Array<Record<string, unknown>> = [];\n if (typeof text === 'string' && text.length) {\n parts.push({ type: 'text', content: text });\n }\n if (Array.isArray(toolCalls)) {\n for (const toolCall of toolCalls) {\n if (isRecord(toolCall)) {\n parts.push(toolCallPart(toolCall));\n }\n }\n }\n return parts;\n}\n\nfunction captureToolError(span: Span, data: VercelAiChannelMessage, error: unknown): void {\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: error instanceof Error ? error.message : 'tool_error',\n });\n\n const toolCall = isRecord(data.event.toolCall) ? data.event.toolCall : {};\n const toolName = asString(toolCall.toolName);\n const toolCallId = asString(data.event.toolCallId) ?? asString(toolCall.toolCallId);\n\n withScope(scope => {\n scope.setContext('trace', spanToTraceContext(span));\n if (toolName) {\n scope.setTag('vercel.ai.tool.name', toolName);\n }\n if (toolCallId) {\n scope.setTag('vercel.ai.tool.callId', toolCallId);\n }\n scope.setLevel('error');\n captureException(\n error instanceof Error ? error : new Error(typeof error === 'string' ? error : 'Tool execution failed'),\n {\n mechanism: { type: 'auto.vercelai.channel', handled: false },\n },\n );\n });\n}\n\nfunction getRecordingOptions(\n event: Record<string, unknown>,\n channelOptions: VercelAiChannelOptions,\n): {\n recordInputs: boolean;\n recordOutputs: boolean;\n enableTruncation: boolean;\n} {\n const genAI = getClient()?.getDataCollectionOptions().genAI;\n\n return {\n recordInputs: resolveRecording(channelOptions.recordInputs, event.recordInputs, genAI?.inputs),\n recordOutputs: resolveRecording(channelOptions.recordOutputs, event.recordOutputs, genAI?.outputs),\n enableTruncation: shouldEnableTruncation(channelOptions.enableTruncation),\n };\n}\n\n/**\n * Mirrors the OTel integration's `determineRecordingSettings` precedence: an integration-level option\n * wins, then the per-call `experimental_telemetry.recordInputs/recordOutputs` flag the AI SDK forwards\n * on the channel event, then the global `dataCollection.genAI` default.\n *\n * NOTE: the OTel integration also defaults recording to `true` for a call with\n * `experimental_telemetry: { isEnabled: true }`. The `ai:telemetry` channel does not expose `isEnabled`\n * (nor a resolved recording flag), so that per-call default cannot be reproduced here — v7 users who\n * want inputs/outputs recorded must enable `dataCollection.genAI` or set `recordInputs`/`recordOutputs`.\n */\nfunction resolveRecording(integrationOption: unknown, perCallOption: unknown, globalDefault: unknown): boolean {\n if (typeof integrationOption === 'boolean') {\n return integrationOption;\n }\n if (typeof perCallOption === 'boolean') {\n return perCallOption;\n }\n return globalDefault === true;\n}\n\nfunction buildInputMessageAttributes(\n event: Record<string, unknown>,\n enableTruncation: boolean,\n): Record<string, string | number> {\n const attributes: Record<string, string | number> = {};\n\n // `ai` >= 7 forbids system messages in `messages`/`prompt` and exposes the system prompt as a\n // separate `instructions` field. The OTel path lifts the system message out of the prompt into\n // `gen_ai.system_instructions` as `[{ type: 'text', content }]`; mirror that shape here.\n const instructions = asString(event.instructions);\n if (instructions) {\n attributes[GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE] = safeStringify([{ type: 'text', content: instructions }]);\n }\n\n // The AI SDK start events extend `StandardizedPrompt`; messages live on `messages`, otherwise the\n // simpler `prompt` field is used.\n const messages = event.messages ?? event.prompt;\n if (messages !== undefined) {\n attributes[GEN_AI_INPUT_MESSAGES] = enableTruncation ? getTruncatedJsonString(messages) : safeStringify(messages);\n // The original (pre-truncation) message count, so the product can show how many were dropped.\n attributes[GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE] = Array.isArray(messages) ? messages.length : 1;\n }\n\n return attributes;\n}\n\nfunction asString(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction asNumber(value: unknown): number | undefined {\n return typeof value === 'number' && !isNaN(value) ? value : undefined;\n}\n\nfunction sum(a: number | undefined, b: number | undefined): number | undefined {\n return a === undefined && b === undefined ? undefined : (a ?? 0) + (b ?? 0);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\nfunction safeStringify(value: unknown): string {\n if (typeof value === 'string') {\n return value;\n }\n try {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AAqB,CAAA,GAAI,gBAAA,GAAmB,uBAAuB,QAAQ,CAAA,GAAI,cAAc,QAAQ,CAAA;AAEhH,IAAA,UAAA,CAAW,+CAA+C,CAAA,GAAI,KAAA,CAAM,QAAQ,QAAQ,CAAA,GAAI,SAAS,MAAA,GAAS,CAAA;AAAA,EAC5G;AAEA,EAAA,OAAO,UAAA;AACT;AAEA,SAAS,SAAS,KAAA,EAAoC;AACpD,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,GAAW,KAAA,GAAQ,MAAA;AAC7C;AAEA,SAAS,SAAS,KAAA,EAAoC;AACpD,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,KAAA,CAAM,KAAK,IAAI,KAAA,GAAQ,MAAA;AAC9D;AAEA,SAAS,GAAA,CAAI,GAAuB,CAAA,EAA2C;AAC7E,EAAA,OAAO,MAAM,MAAA,IAAa,CAAA,KAAM,SAAY,MAAA,GAAA,CAAa,CAAA,IAAK,MAAM,CAAA,IAAK,CAAA,CAAA;AAC3E;AAEA,SAAS,SAAS,KAAA,EAAkD;AAClE,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA;AAChD;AAEA,SAAS,cAAc,KAAA,EAAwB;AAC7C,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,IAAI;AACF,IAAA,OAAO,IAAA,CAAK,UAAU,KAAK,CAAA;AAAA,EAC7B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,kBAAA;AAAA,EACT;AACF;;;;"}
@@ -4,5 +4,8 @@
4
4
  * @module
5
5
  */
6
6
  export { IOREDIS_DC_CHANNEL_COMMAND, IOREDIS_DC_CHANNEL_CONNECT, REDIS_DC_CHANNEL_BATCH, REDIS_DC_CHANNEL_COMMAND, REDIS_DC_CHANNEL_CONNECT, subscribeRedisDiagnosticChannels, } from './redis/redis-dc-subscriber';
7
- export type { IORedisCommandData, RedisBatchData, RedisCommandData, RedisConnectData, RedisDiagnosticChannelResponseHook, RedisTracingChannel, RedisTracingChannelContextWithSpan, RedisTracingChannelFactory, RedisTracingChannelSubscribers, } from './redis/redis-dc-subscriber';
7
+ export type { IORedisCommandData, RedisBatchData, RedisCommandData, RedisConnectData, RedisDiagnosticChannelResponseHook, RedisTracingChannelFactory, } from './redis/redis-dc-subscriber';
8
+ export { bindTracingChannelToSpan } from './tracing-channel';
9
+ export type { SentryTracingChannel, TracingChannelLifeCycleOptions, TracingChannelBindingHandle, TracingChannelPayloadWithSpan, } from './tracing-channel';
10
+ export { vercelAiIntegration } from './vercel-ai';
8
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,gCAAgC,GACjC,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,kCAAkC,EAClC,mBAAmB,EACnB,kCAAkC,EAClC,0BAA0B,EAC1B,8BAA8B,GAC/B,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,gCAAgC,GACjC,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,kCAAkC,EAClC,0BAA0B,GAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,YAAY,EACV,oBAAoB,EACpB,8BAA8B,EAC9B,2BAA2B,EAC3B,6BAA6B,GAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../../../src/integrations/tracing-channel/mysql.ts"],"names":[],"mappings":"AAkRA;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,0CAA8C,CAAC"}
1
+ {"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../../../src/integrations/tracing-channel/mysql.ts"],"names":[],"mappings":"AAoRA;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,0CAA8C,CAAC"}
@@ -1,3 +1,4 @@
1
+ import type { TracingChannel } from 'node:diagnostics_channel';
1
2
  import type { Span } from '@sentry/core';
2
3
  export declare const REDIS_DC_CHANNEL_COMMAND = "node-redis:command";
3
4
  export declare const REDIS_DC_CHANNEL_BATCH = "node-redis:batch";
@@ -68,39 +69,13 @@ export interface RedisConnectData {
68
69
  */
69
70
  export type RedisDiagnosticChannelResponseHook = (span: Span, cmdName: string, cmdArgs: string[], result: unknown) => void;
70
71
  /**
71
- * Payload type observed by tracing-channel subscribers — the channel payload
72
- * with `_sentrySpan` stamped on it by the start handler so async/error
73
- * handlers downstream can read it back.
74
- */
75
- export type RedisTracingChannelContextWithSpan<T> = T & {
76
- _sentrySpan?: Span;
77
- };
78
- /** Subscriber object accepted by {@link RedisTracingChannel.subscribe}. */
79
- export interface RedisTracingChannelSubscribers<T> {
80
- start: (data: RedisTracingChannelContextWithSpan<T>) => void;
81
- asyncStart: (data: RedisTracingChannelContextWithSpan<T>) => void;
82
- asyncEnd: (data: RedisTracingChannelContextWithSpan<T>) => void;
83
- end: (data: RedisTracingChannelContextWithSpan<T>) => void;
84
- error: (data: RedisTracingChannelContextWithSpan<T>) => void;
85
- }
86
- /** Minimal tracing-channel surface the subscriber depends on. */
87
- export interface RedisTracingChannel<T extends object> {
88
- subscribe(subs: Partial<RedisTracingChannelSubscribers<T>>): void;
89
- }
90
- /**
91
- * Platform-provided factory that returns a tracing channel for the given
92
- * channel name. Implementations are responsible for ensuring that, when the
93
- * channel's `start` event fires, the span returned by `transformStart(data)`
94
- * ends up stored on `data._sentrySpan` so the subscriber's `asyncEnd`/`error`
95
- * handlers can read it.
72
+ * Platform-provided factory that creates a native tracing channel for the given name. The
73
+ * subscriber binds the span and its lifecycle onto the channel via `bindTracingChannelToSpan`,
74
+ * which propagates the active span through the runtime's async context.
96
75
  *
97
- * - Node passes `@sentry/opentelemetry/tracing-channel` which uses
98
- * `bindStore` to also propagate the span as the active OTel context.
99
- * - Deno (and other non-OTel runtimes) pass a portable wrapper around
100
- * `node:diagnostics_channel.tracingChannel` that just stamps
101
- * `data._sentrySpan` in `start` without `bindStore`.
76
+ * Both Node and Deno pass `node:diagnostics_channel`'s `tracingChannel` directly.
102
77
  */
103
- export type RedisTracingChannelFactory = <T extends object>(name: string, transformStart: (data: T) => Span) => RedisTracingChannel<T>;
78
+ export type RedisTracingChannelFactory = <T extends object>(name: string) => TracingChannel<T, T>;
104
79
  /**
105
80
  * Subscribe Sentry span handlers to node-redis and ioredis diagnostics-channel
106
81
  * events: `node-redis:command`/`:batch`/`:connect` (published by node-redis
@@ -114,6 +89,6 @@ export type RedisTracingChannelFactory = <T extends object>(name: string, transf
114
89
  * re-subscribe.
115
90
  */
116
91
  export declare function subscribeRedisDiagnosticChannels(tracingChannel: RedisTracingChannelFactory, responseHook?: RedisDiagnosticChannelResponseHook): void;
117
- /** Test-only: reset module-local subscribe state. */
92
+ /** Test-only: detach all channel bindings and reset module-local subscribe state. */
118
93
  export declare function _resetRedisDiagnosticChannelsForTesting(): void;
119
94
  //# sourceMappingURL=redis-dc-subscriber.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"redis-dc-subscriber.d.ts","sourceRoot":"","sources":["../../../src/redis/redis-dc-subscriber.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,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AK9D"}
@@ -0,0 +1,46 @@
1
+ import type { TracingChannel, TracingChannelSubscribers } from 'node:diagnostics_channel';
2
+ import type { ExclusiveEventHintOrCaptureContext, Span } from '@sentry/core';
3
+ export type TracingChannelPayloadWithSpan<TData extends object> = TData & {
4
+ _sentrySpan?: Span;
5
+ };
6
+ export interface SentryTracingChannel<TData extends object = object> extends Omit<TracingChannel<TData, TracingChannelPayloadWithSpan<TData>>, 'subscribe' | 'unsubscribe'> {
7
+ subscribe(subscribers: Partial<TracingChannelSubscribers<TracingChannelPayloadWithSpan<TData>>>): void;
8
+ unsubscribe(subscribers: Partial<TracingChannelSubscribers<TracingChannelPayloadWithSpan<TData>>>): void;
9
+ }
10
+ export interface TracingChannelLifeCycleOptions<TData extends object = object> {
11
+ /**
12
+ * Invoked with the span and the channel context object once the traced operation completes
13
+ * Use it to enrich the span from the result/error (branch on `'error' in data` / `'result' in data`) or to run cleanup.
14
+ */
15
+ beforeSpanEnd?: (span: Span, data: TracingChannelPayloadWithSpan<TData>) => void;
16
+ /**
17
+ * Whether a thrown error is captured as a Sentry event. The span is always marked with error status regardless. Defaults to `false`.
18
+ * You can alternatively pass a function that sets the ExclusiveEventHintOrCaptureContext on the captured error.
19
+ * Set `true` for instrumentations that own the error boundary, (e.g: route handlers)
20
+ * For database drivers, it is not recommended to set this at all.
21
+ */
22
+ captureError?: boolean | ((e: unknown) => ExclusiveEventHintOrCaptureContext);
23
+ }
24
+ /** Returned by {@link bindTracingChannelToSpan}: the bound channel plus a teardown handle. */
25
+ export interface TracingChannelBindingHandle<TData extends object = object> {
26
+ /**
27
+ * The tracing channel with the span bound into async context.
28
+ */
29
+ channel: SentryTracingChannel<TData>;
30
+ /**
31
+ * Tears down the binding: unsubscribes lifecycle handlers, when present, and unbinds the start store.
32
+ * Idempotent, and a no-op when no async context binding was available.
33
+ */
34
+ unbind: () => void;
35
+ }
36
+ /**
37
+ * Bind a span and its lifecycle to a tracing channel so the span becomes the active async context
38
+ * for the traced operation and is ended when the operation completes.
39
+ *
40
+ * `getSpan` may return `undefined` to opt a payload out entirely: nothing is bound, no span is
41
+ * tracked, and the active context is left untouched. Use it for events that ride the same channel
42
+ * but should reuse the enclosing span instead of opening (and ending) their own — e.g. an agent
43
+ * loop's per-step events, where ending a freshly opened span would close the parent prematurely.
44
+ */
45
+ export declare function bindTracingChannelToSpan<TData extends object>(channel: TracingChannel<TData, TData>, getSpan: (data: TracingChannelPayloadWithSpan<TData>) => Span | undefined, opts?: TracingChannelLifeCycleOptions<TData>): TracingChannelBindingHandle<TData>;
46
+ //# sourceMappingURL=tracing-channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing-channel.d.ts","sourceRoot":"","sources":["../../src/tracing-channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAE1F,OAAO,KAAK,EAAE,kCAAkC,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAI7E,MAAM,MAAM,6BAA6B,CAAC,KAAK,SAAS,MAAM,IAAI,KAAK,GAAG;IACxE,WAAW,CAAC,EAAE,IAAI,CAAC;CACpB,CAAC;AAKF,MAAM,WAAW,oBAAoB,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,IAAI,CAC/E,cAAc,CAAC,KAAK,EAAE,6BAA6B,CAAC,KAAK,CAAC,CAAC,EAC3D,WAAW,GAAG,aAAa,CAC5B;IACC,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,yBAAyB,CAAC,6BAA6B,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACvG,WAAW,CAAC,WAAW,EAAE,OAAO,CAAC,yBAAyB,CAAC,6BAA6B,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAC1G;AAED,MAAM,WAAW,8BAA8B,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IAC3E;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,6BAA6B,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;IAEjF;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,KAAK,kCAAkC,CAAC,CAAC;CAC/E;AAED,8FAA8F;AAC9F,MAAM,WAAW,2BAA2B,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IACxE;;OAEG;IACH,OAAO,EAAE,oBAAoB,CAAC,KAAK,CAAC,CAAC;IAErC;;;OAGG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAID;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,SAAS,MAAM,EAC3D,OAAO,EAAE,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,EACrC,OAAO,EAAE,CAAC,IAAI,EAAE,6BAA6B,CAAC,KAAK,CAAC,KAAK,IAAI,GAAG,SAAS,EACzE,IAAI,CAAC,EAAE,8BAA8B,CAAC,KAAK,CAAC,GAC3C,2BAA2B,CAAC,KAAK,CAAC,CAuDpC"}
@@ -0,0 +1,25 @@
1
+ type VercelAiOptions = {
2
+ /**
3
+ * Enable or disable input recording. Enabled if `dataCollection.genAI.inputs` (or the deprecated `sendDefaultPii` option) is `true`
4
+ * or if you set `isEnabled` to `true` in your ai SDK method telemetry settings.
5
+ * Integration-level options take precedence over global `dataCollection` config.
6
+ */
7
+ recordInputs?: boolean;
8
+ /**
9
+ * Enable or disable output recording. Enabled if `dataCollection.genAI.outputs` (or the deprecated `sendDefaultPii` option) is `true`
10
+ * or if you set `isEnabled` to `true` in your ai SDK method telemetry settings.
11
+ * Integration-level options take precedence over global `dataCollection` config.
12
+ */
13
+ recordOutputs?: boolean;
14
+ /**
15
+ * Enable or disable truncation of recorded input messages.
16
+ * Defaults to `true`.
17
+ */
18
+ enableTruncation?: boolean;
19
+ };
20
+ /**
21
+ * Auto-instrument the `ai` SDK's native telemetry tracing channel (ai >= 7).
22
+ */
23
+ export declare const vercelAiIntegration: (options?: VercelAiOptions | undefined) => import("@sentry/core").Integration;
24
+ export {};
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/vercel-ai/index.ts"],"names":[],"mappings":"AAIA,KAAK,eAAe,GAAG;IACrB;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAoBF;;GAEG;AACH,eAAO,MAAM,mBAAmB,+EAA0C,CAAC"}