@sentry/server-utils 10.61.0 → 10.63.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/index.js +6 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/integrations/tracing-channel/fastify/errors.js +42 -0
- package/build/cjs/integrations/tracing-channel/fastify/errors.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/fastify/index.js +34 -0
- package/build/cjs/integrations/tracing-channel/fastify/index.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/fastify/instrumentation.js +279 -0
- package/build/cjs/integrations/tracing-channel/fastify/instrumentation.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/fastify/utils.js +11 -0
- package/build/cjs/integrations/tracing-channel/fastify/utils.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/lru-memoizer.js +31 -0
- package/build/cjs/integrations/tracing-channel/lru-memoizer.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/mysql.js +44 -82
- package/build/cjs/integrations/tracing-channel/mysql.js.map +1 -1
- package/build/cjs/orchestrion/channels.js +2 -1
- package/build/cjs/orchestrion/channels.js.map +1 -1
- package/build/cjs/orchestrion/config.js +6 -0
- package/build/cjs/orchestrion/config.js.map +1 -1
- package/build/cjs/orchestrion/index.js +2 -0
- package/build/cjs/orchestrion/index.js.map +1 -1
- package/build/cjs/tracing-channel.js +50 -11
- package/build/cjs/tracing-channel.js.map +1 -1
- package/build/cjs/vercel-ai/index.js +23 -0
- package/build/cjs/vercel-ai/index.js.map +1 -0
- package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js +362 -0
- package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -0
- package/build/esm/index.js +2 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/integrations/tracing-channel/fastify/errors.js +39 -0
- package/build/esm/integrations/tracing-channel/fastify/errors.js.map +1 -0
- package/build/esm/integrations/tracing-channel/fastify/index.js +30 -0
- package/build/esm/integrations/tracing-channel/fastify/index.js.map +1 -0
- package/build/esm/integrations/tracing-channel/fastify/instrumentation.js +277 -0
- package/build/esm/integrations/tracing-channel/fastify/instrumentation.js.map +1 -0
- package/build/esm/integrations/tracing-channel/fastify/utils.js +8 -0
- package/build/esm/integrations/tracing-channel/fastify/utils.js.map +1 -0
- package/build/esm/integrations/tracing-channel/lru-memoizer.js +29 -0
- package/build/esm/integrations/tracing-channel/lru-memoizer.js.map +1 -0
- package/build/esm/integrations/tracing-channel/mysql.js +45 -83
- package/build/esm/integrations/tracing-channel/mysql.js.map +1 -1
- package/build/esm/orchestrion/channels.js +2 -1
- package/build/esm/orchestrion/channels.js.map +1 -1
- package/build/esm/orchestrion/config.js +6 -0
- package/build/esm/orchestrion/config.js.map +1 -1
- package/build/esm/orchestrion/index.js +1 -0
- package/build/esm/orchestrion/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/tracing-channel.js +51 -12
- package/build/esm/tracing-channel.js.map +1 -1
- package/build/esm/vercel-ai/index.js +21 -0
- package/build/esm/vercel-ai/index.js.map +1 -0
- package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js +357 -0
- package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -0
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integrations/tracing-channel/fastify/errors.d.ts +12 -0
- package/build/types/integrations/tracing-channel/fastify/errors.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/fastify/index.d.ts +66 -0
- package/build/types/integrations/tracing-channel/fastify/index.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/fastify/instrumentation.d.ts +10 -0
- package/build/types/integrations/tracing-channel/fastify/instrumentation.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/fastify/types.d.ts +32 -0
- package/build/types/integrations/tracing-channel/fastify/types.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/fastify/utils.d.ts +9 -0
- package/build/types/integrations/tracing-channel/fastify/utils.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/lru-memoizer.d.ts +10 -0
- package/build/types/integrations/tracing-channel/lru-memoizer.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/mysql.d.ts +3 -1
- package/build/types/integrations/tracing-channel/mysql.d.ts.map +1 -1
- package/build/types/orchestrion/channels.d.ts +1 -0
- package/build/types/orchestrion/channels.d.ts.map +1 -1
- package/build/types/orchestrion/config.d.ts.map +1 -1
- package/build/types/orchestrion/index.d.ts +1 -0
- package/build/types/orchestrion/index.d.ts.map +1 -1
- package/build/types/tracing-channel.d.ts +22 -0
- package/build/types/tracing-channel.d.ts.map +1 -1
- package/build/types/vercel-ai/index.d.ts +27 -0
- package/build/types/vercel-ai/index.d.ts.map +1 -0
- package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts +62 -0
- package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -0
- package/build/types-ts3.8/index.d.ts +3 -0
- package/build/types-ts3.8/integrations/tracing-channel/fastify/errors.d.ts +12 -0
- package/build/types-ts3.8/integrations/tracing-channel/fastify/index.d.ts +66 -0
- package/build/types-ts3.8/integrations/tracing-channel/fastify/instrumentation.d.ts +10 -0
- package/build/types-ts3.8/integrations/tracing-channel/fastify/types.d.ts +32 -0
- package/build/types-ts3.8/integrations/tracing-channel/fastify/utils.d.ts +9 -0
- package/build/types-ts3.8/integrations/tracing-channel/lru-memoizer.d.ts +10 -0
- package/build/types-ts3.8/integrations/tracing-channel/mysql.d.ts +3 -1
- package/build/types-ts3.8/node-diagnostics-channel.d.ts +19 -0
- package/build/types-ts3.8/orchestrion/channels.d.ts +1 -0
- package/build/types-ts3.8/orchestrion/index.d.ts +1 -0
- package/build/types-ts3.8/tracing-channel.d.ts +22 -0
- package/build/types-ts3.8/vercel-ai/index.d.ts +27 -0
- package/build/types-ts3.8/vercel-ai/vercel-ai-dc-subscriber.d.ts +62 -0
- package/package.json +3 -3
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const attributes = require('@sentry/conventions/attributes');
|
|
4
|
+
const op = require('@sentry/conventions/op');
|
|
5
|
+
const core = require('@sentry/core');
|
|
6
|
+
const tracingChannel = require('../tracing-channel.js');
|
|
7
|
+
|
|
8
|
+
const AI_SDK_TELEMETRY_TRACING_CHANNEL = "ai:telemetry";
|
|
9
|
+
const ORIGIN = "auto.vercelai.channel";
|
|
10
|
+
const GEN_AI_TOOL_CALL_ID_ATTRIBUTE = "gen_ai.tool.call.id";
|
|
11
|
+
const GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE = "gen_ai.tool.description";
|
|
12
|
+
const GEN_AI_EMBEDDINGS_OPERATION = "embeddings";
|
|
13
|
+
const GEN_AI_RERANK_OPERATION = "rerank";
|
|
14
|
+
const GEN_AI_GENERATE_CONTENT_OPERATION = "generate_content";
|
|
15
|
+
const VERCEL_AI_OPERATION_ID_ATTRIBUTE = "vercel.ai.operationId";
|
|
16
|
+
const VERCEL_AI_MODEL_PROVIDER_ATTRIBUTE = "vercel.ai.model.provider";
|
|
17
|
+
const VERCEL_AI_SETTINGS_MAX_RETRIES_ATTRIBUTE = "vercel.ai.settings.maxRetries";
|
|
18
|
+
const operationIdByCallId = /* @__PURE__ */ new Map();
|
|
19
|
+
const toolDescriptionsByCallId = /* @__PURE__ */ new Map();
|
|
20
|
+
const ROOT_OPERATION_TYPES = /* @__PURE__ */ new Set(["generateText", "streamText", "embed", "rerank"]);
|
|
21
|
+
function clearOperationId(data) {
|
|
22
|
+
if (!ROOT_OPERATION_TYPES.has(data.type)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const callId = asString(data.event.callId);
|
|
26
|
+
if (callId) {
|
|
27
|
+
operationIdByCallId.delete(callId);
|
|
28
|
+
toolDescriptionsByCallId.delete(callId);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function recordToolDescriptions(callId, tools) {
|
|
32
|
+
if (!callId || !Array.isArray(tools)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
let descriptions = toolDescriptionsByCallId.get(callId);
|
|
36
|
+
for (const tool of tools) {
|
|
37
|
+
if (isRecord(tool) && typeof tool.name === "string" && typeof tool.description === "string") {
|
|
38
|
+
descriptions = descriptions ?? /* @__PURE__ */ new Map();
|
|
39
|
+
if (!descriptions.has(tool.name)) {
|
|
40
|
+
descriptions.set(tool.name, tool.description);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (descriptions) {
|
|
45
|
+
toolDescriptionsByCallId.set(callId, descriptions);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function resolveToolDescription(callId, toolName, tools) {
|
|
49
|
+
const fromMap = callId ? toolDescriptionsByCallId.get(callId)?.get(toolName) : void 0;
|
|
50
|
+
if (fromMap) {
|
|
51
|
+
return fromMap;
|
|
52
|
+
}
|
|
53
|
+
if (Array.isArray(tools)) {
|
|
54
|
+
const match = tools.find((tool) => isRecord(tool) && tool.name === toolName);
|
|
55
|
+
return isRecord(match) ? asString(match.description) : void 0;
|
|
56
|
+
}
|
|
57
|
+
if (isRecord(tools)) {
|
|
58
|
+
const tool = tools[toolName];
|
|
59
|
+
return isRecord(tool) ? asString(tool.description) : void 0;
|
|
60
|
+
}
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
let subscribed = false;
|
|
64
|
+
function subscribeVercelAiTracingChannel(tracingChannel$1, options = {}) {
|
|
65
|
+
if (subscribed) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
subscribed = true;
|
|
69
|
+
tracingChannel.bindTracingChannelToSpan(
|
|
70
|
+
tracingChannel$1(AI_SDK_TELEMETRY_TRACING_CHANNEL),
|
|
71
|
+
(data) => createSpanFromMessage(data, options),
|
|
72
|
+
{
|
|
73
|
+
// The helper ends the span; we enrich it from the settled result first (tokens, output messages,
|
|
74
|
+
// finish reasons, response model/id, provider metadata) and drop the per-operation `callId` maps.
|
|
75
|
+
beforeSpanEnd: (span, data) => {
|
|
76
|
+
enrichSpanOnEnd(span, data, options);
|
|
77
|
+
clearOperationId(data);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
function createSpanFromMessage(data, channelOptions) {
|
|
83
|
+
const { type, event } = data;
|
|
84
|
+
if (type === "step" || !event || typeof event !== "object") {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
const { recordInputs, enableTruncation } = getRecordingOptions(event, channelOptions);
|
|
88
|
+
const provider = asString(event.provider);
|
|
89
|
+
const modelId = asString(event.modelId);
|
|
90
|
+
const callId = asString(event.callId);
|
|
91
|
+
const maxRetries = asNumber(event.maxRetries);
|
|
92
|
+
if (recordInputs) {
|
|
93
|
+
recordToolDescriptions(callId, event.tools);
|
|
94
|
+
}
|
|
95
|
+
const baseAttributes = {
|
|
96
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
|
|
97
|
+
...provider ? { [attributes.GEN_AI_SYSTEM]: provider, [VERCEL_AI_MODEL_PROVIDER_ATTRIBUTE]: provider } : {},
|
|
98
|
+
...modelId ? { [attributes.GEN_AI_REQUEST_MODEL]: modelId } : {},
|
|
99
|
+
...maxRetries !== void 0 ? { [VERCEL_AI_SETTINGS_MAX_RETRIES_ATTRIBUTE]: maxRetries } : {}
|
|
100
|
+
};
|
|
101
|
+
switch (type) {
|
|
102
|
+
case "generateText":
|
|
103
|
+
case "streamText":
|
|
104
|
+
return buildInvokeAgentSpan(event, baseAttributes, recordInputs, enableTruncation, callId, type === "streamText");
|
|
105
|
+
case "languageModelCall":
|
|
106
|
+
return buildModelCallSpan(event, baseAttributes, recordInputs, enableTruncation, callId, modelId);
|
|
107
|
+
case "executeTool":
|
|
108
|
+
return buildToolSpan(event, recordInputs);
|
|
109
|
+
case "embed":
|
|
110
|
+
return startGenAiSpan(GEN_AI_EMBEDDINGS_OPERATION, modelId, {
|
|
111
|
+
...baseAttributes,
|
|
112
|
+
...recordInputs && event.value !== void 0 ? { [attributes.GEN_AI_EMBEDDINGS_INPUT]: safeStringify(event.value) } : {}
|
|
113
|
+
});
|
|
114
|
+
case "rerank":
|
|
115
|
+
return startGenAiSpan(GEN_AI_RERANK_OPERATION, modelId, baseAttributes);
|
|
116
|
+
default:
|
|
117
|
+
return void 0;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function startGenAiSpan(operation, suffix, attributes$1) {
|
|
121
|
+
return core.startInactiveSpan({
|
|
122
|
+
name: suffix ? `${operation} ${suffix}` : operation,
|
|
123
|
+
op: `gen_ai.${operation}`,
|
|
124
|
+
attributes: { [attributes.GEN_AI_OPERATION_NAME]: operation, ...attributes$1 }
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function buildInvokeAgentSpan(event, baseAttributes, recordInputs, enableTruncation, callId, isStream) {
|
|
128
|
+
const functionId = asString(event.functionId);
|
|
129
|
+
const operationId = asString(event.operationId) ?? (isStream ? "ai.streamText" : "ai.generateText");
|
|
130
|
+
if (callId) {
|
|
131
|
+
operationIdByCallId.set(callId, { operationId, isStream });
|
|
132
|
+
}
|
|
133
|
+
return startGenAiSpan(op.GEN_AI_INVOKE_AGENT_SPAN_OP, functionId, {
|
|
134
|
+
...baseAttributes,
|
|
135
|
+
[VERCEL_AI_OPERATION_ID_ATTRIBUTE]: operationId,
|
|
136
|
+
[attributes.GEN_AI_RESPONSE_STREAMING]: isStream,
|
|
137
|
+
...functionId ? { [attributes.GEN_AI_FUNCTION_ID]: functionId } : {},
|
|
138
|
+
...recordInputs ? buildInputMessageAttributes(event, enableTruncation) : {}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function buildModelCallSpan(event, baseAttributes, recordInputs, enableTruncation, callId, modelId) {
|
|
142
|
+
const parent = callId ? operationIdByCallId.get(callId) : void 0;
|
|
143
|
+
const operationId = parent ? `${parent.operationId}.${parent.isStream ? "doStream" : "doGenerate"}` : "ai.generateText.doGenerate";
|
|
144
|
+
return startGenAiSpan(GEN_AI_GENERATE_CONTENT_OPERATION, modelId, {
|
|
145
|
+
...baseAttributes,
|
|
146
|
+
[VERCEL_AI_OPERATION_ID_ATTRIBUTE]: operationId,
|
|
147
|
+
...recordInputs ? buildInputMessageAttributes(event, enableTruncation) : {},
|
|
148
|
+
...recordInputs && Array.isArray(event.tools) ? { [attributes.GEN_AI_REQUEST_AVAILABLE_TOOLS]: safeStringify(event.tools) } : {}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function buildToolSpan(event, recordInputs) {
|
|
152
|
+
const toolCall = isRecord(event.toolCall) ? event.toolCall : {};
|
|
153
|
+
const toolName = asString(toolCall.toolName);
|
|
154
|
+
const toolCallId = asString(event.toolCallId) ?? asString(toolCall.toolCallId);
|
|
155
|
+
const toolInput = toolCall.input ?? toolCall.args;
|
|
156
|
+
const description = recordInputs && toolName ? resolveToolDescription(asString(event.callId), toolName, event.tools) : void 0;
|
|
157
|
+
return startGenAiSpan(op.GEN_AI_EXECUTE_TOOL_SPAN_OP, toolName, {
|
|
158
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
|
|
159
|
+
[attributes.GEN_AI_TOOL_TYPE]: "function",
|
|
160
|
+
...toolName ? { [attributes.GEN_AI_TOOL_NAME]: toolName } : {},
|
|
161
|
+
...toolCallId ? { [GEN_AI_TOOL_CALL_ID_ATTRIBUTE]: toolCallId } : {},
|
|
162
|
+
...description ? { [GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE]: description } : {},
|
|
163
|
+
...recordInputs && toolInput !== void 0 ? { [attributes.GEN_AI_TOOL_INPUT]: safeStringify(toolInput) } : {}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function enrichSpanOnEnd(span, data, channelOptions) {
|
|
167
|
+
const { type, result } = data;
|
|
168
|
+
if (!isRecord(result)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const { recordOutputs } = getRecordingOptions(data.event, channelOptions);
|
|
172
|
+
if (type === "executeTool") {
|
|
173
|
+
if (recordOutputs) {
|
|
174
|
+
span.setAttribute(attributes.GEN_AI_TOOL_OUTPUT, safeStringify(result.output ?? result));
|
|
175
|
+
}
|
|
176
|
+
const output = isRecord(result.output) ? result.output : void 0;
|
|
177
|
+
if (output?.type === "tool-error") {
|
|
178
|
+
captureToolError(span, data, output.error);
|
|
179
|
+
}
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const usage = isRecord(result.usage) ? result.usage : void 0;
|
|
183
|
+
if (usage) {
|
|
184
|
+
const inputTokens = tokenCount(usage.inputTokens) ?? tokenCount(usage.tokens);
|
|
185
|
+
const outputTokens = tokenCount(usage.outputTokens);
|
|
186
|
+
const totalTokens = tokenCount(usage.totalTokens) ?? sum(inputTokens, outputTokens);
|
|
187
|
+
if (inputTokens !== void 0) {
|
|
188
|
+
span.setAttribute(attributes.GEN_AI_USAGE_INPUT_TOKENS, inputTokens);
|
|
189
|
+
}
|
|
190
|
+
if (outputTokens !== void 0) {
|
|
191
|
+
span.setAttribute(attributes.GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);
|
|
192
|
+
}
|
|
193
|
+
if (totalTokens !== void 0) {
|
|
194
|
+
span.setAttribute(attributes.GEN_AI_USAGE_TOTAL_TOKENS, totalTokens);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const finishReason = getFinishReason(result);
|
|
198
|
+
if (finishReason && type === "languageModelCall") {
|
|
199
|
+
span.setAttribute(attributes.GEN_AI_RESPONSE_FINISH_REASONS, safeStringify([finishReason]));
|
|
200
|
+
}
|
|
201
|
+
const response = isRecord(result.response) ? result.response : void 0;
|
|
202
|
+
const responseId = asString(response?.id) ?? asString(result.responseId);
|
|
203
|
+
if (responseId) {
|
|
204
|
+
span.setAttribute(attributes.GEN_AI_RESPONSE_ID, responseId);
|
|
205
|
+
}
|
|
206
|
+
const responseModel = asString(response?.modelId) ?? asString(data.event.modelId);
|
|
207
|
+
if (responseModel) {
|
|
208
|
+
span.setAttribute(attributes.GEN_AI_RESPONSE_MODEL, responseModel);
|
|
209
|
+
}
|
|
210
|
+
const providerMetadata = result.providerMetadata;
|
|
211
|
+
const providerAttributes = core.getProviderMetadataAttributes(providerMetadata);
|
|
212
|
+
if (core.GEN_AI_CONVERSATION_ID_ATTRIBUTE in providerAttributes && core.spanToJSON(span).data[core.GEN_AI_CONVERSATION_ID_ATTRIBUTE]) {
|
|
213
|
+
delete providerAttributes[core.GEN_AI_CONVERSATION_ID_ATTRIBUTE];
|
|
214
|
+
}
|
|
215
|
+
span.setAttributes(providerAttributes);
|
|
216
|
+
if (recordOutputs) {
|
|
217
|
+
const parts = type === "languageModelCall" && Array.isArray(result.content) ? partsFromContent(result.content) : partsFromTextAndToolCalls(result.text, result.toolCalls);
|
|
218
|
+
const outputMessages = buildOutputMessages(parts, finishReason);
|
|
219
|
+
if (outputMessages) {
|
|
220
|
+
span.setAttribute(attributes.GEN_AI_OUTPUT_MESSAGES, outputMessages);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function normalizeFinishReason(finishReason) {
|
|
225
|
+
return finishReason === "tool-calls" ? "tool_call" : finishReason ?? "stop";
|
|
226
|
+
}
|
|
227
|
+
function getFinishReason(result) {
|
|
228
|
+
const finishReason = result.finishReason;
|
|
229
|
+
if (typeof finishReason === "string") {
|
|
230
|
+
return finishReason;
|
|
231
|
+
}
|
|
232
|
+
return isRecord(finishReason) ? asString(finishReason.unified) : void 0;
|
|
233
|
+
}
|
|
234
|
+
function tokenCount(value) {
|
|
235
|
+
return asNumber(value) ?? (isRecord(value) ? asNumber(value.total) : void 0);
|
|
236
|
+
}
|
|
237
|
+
function buildOutputMessages(parts, finishReason) {
|
|
238
|
+
if (!parts.length) {
|
|
239
|
+
return void 0;
|
|
240
|
+
}
|
|
241
|
+
return safeStringify([{ role: "assistant", parts, finish_reason: normalizeFinishReason(finishReason) }]);
|
|
242
|
+
}
|
|
243
|
+
function toolCallPart(toolCall) {
|
|
244
|
+
const args = toolCall.input ?? toolCall.args;
|
|
245
|
+
return {
|
|
246
|
+
type: "tool_call",
|
|
247
|
+
id: asString(toolCall.toolCallId),
|
|
248
|
+
name: asString(toolCall.toolName),
|
|
249
|
+
arguments: typeof args === "string" ? args : safeStringify(args ?? {})
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function partsFromContent(content) {
|
|
253
|
+
const parts = [];
|
|
254
|
+
for (const item of content) {
|
|
255
|
+
if (!isRecord(item)) {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (item.type === "text" && typeof item.text === "string") {
|
|
259
|
+
parts.push({ type: "text", content: item.text });
|
|
260
|
+
} else if (item.type === "tool-call") {
|
|
261
|
+
parts.push(toolCallPart(item));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return parts;
|
|
265
|
+
}
|
|
266
|
+
function partsFromTextAndToolCalls(text, toolCalls) {
|
|
267
|
+
const parts = [];
|
|
268
|
+
if (typeof text === "string" && text.length) {
|
|
269
|
+
parts.push({ type: "text", content: text });
|
|
270
|
+
}
|
|
271
|
+
if (Array.isArray(toolCalls)) {
|
|
272
|
+
for (const toolCall of toolCalls) {
|
|
273
|
+
if (isRecord(toolCall)) {
|
|
274
|
+
parts.push(toolCallPart(toolCall));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return parts;
|
|
279
|
+
}
|
|
280
|
+
function captureToolError(span, data, error) {
|
|
281
|
+
span.setStatus({
|
|
282
|
+
code: core.SPAN_STATUS_ERROR,
|
|
283
|
+
message: error instanceof Error ? error.message : "tool_error"
|
|
284
|
+
});
|
|
285
|
+
const toolCall = isRecord(data.event.toolCall) ? data.event.toolCall : {};
|
|
286
|
+
const toolName = asString(toolCall.toolName);
|
|
287
|
+
const toolCallId = asString(data.event.toolCallId) ?? asString(toolCall.toolCallId);
|
|
288
|
+
core.withScope((scope) => {
|
|
289
|
+
scope.setContext("trace", core.spanToTraceContext(span));
|
|
290
|
+
if (toolName) {
|
|
291
|
+
scope.setTag("vercel.ai.tool.name", toolName);
|
|
292
|
+
}
|
|
293
|
+
if (toolCallId) {
|
|
294
|
+
scope.setTag("vercel.ai.tool.callId", toolCallId);
|
|
295
|
+
}
|
|
296
|
+
scope.setLevel("error");
|
|
297
|
+
core.captureException(
|
|
298
|
+
error instanceof Error ? error : new Error(typeof error === "string" ? error : "Tool execution failed"),
|
|
299
|
+
{
|
|
300
|
+
mechanism: { type: "auto.vercelai.channel", handled: false }
|
|
301
|
+
}
|
|
302
|
+
);
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
function getRecordingOptions(event, channelOptions) {
|
|
306
|
+
const genAI = core.getClient()?.getDataCollectionOptions().genAI;
|
|
307
|
+
return {
|
|
308
|
+
recordInputs: resolveRecording(channelOptions.recordInputs, event.recordInputs, genAI?.inputs),
|
|
309
|
+
recordOutputs: resolveRecording(channelOptions.recordOutputs, event.recordOutputs, genAI?.outputs),
|
|
310
|
+
enableTruncation: core.shouldEnableTruncation(channelOptions.enableTruncation)
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function resolveRecording(integrationOption, perCallOption, globalDefault) {
|
|
314
|
+
if (typeof integrationOption === "boolean") {
|
|
315
|
+
return integrationOption;
|
|
316
|
+
}
|
|
317
|
+
if (typeof perCallOption === "boolean") {
|
|
318
|
+
return perCallOption;
|
|
319
|
+
}
|
|
320
|
+
return globalDefault === true;
|
|
321
|
+
}
|
|
322
|
+
function buildInputMessageAttributes(event, enableTruncation) {
|
|
323
|
+
const attributes$1 = {};
|
|
324
|
+
const instructions = asString(event.instructions);
|
|
325
|
+
if (instructions) {
|
|
326
|
+
attributes$1[core.GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE] = safeStringify([{ type: "text", content: instructions }]);
|
|
327
|
+
}
|
|
328
|
+
const messages = event.messages ?? event.prompt;
|
|
329
|
+
if (messages !== void 0) {
|
|
330
|
+
attributes$1[attributes.GEN_AI_INPUT_MESSAGES] = enableTruncation ? core.getTruncatedJsonString(messages) : safeStringify(messages);
|
|
331
|
+
attributes$1[core.GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE] = Array.isArray(messages) ? messages.length : 1;
|
|
332
|
+
}
|
|
333
|
+
return attributes$1;
|
|
334
|
+
}
|
|
335
|
+
function asString(value) {
|
|
336
|
+
return typeof value === "string" ? value : void 0;
|
|
337
|
+
}
|
|
338
|
+
function asNumber(value) {
|
|
339
|
+
return typeof value === "number" && !isNaN(value) ? value : void 0;
|
|
340
|
+
}
|
|
341
|
+
function sum(a, b) {
|
|
342
|
+
return a === void 0 && b === void 0 ? void 0 : (a ?? 0) + (b ?? 0);
|
|
343
|
+
}
|
|
344
|
+
function isRecord(value) {
|
|
345
|
+
return typeof value === "object" && value !== null;
|
|
346
|
+
}
|
|
347
|
+
function safeStringify(value) {
|
|
348
|
+
if (typeof value === "string") {
|
|
349
|
+
return value;
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
return JSON.stringify(value);
|
|
353
|
+
} catch {
|
|
354
|
+
return "[unserializable]";
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
exports.clearOperationId = clearOperationId;
|
|
359
|
+
exports.createSpanFromMessage = createSpanFromMessage;
|
|
360
|
+
exports.enrichSpanOnEnd = enrichSpanOnEnd;
|
|
361
|
+
exports.subscribeVercelAiTracingChannel = subscribeVercelAiTracingChannel;
|
|
362
|
+
//# 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 {\n return JSON.stringify(value);\n } catch {\n return '[unserializable]';\n }\n}\n"],"names":["tracingChannel","bindTracingChannelToSpan","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","GEN_AI_SYSTEM","GEN_AI_REQUEST_MODEL","GEN_AI_EMBEDDINGS_INPUT","attributes","startInactiveSpan","GEN_AI_OPERATION_NAME","GEN_AI_INVOKE_AGENT_SPAN_OP","GEN_AI_RESPONSE_STREAMING","GEN_AI_FUNCTION_ID","GEN_AI_REQUEST_AVAILABLE_TOOLS","GEN_AI_EXECUTE_TOOL_SPAN_OP","GEN_AI_TOOL_TYPE","GEN_AI_TOOL_NAME","GEN_AI_TOOL_INPUT","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","getProviderMetadataAttributes","GEN_AI_CONVERSATION_ID_ATTRIBUTE","spanToJSON","GEN_AI_OUTPUT_MESSAGES","SPAN_STATUS_ERROR","withScope","spanToTraceContext","captureException","getClient","shouldEnableTruncation","GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE","GEN_AI_INPUT_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_COMMAND, REDIS_DC_CHANNEL_CONNECT, subscribeRedisDiagnosticChannels } from './redis/redis-dc-subscriber.js';
|
|
2
2
|
export { bindTracingChannelToSpan } from './tracing-channel.js';
|
|
3
|
+
export { vercelAiIntegration } from './vercel-ai/index.js';
|
|
4
|
+
export { fastifyIntegration, handleFastifyError, instrumentFastify } from './integrations/tracing-channel/fastify/index.js';
|
|
3
5
|
//# sourceMappingURL=index.js.map
|
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as diagnosticsChannel from 'node:diagnostics_channel';
|
|
2
|
+
import { DEBUG_BUILD } from '../../../debug-build.js';
|
|
3
|
+
import { debug, captureException, getClient } from '@sentry/core';
|
|
4
|
+
import { defaultShouldHandleError, INTEGRATION_NAME } from './utils.js';
|
|
5
|
+
|
|
6
|
+
function getFastifyIntegration() {
|
|
7
|
+
const client = getClient();
|
|
8
|
+
return client?.getIntegrationByName(INTEGRATION_NAME);
|
|
9
|
+
}
|
|
10
|
+
function subscribeToFastifyErrorChannel() {
|
|
11
|
+
diagnosticsChannel.subscribe("tracing:fastify.request.handler:error", (message) => {
|
|
12
|
+
const { error, request, reply } = message;
|
|
13
|
+
handleFastifyError.call(handleFastifyError, error, request, reply, "diagnostics-channel");
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function handleFastifyError(error, request, reply, handlerOrigin) {
|
|
17
|
+
const shouldHandleError = getFastifyIntegration()?.getShouldHandleError() || defaultShouldHandleError;
|
|
18
|
+
if (handlerOrigin === "diagnostics-channel") {
|
|
19
|
+
this.diagnosticsChannelExists = true;
|
|
20
|
+
}
|
|
21
|
+
if (this.diagnosticsChannelExists && handlerOrigin === "onError-hook") {
|
|
22
|
+
DEBUG_BUILD && debug.warn(
|
|
23
|
+
"Fastify error handler was already registered via diagnostics channel.",
|
|
24
|
+
"You can safely remove `setupFastifyErrorHandler` call and set `shouldHandleError` on the integration options."
|
|
25
|
+
);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (shouldHandleError(error, request, reply)) {
|
|
29
|
+
captureException(error, {
|
|
30
|
+
mechanism: {
|
|
31
|
+
handled: false,
|
|
32
|
+
type: "auto.function.fastify"
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { handleFastifyError, subscribeToFastifyErrorChannel };
|
|
39
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sources":["../../../../../src/integrations/tracing-channel/fastify/errors.ts"],"sourcesContent":["import type { FastifyIntegration, FastifyReply, FastifyRequest } from './types';\nimport * as diagnosticsChannel from 'node:diagnostics_channel';\nimport { DEBUG_BUILD } from '../../../debug-build';\nimport { getClient, debug, captureException } from '@sentry/core';\nimport { defaultShouldHandleError, INTEGRATION_NAME } from './utils';\n\nfunction getFastifyIntegration(): FastifyIntegration | undefined {\n const client = getClient();\n return client?.getIntegrationByName(INTEGRATION_NAME);\n}\n\n/**\n * Subscribe to the Fastify v5 error diagnostics channel.\n */\nexport function subscribeToFastifyErrorChannel(): void {\n diagnosticsChannel.subscribe('tracing:fastify.request.handler:error', message => {\n const { error, request, reply } = message as {\n error: Error;\n request: FastifyRequest;\n reply: FastifyReply;\n };\n\n handleFastifyError.call(handleFastifyError, error, request, reply, 'diagnostics-channel');\n });\n}\n\n/**\n * Handle a Fastify error, and possibly send it to Sentry.\n */\nexport function handleFastifyError(\n this: {\n diagnosticsChannelExists?: boolean;\n },\n error: Error,\n request: FastifyRequest,\n reply: FastifyReply,\n handlerOrigin: 'diagnostics-channel' | 'onError-hook',\n): void {\n const shouldHandleError = getFastifyIntegration()?.getShouldHandleError() || defaultShouldHandleError;\n // Diagnostics channel runs before the onError hook, so we can use it to check if the handler was already registered\n if (handlerOrigin === 'diagnostics-channel') {\n this.diagnosticsChannelExists = true;\n }\n\n if (this.diagnosticsChannelExists && handlerOrigin === 'onError-hook') {\n DEBUG_BUILD &&\n debug.warn(\n 'Fastify error handler was already registered via diagnostics channel.',\n 'You can safely remove `setupFastifyErrorHandler` call and set `shouldHandleError` on the integration options.',\n );\n\n // If the diagnostics channel already exists, we don't need to handle the error again\n return;\n }\n\n if (shouldHandleError(error, request, reply)) {\n captureException(error, {\n mechanism: {\n handled: false,\n type: 'auto.function.fastify',\n },\n });\n }\n}\n"],"names":[],"mappings":";;;;;AAMA,SAAS,qBAAA,GAAwD;AAC/D,EAAA,MAAM,SAAS,SAAA,EAAU;AACzB,EAAA,OAAO,MAAA,EAAQ,qBAAqB,gBAAgB,CAAA;AACtD;AAKO,SAAS,8BAAA,GAAuC;AACrD,EAAA,kBAAA,CAAmB,SAAA,CAAU,yCAAyC,CAAA,OAAA,KAAW;AAC/E,IAAA,MAAM,EAAE,KAAA,EAAO,OAAA,EAAS,KAAA,EAAM,GAAI,OAAA;AAMlC,IAAA,kBAAA,CAAmB,IAAA,CAAK,kBAAA,EAAoB,KAAA,EAAO,OAAA,EAAS,OAAO,qBAAqB,CAAA;AAAA,EAC1F,CAAC,CAAA;AACH;AAKO,SAAS,kBAAA,CAId,KAAA,EACA,OAAA,EACA,KAAA,EACA,aAAA,EACM;AACN,EAAA,MAAM,iBAAA,GAAoB,qBAAA,EAAsB,EAAG,oBAAA,EAAqB,IAAK,wBAAA;AAE7E,EAAA,IAAI,kBAAkB,qBAAA,EAAuB;AAC3C,IAAA,IAAA,CAAK,wBAAA,GAA2B,IAAA;AAAA,EAClC;AAEA,EAAA,IAAI,IAAA,CAAK,wBAAA,IAA4B,aAAA,KAAkB,cAAA,EAAgB;AACrE,IAAA,WAAA,IACE,KAAA,CAAM,IAAA;AAAA,MACJ,uEAAA;AAAA,MACA;AAAA,KACF;AAGF,IAAA;AAAA,EACF;AAEA,EAAA,IAAI,iBAAA,CAAkB,KAAA,EAAO,OAAA,EAAS,KAAK,CAAA,EAAG;AAC5C,IAAA,gBAAA,CAAiB,KAAA,EAAO;AAAA,MACtB,SAAA,EAAW;AAAA,QACT,OAAA,EAAS,KAAA;AAAA,QACT,IAAA,EAAM;AAAA;AACR,KACD,CAAA;AAAA,EACH;AACF;;;;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineIntegration } from '@sentry/core';
|
|
2
|
+
import { instrumentFastify as instrumentFastify$1 } from './instrumentation.js';
|
|
3
|
+
import { INTEGRATION_NAME, defaultShouldHandleError } from './utils.js';
|
|
4
|
+
import { subscribeToFastifyErrorChannel, handleFastifyError as handleFastifyError$1 } from './errors.js';
|
|
5
|
+
|
|
6
|
+
const _fastifyIntegration = (({ shouldHandleError }) => {
|
|
7
|
+
let _shouldHandleError;
|
|
8
|
+
return {
|
|
9
|
+
name: INTEGRATION_NAME,
|
|
10
|
+
setupOnce() {
|
|
11
|
+
_shouldHandleError = shouldHandleError || defaultShouldHandleError;
|
|
12
|
+
subscribeToFastifyErrorChannel();
|
|
13
|
+
instrumentFastify$1();
|
|
14
|
+
},
|
|
15
|
+
getShouldHandleError() {
|
|
16
|
+
return _shouldHandleError;
|
|
17
|
+
},
|
|
18
|
+
setShouldHandleError(shouldHandleError2) {
|
|
19
|
+
_shouldHandleError = shouldHandleError2;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
const fastifyIntegration = defineIntegration(
|
|
24
|
+
(options = {}) => _fastifyIntegration(options)
|
|
25
|
+
);
|
|
26
|
+
const instrumentFastify = instrumentFastify$1;
|
|
27
|
+
const handleFastifyError = handleFastifyError$1;
|
|
28
|
+
|
|
29
|
+
export { fastifyIntegration, handleFastifyError, instrumentFastify };
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing-channel/fastify/index.ts"],"sourcesContent":["import type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration } from '@sentry/core';\nimport type { FastifyIntegration, FastifyReply, FastifyRequest } from './types';\n\nimport { instrumentFastify as _instrumentFastify } from './instrumentation';\nimport { defaultShouldHandleError, INTEGRATION_NAME } from './utils';\nimport { subscribeToFastifyErrorChannel, handleFastifyError as _handleFastifyError } from './errors';\n\n/**\n * Options for the Fastify integration.\n *\n * `shouldHandleError` - Callback method deciding whether error should be captured and sent to Sentry\n * This is used on Fastify v5 where Sentry handles errors in the diagnostics channel.\n * Fastify v3 and v4 use `setupFastifyErrorHandler` instead.\n *\n * @example\n *\n * ```javascript\n * Sentry.init({\n * integrations: [\n * Sentry.fastifyIntegration({\n * shouldHandleError(_error, _request, reply) {\n * return reply.statusCode >= 500;\n * },\n * });\n * },\n * });\n * ```\n *\n */\ninterface FastifyIntegrationOptions {\n /**\n * Callback method deciding whether error should be captured and sent to Sentry\n * This is used on Fastify v5 where Sentry handles errors in the diagnostics channel.\n * Fastify v3 and v4 use `setupFastifyErrorHandler` instead.\n *\n * @param error Captured Fastify error\n * @param request Fastify request (or any object containing at least method, routeOptions.url, and routerPath)\n * @param reply Fastify reply (or any object containing at least statusCode)\n */\n shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean;\n}\n\nconst _fastifyIntegration = (({ shouldHandleError }: Partial<FastifyIntegrationOptions>) => {\n let _shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean;\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n _shouldHandleError = shouldHandleError || defaultShouldHandleError;\n\n subscribeToFastifyErrorChannel();\n _instrumentFastify();\n },\n getShouldHandleError() {\n return _shouldHandleError;\n },\n setShouldHandleError(shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean) {\n _shouldHandleError = shouldHandleError;\n },\n } satisfies FastifyIntegration;\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for [Fastify](https://fastify.dev/).\n * This integration supports Fastify v5 only.\n *\n * For more information, see the [fastify documentation](https://docs.sentry.io/platforms/javascript/guides/fastify/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.fastifyIntegration()],\n * })\n * ```\n */\nexport const fastifyIntegration = defineIntegration((options: Partial<FastifyIntegrationOptions> = {}) =>\n _fastifyIntegration(options),\n);\n\n/**\n * @deprecated This export is deprecated and will not longer be exposed in the next major version.\n */\nexport const instrumentFastify = _instrumentFastify;\n\n/**\n * @deprecated This export is deprecated and will not longer be exposed in the next major version.\n */\nexport const handleFastifyError = _handleFastifyError;\n"],"names":["_instrumentFastify","shouldHandleError","_handleFastifyError"],"mappings":";;;;;AA2CA,MAAM,mBAAA,IAAuB,CAAC,EAAE,iBAAA,EAAkB,KAA0C;AAC1F,EAAA,IAAI,kBAAA;AAEJ,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AACV,MAAA,kBAAA,GAAqB,iBAAA,IAAqB,wBAAA;AAE1C,MAAA,8BAAA,EAA+B;AAC/B,MAAAA,mBAAA,EAAmB;AAAA,IACrB,CAAA;AAAA,IACA,oBAAA,GAAuB;AACrB,MAAA,OAAO,kBAAA;AAAA,IACT,CAAA;AAAA,IACA,qBAAqBC,kBAAAA,EAA4F;AAC/G,MAAA,kBAAA,GAAqBA,kBAAAA;AAAA,IACvB;AAAA,GACF;AACF,CAAA,CAAA;AAiBO,MAAM,kBAAA,GAAqB,iBAAA;AAAA,EAAkB,CAAC,OAAA,GAA8C,EAAC,KAClG,oBAAoB,OAAO;AAC7B;AAKO,MAAM,iBAAA,GAAoBD;AAK1B,MAAM,kBAAA,GAAqBE;;;;"}
|