@sentry/server-utils 11.20.0 → 11.21.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 (40) hide show
  1. package/build/cjs/chunks/config.js +28 -0
  2. package/build/cjs/chunks/config.js.map +1 -1
  3. package/build/cjs/chunks/exports.js +6 -0
  4. package/build/cjs/index.js +328 -0
  5. package/build/cjs/index.js.map +1 -1
  6. package/build/esm/ai/tanstack-ai/constants.js +11 -0
  7. package/build/esm/ai/tanstack-ai/constants.js.map +1 -0
  8. package/build/esm/ai/tanstack-ai/index.js +206 -0
  9. package/build/esm/ai/tanstack-ai/index.js.map +1 -0
  10. package/build/esm/ai/tanstack-ai/utils.js +81 -0
  11. package/build/esm/ai/tanstack-ai/utils.js.map +1 -0
  12. package/build/esm/index.js +2 -1
  13. package/build/esm/index.js.map +1 -1
  14. package/build/esm/integrations/tanstack-ai.js +59 -0
  15. package/build/esm/integrations/tanstack-ai.js.map +1 -0
  16. package/build/esm/orchestrion/channels.js +2 -0
  17. package/build/esm/orchestrion/channels.js.map +1 -1
  18. package/build/esm/orchestrion/config/index.js +2 -0
  19. package/build/esm/orchestrion/config/index.js.map +1 -1
  20. package/build/esm/orchestrion/config/tanstack-ai.js +19 -0
  21. package/build/esm/orchestrion/config/tanstack-ai.js.map +1 -0
  22. package/build/esm/package.json +1 -1
  23. package/build/types/ai/tanstack-ai/constants.d.ts +8 -0
  24. package/build/types/ai/tanstack-ai/constants.d.ts.map +1 -0
  25. package/build/types/ai/tanstack-ai/index.d.ts +18 -0
  26. package/build/types/ai/tanstack-ai/index.d.ts.map +1 -0
  27. package/build/types/ai/tanstack-ai/types.d.ts +127 -0
  28. package/build/types/ai/tanstack-ai/types.d.ts.map +1 -0
  29. package/build/types/ai/tanstack-ai/utils.d.ts +21 -0
  30. package/build/types/ai/tanstack-ai/utils.d.ts.map +1 -0
  31. package/build/types/index.d.ts +2 -0
  32. package/build/types/index.d.ts.map +1 -1
  33. package/build/types/integrations/tanstack-ai.d.ts +18 -0
  34. package/build/types/integrations/tanstack-ai.d.ts.map +1 -0
  35. package/build/types/orchestrion/channels.d.ts +1 -0
  36. package/build/types/orchestrion/channels.d.ts.map +1 -1
  37. package/build/types/orchestrion/config/index.d.ts.map +1 -1
  38. package/build/types/orchestrion/config/tanstack-ai.d.ts +17 -0
  39. package/build/types/orchestrion/config/tanstack-ai.d.ts.map +1 -0
  40. package/package.json +3 -3
