@sentry/server-utils 11.7.0 → 11.9.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 (199) hide show
  1. package/build/THIRD-PARTY-LICENSES.txt +38 -38
  2. package/build/cjs/ai/anthropic-ai/constants.js +2 -0
  3. package/build/cjs/ai/anthropic-ai/constants.js.map +1 -1
  4. package/build/cjs/ai/anthropic-ai/index.js +6 -1
  5. package/build/cjs/ai/anthropic-ai/index.js.map +1 -1
  6. package/build/cjs/ai/anthropic-ai/tool-runner.js +93 -0
  7. package/build/cjs/ai/anthropic-ai/tool-runner.js.map +1 -0
  8. package/build/cjs/ai/langchain/index.js +75 -50
  9. package/build/cjs/ai/langchain/index.js.map +1 -1
  10. package/build/cjs/ai/openai/constants.js +3 -1
  11. package/build/cjs/ai/openai/constants.js.map +1 -1
  12. package/build/cjs/ai/openai/index.js +10 -4
  13. package/build/cjs/ai/openai/index.js.map +1 -1
  14. package/build/cjs/ai/openai/mapping.js +67 -0
  15. package/build/cjs/ai/openai/mapping.js.map +1 -0
  16. package/build/cjs/ai/openai/utils.js +36 -23
  17. package/build/cjs/ai/openai/utils.js.map +1 -1
  18. package/build/cjs/ai/pi-durable/tools.js +1 -1
  19. package/build/cjs/ai/pi-durable/tools.js.map +1 -1
  20. package/build/cjs/index.js +8 -6
  21. package/build/cjs/index.js.map +1 -1
  22. package/build/cjs/integrations/anthropic.js +6 -2
  23. package/build/cjs/integrations/anthropic.js.map +1 -1
  24. package/build/cjs/integrations/graphql/constants.js +1 -1
  25. package/build/cjs/integrations/graphql/constants.js.map +1 -1
  26. package/build/cjs/integrations/hono/connInfo.js +37 -0
  27. package/build/cjs/integrations/hono/connInfo.js.map +1 -0
  28. package/build/cjs/integrations/hono/createHonoMiddleware.js +2 -2
  29. package/build/cjs/integrations/hono/createHonoMiddleware.js.map +1 -1
  30. package/build/cjs/integrations/hono/honoIntegration.js +3 -24
  31. package/build/cjs/integrations/hono/honoIntegration.js.map +1 -1
  32. package/build/cjs/integrations/hono/middlewareHandlers.js +31 -19
  33. package/build/cjs/integrations/hono/middlewareHandlers.js.map +1 -1
  34. package/build/cjs/integrations/index.js +29 -21
  35. package/build/cjs/integrations/index.js.map +1 -1
  36. package/build/cjs/integrations/mongoose/mongoose-dc-subscriber.js +1 -1
  37. package/build/cjs/integrations/mongoose/mongoose-dc-subscriber.js.map +1 -1
  38. package/build/cjs/integrations/mysql2/mysql2-dc-subscriber.js +1 -1
  39. package/build/cjs/integrations/mysql2/mysql2-dc-subscriber.js.map +1 -1
  40. package/build/cjs/integrations/nitro/captureStorageEvents.js +132 -0
  41. package/build/cjs/integrations/nitro/captureStorageEvents.js.map +1 -0
  42. package/build/cjs/integrations/nitro/captureTracingEvents.js +202 -0
  43. package/build/cjs/integrations/nitro/captureTracingEvents.js.map +1 -0
  44. package/build/cjs/integrations/nitro/index.js +27 -0
  45. package/build/cjs/integrations/nitro/index.js.map +1 -0
  46. package/build/cjs/integrations/nitro/setServerTimingHeaders.js +40 -0
  47. package/build/cjs/integrations/nitro/setServerTimingHeaders.js.map +1 -0
  48. package/build/cjs/integrations/openai.js +3 -2
  49. package/build/cjs/integrations/openai.js.map +1 -1
  50. package/build/cjs/integrations/redis/redis-dc-subscriber.js +1 -1
  51. package/build/cjs/integrations/redis/redis-dc-subscriber.js.map +1 -1
  52. package/build/cjs/integrations/vercel-ai/vercel-ai-dc-subscriber.js +2 -2
  53. package/build/cjs/integrations/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
  54. package/build/cjs/orchestrion/bundler/externalRequire.js +82 -0
  55. package/build/cjs/orchestrion/bundler/externalRequire.js.map +1 -0
  56. package/build/cjs/orchestrion/bundler/vite.js +29 -8
  57. package/build/cjs/orchestrion/bundler/vite.js.map +1 -1
  58. package/build/cjs/orchestrion/config/anthropic-ai.js +7 -1
  59. package/build/cjs/orchestrion/config/anthropic-ai.js.map +1 -1
  60. package/build/cjs/orchestrion/config/channel-integration-definitions.js +2 -1
  61. package/build/cjs/orchestrion/config/channel-integration-definitions.js.map +1 -1
  62. package/build/cjs/orchestrion/config/index.js +2 -0
  63. package/build/cjs/orchestrion/config/index.js.map +1 -1
  64. package/build/cjs/orchestrion/config/nitro.js +10 -0
  65. package/build/cjs/orchestrion/config/nitro.js.map +1 -0
  66. package/build/cjs/orchestrion/config/openai.js +8 -1
  67. package/build/cjs/orchestrion/config/openai.js.map +1 -1
  68. package/build/cjs/orchestrion/config/prisma.js +2 -2
  69. package/build/cjs/orchestrion/config/prisma.js.map +1 -1
  70. package/build/esm/ai/anthropic-ai/constants.js +2 -1
  71. package/build/esm/ai/anthropic-ai/constants.js.map +1 -1
  72. package/build/esm/ai/anthropic-ai/index.js +7 -2
  73. package/build/esm/ai/anthropic-ai/index.js.map +1 -1
  74. package/build/esm/ai/anthropic-ai/tool-runner.js +90 -0
  75. package/build/esm/ai/anthropic-ai/tool-runner.js.map +1 -0
  76. package/build/esm/ai/langchain/index.js +77 -52
  77. package/build/esm/ai/langchain/index.js.map +1 -1
  78. package/build/esm/ai/openai/constants.js +3 -1
  79. package/build/esm/ai/openai/constants.js.map +1 -1
  80. package/build/esm/ai/openai/index.js +11 -5
  81. package/build/esm/ai/openai/index.js.map +1 -1
  82. package/build/esm/ai/openai/mapping.js +64 -0
  83. package/build/esm/ai/openai/mapping.js.map +1 -0
  84. package/build/esm/ai/openai/utils.js +37 -24
  85. package/build/esm/ai/openai/utils.js.map +1 -1
  86. package/build/esm/ai/pi-durable/tools.js +1 -1
  87. package/build/esm/ai/pi-durable/tools.js.map +1 -1
  88. package/build/esm/index.js +1 -0
  89. package/build/esm/index.js.map +1 -1
  90. package/build/esm/integrations/anthropic.js +6 -2
  91. package/build/esm/integrations/anthropic.js.map +1 -1
  92. package/build/esm/integrations/graphql/constants.js +1 -1
  93. package/build/esm/integrations/graphql/constants.js.map +1 -1
  94. package/build/esm/integrations/hono/connInfo.js +35 -0
  95. package/build/esm/integrations/hono/connInfo.js.map +1 -0
  96. package/build/esm/integrations/hono/createHonoMiddleware.js +2 -2
  97. package/build/esm/integrations/hono/createHonoMiddleware.js.map +1 -1
  98. package/build/esm/integrations/hono/honoIntegration.js +4 -25
  99. package/build/esm/integrations/hono/honoIntegration.js.map +1 -1
  100. package/build/esm/integrations/hono/middlewareHandlers.js +33 -21
  101. package/build/esm/integrations/hono/middlewareHandlers.js.map +1 -1
  102. package/build/esm/integrations/index.js +9 -1
  103. package/build/esm/integrations/index.js.map +1 -1
  104. package/build/esm/integrations/mongoose/mongoose-dc-subscriber.js +1 -1
  105. package/build/esm/integrations/mongoose/mongoose-dc-subscriber.js.map +1 -1
  106. package/build/esm/integrations/mysql2/mysql2-dc-subscriber.js +1 -1
  107. package/build/esm/integrations/mysql2/mysql2-dc-subscriber.js.map +1 -1
  108. package/build/esm/integrations/nitro/captureStorageEvents.js +130 -0
  109. package/build/esm/integrations/nitro/captureStorageEvents.js.map +1 -0
  110. package/build/esm/integrations/nitro/captureTracingEvents.js +200 -0
  111. package/build/esm/integrations/nitro/captureTracingEvents.js.map +1 -0
  112. package/build/esm/integrations/nitro/index.js +25 -0
  113. package/build/esm/integrations/nitro/index.js.map +1 -0
  114. package/build/esm/integrations/nitro/setServerTimingHeaders.js +38 -0
  115. package/build/esm/integrations/nitro/setServerTimingHeaders.js.map +1 -0
  116. package/build/esm/integrations/openai.js +3 -2
  117. package/build/esm/integrations/openai.js.map +1 -1
  118. package/build/esm/integrations/redis/redis-dc-subscriber.js +1 -1
  119. package/build/esm/integrations/redis/redis-dc-subscriber.js.map +1 -1
  120. package/build/esm/integrations/vercel-ai/vercel-ai-dc-subscriber.js +2 -2
  121. package/build/esm/integrations/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
  122. package/build/esm/orchestrion/bundler/externalRequire.js +80 -0
  123. package/build/esm/orchestrion/bundler/externalRequire.js.map +1 -0
  124. package/build/esm/orchestrion/bundler/vite.js +29 -8
  125. package/build/esm/orchestrion/bundler/vite.js.map +1 -1
  126. package/build/esm/orchestrion/config/anthropic-ai.js +7 -1
  127. package/build/esm/orchestrion/config/anthropic-ai.js.map +1 -1
  128. package/build/esm/orchestrion/config/channel-integration-definitions.js +2 -1
  129. package/build/esm/orchestrion/config/channel-integration-definitions.js.map +1 -1
  130. package/build/esm/orchestrion/config/index.js +2 -0
  131. package/build/esm/orchestrion/config/index.js.map +1 -1
  132. package/build/esm/orchestrion/config/nitro.js +8 -0
  133. package/build/esm/orchestrion/config/nitro.js.map +1 -0
  134. package/build/esm/orchestrion/config/openai.js +8 -1
  135. package/build/esm/orchestrion/config/openai.js.map +1 -1
  136. package/build/esm/orchestrion/config/prisma.js +2 -2
  137. package/build/esm/orchestrion/config/prisma.js.map +1 -1
  138. package/build/esm/package.json +1 -1
  139. package/build/types/ai/anthropic-ai/constants.d.ts +1 -0
  140. package/build/types/ai/anthropic-ai/constants.d.ts.map +1 -1
  141. package/build/types/ai/anthropic-ai/index.d.ts.map +1 -1
  142. package/build/types/ai/anthropic-ai/tool-runner.d.ts +6 -0
  143. package/build/types/ai/anthropic-ai/tool-runner.d.ts.map +1 -0
  144. package/build/types/ai/langchain/index.d.ts.map +1 -1
  145. package/build/types/ai/openai/constants.d.ts +3 -0
  146. package/build/types/ai/openai/constants.d.ts.map +1 -1
  147. package/build/types/ai/openai/index.d.ts.map +1 -1
  148. package/build/types/ai/openai/mapping.d.ts +8 -0
  149. package/build/types/ai/openai/mapping.d.ts.map +1 -0
  150. package/build/types/ai/openai/utils.d.ts +3 -2
  151. package/build/types/ai/openai/utils.d.ts.map +1 -1
  152. package/build/types/ai/pi-durable/types.d.ts +3 -0
  153. package/build/types/ai/pi-durable/types.d.ts.map +1 -1
  154. package/build/types/index.d.ts +2 -0
  155. package/build/types/index.d.ts.map +1 -1
  156. package/build/types/integrations/anthropic.d.ts.map +1 -1
  157. package/build/types/integrations/graphql/constants.d.ts +1 -1
  158. package/build/types/integrations/graphql/constants.d.ts.map +1 -1
  159. package/build/types/integrations/hono/connInfo.d.ts +12 -0
  160. package/build/types/integrations/hono/connInfo.d.ts.map +1 -0
  161. package/build/types/integrations/hono/createHonoMiddleware.d.ts +5 -7
  162. package/build/types/integrations/hono/createHonoMiddleware.d.ts.map +1 -1
  163. package/build/types/integrations/hono/honoIntegration.d.ts.map +1 -1
  164. package/build/types/integrations/hono/honoTypes.d.ts +0 -9
  165. package/build/types/integrations/hono/honoTypes.d.ts.map +1 -1
  166. package/build/types/integrations/hono/middlewareHandlers.d.ts +3 -2
  167. package/build/types/integrations/hono/middlewareHandlers.d.ts.map +1 -1
  168. package/build/types/integrations/index.d.ts +5 -1
  169. package/build/types/integrations/index.d.ts.map +1 -1
  170. package/build/types/integrations/nitro/captureStorageEvents.d.ts +5 -0
  171. package/build/types/integrations/nitro/captureStorageEvents.d.ts.map +1 -0
  172. package/build/types/integrations/nitro/captureTracingEvents.d.ts +5 -0
  173. package/build/types/integrations/nitro/captureTracingEvents.d.ts.map +1 -0
  174. package/build/types/integrations/nitro/index.d.ts +29 -0
  175. package/build/types/integrations/nitro/index.d.ts.map +1 -0
  176. package/build/types/integrations/nitro/nitroTypes.d.ts +72 -0
  177. package/build/types/integrations/nitro/nitroTypes.d.ts.map +1 -0
  178. package/build/types/integrations/nitro/setServerTimingHeaders.d.ts +10 -0
  179. package/build/types/integrations/nitro/setServerTimingHeaders.d.ts.map +1 -0
  180. package/build/types/integrations/openai.d.ts +1 -1
  181. package/build/types/integrations/openai.d.ts.map +1 -1
  182. package/build/types/integrations/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -1
  183. package/build/types/orchestrion/bundler/externalRequire.d.ts +15 -0
  184. package/build/types/orchestrion/bundler/externalRequire.d.ts.map +1 -0
  185. package/build/types/orchestrion/bundler/vite.d.ts.map +1 -1
  186. package/build/types/orchestrion/channels.d.ts +2 -0
  187. package/build/types/orchestrion/channels.d.ts.map +1 -1
  188. package/build/types/orchestrion/config/anthropic-ai.d.ts +1 -0
  189. package/build/types/orchestrion/config/anthropic-ai.d.ts.map +1 -1
  190. package/build/types/orchestrion/config/channel-integration-definitions.d.ts +3 -0
  191. package/build/types/orchestrion/config/channel-integration-definitions.d.ts.map +1 -1
  192. package/build/types/orchestrion/config/index.d.ts.map +1 -1
  193. package/build/types/orchestrion/config/nitro.d.ts +19 -0
  194. package/build/types/orchestrion/config/nitro.d.ts.map +1 -0
  195. package/build/types/orchestrion/config/openai.d.ts +1 -0
  196. package/build/types/orchestrion/config/openai.d.ts.map +1 -1
  197. package/build/types/orchestrion/config/pg.d.ts +1 -1
  198. package/build/types/orchestrion/config/prisma.d.ts.map +1 -1
  199. package/package.json +4 -4
@@ -0,0 +1,90 @@
1
+ import { getOriginalFunction, fill, startSpan, stringify, handleCallbackErrors, SPAN_STATUS_ERROR, captureException } from '@sentry/core';
2
+ import { GEN_AI_TOOL_CALL_ARGUMENTS, GEN_AI_TOOL_DESCRIPTION, GEN_AI_TOOL_NAME, GEN_AI_OPERATION_NAME, SENTRY_ORIGIN, GEN_AI_TOOL_CALL_RESULT } from '@sentry/conventions/attributes';
3
+ import { GEN_AI_EXECUTE_TOOL } from '@sentry/conventions/op';
4
+ import { GEN_AI_TOOL_CALL_ID_ATTRIBUTE } from '../core/gen-ai-attributes.js';
5
+ import { resolveAIRecordingOptions } from '../core/utils.js';
6
+ import { ANTHROPIC_AI_ORIGIN } from './constants.js';
7
+
8
+ function instrumentToolRunnerMethod(messages, options) {
9
+ wrapInPlace(messages, "toolRunner", (toolRunner, thisArg, args) => {
10
+ const runner = toolRunner.apply(thisArg, args);
11
+ instrumentToolRunner(runner, options);
12
+ return runner;
13
+ });
14
+ }
15
+ function instrumentToolRunner(runner, options) {
16
+ if (!runner || typeof runner !== "object") {
17
+ return;
18
+ }
19
+ instrumentTools(runner.params?.tools, options);
20
+ wrapInPlace(runner, "addTools", (addTools, thisArg, tools) => {
21
+ instrumentTools(tools, options);
22
+ return addTools.apply(thisArg, tools);
23
+ });
24
+ wrapInPlace(runner, "setMessagesParams", (setMessagesParams, thisArg, args) => {
25
+ const result = setMessagesParams.apply(thisArg, args);
26
+ instrumentTools(runner.params?.tools, options);
27
+ return result;
28
+ });
29
+ }
30
+ function instrumentTools(tools, options) {
31
+ if (!Array.isArray(tools)) {
32
+ return;
33
+ }
34
+ for (const tool of tools) {
35
+ if (tool && typeof tool === "object" && typeof tool.name === "string") {
36
+ wrapInPlace(tool, "run", (run, thisArg, args) => runWithSpan(tool, run, thisArg, args, options));
37
+ }
38
+ }
39
+ }
40
+ function wrapInPlace(owner, key, call) {
41
+ const current = owner[key];
42
+ if (typeof current === "function" && !getOriginalFunction(current)) {
43
+ fill(
44
+ owner,
45
+ key,
46
+ (original) => function(...args) {
47
+ return call(original, this, args);
48
+ }
49
+ );
50
+ }
51
+ }
52
+ function runWithSpan(tool, run, thisArg, args, options) {
53
+ const { recordInputs, recordOutputs } = resolveAIRecordingOptions(options);
54
+ const [input, context] = args;
55
+ const callId = (context?.toolUse ?? context?.toolUseBlock)?.id;
56
+ return startSpan(
57
+ {
58
+ name: `execute_tool ${tool.name}`,
59
+ op: GEN_AI_EXECUTE_TOOL,
60
+ attributes: {
61
+ [SENTRY_ORIGIN]: ANTHROPIC_AI_ORIGIN,
62
+ [GEN_AI_OPERATION_NAME]: "execute_tool",
63
+ [GEN_AI_TOOL_NAME]: tool.name,
64
+ ...typeof tool.description === "string" ? { [GEN_AI_TOOL_DESCRIPTION]: tool.description } : {},
65
+ ...typeof callId === "string" ? { [GEN_AI_TOOL_CALL_ID_ATTRIBUTE]: callId } : {},
66
+ ...recordInputs ? { [GEN_AI_TOOL_CALL_ARGUMENTS]: stringify(input) } : {}
67
+ }
68
+ },
69
+ (span) => handleCallbackErrors(
70
+ () => run.apply(thisArg, args),
71
+ (error) => handleToolError(span, error, context),
72
+ void 0,
73
+ (result) => recordOutputs && span.setAttribute(GEN_AI_TOOL_CALL_RESULT, stringify(result))
74
+ )
75
+ );
76
+ }
77
+ function handleToolError(span, error, context) {
78
+ if (context?.signal?.aborted) {
79
+ span.setStatus({ code: SPAN_STATUS_ERROR, message: "cancelled" });
80
+ return;
81
+ }
82
+ span.setStatus({ code: SPAN_STATUS_ERROR, message: "internal_error" });
83
+ const fromRunner = !!(context?.toolUse ?? context?.toolUseBlock);
84
+ if (fromRunner && error?.name !== "ToolError") {
85
+ captureException(error, { mechanism: { handled: true, type: ANTHROPIC_AI_ORIGIN } });
86
+ }
87
+ }
88
+
89
+ export { instrumentToolRunner, instrumentToolRunnerMethod };
90
+ //# sourceMappingURL=tool-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-runner.js","sources":["../../../../src/ai/anthropic-ai/tool-runner.ts"],"sourcesContent":["import type { Span, WrappedFunction } from '@sentry/core';\nimport {\n captureException,\n fill,\n getOriginalFunction,\n handleCallbackErrors,\n SPAN_STATUS_ERROR,\n startSpan,\n stringify,\n} from '@sentry/core';\nimport {\n GEN_AI_OPERATION_NAME,\n GEN_AI_TOOL_CALL_ARGUMENTS,\n GEN_AI_TOOL_CALL_RESULT,\n GEN_AI_TOOL_DESCRIPTION,\n GEN_AI_TOOL_NAME,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { GEN_AI_EXECUTE_TOOL } from '@sentry/conventions/op';\nimport { GEN_AI_TOOL_CALL_ID_ATTRIBUTE } from '../core/gen-ai-attributes';\nimport { resolveAIRecordingOptions } from '../core/utils';\nimport { ANTHROPIC_AI_ORIGIN } from './constants';\nimport type { AnthropicAiOptions } from './types';\n\ntype AnyFunction = (...args: unknown[]) => unknown;\ntype RunnableTool = { name: string; description?: unknown };\ntype RunContext = { toolUse?: { id?: unknown }; toolUseBlock?: { id?: unknown }; signal?: AbortSignal } | undefined;\ntype ToolRunner = { params?: { tools?: unknown } };\n\n/** Wrap `beta.messages.toolRunner()` so the runners it returns trace their tool calls. */\nexport function instrumentToolRunnerMethod(messages: object, options: AnthropicAiOptions): void {\n wrapInPlace(messages, 'toolRunner', (toolRunner, thisArg, args) => {\n const runner = toolRunner.apply(thisArg, args);\n instrumentToolRunner(runner, options);\n return runner;\n });\n}\n\n/** Give each tool call of a tool runner a `gen_ai.execute_tool` span. */\nexport function instrumentToolRunner(runner: unknown, options: AnthropicAiOptions): void {\n if (!runner || typeof runner !== 'object') {\n return;\n }\n\n instrumentTools((runner as ToolRunner).params?.tools, options);\n\n // `addTools()` keeps its tools out of `params`.\n wrapInPlace(runner, 'addTools', (addTools, thisArg, tools) => {\n instrumentTools(tools, options);\n return addTools.apply(thisArg, tools);\n });\n wrapInPlace(runner, 'setMessagesParams', (setMessagesParams, thisArg, args) => {\n const result = setMessagesParams.apply(thisArg, args);\n instrumentTools((runner as ToolRunner).params?.tools, options);\n return result;\n });\n}\n\nfunction instrumentTools(tools: unknown, options: AnthropicAiOptions): void {\n if (!Array.isArray(tools)) {\n return;\n }\n\n for (const tool of tools) {\n // Toolsets are nameless entries whose `run` takes `(ctx, toolUse)`, so only named tools are wrapped.\n if (tool && typeof tool === 'object' && typeof (tool as RunnableTool).name === 'string') {\n wrapInPlace(tool, 'run', (run, thisArg, args) => runWithSpan(tool as RunnableTool, run, thisArg, args, options));\n }\n }\n}\n\nfunction wrapInPlace(\n owner: object,\n key: string,\n call: (original: AnyFunction, thisArg: unknown, args: unknown[]) => unknown,\n): void {\n const current = (owner as Record<string, unknown>)[key];\n if (typeof current === 'function' && !getOriginalFunction(current as WrappedFunction)) {\n fill(\n owner,\n key,\n (original: AnyFunction) =>\n function (this: unknown, ...args: unknown[]): unknown {\n return call(original, this, args);\n },\n );\n }\n}\n\nfunction runWithSpan(\n tool: RunnableTool,\n run: AnyFunction,\n thisArg: unknown,\n args: unknown[],\n options: AnthropicAiOptions,\n): unknown {\n const { recordInputs, recordOutputs } = resolveAIRecordingOptions(options);\n const [input, context] = args as [unknown, RunContext];\n // SDK versions before `toolUse` existed pass only `toolUseBlock`.\n const callId = (context?.toolUse ?? context?.toolUseBlock)?.id;\n\n return startSpan(\n {\n name: `execute_tool ${tool.name}`,\n op: GEN_AI_EXECUTE_TOOL,\n attributes: {\n [SENTRY_ORIGIN]: ANTHROPIC_AI_ORIGIN,\n [GEN_AI_OPERATION_NAME]: 'execute_tool',\n [GEN_AI_TOOL_NAME]: tool.name,\n ...(typeof tool.description === 'string' ? { [GEN_AI_TOOL_DESCRIPTION]: tool.description } : {}),\n ...(typeof callId === 'string' ? { [GEN_AI_TOOL_CALL_ID_ATTRIBUTE]: callId } : {}),\n ...(recordInputs ? { [GEN_AI_TOOL_CALL_ARGUMENTS]: stringify(input) } : {}),\n },\n },\n span =>\n handleCallbackErrors(\n () => run.apply(thisArg, args),\n error => handleToolError(span, error, context),\n undefined,\n result => recordOutputs && span.setAttribute(GEN_AI_TOOL_CALL_RESULT, stringify(result)),\n ),\n );\n}\n\nfunction handleToolError(span: Span, error: unknown, context: RunContext): void {\n if (context?.signal?.aborted) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'cancelled' });\n return;\n }\n\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n\n // Only a runner passes `toolUse`/`toolUseBlock` (SDK 0.85+), and it hands the throw to the model as a result.\n // A direct call rethrows to its caller, and a `ToolError` is sent on purpose, so neither is captured.\n const fromRunner = !!(context?.toolUse ?? context?.toolUseBlock);\n if (fromRunner && (error as Error | undefined)?.name !== 'ToolError') {\n captureException(error, { mechanism: { handled: true, type: ANTHROPIC_AI_ORIGIN } });\n }\n}\n"],"names":[],"mappings":";;;;;;;AA8BO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA2B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAkB,OAAA,CAAA,CAAmC;AAC9F,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,C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CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,KAAW,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AACnD,CAAA,CAAA,CAAA,CAAA,CAAA,CAAI,UAAA,CAAA,CAAA,CAAA,CAAe,CAAA,CAAA,CAAA,CAAA,CAAA,EAA6B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,WAAA,CAAA,CAAa;AACpE,CAAA,CAAA,CAAA,CAAA,gBAAA,CAAiB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAE,SAAA,CAAA,CAAW,CAAA,CAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAS,IAAA,CAAA,CAAM,CAAA,CAAA,CAAA,CAAA,EAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAoB,EAAG,CAAA;AAAA,CAAA,CACrF;AACF;;"}
@@ -1,5 +1,5 @@
1
- import { SPAN_STATUS_ERROR, stringify, startSpanManual, getClient, hasSpanStreamingEnabled } from '@sentry/core';
2
- import { GEN_AI_TOOL_CALL_RESULT, SENTRY_OP, GEN_AI_TOOL_DEFINITIONS, GEN_AI_REQUEST_MODEL, GEN_AI_OPERATION_NAME, GEN_AI_TOOL_NAME, SENTRY_ORIGIN, GEN_AI_TOOL_CALL_ARGUMENTS, GEN_AI_PIPELINE_NAME } from '@sentry/conventions/attributes';
1
+ import { SPAN_STATUS_ERROR, stringify, getClient, getActiveSpan, withActiveSpan, spanToJSON, spanIsIgnored, getRootSpan, startInactiveSpan, hasSpanStreamingEnabled } from '@sentry/core';
2
+ import { GEN_AI_TOOL_CALL_RESULT, GEN_AI_TOOL_DEFINITIONS, GEN_AI_REQUEST_MODEL, GEN_AI_OPERATION_NAME, GEN_AI_CONVERSATION_ID, SENTRY_OP, GEN_AI_TOOL_NAME, SENTRY_ORIGIN, GEN_AI_TOOL_CALL_ARGUMENTS, GEN_AI_PIPELINE_NAME } from '@sentry/conventions/attributes';
3
3
  import { GEN_AI_EXECUTE_TOOL, GEN_AI_INVOKE_AGENT, GEN_AI_CHAT } from '@sentry/conventions/op';