@@ -0,0 +1,11 @@
1
+ // src/ai/tanstack-ai/constants.ts
2
+ const TANSTACK_AI_INTEGRATION_NAME = "TanStackAI";
3
+ const TANSTACK_AI_ORIGIN = "auto.ai.tanstack_ai";
4
+ /**
5
+ * Marks our middleware, so a `chat()` call that already has it does not get a second one.
6
+ * `Symbol.for`, so that two copies of the SDK in one process see each other's middleware.
7
+ */
8
+ const TANSTACK_AI_MIDDLEWARE_BRAND = Symbol.for("sentry.tanstack-ai.middleware");
9
+ export { TANSTACK_AI_INTEGRATION_NAME, TANSTACK_AI_MIDDLEWARE_BRAND, TANSTACK_AI_ORIGIN };
10
+
11
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../../../../src/ai/tanstack-ai/constants.ts"],"sourcesContent":["export const TANSTACK_AI_INTEGRATION_NAME = 'TanStackAI' as const;\n\nexport const TANSTACK_AI_ORIGIN = 'auto.ai.tanstack_ai';\n\n/**\n * Marks our middleware, so a `chat()` call that already has it does not get a second one.\n * `Symbol.for`, so that two copies of the SDK in one process see each other's middleware.\n */\nexport const TANSTACK_AI_MIDDLEWARE_BRAND = Symbol.for('sentry.tanstack-ai.middleware');\n"],"mappings":";AAAA,MAAa,+BAA+B;AAE5C,MAAa,qBAAqB;;;;;AAMlC,MAAa,+BAA+B,OAAO,IAAI,+BAA+B"}
@@ -0,0 +1,206 @@
1
+ import { GEN_AI_TOOL_CALL_ID_ATTRIBUTE } from "../core/gen-ai-attributes.js";
2
+ import { runGenAiSpanEnd, runGenAiSpanStart } from "../core/span-hooks.js";
3
+ import { recordTimeToFirstChunk } from "../core/time-to-first-chunk.js";
4
+ import { getErrorStatus, getGenAiSpanOp, resolveGenAiCallRecording, setOutputMessagesAttribute } from "../core/utils.js";
5
+ import { TANSTACK_AI_MIDDLEWARE_BRAND, TANSTACK_AI_ORIGIN } from "./constants.js";
6
+ import { getInputAttributes, getProviderName, getRequestAttributes, getRunError, getUsageAttributes } from "./utils.js";
7
+ import { GEN_AI_AGENT_NAME, GEN_AI_CONVERSATION_ID, GEN_AI_OPERATION_NAME, GEN_AI_PROVIDER_NAME, GEN_AI_REQUEST_MODEL, GEN_AI_RESPONSE_FINISH_REASONS, GEN_AI_RESPONSE_ID, GEN_AI_RESPONSE_MODEL, GEN_AI_RESPONSE_STREAMING, GEN_AI_TOOL_CALL_ARGUMENTS, GEN_AI_TOOL_CALL_RESULT, GEN_AI_TOOL_DEFINITIONS, GEN_AI_TOOL_DESCRIPTION, GEN_AI_TOOL_NAME, SENTRY_ORIGIN } from "@sentry/conventions/attributes";
8
+ import { SPAN_STATUS_ERROR, captureException, getActiveSpan, startInactiveSpan, stringify, withActiveSpan } from "@sentry/core";
9
+ // src/ai/tanstack-ai/index.ts
10
+ const OUTPUT_CHUNK_TYPES = /* @__PURE__ */ new Set([
11
+ "TEXT_MESSAGE_CONTENT",
12
+ "TOOL_CALL_START",
13
+ "REASONING_MESSAGE_CONTENT"
14
+ ]);
15
+ /**
16
+ * Makes the chat middleware for one `chat()` call. Call it when `chat()` is called: the parent of the
17
+ * `invoke_agent` span is the span that is active then, and the recording options are decided then.
18
+ * The middleware cannot make its spans active, so the spans of other work in the run do not nest
19
+ * below them.
20
+ */
21
+ function createTanstackAIMiddleware(options, call) {
22
+ const parentSpan = getActiveSpan() ?? null;
23
+ const { recordInputs, recordOutputs } = resolveGenAiCallRecording(options, call);
24
+ const streaming = call.outputSchema ? call.stream === true : call.stream !== false;
25
+ let agentSpan;
26
+ let chatSpan;
27
+ let outputText = "";
28
+ let outputToolCalls = [];
29
+ const toolCallNames = /* @__PURE__ */ new Map();
30
+ const toolSpans = /* @__PURE__ */ new Map();
31
+ const startSpan = (spanOptions) => {
32
+ const span = startInactiveSpan(spanOptions);
33
+ runGenAiSpanStart(options, span, call);
34
+ return span;
35
+ };
36
+ const endSpan = (span, status, error) => {
37
+ if (status) span.setStatus(status);
38
+ runGenAiSpanEnd(options, span, call, status ? { error } : {});
39
+ span.end();
40
+ };
41
+ const endChatSpan = (status, error) => {
42
+ if (chatSpan) {
43
+ endSpan(chatSpan, status, error);
44
+ chatSpan = void 0;
45
+ }
46
+ };
47
+ const endRun = (status, error) => {
48
+ if (!agentSpan) return;
49
+ for (const span of toolSpans.values()) endSpan(span, status, error);
50
+ toolSpans.clear();
51
+ endChatSpan(status, error);
52
+ endSpan(agentSpan, status, error);
53
+ agentSpan = void 0;
54
+ };
55
+ const startChatSpan = (ctx, config) => {
56
+ outputText = "";
57
+ outputToolCalls = [];
58
+ toolCallNames.clear();
59
+ return startSpan({
60
+ name: `chat ${ctx.model}`,
61
+ op: getGenAiSpanOp("chat"),
62
+ parentSpan: agentSpan,
63
+ attributes: {
64
+ [SENTRY_ORIGIN]: TANSTACK_AI_ORIGIN,
65
+ [GEN_AI_OPERATION_NAME]: "chat",
66
+ [GEN_AI_PROVIDER_NAME]: getProviderName(ctx),
67
+ [GEN_AI_REQUEST_MODEL]: ctx.model,
68
+ [GEN_AI_CONVERSATION_ID]: ctx.threadId,
69
+ [GEN_AI_RESPONSE_STREAMING]: streaming,
70
+ ...getRequestAttributes(config.modelOptions),
71
+ ...recordInputs && config.tools.length && ctx.phase !== "structuredOutput" ? { [GEN_AI_TOOL_DEFINITIONS]: stringify(config.tools.map(({ name, description, inputSchema }) => ({
72
+ name,
73
+ description,
74
+ inputSchema
75
+ }))) } : {},
76
+ ...recordInputs ? getInputAttributes(config.providerMessages ?? config.messages, config.systemPrompts) : {}
77
+ }
78
+ });
79
+ };
80
+ return {
81
+ name: "sentry",
82
+ [TANSTACK_AI_MIDDLEWARE_BRAND]: true,
83
+ onConfig(ctx, config) {
84
+ if (ctx.phase === "init" && !agentSpan) {
85
+ const agentName = ctx.subagentName;
86
+ agentSpan = startSpan({
87
+ name: agentName ? `invoke_agent ${agentName}` : "invoke_agent",
88
+ op: getGenAiSpanOp("invoke_agent"),
89
+ parentSpan,
90
+ attributes: {
91
+ [SENTRY_ORIGIN]: TANSTACK_AI_ORIGIN,
92
+ [GEN_AI_OPERATION_NAME]: "invoke_agent",
93
+ [GEN_AI_PROVIDER_NAME]: getProviderName(ctx),
94
+ [GEN_AI_REQUEST_MODEL]: ctx.model,
95
+ [GEN_AI_CONVERSATION_ID]: ctx.threadId,
96
+ [GEN_AI_RESPONSE_STREAMING]: streaming,
97
+ [GEN_AI_AGENT_NAME]: agentName,
98
+ ...recordInputs ? getInputAttributes(config.messages, config.systemPrompts) : {}
99
+ }
100
+ });
101
+ }
102
+ if (!agentSpan || ctx.phase !== "beforeModel" && ctx.phase !== "structuredOutput") return;
103
+ endChatSpan({
104
+ code: SPAN_STATUS_ERROR,
105
+ message: "internal_error"
106
+ });
107
+ chatSpan = startChatSpan(ctx, config);
108
+ },
109
+ onChunk(ctx, chunk) {
110
+ if (!agentSpan) return;
111
+ if (chunk.type === "RUN_FINISHED" || chunk.type === "RUN_ERROR") {
112
+ const provider = getProviderName(ctx);
113
+ chatSpan?.setAttribute(GEN_AI_PROVIDER_NAME, provider);
114
+ agentSpan.setAttribute(GEN_AI_PROVIDER_NAME, provider);
115
+ }
116
+ if (chunk.type === "RUN_ERROR") {
117
+ endRun(getErrorStatus(ctx.signal), getRunError(chunk));
118
+ return;
119
+ }
120
+ if (chunk.type === "RUN_FINISHED" && chunk.outcome?.type === "interrupt") {
121
+ endRun();
122
+ return;
123
+ }
124
+ if (!chatSpan) return;
125
+ if (streaming && OUTPUT_CHUNK_TYPES.has(chunk.type)) recordTimeToFirstChunk(chatSpan);
126
+ if (chunk.type === "TEXT_MESSAGE_CONTENT" && recordOutputs && chunk.delta) outputText += chunk.delta;
127
+ else if (chunk.type === "TOOL_CALL_START" && chunk.toolCallId && chunk.toolCallName) toolCallNames.set(chunk.toolCallId, chunk.toolCallName);
128
+ else if (chunk.type === "TOOL_CALL_END" && recordOutputs && chunk.toolCallId) outputToolCalls.push({
129
+ id: chunk.toolCallId,
130
+ name: toolCallNames.get(chunk.toolCallId),
131
+ arguments: chunk.input ?? {}
132
+ });
133
+ else if (chunk.type === "RUN_FINISHED") {
134
+ const responseModel = chunk.model ?? ctx.callMetadata?.model;
135
+ const responseId = chunk.responseId ?? ctx.callMetadata?.responseId;
136
+ const finishReason = chunk.finishReason ?? void 0;
137
+ if (finishReason) chatSpan.setAttribute(GEN_AI_RESPONSE_FINISH_REASONS, stringify([finishReason]));
138
+ for (const span of [chatSpan, agentSpan]) {
139
+ if (responseModel) span.setAttribute(GEN_AI_RESPONSE_MODEL, responseModel);
140
+ if (responseId) span.setAttribute(GEN_AI_RESPONSE_ID, responseId);
141
+ if (recordOutputs) setOutputMessagesAttribute(span, {
142
+ responseText: outputText,
143
+ toolCalls: outputToolCalls,
144
+ finishReason
145
+ });
146
+ }
147
+ }
148
+ },
149
+ onInterruptBoundary(ctx) {
150
+ if (ctx.phase === "afterModel") endChatSpan();
151
+ },
152
+ onUsage(_ctx, usage) {
153
+ chatSpan?.setAttributes(getUsageAttributes(usage));
154
+ },
155
+ onGuardToolCall(ctx, { toolName, toolCallId, args, tool }) {
156
+ if (!agentSpan || tool && typeof tool.execute !== "function") return;
157
+ toolSpans.set(toolCallId, startSpan({
158
+ name: `execute_tool ${toolName}`,
159
+ op: getGenAiSpanOp("execute_tool"),
160
+ parentSpan: agentSpan,
161
+ attributes: {
162
+ [SENTRY_ORIGIN]: TANSTACK_AI_ORIGIN,
163
+ [GEN_AI_OPERATION_NAME]: "execute_tool",
164
+ [GEN_AI_TOOL_NAME]: toolName,
165
+ [GEN_AI_TOOL_CALL_ID_ATTRIBUTE]: toolCallId,
166
+ [GEN_AI_CONVERSATION_ID]: ctx.threadId,
167
+ [GEN_AI_TOOL_DESCRIPTION]: tool?.description,
168
+ ...recordInputs ? { [GEN_AI_TOOL_CALL_ARGUMENTS]: stringify(args) } : {}
169
+ }
170
+ }));
171
+ },
172
+ onAfterToolCall(ctx, { toolCallId, ok, result, error }) {
173
+ const span = toolSpans.get(toolCallId);
174
+ if (!span) return;
175
+ toolSpans.delete(toolCallId);
176
+ if (recordOutputs && ok && result !== void 0) span.setAttribute(GEN_AI_TOOL_CALL_RESULT, typeof result === "string" ? result : stringify(result));
177
+ if (ok) {
178
+ endSpan(span);
179
+ return;
180
+ }
181
+ const status = getErrorStatus(ctx.signal);
182
+ if (status.message === "internal_error") withActiveSpan(span, () => {
183
+ captureException(error, { mechanism: {
184
+ type: TANSTACK_AI_ORIGIN,
185
+ handled: false
186
+ } });
187
+ });
188
+ endSpan(span, status, error);
189
+ },
190
+ onFinish() {
191
+ endRun();
192
+ },
193
+ onAbort() {
194
+ endRun({
195
+ code: SPAN_STATUS_ERROR,
196
+ message: "cancelled"
197
+ });
198
+ },
199
+ onError(ctx, { error }) {
200
+ endRun(getErrorStatus(ctx.signal), error);
201
+ }
202
+ };
203
+ }
204
+ export { createTanstackAIMiddleware };
205
+
206
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/ai/tanstack-ai/index.ts"],"sourcesContent":["import type { Span, SpanStatus } from '@sentry/core';\nimport {\n captureException,\n getActiveSpan,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n stringify,\n withActiveSpan,\n} from '@sentry/core';\nimport {\n GEN_AI_AGENT_NAME,\n GEN_AI_CONVERSATION_ID,\n GEN_AI_OPERATION_NAME,\n GEN_AI_PROVIDER_NAME,\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_TOOL_CALL_ARGUMENTS,\n GEN_AI_TOOL_CALL_RESULT,\n GEN_AI_TOOL_DEFINITIONS,\n GEN_AI_TOOL_DESCRIPTION,\n GEN_AI_TOOL_NAME,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { GEN_AI_TOOL_CALL_ID_ATTRIBUTE } from '../core/gen-ai-attributes';\nimport type { GenAiSpanHooks } from '../core/span-hooks';\nimport { runGenAiSpanEnd, runGenAiSpanStart } from '../core/span-hooks';\nimport { recordTimeToFirstChunk } from '../core/time-to-first-chunk';\nimport type { GenAiCallOptions } from '../core/utils';\nimport { getErrorStatus, getGenAiSpanOp, resolveGenAiCallRecording, setOutputMessagesAttribute } from '../core/utils';\nimport { TANSTACK_AI_MIDDLEWARE_BRAND, TANSTACK_AI_ORIGIN } from './constants';\nimport type {\n TanstackAICallInfo,\n TanstackAIChatMiddleware,\n TanstackAIMiddlewareConfig,\n TanstackAIMiddlewareContext,\n} from './types';\nimport { getInputAttributes, getProviderName, getRequestAttributes, getRunError, getUsageAttributes } from './utils';\n\n/**\n * `call` is the options object of the `chat()` call. The recording options run when `chat()` is\n * called. The hooks run for every span (`invoke_agent`, `chat` and `execute_tool`) while the run is\n * read, which can be in another async context than the call. `onSpanEnd` gets the `error` of a\n * failed run or tool.\n */\nexport type TanstackAIOptions = GenAiCallOptions<TanstackAICallInfo> & GenAiSpanHooks<TanstackAICallInfo>;\n\n// The chunks that carry model output. The adapters send `RUN_STARTED` before the provider answers.\nconst OUTPUT_CHUNK_TYPES = new Set(['TEXT_MESSAGE_CONTENT', 'TOOL_CALL_START', 'REASONING_MESSAGE_CONTENT']);\n\n/**\n * Makes the chat middleware for one `chat()` call. Call it when `chat()` is called: the parent of the\n * `invoke_agent` span is the span that is active then, and the recording options are decided then.\n * The middleware cannot make its spans active, so the spans of other work in the run do not nest\n * below them.\n */\nexport function createTanstackAIMiddleware(\n options: TanstackAIOptions,\n call: TanstackAICallInfo,\n): TanstackAIChatMiddleware {\n const parentSpan = getActiveSpan() ?? null;\n const { recordInputs, recordOutputs } = resolveGenAiCallRecording(options, call);\n // `ctx.streaming` is also true when `chat()` returns a promise, because `chat()` reads the same stream\n // inside. With `outputSchema`, `chat()` streams only with `stream: true`.\n const streaming = call.outputSchema ? call.stream === true : call.stream !== false;\n\n let agentSpan: Span | undefined;\n let chatSpan: Span | undefined;\n let outputText = '';\n let outputToolCalls: Array<{ id: string; name?: string; arguments: unknown }> = [];\n // `TOOL_CALL_END` has the arguments but not the name, which only `TOOL_CALL_START` has.\n const toolCallNames = new Map<string, string>();\n const toolSpans = new Map<string, Span>();\n\n const startSpan = (spanOptions: Parameters<typeof startInactiveSpan>[0]): Span => {\n const span = startInactiveSpan(spanOptions);\n runGenAiSpanStart(options, span, call);\n return span;\n };\n\n const endSpan = (span: Span, status?: SpanStatus, error?: unknown): void => {\n if (status) {\n span.setStatus(status);\n }\n runGenAiSpanEnd(options, span, call, status ? { error } : {});\n span.end();\n };\n\n const endChatSpan = (status?: SpanStatus, error?: unknown): void => {\n if (chatSpan) {\n endSpan(chatSpan, status, error);\n chatSpan = undefined;\n }\n };\n\n const endRun = (status?: SpanStatus, error?: unknown): void => {\n if (!agentSpan) {\n return;\n }\n for (const span of toolSpans.values()) {\n endSpan(span, status, error);\n }\n toolSpans.clear();\n endChatSpan(status, error);\n endSpan(agentSpan, status, error);\n agentSpan = undefined;\n };\n\n const startChatSpan = (ctx: TanstackAIMiddlewareContext, config: TanstackAIMiddlewareConfig): Span => {\n outputText = '';\n outputToolCalls = [];\n toolCallNames.clear();\n\n return startSpan({\n name: `chat ${ctx.model}`,\n op: getGenAiSpanOp('chat'),\n parentSpan: agentSpan,\n attributes: {\n [SENTRY_ORIGIN]: TANSTACK_AI_ORIGIN,\n [GEN_AI_OPERATION_NAME]: 'chat',\n [GEN_AI_PROVIDER_NAME]: getProviderName(ctx),\n [GEN_AI_REQUEST_MODEL]: ctx.model,\n [GEN_AI_CONVERSATION_ID]: ctx.threadId,\n [GEN_AI_RESPONSE_STREAMING]: streaming,\n ...getRequestAttributes(config.modelOptions),\n // The `structuredOutput` call sends no tools, but its config still lists them.\n ...(recordInputs && config.tools.length && ctx.phase !== 'structuredOutput'\n ? {\n [GEN_AI_TOOL_DEFINITIONS]: stringify(\n config.tools.map(({ name, description, inputSchema }) => ({ name, description, inputSchema })),\n ),\n }\n : {}),\n // A middleware can send the provider other messages than the history of the run.\n ...(recordInputs ? getInputAttributes(config.providerMessages ?? config.messages, config.systemPrompts) : {}),\n },\n });\n };\n\n return {\n name: 'sentry',\n [TANSTACK_AI_MIDDLEWARE_BRAND]: true,\n\n onConfig(ctx, config) {\n // `init` runs once per run, before `onStart` and before any tool can run.\n if (ctx.phase === 'init' && !agentSpan) {\n const agentName = ctx.subagentName;\n agentSpan = startSpan({\n name: agentName ? `invoke_agent ${agentName}` : 'invoke_agent',\n op: getGenAiSpanOp('invoke_agent'),\n parentSpan,\n attributes: {\n [SENTRY_ORIGIN]: TANSTACK_AI_ORIGIN,\n [GEN_AI_OPERATION_NAME]: 'invoke_agent',\n [GEN_AI_PROVIDER_NAME]: getProviderName(ctx),\n [GEN_AI_REQUEST_MODEL]: ctx.model,\n [GEN_AI_CONVERSATION_ID]: ctx.threadId,\n [GEN_AI_RESPONSE_STREAMING]: streaming,\n [GEN_AI_AGENT_NAME]: agentName,\n ...(recordInputs ? getInputAttributes(config.messages, config.systemPrompts) : {}),\n },\n });\n }\n\n // `beforeModel` starts each model call of the agent loop. `structuredOutput` starts the\n // separate last call for `outputSchema`.\n if (!agentSpan || (ctx.phase !== 'beforeModel' && ctx.phase !== 'structuredOutput')) {\n return;\n }\n // A model call that completes ends its span at the `afterModel` boundary. A span that is still\n // open here is of a call that failed and that a middleware retried with `ctx.retry()`.\n endChatSpan({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n chatSpan = startChatSpan(ctx, config);\n },\n\n onChunk(ctx, chunk) {\n if (!agentSpan) {\n return;\n }\n if (chunk.type === 'RUN_FINISHED' || chunk.type === 'RUN_ERROR') {\n // TanStack sets the call metadata of the `structuredOutput` call only after `onConfig`.\n const provider = getProviderName(ctx);\n chatSpan?.setAttribute(GEN_AI_PROVIDER_NAME, provider);\n agentSpan.setAttribute(GEN_AI_PROVIDER_NAME, provider);\n }\n // A provider error ends the run with this chunk. `chat({ stream: false })` then throws and\n // stops reading, so TanStack calls no terminal hook.\n if (chunk.type === 'RUN_ERROR') {\n endRun(getErrorStatus(ctx.signal), getRunError(chunk));\n return;\n }\n // A run that stops at an interrupt ends with this chunk. For an interrupt at `beforeModel` or\n // `afterModel`, TanStack calls no terminal hook.\n if (chunk.type === 'RUN_FINISHED' && chunk.outcome?.type === 'interrupt') {\n endRun();\n return;\n }\n if (!chatSpan) {\n return;\n }\n\n if (streaming && OUTPUT_CHUNK_TYPES.has(chunk.type)) {\n recordTimeToFirstChunk(chatSpan);\n }\n\n if (chunk.type === 'TEXT_MESSAGE_CONTENT' && recordOutputs && chunk.delta) {\n outputText += chunk.delta;\n } else if (chunk.type === 'TOOL_CALL_START' && chunk.toolCallId && chunk.toolCallName) {\n toolCallNames.set(chunk.toolCallId, chunk.toolCallName);\n } else if (chunk.type === 'TOOL_CALL_END' && recordOutputs && chunk.toolCallId) {\n outputToolCalls.push({\n id: chunk.toolCallId,\n name: toolCallNames.get(chunk.toolCallId),\n arguments: chunk.input ?? {},\n });\n } else if (chunk.type === 'RUN_FINISHED') {\n // An adapter can report these only in the `metadata.tanstack` of the chunk. TanStack copies\n // them into `callMetadata` before the middleware gets the chunk.\n const responseModel = chunk.model ?? ctx.callMetadata?.model;\n const responseId = chunk.responseId ?? ctx.callMetadata?.responseId;\n const finishReason = chunk.finishReason ?? undefined;\n if (finishReason) {\n chatSpan.setAttribute(GEN_AI_RESPONSE_FINISH_REASONS, stringify([finishReason]));\n }\n // The agent span keeps the response of the last model call, which is the answer of the run.\n for (const span of [chatSpan, agentSpan]) {\n if (responseModel) {\n span.setAttribute(GEN_AI_RESPONSE_MODEL, responseModel);\n }\n if (responseId) {\n span.setAttribute(GEN_AI_RESPONSE_ID, responseId);\n }\n if (recordOutputs) {\n setOutputMessagesAttribute(span, { responseText: outputText, toolCalls: outputToolCalls, finishReason });\n }\n }\n }\n },\n\n // Runs after each model call and before the tools it asked for, so the `chat` span does not\n // include the tools.\n onInterruptBoundary(ctx) {\n if (ctx.phase === 'afterModel') {\n endChatSpan();\n }\n },\n\n onUsage(_ctx, usage) {\n chatSpan?.setAttributes(getUsageAttributes(usage));\n },\n\n // The guards run after all `onBeforeToolCall` decisions and after the input check, so `args`\n // are the arguments that the tool gets.\n onGuardToolCall(ctx, { toolName, toolCallId, args, tool }) {\n // A client tool runs in the browser, not here.\n if (!agentSpan || (tool && typeof tool.execute !== 'function')) {\n return;\n }\n toolSpans.set(\n toolCallId,\n startSpan({\n name: `execute_tool ${toolName}`,\n op: getGenAiSpanOp('execute_tool'),\n parentSpan: agentSpan,\n attributes: {\n [SENTRY_ORIGIN]: TANSTACK_AI_ORIGIN,\n [GEN_AI_OPERATION_NAME]: 'execute_tool',\n [GEN_AI_TOOL_NAME]: toolName,\n [GEN_AI_TOOL_CALL_ID_ATTRIBUTE]: toolCallId,\n [GEN_AI_CONVERSATION_ID]: ctx.threadId,\n [GEN_AI_TOOL_DESCRIPTION]: tool?.description,\n ...(recordInputs ? { [GEN_AI_TOOL_CALL_ARGUMENTS]: stringify(args) } : {}),\n },\n }),\n );\n },\n\n onAfterToolCall(ctx, { toolCallId, ok, result, error }) {\n const span = toolSpans.get(toolCallId);\n if (!span) {\n return;\n }\n toolSpans.delete(toolCallId);\n\n if (recordOutputs && ok && result !== undefined) {\n span.setAttribute(GEN_AI_TOOL_CALL_RESULT, typeof result === 'string' ? result : stringify(result));\n }\n if (ok) {\n endSpan(span);\n return;\n }\n // TanStack fails each tool that did not start yet with an `Operation aborted` error.\n const status = getErrorStatus(ctx.signal);\n if (status.message === 'internal_error') {\n // TanStack gives a tool failure back to the model as the tool result, so the error handlers\n // of the app never see it.\n withActiveSpan(span, () => {\n captureException(error, { mechanism: { type: TANSTACK_AI_ORIGIN, handled: false } });\n });\n }\n endSpan(span, status, error);\n },\n\n onFinish() {\n endRun();\n },\n\n // Also for an abort from a middleware, which leaves the signal of the caller alone.\n onAbort() {\n endRun({ code: SPAN_STATUS_ERROR, message: 'cancelled' });\n },\n\n onError(ctx, { error }) {\n endRun(getErrorStatus(ctx.signal), error);\n },\n };\n}\n"],"mappings":"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"}
@@ -0,0 +1,81 @@
1
+ import { getTokenUsageAttributes } from "../core/utils.js";
2
+ import { GEN_AI_INPUT_MESSAGES, GEN_AI_REQUEST_MAX_TOKENS, GEN_AI_REQUEST_TEMPERATURE, GEN_AI_REQUEST_TOP_P, GEN_AI_SYSTEM_INSTRUCTIONS, GEN_AI_USAGE_REASONING_OUTPUT_TOKENS } from "@sentry/conventions/attributes";
3
+ import { stringify } from "@sentry/core";
4
+ // src/ai/tanstack-ai/utils.ts
5
+ /**
6
+ * `ctx.provider` is the adapter name, which for some adapters also names the API (for example
7
+ * `openrouter-responses`). The call metadata has the provider of the adapter, but only after the
8
+ * first model call started.
9
+ */
10
+ function getProviderName(ctx) {
11
+ return ctx.callMetadata?.source?.provider ?? ctx.provider;
12
+ }
13
+ function getInputAttributes(messages, systemPrompts) {
14
+ return {
15
+ [GEN_AI_INPUT_MESSAGES]: stringify(messages.map(toGenAiMessage)),
16
+ [GEN_AI_SYSTEM_INSTRUCTIONS]: systemPrompts.length ? stringify(systemPrompts.map((prompt) => ({
17
+ type: "text",
18
+ content: typeof prompt === "string" ? prompt : prompt.content
19
+ }))) : void 0
20
+ };
21
+ }
22
+ /**
23
+ * TanStack AI has no common option for temperature, top p or max tokens. Each adapter takes them in
24
+ * `modelOptions` and passes them to the provider with the provider's key name (snake_case or camelCase,
25
+ * and `max_tokens` or `max_output_tokens`). So we take the first of the known keys that has a value.
26
+ */
27
+ function getRequestAttributes(modelOptions = {}) {
28
+ const pick = (...keys) => {
29
+ for (const key of keys) {
30
+ const value = modelOptions[key];
31
+ if (typeof value === "number") return value;
32
+ }
33
+ };
34
+ return {
35
+ [GEN_AI_REQUEST_TEMPERATURE]: pick("temperature"),
36
+ [GEN_AI_REQUEST_TOP_P]: pick("top_p", "topP"),
37
+ [GEN_AI_REQUEST_MAX_TOKENS]: pick("max_tokens", "maxTokens", "max_output_tokens", "maxOutputTokens")
38
+ };
39
+ }
40
+ function getUsageAttributes(usage) {
41
+ const attributes = getTokenUsageAttributes(usage.promptTokens, usage.completionTokens, usage.promptTokensDetails?.cacheWriteTokens, usage.promptTokensDetails?.cachedTokens, usage.totalTokens);
42
+ if (typeof usage.completionTokensDetails?.reasoningTokens === "number") attributes[GEN_AI_USAGE_REASONING_OUTPUT_TOKENS] = usage.completionTokensDetails.reasoningTokens;
43
+ return attributes;
44
+ }
45
+ function toGenAiMessage(message) {
46
+ const parts = [];
47
+ const { content } = message;
48
+ if (message.role === "tool") parts.push({
49
+ type: "tool_call_response",
50
+ id: message.toolCallId,
51
+ result: content
52
+ });
53
+ else if (typeof content === "string") parts.push({
54
+ type: "text",
55
+ content
56
+ });
57
+ else if (Array.isArray(content)) for (const part of content) parts.push(part.type === "text" ? {
58
+ type: "text",
59
+ content: part.content
60
+ } : { type: part.type });
61
+ for (const toolCall of message.toolCalls ?? []) parts.push({
62
+ type: "tool_call",
63
+ id: toolCall.id,
64
+ name: toolCall.function?.name,
65
+ arguments: toolCall.function?.arguments
66
+ });
67
+ return {
68
+ role: message.role,
69
+ parts
70
+ };
71
+ }
72
+ /** The error of a `RUN_ERROR` chunk. */
73
+ function getRunError(chunk) {
74
+ return chunk.error ?? {
75
+ message: chunk.message,
76
+ code: chunk.code
77
+ };
78
+ }
79
+ export { getInputAttributes, getProviderName, getRequestAttributes, getRunError, getUsageAttributes };
80
+
81
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../../../src/ai/tanstack-ai/utils.ts"],"sourcesContent":["import { stringify } from '@sentry/core';\nimport {\n GEN_AI_INPUT_MESSAGES,\n GEN_AI_REQUEST_MAX_TOKENS,\n GEN_AI_REQUEST_TEMPERATURE,\n GEN_AI_REQUEST_TOP_P,\n GEN_AI_SYSTEM_INSTRUCTIONS,\n GEN_AI_USAGE_REASONING_OUTPUT_TOKENS,\n} from '@sentry/conventions/attributes';\nimport { getTokenUsageAttributes } from '../core/utils';\nimport type {\n TanstackAIChunk,\n TanstackAIMiddlewareContext,\n TanstackAIModelMessage,\n TanstackAISystemPrompt,\n TanstackAIUsage,\n} from './types';\n\n/**\n * `ctx.provider` is the adapter name, which for some adapters also names the API (for example\n * `openrouter-responses`). The call metadata has the provider of the adapter, but only after the\n * first model call started.\n */\nexport function getProviderName(ctx: TanstackAIMiddlewareContext): string {\n return ctx.callMetadata?.source?.provider ?? ctx.provider;\n}\n\nexport function getInputAttributes(\n messages: ReadonlyArray<TanstackAIModelMessage>,\n systemPrompts: ReadonlyArray<TanstackAISystemPrompt>,\n): Record<string, string | undefined> {\n return {\n [GEN_AI_INPUT_MESSAGES]: stringify(messages.map(toGenAiMessage)),\n [GEN_AI_SYSTEM_INSTRUCTIONS]: systemPrompts.length\n ? stringify(\n systemPrompts.map(prompt => ({\n type: 'text',\n content: typeof prompt === 'string' ? prompt : prompt.content,\n })),\n )\n : undefined,\n };\n}\n\n/**\n * TanStack AI has no common option for temperature, top p or max tokens. Each adapter takes them in\n * `modelOptions` and passes them to the provider with the provider's key name (snake_case or camelCase,\n * and `max_tokens` or `max_output_tokens`). So we take the first of the known keys that has a value.\n */\nexport function getRequestAttributes(modelOptions: Record<string, unknown> = {}): Record<string, number | undefined> {\n const pick = (...keys: string[]): number | undefined => {\n for (const key of keys) {\n const value = modelOptions[key];\n if (typeof value === 'number') {\n return value;\n }\n }\n return undefined;\n };\n return {\n [GEN_AI_REQUEST_TEMPERATURE]: pick('temperature'),\n [GEN_AI_REQUEST_TOP_P]: pick('top_p', 'topP'),\n [GEN_AI_REQUEST_MAX_TOKENS]: pick('max_tokens', 'maxTokens', 'max_output_tokens', 'maxOutputTokens'),\n };\n}\n\nexport function getUsageAttributes(usage: TanstackAIUsage): Record<string, number> {\n const attributes = getTokenUsageAttributes(\n usage.promptTokens,\n usage.completionTokens,\n usage.promptTokensDetails?.cacheWriteTokens,\n usage.promptTokensDetails?.cachedTokens,\n usage.totalTokens,\n );\n if (typeof usage.completionTokensDetails?.reasoningTokens === 'number') {\n attributes[GEN_AI_USAGE_REASONING_OUTPUT_TOKENS] = usage.completionTokensDetails.reasoningTokens;\n }\n return attributes;\n}\n\nfunction toGenAiMessage(message: TanstackAIModelMessage): Record<string, unknown> {\n const parts: Array<Record<string, unknown>> = [];\n const { content } = message;\n\n if (message.role === 'tool') {\n parts.push({ type: 'tool_call_response', id: message.toolCallId, result: content });\n } else if (typeof content === 'string') {\n parts.push({ type: 'text', content });\n } else if (Array.isArray(content)) {\n for (const part of content) {\n // Media parts carry inline data or provider handles, so keep only their type.\n parts.push(part.type === 'text' ? { type: 'text', content: part.content } : { type: part.type });\n }\n }\n for (const toolCall of message.toolCalls ?? []) {\n parts.push({\n type: 'tool_call',\n id: toolCall.id,\n name: toolCall.function?.name,\n arguments: toolCall.function?.arguments,\n });\n }\n return { role: message.role, parts };\n}\n\n/** The error of a `RUN_ERROR` chunk. */\nexport function getRunError(chunk: TanstackAIChunk): { message?: string; code?: string } {\n return chunk.error ?? { message: chunk.message, code: chunk.code };\n}\n"],"mappings":";;;;;;;;;AAuBA,SAAgB,gBAAgB,KAA0C;CACxE,OAAO,IAAI,cAAc,QAAQ,YAAY,IAAI;AACnD;AAEA,SAAgB,mBACd,UACA,eACoC;CACpC,OAAO;GACJ,wBAAwB,UAAU,SAAS,IAAI,cAAc,CAAC;GAC9D,6BAA6B,cAAc,SACxC,UACE,cAAc,KAAI,YAAW;GAC3B,MAAM;GACN,SAAS,OAAO,WAAW,WAAW,SAAS,OAAO;EACxD,EAAE,CACJ,IACA,KAAA;CACN;AACF;;;;;;AAOA,SAAgB,qBAAqB,eAAwC,CAAC,GAAuC;CACnH,MAAM,QAAQ,GAAG,SAAuC;EACtD,KAAK,MAAM,OAAO,MAAM;GACtB,MAAM,QAAQ,aAAa;GAC3B,IAAI,OAAO,UAAU,UACnB,OAAO;EAEX;CAEF;CACA,OAAO;GACJ,6BAA6B,KAAK,aAAa;GAC/C,uBAAuB,KAAK,SAAS,MAAM;GAC3C,4BAA4B,KAAK,cAAc,aAAa,qBAAqB,iBAAiB;CACrG;AACF;AAEA,SAAgB,mBAAmB,OAAgD;CACjF,MAAM,aAAa,wBACjB,MAAM,cACN,MAAM,kBACN,MAAM,qBAAqB,kBAC3B,MAAM,qBAAqB,cAC3B,MAAM,WACR;CACA,IAAI,OAAO,MAAM,yBAAyB,oBAAoB,UAC5D,WAAW,wCAAwC,MAAM,wBAAwB;CAEnF,OAAO;AACT;AAEA,SAAS,eAAe,SAA0D;CAChF,MAAM,QAAwC,CAAC;CAC/C,MAAM,EAAE,YAAY;CAEpB,IAAI,QAAQ,SAAS,QACnB,MAAM,KAAK;EAAE,MAAM;EAAsB,IAAI,QAAQ;EAAY,QAAQ;CAAQ,CAAC;MAC7E,IAAI,OAAO,YAAY,UAC5B,MAAM,KAAK;EAAE,MAAM;EAAQ;CAAQ,CAAC;MAC/B,IAAI,MAAM,QAAQ,OAAO,GAC9B,KAAK,MAAM,QAAQ,SAEjB,MAAM,KAAK,KAAK,SAAS,SAAS;EAAE,MAAM;EAAQ,SAAS,KAAK;CAAQ,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC;CAGnG,KAAK,MAAM,YAAY,QAAQ,aAAa,CAAC,GAC3C,MAAM,KAAK;EACT,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS,UAAU;EACzB,WAAW,SAAS,UAAU;CAChC,CAAC;CAEH,OAAO;EAAE,MAAM,QAAQ;EAAM;CAAM;AACrC;;AAGA,SAAgB,YAAY,OAA6D;CACvF,OAAO,MAAM,SAAS;EAAE,SAAS,MAAM;EAAS,MAAM,MAAM;CAAK;AACnE"}
@@ -53,6 +53,7 @@ import { createFlueInstrumentation } from "./ai/flue/index.js";
53
53
  import { flueIntegration } from "./integrations/flue.js";
54
54
  import { piAiIntegration } from "./integrations/pi-ai.js";
55
55
  import { piDurableIntegration } from "./integrations/pi-durable.js";
56
+ import { tanstackAIIntegration } from "./integrations/tanstack-ai.js";
56
57
  import { mastraIntegration } from "./integrations/mastra.js";
57
58
  import { mcpServerIntegration } from "./integrations/mcp-server.js";
58
59
  import { instrumentTunnelServers, makeServeTunnelIntegration } from "./integrations/serveTunnel.js";
@@ -87,6 +88,6 @@ import { getErrorIntegrations, getTracingIntegrations } from "./integrations/ind
87
88
  * @deprecated This is a temporary export to avoid breaking changes. It will be removed in the next major version.
88
89
  */
89
90
  const attachHapiErrorHandler = attachHapiErrorHandler$1;
90
- export { BullMQTelemetry, SentryMastraExporter, cronExpressionToMonitorConfig as _INTERNAL_cronExpressionToMonitorConfig, amqplibIntegration, anthropicAIIntegration, applyHonoPatches, attachHapiErrorHandler, attachKoaErrorHandler, awsIntegration, bindTracingChannelToSpan, clickhouseIntegration, collectInstalledModules, createFlueInstrumentation, createGetModuleFromFilename, createHonoRequestMiddleware, createLangChainCallbackHandler, createSentryWinstonTransport, cron, cronJobIntegration, dataloaderIntegration, detectOrchestrionSetup, tracingChannel as diagnosticsTracingChannel, earlyPatchHono, eveConversationHook, eveIntegration, eveTracePolicy, expressErrorHandler, expressIntegration, fastifyIntegration, firebaseIntegration, flueIntegration, genericPoolIntegration, getErrorIntegrations, getInstrumentedModuleNames, getOtlpTracesEndpoint, getSqlQueryAttributes, getSqlQuerySummary, getSqlSpanName, getTracingIntegrations, googleGenAIIntegration, graphqlIntegration, groqIntegration, hapiIntegration, honoIntegration, honoMiddleware, instrumentAnthropicAiClient, instrumentCreateReactAgent, instrumentGoogleGenAIClient, instrumentLangChainEmbeddings, instrumentMistralAiClient, instrumentOpenAiClient, instrumentPostgresJsSql, instrumentStateGraph, instrumentStateGraphCompile, instrumentTunnelServer, instrumentTunnelServers, instrumentTypeSafeClient, instrumentWorkersAiClient, isBun, isCloudflareWorkers, isDeno, kafkaIntegration, knexIntegration, koaIntegration, langChainIntegration, langGraphIntegration, lruMemoizerIntegration, makeServeTunnelIntegration, mastraIntegration, mcpServerIntegration, mistralAIIntegration, mongoIntegration, mongooseIntegration, mysql2Integration, mysqlIntegration, neonIntegration, nitroIntegration, nodeCronIntegration, nodeScheduleIntegration, openAIIntegration, openTelemetryIntegration, orchestrionModuleInjected, piAiIntegration, piDurableIntegration, pinoIntegration, postgresIntegration, postgresJsIntegration, prismaIntegration, redisIntegration, sanitizeSqlQuery, setAsyncLocalStorageAsyncContextStrategy, setHttpServerSpanRouteAttribute, setupExpressErrorHandler, setupFastifyErrorHandler, setupHapiErrorHandler, subscribe as subscribeDiagnosticsChannel, tediousIntegration, togetherAIIntegration, typesafeIntegration, vercelAIIntegration };
91
+ export { BullMQTelemetry, SentryMastraExporter, cronExpressionToMonitorConfig as _INTERNAL_cronExpressionToMonitorConfig, amqplibIntegration, anthropicAIIntegration, applyHonoPatches, attachHapiErrorHandler, attachKoaErrorHandler, awsIntegration, bindTracingChannelToSpan, clickhouseIntegration, collectInstalledModules, createFlueInstrumentation, createGetModuleFromFilename, createHonoRequestMiddleware, createLangChainCallbackHandler, createSentryWinstonTransport, cron, cronJobIntegration, dataloaderIntegration, detectOrchestrionSetup, tracingChannel as diagnosticsTracingChannel, earlyPatchHono, eveConversationHook, eveIntegration, eveTracePolicy, expressErrorHandler, expressIntegration, fastifyIntegration, firebaseIntegration, flueIntegration, genericPoolIntegration, getErrorIntegrations, getInstrumentedModuleNames, getOtlpTracesEndpoint, getSqlQueryAttributes, getSqlQuerySummary, getSqlSpanName, getTracingIntegrations, googleGenAIIntegration, graphqlIntegration, groqIntegration, hapiIntegration, honoIntegration, honoMiddleware, instrumentAnthropicAiClient, instrumentCreateReactAgent, instrumentGoogleGenAIClient, instrumentLangChainEmbeddings, instrumentMistralAiClient, instrumentOpenAiClient, instrumentPostgresJsSql, instrumentStateGraph, instrumentStateGraphCompile, instrumentTunnelServer, instrumentTunnelServers, instrumentTypeSafeClient, instrumentWorkersAiClient, isBun, isCloudflareWorkers, isDeno, kafkaIntegration, knexIntegration, koaIntegration, langChainIntegration, langGraphIntegration, lruMemoizerIntegration, makeServeTunnelIntegration, mastraIntegration, mcpServerIntegration, mistralAIIntegration, mongoIntegration, mongooseIntegration, mysql2Integration, mysqlIntegration, neonIntegration, nitroIntegration, nodeCronIntegration, nodeScheduleIntegration, openAIIntegration, openTelemetryIntegration, orchestrionModuleInjected, piAiIntegration, piDurableIntegration, pinoIntegration, postgresIntegration, postgresJsIntegration, prismaIntegration, redisIntegration, sanitizeSqlQuery, setAsyncLocalStorageAsyncContextStrategy, setHttpServerSpanRouteAttribute, setupExpressErrorHandler, setupFastifyErrorHandler, setupHapiErrorHandler, subscribe as subscribeDiagnosticsChannel, tanstackAIIntegration, tediousIntegration, togetherAIIntegration, typesafeIntegration, vercelAIIntegration };
91
92
 
92
93
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_attachHapiErrorHandler"],"sources":["../../src/index.ts"],"sourcesContent":["export * from './exports';\n\n// Exports using diagnostics channels\nexport { detectOrchestrionSetup } from './orchestrion/detect';\n// oxlint-disable-next-line typescript/no-deprecated -- re-exported so the deprecated `setupKoaErrorHandler` can delegate\nexport { attachKoaErrorHandler } from './integrations/koa/koa-error-handler';\nimport { attachHapiErrorHandler as _attachHapiErrorHandler } from './integrations/hapi/hapi-error-handler';\nexport { bindTracingChannelToSpan } from './tracing-channel';\nexport type { TracingChannelPayloadWithSpan } from './tracing-channel';\nexport type { InstrumentationConfig } from './orchestrion/apmTypes';\nexport type { OrchestrionChannelContext } from './orchestrion/types';\n// Runtime target of the bundler-injected module snippet. The snippet imports it\n// from this entry alongside the module's subscriber factory (see\n// `orchestrion/bundler/moduleInjectedTransform.ts`); it is a plain runtime\n// helper with no orchestrion build-time dependency.\nexport { orchestrionModuleInjected } from './utils/moduleInjected';\nexport {\n subscribe as subscribeDiagnosticsChannel,\n tracingChannel as diagnosticsTracingChannel,\n} from './utils/diagnosticsChannel';\nexport { eveConversationHook, eveIntegration, eveTracePolicy } from './eve';\nexport { getInstrumentedModuleNames } from './orchestrion/config';\nexport {\n fastifyIntegration,\n // oxlint-disable-next-line typescript/no-deprecated\n setupFastifyErrorHandler,\n} from './integrations/fastify';\n\n/**\n * @deprecated This is a temporary export to avoid breaking changes. It will be removed in the next major version.\n */\nexport const attachHapiErrorHandler = _attachHapiErrorHandler;\n\n// Integrations\nexport { prismaIntegration } from './integrations/prisma';\nexport { amqplibIntegration } from './integrations/amqplib';\nexport { anthropicAIIntegration } from './integrations/anthropic';\nexport { awsIntegration } from './integrations/aws-sdk';\nexport { dataloaderIntegration } from './integrations/dataloader';\nexport { genericPoolIntegration } from './integrations/generic-pool';\nexport { cronJobIntegration } from './integrations/cron';\nexport type { CronJobIntegrationOptions } from './integrations/cron';\nexport { nodeCronIntegration } from './integrations/node-cron';\nexport type { NodeCronIntegrationOptions } from './integrations/node-cron';\nexport { nodeScheduleIntegration } from './integrations/node-schedule';\nexport type { NodeScheduleIntegrationOptions } from './integrations/node-schedule';\nexport { cronExpressionToMonitorConfig as _INTERNAL_cronExpressionToMonitorConfig } from './utils/cronMonitoring';\nexport { cron } from './cron';\nexport { BullMQTelemetry } from './integrations/bullmq';\nexport { googleGenAIIntegration } from './integrations/google-genai';\nexport { graphqlIntegration } from './integrations/graphql';\nexport {\n hapiIntegration,\n // oxlint-disable-next-line typescript/no-deprecated\n setupHapiErrorHandler,\n} from './integrations/hapi';\nexport { honoIntegration, honoMiddleware } from './integrations/hono';\nexport type { HonoIntegrationOptions } from './integrations/hono';\nexport { koaIntegration } from './integrations/koa';\nexport { redisIntegration } from './integrations/redis';\nexport { kafkaIntegration } from './integrations/kafkajs';\nexport { knexIntegration } from './integrations/knex';\nexport { langChainIntegration } from './integrations/langchain';\nexport { langGraphIntegration } from './integrations/langgraph';\nexport { createFlueInstrumentation } from './ai/flue';\nexport { flueIntegration } from './integrations/flue';\nexport { piAiIntegration } from './integrations/pi-ai';\nexport { piDurableIntegration } from './integrations/pi-durable';\nexport type { FlueOptions } from './ai/flue';\nexport { mastraIntegration } from './integrations/mastra';\nexport { mcpServerIntegration } from './integrations/mcp-server';\nexport { instrumentTunnelServers, makeServeTunnelIntegration } from './integrations/serveTunnel';\nexport { instrumentTunnelServer } from './utils/tunnelServer';\nexport { createGetModuleFromFilename } from './utils/module';\nexport { SentryMastraExporter } from './ai/mastra';\nexport { lruMemoizerIntegration } from './integrations/lru-memoizer';\nexport { mongoIntegration } from './integrations/mongodb';\nexport { mongooseIntegration } from './integrations/mongoose';\nexport { mistralAIIntegration } from './integrations/mistral';\nexport { groqIntegration } from './integrations/groq';\nexport { togetherAIIntegration } from './integrations/together-ai';\nexport { typesafeIntegration } from './integrations/typesafe';\nexport { mysqlIntegration } from './integrations/mysql';\nexport { mysql2Integration } from './integrations/mysql2';\nexport { pinoIntegration } from './integrations/pino';\nexport { createSentryWinstonTransport } from './integrations/winston';\nexport { openAIIntegration } from './integrations/openai';\nexport { postgresIntegration } from './integrations/pg';\nexport { postgresJsIntegration } from './integrations/postgresjs';\nexport { neonIntegration } from './integrations/neon';\nexport { clickhouseIntegration } from './integrations/clickhouse';\nexport { tediousIntegration } from './integrations/tedious';\nexport { vercelAIIntegration } from './integrations/vercel-ai';\nexport { expressIntegration } from './integrations/express';\nexport type { ExpressIntegrationOptions } from './integrations/express/types';\n/* oxlint-disable typescript/no-deprecated -- deprecated Express error-handler exports, kept until the next major */\nexport { expressErrorHandler, setupExpressErrorHandler } from './integrations/express/error-handler';\n/* oxlint-enable typescript/no-deprecated */\nexport { firebaseIntegration } from './integrations/firebase';\nexport { nitroIntegration } from './integrations/nitro';\nexport type { NitroIntegrationOptions } from './integrations/nitro';\n\nexport { getTracingIntegrations, getErrorIntegrations } from './integrations';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,yBAAyBA"}
1
+ {"version":3,"file":"index.js","names":["_attachHapiErrorHandler"],"sources":["../../src/index.ts"],"sourcesContent":["export * from './exports';\n\n// Exports using diagnostics channels\nexport { detectOrchestrionSetup } from './orchestrion/detect';\n// oxlint-disable-next-line typescript/no-deprecated -- re-exported so the deprecated `setupKoaErrorHandler` can delegate\nexport { attachKoaErrorHandler } from './integrations/koa/koa-error-handler';\nimport { attachHapiErrorHandler as _attachHapiErrorHandler } from './integrations/hapi/hapi-error-handler';\nexport { bindTracingChannelToSpan } from './tracing-channel';\nexport type { TracingChannelPayloadWithSpan } from './tracing-channel';\nexport type { InstrumentationConfig } from './orchestrion/apmTypes';\nexport type { OrchestrionChannelContext } from './orchestrion/types';\n// Runtime target of the bundler-injected module snippet. The snippet imports it\n// from this entry alongside the module's subscriber factory (see\n// `orchestrion/bundler/moduleInjectedTransform.ts`); it is a plain runtime\n// helper with no orchestrion build-time dependency.\nexport { orchestrionModuleInjected } from './utils/moduleInjected';\nexport {\n subscribe as subscribeDiagnosticsChannel,\n tracingChannel as diagnosticsTracingChannel,\n} from './utils/diagnosticsChannel';\nexport { eveConversationHook, eveIntegration, eveTracePolicy } from './eve';\nexport { getInstrumentedModuleNames } from './orchestrion/config';\nexport {\n fastifyIntegration,\n // oxlint-disable-next-line typescript/no-deprecated\n setupFastifyErrorHandler,\n} from './integrations/fastify';\n\n/**\n * @deprecated This is a temporary export to avoid breaking changes. It will be removed in the next major version.\n */\nexport const attachHapiErrorHandler = _attachHapiErrorHandler;\n\n// Integrations\nexport { prismaIntegration } from './integrations/prisma';\nexport { amqplibIntegration } from './integrations/amqplib';\nexport { anthropicAIIntegration } from './integrations/anthropic';\nexport { awsIntegration } from './integrations/aws-sdk';\nexport { dataloaderIntegration } from './integrations/dataloader';\nexport { genericPoolIntegration } from './integrations/generic-pool';\nexport { cronJobIntegration } from './integrations/cron';\nexport type { CronJobIntegrationOptions } from './integrations/cron';\nexport { nodeCronIntegration } from './integrations/node-cron';\nexport type { NodeCronIntegrationOptions } from './integrations/node-cron';\nexport { nodeScheduleIntegration } from './integrations/node-schedule';\nexport type { NodeScheduleIntegrationOptions } from './integrations/node-schedule';\nexport { cronExpressionToMonitorConfig as _INTERNAL_cronExpressionToMonitorConfig } from './utils/cronMonitoring';\nexport { cron } from './cron';\nexport { BullMQTelemetry } from './integrations/bullmq';\nexport { googleGenAIIntegration } from './integrations/google-genai';\nexport { graphqlIntegration } from './integrations/graphql';\nexport {\n hapiIntegration,\n // oxlint-disable-next-line typescript/no-deprecated\n setupHapiErrorHandler,\n} from './integrations/hapi';\nexport { honoIntegration, honoMiddleware } from './integrations/hono';\nexport type { HonoIntegrationOptions } from './integrations/hono';\nexport { koaIntegration } from './integrations/koa';\nexport { redisIntegration } from './integrations/redis';\nexport { kafkaIntegration } from './integrations/kafkajs';\nexport { knexIntegration } from './integrations/knex';\nexport { langChainIntegration } from './integrations/langchain';\nexport { langGraphIntegration } from './integrations/langgraph';\nexport { createFlueInstrumentation } from './ai/flue';\nexport { flueIntegration } from './integrations/flue';\nexport { piAiIntegration } from './integrations/pi-ai';\nexport { piDurableIntegration } from './integrations/pi-durable';\nexport { tanstackAIIntegration } from './integrations/tanstack-ai';\nexport type { TanstackAIOptions } from './ai/tanstack-ai';\nexport type { FlueOptions } from './ai/flue';\nexport { mastraIntegration } from './integrations/mastra';\nexport { mcpServerIntegration } from './integrations/mcp-server';\nexport { instrumentTunnelServers, makeServeTunnelIntegration } from './integrations/serveTunnel';\nexport { instrumentTunnelServer } from './utils/tunnelServer';\nexport { createGetModuleFromFilename } from './utils/module';\nexport { SentryMastraExporter } from './ai/mastra';\nexport { lruMemoizerIntegration } from './integrations/lru-memoizer';\nexport { mongoIntegration } from './integrations/mongodb';\nexport { mongooseIntegration } from './integrations/mongoose';\nexport { mistralAIIntegration } from './integrations/mistral';\nexport { groqIntegration } from './integrations/groq';\nexport { togetherAIIntegration } from './integrations/together-ai';\nexport { typesafeIntegration } from './integrations/typesafe';\nexport { mysqlIntegration } from './integrations/mysql';\nexport { mysql2Integration } from './integrations/mysql2';\nexport { pinoIntegration } from './integrations/pino';\nexport { createSentryWinstonTransport } from './integrations/winston';\nexport { openAIIntegration } from './integrations/openai';\nexport { postgresIntegration } from './integrations/pg';\nexport { postgresJsIntegration } from './integrations/postgresjs';\nexport { neonIntegration } from './integrations/neon';\nexport { clickhouseIntegration } from './integrations/clickhouse';\nexport { tediousIntegration } from './integrations/tedious';\nexport { vercelAIIntegration } from './integrations/vercel-ai';\nexport { expressIntegration } from './integrations/express';\nexport type { ExpressIntegrationOptions } from './integrations/express/types';\n/* oxlint-disable typescript/no-deprecated -- deprecated Express error-handler exports, kept until the next major */\nexport { expressErrorHandler, setupExpressErrorHandler } from './integrations/express/error-handler';\n/* oxlint-enable typescript/no-deprecated */\nexport { firebaseIntegration } from './integrations/firebase';\nexport { nitroIntegration } from './integrations/nitro';\nexport type { NitroIntegrationOptions } from './integrations/nitro';\n\nexport { getTracingIntegrations, getErrorIntegrations } from './integrations';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,yBAAyBA"}
@@ -0,0 +1,59 @@
1
+ import { tracingChannel } from "../utils/diagnosticsChannel.js";
2
+ import { createTanstackAIMiddleware } from "../ai/tanstack-ai/index.js";
3
+ import { TANSTACK_AI_INTEGRATION_NAME, TANSTACK_AI_MIDDLEWARE_BRAND } from "../ai/tanstack-ai/constants.js";
4
+ import { CHANNELS } from "../orchestrion/channels.js";
5
+ import { tanstackAiModuleNames } from "../orchestrion/config/tanstack-ai.js";
6
+ import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
7
+ import { safeChannelCallback } from "../tracing-channel.js";
8
+ import { consoleSandbox, defineIntegration, isObjectLike } from "@sentry/core";
9
+ // src/integrations/tanstack-ai.ts
10
+ const _tanstackAIIntegration = ((options = {}) => {
11
+ return {
12
+ name: TANSTACK_AI_INTEGRATION_NAME,
13
+ setup(client) {
14
+ invokeOrchestrionInstrumentation(client, tanstackAiModuleNames, instrumentTanstackAI, [options], { requiresTracingChannelBinding: false });
15
+ }
16
+ };
17
+ });
18
+ let warnedOtelMiddleware = false;
19
+ function instrumentTanstackAI(options) {
20
+ tracingChannel(CHANNELS.TANSTACK_AI_CHAT).start.subscribe((message) => {
21
+ safeChannelCallback(() => {
22
+ const data = message;
23
+ const call = data.arguments[0];
24
+ if (!isObjectLike(call)) return;
25
+ const existing = call.middleware;
26
+ if (existing !== void 0 && !Array.isArray(existing)) return;
27
+ if (existing?.some((entry) => isObjectLike(entry) && entry[TANSTACK_AI_MIDDLEWARE_BRAND])) return;
28
+ if (existing?.some((entry) => isObjectLike(entry) && entry.name === "otel")) warnOtelMiddleware();
29
+ data.arguments[0] = {
30
+ ...call,
31
+ middleware: [...existing ?? [], createTanstackAIMiddleware(options, call)]
32
+ };
33
+ });
34
+ });
35
+ }
36
+ function warnOtelMiddleware() {
37
+ if (warnedOtelMiddleware) return;
38
+ warnedOtelMiddleware = true;
39
+ consoleSandbox(() => {
40
+ console.warn("[Sentry] `tanstackAIIntegration` is active and a `chat()` call also uses TanStack's otelMiddleware, so each run is recorded twice. Remove otelMiddleware to avoid duplicate spans.");
41
+ });
42
+ }
43
+ /**
44
+ * Traces the `chat()` calls of TanStack AI (`@tanstack/ai` >= 1.0.0 < 2), through the
45
+ * `orchestrion:@tanstack/ai:chat` channel. Each call gets a `gen_ai.invoke_agent` span, with a
46
+ * `gen_ai.chat` span for each model call and a `gen_ai.execute_tool` span for each tool run.
47
+ * Needs the Sentry runtime hook (`--import`) or bundler plugin.
48
+ *
49
+ * @example
50
+ * ```javascript
51
+ * Sentry.init({
52
+ * integrations: [Sentry.tanstackAIIntegration({ recordInputs: true, recordOutputs: true })],
53
+ * });
54
+ * ```
55
+ */
56
+ const tanstackAIIntegration = defineIntegration(_tanstackAIIntegration);
57
+ export { tanstackAIIntegration };
58
+
59
+ //# sourceMappingURL=tanstack-ai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tanstack-ai.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/integrations/tanstack-ai.ts"],"sourcesContent":["import * as diagnosticsChannel from '../utils/diagnosticsChannel';\nimport type { IntegrationFn } from '@sentry/core';\nimport { consoleSandbox, defineIntegration, isObjectLike } from '@sentry/core';\nimport type { TanstackAIOptions } from '../ai/tanstack-ai';\nimport { createTanstackAIMiddleware } from '../ai/tanstack-ai';\nimport { TANSTACK_AI_INTEGRATION_NAME, TANSTACK_AI_MIDDLEWARE_BRAND } from '../ai/tanstack-ai/constants';\nimport { CHANNELS } from '../orchestrion/channels';\nimport { tanstackAiModuleNames } from '../orchestrion/config/tanstack-ai';\nimport { invokeOrchestrionInstrumentation } from '../orchestrion/instrumentation';\nimport type { OrchestrionChannelContext } from '../orchestrion/types';\nimport { safeChannelCallback } from '../tracing-channel';\n\nconst _tanstackAIIntegration = ((options: TanstackAIOptions = {}) => {\n return {\n name: TANSTACK_AI_INTEGRATION_NAME,\n setup(client) {\n // Adding the middleware starts no span, so the subscription does not need the binding.\n invokeOrchestrionInstrumentation(client, tanstackAiModuleNames, instrumentTanstackAI, [options], {\n requiresTracingChannelBinding: false,\n });\n },\n };\n}) satisfies IntegrationFn;\n\nlet warnedOtelMiddleware = false;\n\nfunction instrumentTanstackAI(options: TanstackAIOptions): void {\n diagnosticsChannel.tracingChannel<OrchestrionChannelContext>(CHANNELS.TANSTACK_AI_CHAT).start.subscribe(message => {\n safeChannelCallback(() => {\n const data = message as OrchestrionChannelContext;\n const call = data.arguments[0];\n if (!isObjectLike(call)) {\n return;\n }\n const existing = call.middleware;\n // `chat()` throws for middleware that is not an array. Leave that error to it.\n if (existing !== undefined && !Array.isArray(existing)) {\n return;\n }\n if (existing?.some(entry => isObjectLike(entry) && entry[TANSTACK_AI_MIDDLEWARE_BRAND])) {\n return;\n }\n if (existing?.some(entry => isObjectLike(entry) && entry.name === 'otel')) {\n warnOtelMiddleware();\n }\n // Last, so that it records the config and the chunks after the other middleware changed them.\n // A copy, so that options which the app uses again do not collect one middleware per call.\n data.arguments[0] = {\n ...call,\n middleware: [...(existing ?? []), createTanstackAIMiddleware(options, call)],\n };\n });\n });\n}\n\nfunction warnOtelMiddleware(): void {\n if (warnedOtelMiddleware) {\n return;\n }\n warnedOtelMiddleware = true;\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.warn(\n \"[Sentry] `tanstackAIIntegration` is active and a `chat()` call also uses TanStack's otelMiddleware, so each run is recorded twice. Remove otelMiddleware to avoid duplicate spans.\",\n );\n });\n}\n\n/**\n * Traces the `chat()` calls of TanStack AI (`@tanstack/ai` >= 1.0.0 < 2), through the\n * `orchestrion:@tanstack/ai:chat` channel. Each call gets a `gen_ai.invoke_agent` span, with a\n * `gen_ai.chat` span for each model call and a `gen_ai.execute_tool` span for each tool run.\n * Needs the Sentry runtime hook (`--import`) or bundler plugin.\n *\n * @example\n * ```javascript\n * Sentry.init({\n * integrations: [Sentry.tanstackAIIntegration({ recordInputs: true, recordOutputs: true })],\n * });\n * ```\n */\nexport const tanstackAIIntegration = defineIntegration(_tanstackAIIntegration);\n"],"mappings":";;;;;;;;;AAYA,MAAM,2BAA2B,UAA6B,CAAC,MAAM;CACnE,OAAO;EACL,MAAM;EACN,MAAM,QAAQ;GAEZ,iCAAiC,QAAQ,uBAAuB,sBAAsB,CAAC,OAAO,GAAG,EAC/F,+BAA+B,MACjC,CAAC;EACH;CACF;AACF;AAEA,IAAI,uBAAuB;AAE3B,SAAS,qBAAqB,SAAkC;CAC9DA,eAA6D,SAAS,gBAAgB,CAAC,CAAC,MAAM,WAAU,YAAW;EACjH,0BAA0B;GACxB,MAAM,OAAO;GACb,MAAM,OAAO,KAAK,UAAU;GAC5B,IAAI,CAAC,aAAa,IAAI,GACpB;GAEF,MAAM,WAAW,KAAK;GAEtB,IAAI,aAAa,KAAA,KAAa,CAAC,MAAM,QAAQ,QAAQ,GACnD;GAEF,IAAI,UAAU,MAAK,UAAS,aAAa,KAAK,KAAK,MAAM,6BAA6B,GACpF;GAEF,IAAI,UAAU,MAAK,UAAS,aAAa,KAAK,KAAK,MAAM,SAAS,MAAM,GACtE,mBAAmB;GAIrB,KAAK,UAAU,KAAK;IAClB,GAAG;IACH,YAAY,CAAC,GAAI,YAAY,CAAC,GAAI,2BAA2B,SAAS,IAAI,CAAC;GAC7E;EACF,CAAC;CACH,CAAC;AACH;AAEA,SAAS,qBAA2B;CAClC,IAAI,sBACF;CAEF,uBAAuB;CACvB,qBAAqB;EAEnB,QAAQ,KACN,oLACF;CACF,CAAC;AACH;;;;;;;;;;;;;;AAeA,MAAa,wBAAwB,kBAAkB,sBAAsB"}
@@ -38,6 +38,7 @@ import { postgresJsChannels } from "./config/postgres.js";
38
38
  import { prismaChannels } from "./config/prisma.js";
39
39
  import { redisChannels } from "./config/redis.js";
40
40
  import { remixChannels } from "./config/remix.js";
41
+ import { tanstackAiChannels } from "./config/tanstack-ai.js";
41
42
  import { tediousChannels } from "./config/tedious.js";
42
43
  import { togetherAiChannels } from "./config/together-ai.js";
43
44
  import { typesafeChannels } from "./config/typesafe.js";
@@ -100,6 +101,7 @@ const CHANNELS = {
100
101
  ...prismaChannels,
101
102
  ...redisChannels,
102
103
  ...remixChannels,
104
+ ...tanstackAiChannels,
103
105
  ...tediousChannels,
104
106
  ...togetherAiChannels,
105
107
  ...typesafeChannels,
@@ -1 +1 @@
1
- {"version":3,"file":"channels.js","names":[],"sources":["../../../src/orchestrion/channels.ts"],"sourcesContent":["import { amqplibChannels } from './config/amqplib';\nimport { anthropicAiChannels } from './config/anthropic-ai';\nimport { awsSdkChannels } from './config/aws-sdk';\nimport { clickhouseChannels } from './config/clickhouse';\nimport { cronChannels } from './config/cron';\nimport { dataloaderChannels } from './config/dataloader';\nimport { expressChannels } from './config/express';\nimport { firebaseChannels } from './config/firebase';\nimport { genericPoolChannels } from './config/generic-pool';\nimport { googleGenAiChannels } from './config/google-genai';\nimport { graphqlChannels } from './config/graphql';\nimport { groqChannels } from './config/groq';\nimport { hapiChannels } from './config/hapi';\nimport { honoChannels } from './config/hono';\nimport { ioredisChannels } from './config/ioredis';\nimport { kafkajsChannels } from './config/kafkajs';\nimport { knexChannels } from './config/knex';\nimport { koaChannels } from './config/koa';\nimport { langchainChannels } from './config/langchain';\nimport { langgraphChannels } from './config/langgraph';\nimport { lruMemoizerChannels } from './config/lru-memoizer';\nimport { mastraChannels } from './config/mastra';\nimport { mcpServerChannels } from './config/mcp-server';\nimport { mistralChannels } from './config/mistral';\nimport { mongodbChannels } from './config/mongodb';\nimport { mongooseChannels } from './config/mongoose';\nimport { mysql2Channels } from './config/mysql2';\nimport { mysqlChannels } from './config/mysql';\nimport { neonChannels } from './config/neon';\nimport { nestjsChannels } from './config/nestjs';\nimport { nodeCronChannels } from './config/node-cron';\nimport { nodeScheduleChannels } from './config/node-schedule';\nimport { openaiChannels } from './config/openai';\nimport { pgChannels } from './config/pg';\nimport { piAiChannels } from './config/pi-ai';\nimport { piDurableChannels } from './config/pi-durable';\nimport { postgresJsChannels } from './config/postgres';\nimport { prismaChannels } from './config/prisma';\nimport { redisChannels } from './config/redis';\nimport { remixChannels } from './config/remix';\nimport { tediousChannels } from './config/tedious';\nimport { togetherAiChannels } from './config/together-ai';\nimport { typesafeChannels } from './config/typesafe';\nimport { vercelAiChannels } from './config/vercel-ai';\n\n/**\n * Fully-qualified `diagnostics_channel` names that orchestrion publishes to.\n *\n * Orchestrion's transform always prefixes the configured `channelName` with\n * `orchestrion:${module.name}:`. So a config of\n * `{ channelName: 'query', module: { name: 'mysql' } }`\n * publishes to `orchestrion:mysql:query`.\n *\n * Subscribers (`integrations/<lib>/tracing-channel.ts`) consume the full\n * prefixed string from this map; the config files set only the unprefixed\n * suffix in `channelName`. Keeping both pieces in one file is what guarantees\n * they don't drift apart and silently stop firing.\n *\n * Kept sorted alphabetically by module so concurrent additions insert at different\n * points rather than all appending to the end (fewer merge conflicts).\n */\nexport const CHANNELS = {\n ...amqplibChannels,\n ...anthropicAiChannels,\n ...awsSdkChannels,\n ...clickhouseChannels,\n ...cronChannels,\n ...dataloaderChannels,\n ...expressChannels,\n ...firebaseChannels,\n ...genericPoolChannels,\n ...googleGenAiChannels,\n ...graphqlChannels,\n ...groqChannels,\n ...hapiChannels,\n ...honoChannels,\n ...ioredisChannels,\n ...kafkajsChannels,\n ...knexChannels,\n ...koaChannels,\n ...langchainChannels,\n ...langgraphChannels,\n ...lruMemoizerChannels,\n ...mastraChannels,\n ...mcpServerChannels,\n ...mistralChannels,\n ...mongodbChannels,\n ...mongooseChannels,\n ...mysql2Channels,\n ...mysqlChannels,\n ...neonChannels,\n ...nestjsChannels,\n ...nodeCronChannels,\n ...nodeScheduleChannels,\n ...openaiChannels,\n ...pgChannels,\n ...piAiChannels,\n ...piDurableChannels,\n ...postgresJsChannels,\n ...prismaChannels,\n ...redisChannels,\n ...remixChannels,\n ...tediousChannels,\n ...togetherAiChannels,\n ...typesafeChannels,\n ...vercelAiChannels,\n} as const;\n\nexport type ChannelName = (typeof CHANNELS)[keyof typeof CHANNELS];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,MAAa,WAAW;CACtB,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL"}
1
+ {"version":3,"file":"channels.js","names":[],"sources":["../../../src/orchestrion/channels.ts"],"sourcesContent":["import { amqplibChannels } from './config/amqplib';\nimport { anthropicAiChannels } from './config/anthropic-ai';\nimport { awsSdkChannels } from './config/aws-sdk';\nimport { clickhouseChannels } from './config/clickhouse';\nimport { cronChannels } from './config/cron';\nimport { dataloaderChannels } from './config/dataloader';\nimport { expressChannels } from './config/express';\nimport { firebaseChannels } from './config/firebase';\nimport { genericPoolChannels } from './config/generic-pool';\nimport { googleGenAiChannels } from './config/google-genai';\nimport { graphqlChannels } from './config/graphql';\nimport { groqChannels } from './config/groq';\nimport { hapiChannels } from './config/hapi';\nimport { honoChannels } from './config/hono';\nimport { ioredisChannels } from './config/ioredis';\nimport { kafkajsChannels } from './config/kafkajs';\nimport { knexChannels } from './config/knex';\nimport { koaChannels } from './config/koa';\nimport { langchainChannels } from './config/langchain';\nimport { langgraphChannels } from './config/langgraph';\nimport { lruMemoizerChannels } from './config/lru-memoizer';\nimport { mastraChannels } from './config/mastra';\nimport { mcpServerChannels } from './config/mcp-server';\nimport { mistralChannels } from './config/mistral';\nimport { mongodbChannels } from './config/mongodb';\nimport { mongooseChannels } from './config/mongoose';\nimport { mysql2Channels } from './config/mysql2';\nimport { mysqlChannels } from './config/mysql';\nimport { neonChannels } from './config/neon';\nimport { nestjsChannels } from './config/nestjs';\nimport { nodeCronChannels } from './config/node-cron';\nimport { nodeScheduleChannels } from './config/node-schedule';\nimport { openaiChannels } from './config/openai';\nimport { pgChannels } from './config/pg';\nimport { piAiChannels } from './config/pi-ai';\nimport { piDurableChannels } from './config/pi-durable';\nimport { postgresJsChannels } from './config/postgres';\nimport { prismaChannels } from './config/prisma';\nimport { redisChannels } from './config/redis';\nimport { remixChannels } from './config/remix';\nimport { tanstackAiChannels } from './config/tanstack-ai';\nimport { tediousChannels } from './config/tedious';\nimport { togetherAiChannels } from './config/together-ai';\nimport { typesafeChannels } from './config/typesafe';\nimport { vercelAiChannels } from './config/vercel-ai';\n\n/**\n * Fully-qualified `diagnostics_channel` names that orchestrion publishes to.\n *\n * Orchestrion's transform always prefixes the configured `channelName` with\n * `orchestrion:${module.name}:`. So a config of\n * `{ channelName: 'query', module: { name: 'mysql' } }`\n * publishes to `orchestrion:mysql:query`.\n *\n * Subscribers (`integrations/<lib>/tracing-channel.ts`) consume the full\n * prefixed string from this map; the config files set only the unprefixed\n * suffix in `channelName`. Keeping both pieces in one file is what guarantees\n * they don't drift apart and silently stop firing.\n *\n * Kept sorted alphabetically by module so concurrent additions insert at different\n * points rather than all appending to the end (fewer merge conflicts).\n */\nexport const CHANNELS = {\n ...amqplibChannels,\n ...anthropicAiChannels,\n ...awsSdkChannels,\n ...clickhouseChannels,\n ...cronChannels,\n ...dataloaderChannels,\n ...expressChannels,\n ...firebaseChannels,\n ...genericPoolChannels,\n ...googleGenAiChannels,\n ...graphqlChannels,\n ...groqChannels,\n ...hapiChannels,\n ...honoChannels,\n ...ioredisChannels,\n ...kafkajsChannels,\n ...knexChannels,\n ...koaChannels,\n ...langchainChannels,\n ...langgraphChannels,\n ...lruMemoizerChannels,\n ...mastraChannels,\n ...mcpServerChannels,\n ...mistralChannels,\n ...mongodbChannels,\n ...mongooseChannels,\n ...mysql2Channels,\n ...mysqlChannels,\n ...neonChannels,\n ...nestjsChannels,\n ...nodeCronChannels,\n ...nodeScheduleChannels,\n ...openaiChannels,\n ...pgChannels,\n ...piAiChannels,\n ...piDurableChannels,\n ...postgresJsChannels,\n ...prismaChannels,\n ...redisChannels,\n ...remixChannels,\n ...tanstackAiChannels,\n ...tediousChannels,\n ...togetherAiChannels,\n ...typesafeChannels,\n ...vercelAiChannels,\n} as const;\n\nexport type ChannelName = (typeof CHANNELS)[keyof typeof CHANNELS];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,MAAa,WAAW;CACtB,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL"}
@@ -41,6 +41,7 @@ import { prismaConfig } from "./prisma.js";
41
41
  import { redisConfig } from "./redis.js";
42
42
  import { remixChannels, remixConfig } from "./remix.js";
43
43
  import { remixV3Channels, remixV3Config } from "./remix-v3.js";
44
+ import { tanstackAiConfig } from "./tanstack-ai.js";
44
45
  import { tediousConfig } from "./tedious.js";
45
46
  import { togetherAiConfig } from "./together-ai.js";
46
47
  import { typesafeConfig } from "./typesafe.js";
@@ -104,6 +105,7 @@ const SENTRY_INSTRUMENTATIONS = [
104
105
  ...redisConfig,
105
106
  ...remixConfig,
106
107
  ...remixV3Config,
108
+ ...tanstackAiConfig,
107
109
  ...tediousConfig,
108
110
  ...togetherAiConfig,
109
111
  ...typesafeConfig,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/orchestrion/config/index.ts"],"sourcesContent":["import type { InstrumentationConfig } from '../apmTypes';\n\nimport { uniq } from '@sentry/core';\n\nimport { awsSdkConfig } from './aws-sdk';\nimport { amqplibConfig } from './amqplib';\nimport { anthropicAiConfig } from './anthropic-ai';\nimport { clickhouseConfig } from './clickhouse';\nimport { cronConfig } from './cron';\nimport { dataloaderConfig } from './dataloader';\nimport { expressConfig } from './express';\nimport { firebaseConfig } from './firebase';\nimport { genericPoolConfig } from './generic-pool';\nimport { googleGenAiConfig } from './google-genai';\nimport { graphqlConfig } from './graphql';\nimport { groqConfig } from './groq';\nimport { hapiConfig } from './hapi';\nimport { honoConfig } from './hono';\nimport { ioredisConfig } from './ioredis';\nimport { kafkajsConfig } from './kafkajs';\nimport { knexConfig } from './knex';\nimport { koaConfig } from './koa';\nimport { langchainConfig } from './langchain';\nimport { langgraphConfig } from './langgraph';\nimport { lruMemoizerConfig } from './lru-memoizer';\nimport { flueConfig } from './flue';\nimport { mastraConfig } from './mastra';\nimport { piAiConfig } from './pi-ai';\nimport { piDurableConfig } from './pi-durable';\nimport { mcpServerConfig } from './mcp-server';\nimport { mistralConfig } from './mistral';\nimport { mongodbConfig } from './mongodb';\nimport { mongooseConfig } from './mongoose';\nimport { mysql2Config } from './mysql2';\nimport { mysqlConfig } from './mysql';\nimport { neonConfig } from './neon';\nimport { nestjsConfig } from './nestjs';\nimport { nitroConfig } from './nitro';\nimport { nodeCronConfig } from './node-cron';\nimport { nodeScheduleConfig } from './node-schedule';\nimport { openaiConfig } from './openai';\nimport { pgConfig } from './pg';\nimport { postgresJsConfig } from './postgres';\nimport { prismaConfig } from './prisma';\nimport { redisConfig } from './redis';\nimport { remixConfig } from './remix';\nimport { remixV3Config } from './remix-v3';\nimport { tediousConfig } from './tedious';\nimport { togetherAiConfig } from './together-ai';\nimport { typesafeConfig } from './typesafe';\nimport { vercelAiConfig } from './vercel-ai';\n// Kept sorted alphabetically by module so concurrent additions insert at different\n// points rather than all appending to the end (fewer merge conflicts).\n\n/**\n * The orchestrion code-transform configs. Every instrumentable library is here\n * so the transform is all-or-nothing: whenever orchestrion is enabled, all of\n * these are injected. The channel LISTENERS may live elsewhere (e.g. the NestJS\n * one lives in `@sentry/nestjs`), but the config that decides what gets\n * transformed is centralized here.\n *\n * This module MUST stay pure, stateless data. It is loaded in more than one realm\n * at once — the build-time bundler plugin inlines it into the server chunk, while\n * `@sentry/server-runtime-injection`'s external `register` loads its own copy from\n * `node_modules` at runtime. Two identical, side-effect-free arrays are harmless;\n * any module-level mutable state here would silently diverge between those copies.\n */\nexport const SENTRY_INSTRUMENTATIONS: InstrumentationConfig[] = [\n ...amqplibConfig,\n ...anthropicAiConfig,\n ...awsSdkConfig,\n ...clickhouseConfig,\n ...cronConfig,\n ...dataloaderConfig,\n ...expressConfig,\n ...firebaseConfig,\n ...genericPoolConfig,\n ...googleGenAiConfig,\n ...graphqlConfig,\n ...groqConfig,\n ...hapiConfig,\n ...honoConfig,\n ...ioredisConfig,\n ...kafkajsConfig,\n ...knexConfig,\n ...koaConfig,\n ...langchainConfig,\n ...langgraphConfig,\n ...lruMemoizerConfig,\n ...flueConfig,\n ...mastraConfig,\n ...mcpServerConfig,\n ...mistralConfig,\n ...mongodbConfig,\n ...mongooseConfig,\n ...mysql2Config,\n ...mysqlConfig,\n ...neonConfig,\n ...nestjsConfig,\n ...nitroConfig,\n ...nodeCronConfig,\n ...nodeScheduleConfig,\n ...openaiConfig,\n ...pgConfig,\n ...piAiConfig,\n ...piDurableConfig,\n ...postgresJsConfig,\n ...prismaConfig,\n ...redisConfig,\n ...remixConfig,\n ...remixV3Config,\n ...tediousConfig,\n ...togetherAiConfig,\n ...typesafeConfig,\n ...vercelAiConfig,\n];\n\n/**\n * The subset of {@link SENTRY_INSTRUMENTATIONS} the RUNTIME loader\n * (`@sentry/server-runtime-injection`'s `register`, reached via `--import` or\n * `Sentry.init()`) can actually apply.\n *\n * Registration-only configs (native-channel libraries such as `ai` v7,\n * `ioredis`, `@redis/client`, `mysql2`, `mongoose`) carry the custom\n * `MODULE_REGISTRATION_TRANSFORM` operator. That operator is wired into the\n * BUNDLER plugins only (see `orchestrion/bundler/moduleInjectedTransform.ts`,\n * applied via `bundler/options.ts`'s `customTransforms`); the runtime loader's\n * `initialize()` receives no custom transforms. Attempting one of these at\n * runtime therefore throws `TypeError: transform is not a function`, which the\n * loader misreports as the always-on \"`@sentry/server-runtime-injection` was\n * bundled ... loads uninstrumented\" warning even though nothing is wrong.\n *\n * Excluding them at runtime is correct, not just a way to silence the warning:\n * these libraries publish their own tracing channels, and their integrations\n * subscribe through `setupOnce()` / `waitForTracingChannelBinding`,\n * independently of the module-injected snippet. That snippet only fires\n * `orchestrion.module-injected`, which drives the `setup()` /\n * `invokeOrchestrionInstrumentation` path; for a native-channel version that\n * path subscribes to the injected `orchestrion:*` channels the library never\n * publishes — a no-op. So running these at runtime would add no spans. The\n * snippet earns its keep only on the BUNDLER path — notably bundler-only SDKs\n * (e.g. `@sentry/cloudflare`) that discover a loaded module via that event to\n * instantiate its integration factory. `@sentry/node` registers its\n * integrations statically, so it does not need it.\n */\nexport const SENTRY_RUNTIME_INSTRUMENTATIONS: InstrumentationConfig[] = SENTRY_INSTRUMENTATIONS.filter(\n config => !config.transform,\n);\n\n/**\n * The unique set of package names instrumented by `SENTRY_INSTRUMENTATIONS`\n * merged with any caller-provided `instrumentations` (e.g. `['mysql']`).\n *\n * Bundler plugins MUST ensure these are actually bundled rather than\n * externalized: an externalized dependency is resolved from `node_modules` at\n * runtime and never passes through the code transform's `onLoad`, so its\n * diagnostics_channel calls are silently never injected. This includes a\n * plugin's custom `instrumentations`, otherwise those extra packages can stay\n * externalized and their transform never runs.\n */\nexport function instrumentedModuleNames(instrumentations: InstrumentationConfig[] = []): string[] {\n return [\n ...uniq([...SENTRY_INSTRUMENTATIONS, ...instrumentations].map(i => i.module.name)),\n // Additional things that need to be bundled but are not covered by the above\n // Remix needs to bundle this so @remix-run/server-runtime is _also_ bundled\n '@remix-run/node',\n ];\n}\n\n/** The instrumented module names from the default Sentry config, with no custom additions. */\nexport const INSTRUMENTED_MODULE_NAMES: string[] = instrumentedModuleNames();\n\n/**\n * The package names the SDK instruments through the orchestrion module transform (its\n * diagnostics-channel injection). Pass these to a server bundler's \"keep external\" option so the\n * packages load through Node's module loader — the only path the transform can hook — instead of\n * being inlined into the server bundle. A framework that has no Sentry bundler plugin (e.g. eve, via\n * `build.externalDependencies`) is the main caller; a listed package the app doesn't use is simply\n * ignored by the bundler.\n *\n * Unlike {@link INSTRUMENTED_MODULE_NAMES}, this is the plain instrumented set with no bundler-only\n * additions — those force a helper package to be *bundled*, the opposite of keeping it external.\n */\nexport function getInstrumentedModuleNames(): string[] {\n return uniq(SENTRY_INSTRUMENTATIONS.map(instrumentation => instrumentation.module.name));\n}\n\n/**\n * Returns `external` with any instrumented packages removed, so a bundler that\n * uses an \"external\" denylist (esbuild, Bun, Rollup) still bundles — and thus\n * transforms — them. Matches an exact package name (`'mysql'`) or a subpath\n * (`'mysql/lib/...'`); wildcard/other patterns are left untouched. `undefined`\n * is returned unchanged.\n *\n * Pass `moduleNames` from `instrumentedModuleNames(options.instrumentations)` so\n * custom instrumentations are stripped too; it defaults to the Sentry config\n * list. (Vite uses an `ssr.noExternal` allowlist instead, so it consumes\n * `instrumentedModuleNames` directly rather than this helper.)\n */\nexport function withoutInstrumentedExternals(\n external: readonly string[] | undefined,\n moduleNames: string[] = INSTRUMENTED_MODULE_NAMES,\n): string[] | undefined {\n if (!external) {\n return undefined;\n }\n return external.filter(entry => !moduleNames.some(name => entry === name || entry.startsWith(`${name}/`)));\n}\n\n// This is exported so that the nestjs package can use it to subscribe to the channels.\nexport { nestjsChannels } from './nestjs';\n// This is exported so that the remix package can use it to subscribe to the channels.\nexport { remixChannels } from './remix';\n// Exported so the remix package can subscribe to the Remix 3 channels, and hand only these configs to\n// the browser transform.\nexport { remixV3Channels, remixV3Config } from './remix-v3';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,0BAAmD;CAC9D,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,kCAA2D,wBAAwB,QAC9F,WAAU,CAAC,OAAO,SACpB;;;;;;;;;;;;AAaA,SAAgB,wBAAwB,mBAA4C,CAAC,GAAa;CAChG,OAAO,CACL,GAAG,KAAK,CAAC,GAAG,yBAAyB,GAAG,gBAAgB,CAAC,CAAC,KAAI,MAAK,EAAE,OAAO,IAAI,CAAC,GAGjF,iBACF;AACF;;AAGA,MAAa,4BAAsC,wBAAwB;;;;;;;;;;;;AAa3E,SAAgB,6BAAuC;CACrD,OAAO,KAAK,wBAAwB,KAAI,oBAAmB,gBAAgB,OAAO,IAAI,CAAC;AACzF;;;;;;;;;;;;;AAcA,SAAgB,6BACd,UACA,cAAwB,2BACF;CACtB,IAAI,CAAC,UACH;CAEF,OAAO,SAAS,QAAO,UAAS,CAAC,YAAY,MAAK,SAAQ,UAAU,QAAQ,MAAM,WAAW,GAAG,KAAK,EAAE,CAAC,CAAC;AAC3G"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/orchestrion/config/index.ts"],"sourcesContent":["import type { InstrumentationConfig } from '../apmTypes';\n\nimport { uniq } from '@sentry/core';\n\nimport { awsSdkConfig } from './aws-sdk';\nimport { amqplibConfig } from './amqplib';\nimport { anthropicAiConfig } from './anthropic-ai';\nimport { clickhouseConfig } from './clickhouse';\nimport { cronConfig } from './cron';\nimport { dataloaderConfig } from './dataloader';\nimport { expressConfig } from './express';\nimport { firebaseConfig } from './firebase';\nimport { genericPoolConfig } from './generic-pool';\nimport { googleGenAiConfig } from './google-genai';\nimport { graphqlConfig } from './graphql';\nimport { groqConfig } from './groq';\nimport { hapiConfig } from './hapi';\nimport { honoConfig } from './hono';\nimport { ioredisConfig } from './ioredis';\nimport { kafkajsConfig } from './kafkajs';\nimport { knexConfig } from './knex';\nimport { koaConfig } from './koa';\nimport { langchainConfig } from './langchain';\nimport { langgraphConfig } from './langgraph';\nimport { lruMemoizerConfig } from './lru-memoizer';\nimport { flueConfig } from './flue';\nimport { mastraConfig } from './mastra';\nimport { piAiConfig } from './pi-ai';\nimport { piDurableConfig } from './pi-durable';\nimport { mcpServerConfig } from './mcp-server';\nimport { mistralConfig } from './mistral';\nimport { mongodbConfig } from './mongodb';\nimport { mongooseConfig } from './mongoose';\nimport { mysql2Config } from './mysql2';\nimport { mysqlConfig } from './mysql';\nimport { neonConfig } from './neon';\nimport { nestjsConfig } from './nestjs';\nimport { nitroConfig } from './nitro';\nimport { nodeCronConfig } from './node-cron';\nimport { nodeScheduleConfig } from './node-schedule';\nimport { openaiConfig } from './openai';\nimport { pgConfig } from './pg';\nimport { postgresJsConfig } from './postgres';\nimport { prismaConfig } from './prisma';\nimport { redisConfig } from './redis';\nimport { remixConfig } from './remix';\nimport { remixV3Config } from './remix-v3';\nimport { tanstackAiConfig } from './tanstack-ai';\nimport { tediousConfig } from './tedious';\nimport { togetherAiConfig } from './together-ai';\nimport { typesafeConfig } from './typesafe';\nimport { vercelAiConfig } from './vercel-ai';\n// Kept sorted alphabetically by module so concurrent additions insert at different\n// points rather than all appending to the end (fewer merge conflicts).\n\n/**\n * The orchestrion code-transform configs. Every instrumentable library is here\n * so the transform is all-or-nothing: whenever orchestrion is enabled, all of\n * these are injected. The channel LISTENERS may live elsewhere (e.g. the NestJS\n * one lives in `@sentry/nestjs`), but the config that decides what gets\n * transformed is centralized here.\n *\n * This module MUST stay pure, stateless data. It is loaded in more than one realm\n * at once — the build-time bundler plugin inlines it into the server chunk, while\n * `@sentry/server-runtime-injection`'s external `register` loads its own copy from\n * `node_modules` at runtime. Two identical, side-effect-free arrays are harmless;\n * any module-level mutable state here would silently diverge between those copies.\n */\nexport const SENTRY_INSTRUMENTATIONS: InstrumentationConfig[] = [\n ...amqplibConfig,\n ...anthropicAiConfig,\n ...awsSdkConfig,\n ...clickhouseConfig,\n ...cronConfig,\n ...dataloaderConfig,\n ...expressConfig,\n ...firebaseConfig,\n ...genericPoolConfig,\n ...googleGenAiConfig,\n ...graphqlConfig,\n ...groqConfig,\n ...hapiConfig,\n ...honoConfig,\n ...ioredisConfig,\n ...kafkajsConfig,\n ...knexConfig,\n ...koaConfig,\n ...langchainConfig,\n ...langgraphConfig,\n ...lruMemoizerConfig,\n ...flueConfig,\n ...mastraConfig,\n ...mcpServerConfig,\n ...mistralConfig,\n ...mongodbConfig,\n ...mongooseConfig,\n ...mysql2Config,\n ...mysqlConfig,\n ...neonConfig,\n ...nestjsConfig,\n ...nitroConfig,\n ...nodeCronConfig,\n ...nodeScheduleConfig,\n ...openaiConfig,\n ...pgConfig,\n ...piAiConfig,\n ...piDurableConfig,\n ...postgresJsConfig,\n ...prismaConfig,\n ...redisConfig,\n ...remixConfig,\n ...remixV3Config,\n ...tanstackAiConfig,\n ...tediousConfig,\n ...togetherAiConfig,\n ...typesafeConfig,\n ...vercelAiConfig,\n];\n\n/**\n * The subset of {@link SENTRY_INSTRUMENTATIONS} the RUNTIME loader\n * (`@sentry/server-runtime-injection`'s `register`, reached via `--import` or\n * `Sentry.init()`) can actually apply.\n *\n * Registration-only configs (native-channel libraries such as `ai` v7,\n * `ioredis`, `@redis/client`, `mysql2`, `mongoose`) carry the custom\n * `MODULE_REGISTRATION_TRANSFORM` operator. That operator is wired into the\n * BUNDLER plugins only (see `orchestrion/bundler/moduleInjectedTransform.ts`,\n * applied via `bundler/options.ts`'s `customTransforms`); the runtime loader's\n * `initialize()` receives no custom transforms. Attempting one of these at\n * runtime therefore throws `TypeError: transform is not a function`, which the\n * loader misreports as the always-on \"`@sentry/server-runtime-injection` was\n * bundled ... loads uninstrumented\" warning even though nothing is wrong.\n *\n * Excluding them at runtime is correct, not just a way to silence the warning:\n * these libraries publish their own tracing channels, and their integrations\n * subscribe through `setupOnce()` / `waitForTracingChannelBinding`,\n * independently of the module-injected snippet. That snippet only fires\n * `orchestrion.module-injected`, which drives the `setup()` /\n * `invokeOrchestrionInstrumentation` path; for a native-channel version that\n * path subscribes to the injected `orchestrion:*` channels the library never\n * publishes — a no-op. So running these at runtime would add no spans. The\n * snippet earns its keep only on the BUNDLER path — notably bundler-only SDKs\n * (e.g. `@sentry/cloudflare`) that discover a loaded module via that event to\n * instantiate its integration factory. `@sentry/node` registers its\n * integrations statically, so it does not need it.\n */\nexport const SENTRY_RUNTIME_INSTRUMENTATIONS: InstrumentationConfig[] = SENTRY_INSTRUMENTATIONS.filter(\n config => !config.transform,\n);\n\n/**\n * The unique set of package names instrumented by `SENTRY_INSTRUMENTATIONS`\n * merged with any caller-provided `instrumentations` (e.g. `['mysql']`).\n *\n * Bundler plugins MUST ensure these are actually bundled rather than\n * externalized: an externalized dependency is resolved from `node_modules` at\n * runtime and never passes through the code transform's `onLoad`, so its\n * diagnostics_channel calls are silently never injected. This includes a\n * plugin's custom `instrumentations`, otherwise those extra packages can stay\n * externalized and their transform never runs.\n */\nexport function instrumentedModuleNames(instrumentations: InstrumentationConfig[] = []): string[] {\n return [\n ...uniq([...SENTRY_INSTRUMENTATIONS, ...instrumentations].map(i => i.module.name)),\n // Additional things that need to be bundled but are not covered by the above\n // Remix needs to bundle this so @remix-run/server-runtime is _also_ bundled\n '@remix-run/node',\n ];\n}\n\n/** The instrumented module names from the default Sentry config, with no custom additions. */\nexport const INSTRUMENTED_MODULE_NAMES: string[] = instrumentedModuleNames();\n\n/**\n * The package names the SDK instruments through the orchestrion module transform (its\n * diagnostics-channel injection). Pass these to a server bundler's \"keep external\" option so the\n * packages load through Node's module loader — the only path the transform can hook — instead of\n * being inlined into the server bundle. A framework that has no Sentry bundler plugin (e.g. eve, via\n * `build.externalDependencies`) is the main caller; a listed package the app doesn't use is simply\n * ignored by the bundler.\n *\n * Unlike {@link INSTRUMENTED_MODULE_NAMES}, this is the plain instrumented set with no bundler-only\n * additions — those force a helper package to be *bundled*, the opposite of keeping it external.\n */\nexport function getInstrumentedModuleNames(): string[] {\n return uniq(SENTRY_INSTRUMENTATIONS.map(instrumentation => instrumentation.module.name));\n}\n\n/**\n * Returns `external` with any instrumented packages removed, so a bundler that\n * uses an \"external\" denylist (esbuild, Bun, Rollup) still bundles — and thus\n * transforms — them. Matches an exact package name (`'mysql'`) or a subpath\n * (`'mysql/lib/...'`); wildcard/other patterns are left untouched. `undefined`\n * is returned unchanged.\n *\n * Pass `moduleNames` from `instrumentedModuleNames(options.instrumentations)` so\n * custom instrumentations are stripped too; it defaults to the Sentry config\n * list. (Vite uses an `ssr.noExternal` allowlist instead, so it consumes\n * `instrumentedModuleNames` directly rather than this helper.)\n */\nexport function withoutInstrumentedExternals(\n external: readonly string[] | undefined,\n moduleNames: string[] = INSTRUMENTED_MODULE_NAMES,\n): string[] | undefined {\n if (!external) {\n return undefined;\n }\n return external.filter(entry => !moduleNames.some(name => entry === name || entry.startsWith(`${name}/`)));\n}\n\n// This is exported so that the nestjs package can use it to subscribe to the channels.\nexport { nestjsChannels } from './nestjs';\n// This is exported so that the remix package can use it to subscribe to the channels.\nexport { remixChannels } from './remix';\n// Exported so the remix package can subscribe to the Remix 3 channels, and hand only these configs to\n// the browser transform.\nexport { remixV3Channels, remixV3Config } from './remix-v3';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAa,0BAAmD;CAC9D,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,kCAA2D,wBAAwB,QAC9F,WAAU,CAAC,OAAO,SACpB;;;;;;;;;;;;AAaA,SAAgB,wBAAwB,mBAA4C,CAAC,GAAa;CAChG,OAAO,CACL,GAAG,KAAK,CAAC,GAAG,yBAAyB,GAAG,gBAAgB,CAAC,CAAC,KAAI,MAAK,EAAE,OAAO,IAAI,CAAC,GAGjF,iBACF;AACF;;AAGA,MAAa,4BAAsC,wBAAwB;;;;;;;;;;;;AAa3E,SAAgB,6BAAuC;CACrD,OAAO,KAAK,wBAAwB,KAAI,oBAAmB,gBAAgB,OAAO,IAAI,CAAC;AACzF;;;;;;;;;;;;;AAcA,SAAgB,6BACd,UACA,cAAwB,2BACF;CACtB,IAAI,CAAC,UACH;CAEF,OAAO,SAAS,QAAO,UAAS,CAAC,YAAY,MAAK,SAAQ,UAAU,QAAQ,MAAM,WAAW,GAAG,KAAK,EAAE,CAAC,CAAC;AAC3G"}