4
4
  import { resolveAIRecordingOptions } from '../core/utils.js';
5
5
  import { LANGCHAIN_ORIGIN } from './constants.js';
@@ -8,15 +8,44 @@ import { getConversationIdFromMetadata, getAgentNameFromMetadata, extractLlmResp
8
8
 
9
9
  function createLangChainCallbackHandler(options = {}) {
10
10
  const { recordInputs, recordOutputs } = resolveAIRecordingOptions(options);
11
- const spanMap = /* @__PURE__ */ new Map();
12
- const decideRunIds = /* @__PURE__ */ new Set();
11
+ const runs = /* @__PURE__ */ new Map();
12
+ const getRun = (runId) => runId ? runs.get(runId) : void 0;
13
13
  const exitSpan = (runId) => {
14
- const span = spanMap.get(runId);
14
+ const span = runs.get(runId)?.span;
15
15
  if (span?.isRecording()) {
16
16
  span.end();
17
17
  }
18
- spanMap.delete(runId);
19
- decideRunIds.delete(runId);
18
+ runs.delete(runId);
19
+ };
20
+ const getParentRunSpan = (parentRunId, activeSpan) => {
21
+ for (let run = getRun(parentRunId); run; run = getRun(run.parentRunId)) {
22
+ if (run.activeSpan !== activeSpan) {
23
+ return void 0;
24
+ }
25
+ if (!spanIsIgnored(run.span) || getRootSpan(run.span) === run.span) {
26
+ return run.span;
27
+ }
28
+ }
29
+ return void 0;
30
+ };
31
+ const startRunSpan = (runId, parentRunId, start) => {
32
+ const activeSpan = getActiveSpan();
33
+ const parentSpan = getParentRunSpan(parentRunId, activeSpan);
34
+ const span = parentSpan ? withActiveSpan(parentSpan, start) : start();
35
+ const ownId = spanToJSON(span).attributes[GEN_AI_CONVERSATION_ID];
36
+ const conversationId = typeof ownId === "string" ? ownId : getRun(parentRunId)?.conversationId;
37
+ if (conversationId && conversationId !== ownId) {
38
+ span.setAttribute(GEN_AI_CONVERSATION_ID, conversationId);
39
+ }
40
+ const run = { span, parentRunId, activeSpan, conversationId };
41
+ runs.set(runId, run);
42
+ if (conversationId) {
43
+ for (let ancestor = getRun(parentRunId); ancestor && !ancestor.conversationId; ancestor = getRun(ancestor.parentRunId)) {
44
+ ancestor.conversationId = conversationId;
45
+ ancestor.span.setAttribute(GEN_AI_CONVERSATION_ID, conversationId);
46
+ }
47
+ }
48
+ return run;
20
49
  };
21
50
  const handler = {
22
51
  // Required LangChain BaseCallbackHandler properties
@@ -37,7 +66,7 @@ function createLangChainCallbackHandler(options = {}) {
37
66
  ignoreCustomEvent: false,
38
67
  raiseError: false,
39
68
  awaitHandlers: true,
40
- handleLLMStart(llm, prompts, runId, _parentRunId, _extraParams, tags, metadata, _runName) {
69
+ handleLLMStart(llm, prompts, runId, parentRunId, _extraParams, tags, metadata, _runName) {
41
70
  const invocationParams = getInvocationParams(tags);
42
71
  const attributes = extractLLMRequestAttributes(
43
72
  llm,
@@ -49,8 +78,10 @@ function createLangChainCallbackHandler(options = {}) {
49
78
  const modelName = attributes[GEN_AI_REQUEST_MODEL] || "unknown";
50
79
  const operationName = typeof attributes[GEN_AI_OPERATION_NAME] === "string" ? attributes[GEN_AI_OPERATION_NAME] : "unknown";
51
80
  const client = getClient();
52
- startSpanManual(
53
- {
81
+ startRunSpan(
82
+ runId,
83
+ parentRunId,
84
+ () => startInactiveSpan({
54
85
  // With span streaming, omit the `'unknown'` model sentinel so the name stays low-cardinality.
55
86
  name: typeof modelName === "string" && modelName !== "unknown" || !(client && hasSpanStreamingEnabled(client)) ? `${operationName} ${modelName}` : operationName,
56
87
  attributes: {
@@ -59,15 +90,11 @@ function createLangChainCallbackHandler(options = {}) {
59
90
  ...attributes,
60
91
  [SENTRY_OP]: GEN_AI_CHAT
61
92
  }
62
- },
63
- (span) => {
64
- spanMap.set(runId, span);
65
- return span;
66
- }
93
+ })
67
94
  );
68
95
  },
69
96
  // Chat Model Start Handler
70
- handleChatModelStart(llm, messages, runId, _parentRunId, extraParams, tags, metadata, _runName) {
97
+ handleChatModelStart(llm, messages, runId, parentRunId, extraParams, tags, metadata, _runName) {
71
98
  const invocationParams = getInvocationParams(tags);
72
99
  const attributes = extractChatModelRequestAttributes(
73
100
  llm,
@@ -83,8 +110,10 @@ function createLangChainCallbackHandler(options = {}) {
83
110
  const modelName = attributes[GEN_AI_REQUEST_MODEL] || "unknown";
84
111
  const operationName = typeof attributes[GEN_AI_OPERATION_NAME] === "string" ? attributes[GEN_AI_OPERATION_NAME] : "unknown";
85
112
  const client = getClient();
86
- startSpanManual(
87
- {
113
+ startRunSpan(
114
+ runId,
115
+ parentRunId,
116
+ () => startInactiveSpan({
88
117
  // With span streaming, omit the `'unknown'` model sentinel so the name stays low-cardinality.
89
118
  name: typeof modelName === "string" && modelName !== "unknown" || !(client && hasSpanStreamingEnabled(client)) ? `${operationName} ${modelName}` : operationName,
90
119
  attributes: {
@@ -93,37 +122,36 @@ function createLangChainCallbackHandler(options = {}) {
93
122
  ...attributes,
94
123
  [SENTRY_OP]: GEN_AI_CHAT
95
124
  }
96
- },
97
- (span) => {
98
- spanMap.set(runId, span);
99
- return span;
100
- }
125
+ })
101
126
  );
102
127
  },
103
128
  // LLM End Handler - note: handleLLMEnd with capital LLM (used by both LLMs and chat models!)
104
129
  handleLLMEnd(output, runId, _parentRunId, _tags, _extraParams) {
105
- const span = spanMap.get(runId);
130
+ const span = runs.get(runId)?.span;
106
131
  if (span?.isRecording()) {
107
132
  const attributes = extractLlmResponseAttributes(output, recordOutputs);
108
133
  if (attributes) {
109
134
  span.setAttributes(attributes);
110
135
  }
111
- exitSpan(runId);
112
136
  }
137
+ exitSpan(runId);
113
138
  },
114
139
  // LLM Error Handler - note: handleLLMError with capital LLM
115
140
  handleLLMError(_error, runId) {
116
- const span = spanMap.get(runId);
141
+ const span = runs.get(runId)?.span;
117
142
  if (span?.isRecording()) {
118
143
  span.setStatus({ code: SPAN_STATUS_ERROR, message: "internal_error" });
119
- exitSpan(runId);
120
144
  }
145
+ exitSpan(runId);
121
146
  },
122
147
  // Chain Start Handler
123
- handleChainStart(chain, inputs, runId, _parentRunId, _tags, metadata, _runType, runName) {
148
+ handleChainStart(chain, inputs, runId, parentRunId, _tags, metadata, _runType, runName) {
124
149
  if (isTypeSafeClassifier(chain)) {
125
- spanMap.set(runId, startTypeSafeClassifierSpan(chain, inputs, metadata, recordInputs));
126
- decideRunIds.add(runId);
150
+ startRunSpan(
151
+ runId,
152
+ parentRunId,
153
+ () => startTypeSafeClassifierSpan(chain, inputs, metadata, recordInputs)
154
+ ).decide = true;
127
155
  return;
128
156
  }
129
157
  if (metadata?.__sentry_langgraph__) {
@@ -142,8 +170,10 @@ function createLangChainCallbackHandler(options = {}) {
142
170
  attributes["langchain.chain.inputs"] = JSON.stringify(inputs);
143
171
  }
144
172
  const client = getClient();
145
- startSpanManual(
146
- {
173
+ startRunSpan(
174
+ runId,
175
+ parentRunId,
176
+ () => startInactiveSpan({
147
177
  // With span streaming, the name leads with the operation per the agent templates. The
148
178
  // chain name is bounded, so it stays; the `'unknown_chain'` sentinel is dropped instead.
149
179
  name: !(client && hasSpanStreamingEnabled(client)) ? `chain ${chainName || "unknown_chain"}` : chainName ? `invoke_agent ${chainName}` : "invoke_agent",
@@ -151,18 +181,15 @@ function createLangChainCallbackHandler(options = {}) {
151
181
  ...attributes,
152
182
  [SENTRY_OP]: GEN_AI_INVOKE_AGENT
153
183
  }
154
- },
155
- (span) => {
156
- spanMap.set(runId, span);
157
- return span;
158
- }
184
+ })
159
185
  );
160
186
  },
161
187
  // Chain End Handler
162
188
  handleChainEnd(outputs, runId) {
163
- const span = spanMap.get(runId);
189
+ const run = runs.get(runId);
190
+ const span = run?.span;
164
191
  if (span?.isRecording()) {
165
- if (decideRunIds.has(runId)) {
192
+ if (run?.decide) {
166
193
  addTypeSafeClassifierResponseAttributes(span, outputs, recordOutputs);
167
194
  } else if (recordOutputs) {
168
195
  span.setAttributes({
@@ -174,14 +201,14 @@ function createLangChainCallbackHandler(options = {}) {
174
201
  },
175
202
  // Chain Error Handler
176
203
  handleChainError(_error, runId) {
177
- const span = spanMap.get(runId);
204
+ const span = runs.get(runId)?.span;
178
205
  if (span?.isRecording()) {
179
206
  span.setStatus({ code: SPAN_STATUS_ERROR, message: "internal_error" });
180
207
  }
181
208
  exitSpan(runId);
182
209
  },
183
210
  // Tool Start Handler
184
- handleToolStart(tool, input, runId, _parentRunId, _tags, metadata, runName) {
211
+ handleToolStart(tool, input, runId, parentRunId, _tags, metadata, runName) {
185
212
  if (metadata?.__sentry_langgraph__) {
186
213
  return;
187
214
  }
@@ -196,23 +223,21 @@ function createLangChainCallbackHandler(options = {}) {
196
223
  if (recordInputs) {
197
224
  attributes[GEN_AI_TOOL_CALL_ARGUMENTS] = input;
198
225
  }
199
- startSpanManual(
200
- {
226
+ startRunSpan(
227
+ runId,
228
+ parentRunId,
229
+ () => startInactiveSpan({
201
230
  name: `execute_tool ${toolName}`,
202
231
  attributes: {
203
232
  ...attributes,
204
233
  [SENTRY_OP]: GEN_AI_EXECUTE_TOOL
205
234
  }
206
- },
207
- (span) => {
208
- spanMap.set(runId, span);
209
- return span;
210
- }
235
+ })
211
236
  );
212
237
  },
213
238
  // Tool End Handler
214
239
  handleToolEnd(output, runId) {
215
- const span = spanMap.get(runId);
240
+ const span = runs.get(runId)?.span;
216
241
  if (span?.isRecording()) {
217
242
  if (recordOutputs) {
218
243
  const outputObj = output;
@@ -221,16 +246,16 @@ function createLangChainCallbackHandler(options = {}) {
221
246
  [GEN_AI_TOOL_CALL_RESULT]: stringify(content, String)
222
247
  });
223
248
  }
224
- exitSpan(runId);
225
249
  }
250
+ exitSpan(runId);
226
251
  },
227
252
  // Tool Error Handler
228
253
  handleToolError(_error, runId) {
229
- const span = spanMap.get(runId);
254
+ const span = runs.get(runId)?.span;
230
255
  if (span?.isRecording()) {
231
256
  span.setStatus({ code: SPAN_STATUS_ERROR, message: "internal_error" });
232
- exitSpan(runId);
233
257
  }
258
+ exitSpan(runId);
234
259
  },
235
260
  // LangChain BaseCallbackHandler required methods
236
261
  copy() {