@sentry/server-utils 11.13.0 → 11.15.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 (328) hide show
  1. package/build/cjs/chunks/config.js +19 -5
  2. package/build/cjs/chunks/config.js.map +1 -1
  3. package/build/cjs/chunks/exports.js +593 -238
  4. package/build/cjs/chunks/exports.js.map +1 -1
  5. package/build/cjs/chunks/moduleInjectedTransform.js +6 -5
  6. package/build/cjs/chunks/moduleInjectedTransform.js.map +1 -1
  7. package/build/cjs/index.js +1186 -182
  8. package/build/cjs/index.js.map +1 -1
  9. package/build/cjs/orchestrion/bundler/rollup.js +4 -4
  10. package/build/cjs/orchestrion/bundler/rollup.js.map +1 -1
  11. package/build/esm/ai/anthropic-ai/index.js +32 -56
  12. package/build/esm/ai/anthropic-ai/index.js.map +1 -1
  13. package/build/esm/ai/anthropic-ai/streaming.js +10 -6
  14. package/build/esm/ai/anthropic-ai/streaming.js.map +1 -1
  15. package/build/esm/ai/anthropic-ai/tool-runner.js +18 -3
  16. package/build/esm/ai/anthropic-ai/tool-runner.js.map +1 -1
  17. package/build/esm/ai/anthropic-ai/utils.js +41 -3
  18. package/build/esm/ai/anthropic-ai/utils.js.map +1 -1
  19. package/build/esm/ai/core/span-hooks.js +23 -0
  20. package/build/esm/ai/core/span-hooks.js.map +1 -0
  21. package/build/esm/ai/core/time-to-first-chunk.js +14 -0
  22. package/build/esm/ai/core/time-to-first-chunk.js.map +1 -0
  23. package/build/esm/ai/core/utils.js +29 -3
  24. package/build/esm/ai/core/utils.js.map +1 -1
  25. package/build/esm/ai/flue/index.js +15 -12
  26. package/build/esm/ai/flue/index.js.map +1 -1
  27. package/build/esm/ai/flue/utils.js +24 -17
  28. package/build/esm/ai/flue/utils.js.map +1 -1
  29. package/build/esm/ai/google-genai/constants.js +2 -1
  30. package/build/esm/ai/google-genai/constants.js.map +1 -1
  31. package/build/esm/ai/google-genai/decisions.js +25 -0
  32. package/build/esm/ai/google-genai/decisions.js.map +1 -0
  33. package/build/esm/ai/google-genai/index.js +35 -11
  34. package/build/esm/ai/google-genai/index.js.map +1 -1
  35. package/build/esm/ai/google-genai/streaming.js +6 -2
  36. package/build/esm/ai/google-genai/streaming.js.map +1 -1
  37. package/build/esm/ai/langchain/embeddings.js +5 -2
  38. package/build/esm/ai/langchain/embeddings.js.map +1 -1
  39. package/build/esm/ai/langchain/index.js +82 -24
  40. package/build/esm/ai/langchain/index.js.map +1 -1
  41. package/build/esm/ai/langchain/utils.js +9 -1
  42. package/build/esm/ai/langchain/utils.js.map +1 -1
  43. package/build/esm/ai/langgraph/agent-span.js +13 -5
  44. package/build/esm/ai/langgraph/agent-span.js.map +1 -1
  45. package/build/esm/ai/langgraph/index.js +13 -15
  46. package/build/esm/ai/langgraph/index.js.map +1 -1
  47. package/build/esm/ai/langgraph/stream.js +4 -3
  48. package/build/esm/ai/langgraph/stream.js.map +1 -1
  49. package/build/esm/ai/langgraph/utils.js +17 -8
  50. package/build/esm/ai/langgraph/utils.js.map +1 -1
  51. package/build/esm/ai/mastra/classifier-evaluation.js.map +1 -1
  52. package/build/esm/ai/mastra/index.js +33 -16
  53. package/build/esm/ai/mastra/index.js.map +1 -1
  54. package/build/esm/ai/mastra/utils.js +3 -5
  55. package/build/esm/ai/mastra/utils.js.map +1 -1
  56. package/build/esm/ai/mistral/index.js +28 -13
  57. package/build/esm/ai/mistral/index.js.map +1 -1
  58. package/build/esm/ai/mistral/streaming.js +6 -8
  59. package/build/esm/ai/mistral/streaming.js.map +1 -1
  60. package/build/esm/ai/mistral/utils.js +9 -1
  61. package/build/esm/ai/mistral/utils.js.map +1 -1
  62. package/build/esm/ai/openai/index.js +19 -8
  63. package/build/esm/ai/openai/index.js.map +1 -1
  64. package/build/esm/ai/openai/streaming.js +7 -2
  65. package/build/esm/ai/openai/streaming.js.map +1 -1
  66. package/build/esm/ai/pi-ai/chat.js +18 -1
  67. package/build/esm/ai/pi-ai/chat.js.map +1 -1
  68. package/build/esm/ai/pi-ai/recording.js +34 -15
  69. package/build/esm/ai/pi-ai/recording.js.map +1 -1
  70. package/build/esm/ai/pi-durable/index.js +7 -2
  71. package/build/esm/ai/pi-durable/index.js.map +1 -1
  72. package/build/esm/ai/pi-durable/runs.js.map +1 -1
  73. package/build/esm/ai/pi-durable/tools.js +18 -3
  74. package/build/esm/ai/pi-durable/tools.js.map +1 -1
  75. package/build/esm/ai/typesafe/index.js +14 -6
  76. package/build/esm/ai/typesafe/index.js.map +1 -1
  77. package/build/esm/ai/vercel-ai/index.js +3 -1
  78. package/build/esm/ai/vercel-ai/index.js.map +1 -1
  79. package/build/esm/ai/workers-ai/index.js +32 -14
  80. package/build/esm/ai/workers-ai/index.js.map +1 -1
  81. package/build/esm/ai/workers-ai/streaming.js +8 -10
  82. package/build/esm/ai/workers-ai/streaming.js.map +1 -1
  83. package/build/esm/cron/common.js +16 -0
  84. package/build/esm/cron/common.js.map +1 -0
  85. package/build/esm/cron/cron.js +82 -0
  86. package/build/esm/cron/cron.js.map +1 -0
  87. package/build/esm/cron/index.js +13 -0
  88. package/build/esm/cron/index.js.map +1 -0
  89. package/build/esm/cron/node-cron.js +66 -0
  90. package/build/esm/cron/node-cron.js.map +1 -0
  91. package/build/esm/cron/node-schedule.js +43 -0
  92. package/build/esm/cron/node-schedule.js.map +1 -0
  93. package/build/esm/index.js +6 -1
  94. package/build/esm/index.js.map +1 -1
  95. package/build/esm/integrations/anthropic.js +25 -16
  96. package/build/esm/integrations/anthropic.js.map +1 -1
  97. package/build/esm/integrations/aws-sdk/index.js +1 -0
  98. package/build/esm/integrations/aws-sdk/index.js.map +1 -1
  99. package/build/esm/integrations/aws-sdk/services/ServicesExtensions.js +3 -0
  100. package/build/esm/integrations/aws-sdk/services/ServicesExtensions.js.map +1 -1
  101. package/build/esm/integrations/aws-sdk/services/bedrock-runtime.js +45 -12
  102. package/build/esm/integrations/aws-sdk/services/bedrock-runtime.js.map +1 -1
  103. package/build/esm/integrations/bullmq/contextManager.js +45 -0
  104. package/build/esm/integrations/bullmq/contextManager.js.map +1 -0
  105. package/build/esm/integrations/bullmq/index.js +44 -0
  106. package/build/esm/integrations/bullmq/index.js.map +1 -0
  107. package/build/esm/integrations/bullmq/meter.js +86 -0
  108. package/build/esm/integrations/bullmq/meter.js.map +1 -0
  109. package/build/esm/integrations/bullmq/span.js +114 -0
  110. package/build/esm/integrations/bullmq/span.js.map +1 -0
  111. package/build/esm/integrations/bullmq/tracer.js +62 -0
  112. package/build/esm/integrations/bullmq/tracer.js.map +1 -0
  113. package/build/esm/integrations/cron.js +2 -2
  114. package/build/esm/integrations/cron.js.map +1 -1
  115. package/build/esm/integrations/express/instrumentation.js +10 -1
  116. package/build/esm/integrations/express/instrumentation.js.map +1 -1
  117. package/build/esm/integrations/google-genai.js +26 -14
  118. package/build/esm/integrations/google-genai.js.map +1 -1
  119. package/build/esm/integrations/langgraph.js +5 -7
  120. package/build/esm/integrations/langgraph.js.map +1 -1
  121. package/build/esm/integrations/mastra-classifier.js +1 -1
  122. package/build/esm/integrations/mastra-classifier.js.map +1 -1
  123. package/build/esm/integrations/mistral.js +15 -5
  124. package/build/esm/integrations/mistral.js.map +1 -1
  125. package/build/esm/integrations/node-cron.js +5 -4
  126. package/build/esm/integrations/node-cron.js.map +1 -1
  127. package/build/esm/integrations/node-schedule.js +2 -2
  128. package/build/esm/integrations/node-schedule.js.map +1 -1
  129. package/build/esm/integrations/openai-compatible.js +16 -8
  130. package/build/esm/integrations/openai-compatible.js.map +1 -1
  131. package/build/esm/integrations/openai.js +16 -8
  132. package/build/esm/integrations/openai.js.map +1 -1
  133. package/build/esm/integrations/pi-ai.js +39 -18
  134. package/build/esm/integrations/pi-ai.js.map +1 -1
  135. package/build/esm/integrations/pino.js +131 -0
  136. package/build/esm/integrations/pino.js.map +1 -0
  137. package/build/esm/integrations/typesafe.js +17 -3
  138. package/build/esm/integrations/typesafe.js.map +1 -1
  139. package/build/esm/integrations/vercel-ai/index.js.map +1 -1
  140. package/build/esm/integrations/vercel-ai/util.js +3 -2
  141. package/build/esm/integrations/vercel-ai/util.js.map +1 -1
  142. package/build/esm/integrations/vercel-ai/vercel-ai-dc-subscriber.js +53 -18
  143. package/build/esm/integrations/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
  144. package/build/esm/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.js +22 -16
  145. package/build/esm/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.js.map +1 -1
  146. package/build/esm/integrations/winston.js +90 -0
  147. package/build/esm/integrations/winston.js.map +1 -0
  148. package/build/esm/orchestrion/bundler/moduleInjectedTransform.js +6 -5
  149. package/build/esm/orchestrion/bundler/moduleInjectedTransform.js.map +1 -1
  150. package/build/esm/orchestrion/bundler/rollup.js +4 -4
  151. package/build/esm/orchestrion/bundler/rollup.js.map +1 -1
  152. package/build/esm/orchestrion/config/google-genai.js +19 -5
  153. package/build/esm/orchestrion/config/google-genai.js.map +1 -1
  154. package/build/esm/orchestrion/detect.js +1 -1
  155. package/build/esm/orchestrion/detect.js.map +1 -1
  156. package/build/esm/package.json +1 -1
  157. package/build/esm/utils/cronMonitoring.js +128 -50
  158. package/build/esm/utils/cronMonitoring.js.map +1 -1
  159. package/build/types/ai/anthropic-ai/index.d.ts +1 -5
  160. package/build/types/ai/anthropic-ai/index.d.ts.map +1 -1
  161. package/build/types/ai/anthropic-ai/streaming.d.ts +3 -2
  162. package/build/types/ai/anthropic-ai/streaming.d.ts.map +1 -1
  163. package/build/types/ai/anthropic-ai/tool-runner.d.ts.map +1 -1
  164. package/build/types/ai/anthropic-ai/types.d.ts +24 -3
  165. package/build/types/ai/anthropic-ai/types.d.ts.map +1 -1
  166. package/build/types/ai/anthropic-ai/utils.d.ts +2 -3
  167. package/build/types/ai/anthropic-ai/utils.d.ts.map +1 -1
  168. package/build/types/ai/core/span-hooks.d.ts +31 -0
  169. package/build/types/ai/core/span-hooks.d.ts.map +1 -0
  170. package/build/types/ai/core/time-to-first-chunk.d.ts +7 -0
  171. package/build/types/ai/core/time-to-first-chunk.d.ts.map +1 -0
  172. package/build/types/ai/core/utils.d.ts +30 -1
  173. package/build/types/ai/core/utils.d.ts.map +1 -1
  174. package/build/types/ai/flue/index.d.ts +13 -5
  175. package/build/types/ai/flue/index.d.ts.map +1 -1
  176. package/build/types/ai/flue/types.d.ts +20 -2
  177. package/build/types/ai/flue/types.d.ts.map +1 -1
  178. package/build/types/ai/flue/utils.d.ts +5 -9
  179. package/build/types/ai/flue/utils.d.ts.map +1 -1
  180. package/build/types/ai/google-genai/constants.d.ts +3 -0
  181. package/build/types/ai/google-genai/constants.d.ts.map +1 -1
  182. package/build/types/ai/google-genai/decisions.d.ts +8 -0
  183. package/build/types/ai/google-genai/decisions.d.ts.map +1 -0
  184. package/build/types/ai/google-genai/index.d.ts +3 -1
  185. package/build/types/ai/google-genai/index.d.ts.map +1 -1
  186. package/build/types/ai/google-genai/streaming.d.ts +2 -1
  187. package/build/types/ai/google-genai/streaming.d.ts.map +1 -1
  188. package/build/types/ai/google-genai/types.d.ts +17 -3
  189. package/build/types/ai/google-genai/types.d.ts.map +1 -1
  190. package/build/types/ai/langchain/index.d.ts.map +1 -1
  191. package/build/types/ai/langchain/types.d.ts +49 -3
  192. package/build/types/ai/langchain/types.d.ts.map +1 -1
  193. package/build/types/ai/langchain/utils.d.ts +6 -0
  194. package/build/types/ai/langchain/utils.d.ts.map +1 -1
  195. package/build/types/ai/langgraph/agent-span.d.ts +4 -1
  196. package/build/types/ai/langgraph/agent-span.d.ts.map +1 -1
  197. package/build/types/ai/langgraph/index.d.ts +1 -1
  198. package/build/types/ai/langgraph/index.d.ts.map +1 -1
  199. package/build/types/ai/langgraph/stream.d.ts.map +1 -1
  200. package/build/types/ai/langgraph/types.d.ts +14 -3
  201. package/build/types/ai/langgraph/types.d.ts.map +1 -1
  202. package/build/types/ai/langgraph/utils.d.ts +3 -0
  203. package/build/types/ai/langgraph/utils.d.ts.map +1 -1
  204. package/build/types/ai/mastra/classifier-evaluation.d.ts +3 -3
  205. package/build/types/ai/mastra/classifier-evaluation.d.ts.map +1 -1
  206. package/build/types/ai/mastra/index.d.ts +17 -3
  207. package/build/types/ai/mastra/index.d.ts.map +1 -1
  208. package/build/types/ai/mastra/types.d.ts +2 -0
  209. package/build/types/ai/mastra/types.d.ts.map +1 -1
  210. package/build/types/ai/mastra/utils.d.ts.map +1 -1
  211. package/build/types/ai/mistral/index.d.ts.map +1 -1
  212. package/build/types/ai/mistral/streaming.d.ts +2 -1
  213. package/build/types/ai/mistral/streaming.d.ts.map +1 -1
  214. package/build/types/ai/mistral/types.d.ts +14 -3
  215. package/build/types/ai/mistral/types.d.ts.map +1 -1
  216. package/build/types/ai/mistral/utils.d.ts +5 -0
  217. package/build/types/ai/mistral/utils.d.ts.map +1 -1
  218. package/build/types/ai/openai/index.d.ts.map +1 -1
  219. package/build/types/ai/openai/streaming.d.ts +3 -1
  220. package/build/types/ai/openai/streaming.d.ts.map +1 -1
  221. package/build/types/ai/openai/types.d.ts +14 -3
  222. package/build/types/ai/openai/types.d.ts.map +1 -1
  223. package/build/types/ai/pi-ai/chat.d.ts +7 -1
  224. package/build/types/ai/pi-ai/chat.d.ts.map +1 -1
  225. package/build/types/ai/pi-ai/recording.d.ts +21 -9
  226. package/build/types/ai/pi-ai/recording.d.ts.map +1 -1
  227. package/build/types/ai/pi-ai/types.d.ts +16 -0
  228. package/build/types/ai/pi-ai/types.d.ts.map +1 -1
  229. package/build/types/ai/pi-durable/index.d.ts +12 -3
  230. package/build/types/ai/pi-durable/index.d.ts.map +1 -1
  231. package/build/types/ai/pi-durable/runs.d.ts +2 -0
  232. package/build/types/ai/pi-durable/runs.d.ts.map +1 -1
  233. package/build/types/ai/pi-durable/tools.d.ts +4 -3
  234. package/build/types/ai/pi-durable/tools.d.ts.map +1 -1
  235. package/build/types/ai/pi-durable/types.d.ts +15 -0
  236. package/build/types/ai/pi-durable/types.d.ts.map +1 -1
  237. package/build/types/ai/typesafe/index.d.ts +10 -2
  238. package/build/types/ai/typesafe/index.d.ts.map +1 -1
  239. package/build/types/ai/vercel-ai/index.d.ts.map +1 -1
  240. package/build/types/ai/vercel-ai/vercel-ai-attributes.d.ts +3 -0
  241. package/build/types/ai/vercel-ai/vercel-ai-attributes.d.ts.map +1 -1
  242. package/build/types/ai/workers-ai/index.d.ts.map +1 -1
  243. package/build/types/ai/workers-ai/streaming.d.ts +2 -1
  244. package/build/types/ai/workers-ai/streaming.d.ts.map +1 -1
  245. package/build/types/ai/workers-ai/types.d.ts +18 -3
  246. package/build/types/ai/workers-ai/types.d.ts.map +1 -1
  247. package/build/types/cron/common.d.ts +8 -0
  248. package/build/types/cron/common.d.ts.map +1 -0
  249. package/build/types/cron/cron.d.ts +45 -0
  250. package/build/types/cron/cron.d.ts.map +1 -0
  251. package/build/types/cron/index.d.ts +10 -0
  252. package/build/types/cron/index.d.ts.map +1 -0
  253. package/build/types/cron/node-cron.d.ts +33 -0
  254. package/build/types/cron/node-cron.d.ts.map +1 -0
  255. package/build/types/cron/node-schedule.d.ts +19 -0
  256. package/build/types/cron/node-schedule.d.ts.map +1 -0
  257. package/build/types/index.d.ts +5 -0
  258. package/build/types/index.d.ts.map +1 -1
  259. package/build/types/integrations/anthropic.d.ts +2 -1
  260. package/build/types/integrations/anthropic.d.ts.map +1 -1
  261. package/build/types/integrations/aws-sdk/index.d.ts +3 -3
  262. package/build/types/integrations/aws-sdk/index.d.ts.map +1 -1
  263. package/build/types/integrations/aws-sdk/services/ServiceExtension.d.ts +1 -0
  264. package/build/types/integrations/aws-sdk/services/ServiceExtension.d.ts.map +1 -1
  265. package/build/types/integrations/aws-sdk/services/ServicesExtensions.d.ts +3 -2
  266. package/build/types/integrations/aws-sdk/services/ServicesExtensions.d.ts.map +1 -1
  267. package/build/types/integrations/aws-sdk/services/bedrock-runtime.d.ts +25 -4
  268. package/build/types/integrations/aws-sdk/services/bedrock-runtime.d.ts.map +1 -1
  269. package/build/types/integrations/bullmq/contextManager.d.ts +13 -0
  270. package/build/types/integrations/bullmq/contextManager.d.ts.map +1 -0
  271. package/build/types/integrations/bullmq/index.d.ts +43 -0
  272. package/build/types/integrations/bullmq/index.d.ts.map +1 -0
  273. package/build/types/integrations/bullmq/meter.d.ts +7 -0
  274. package/build/types/integrations/bullmq/meter.d.ts.map +1 -0
  275. package/build/types/integrations/bullmq/span.d.ts +35 -0
  276. package/build/types/integrations/bullmq/span.d.ts.map +1 -0
  277. package/build/types/integrations/bullmq/tracer.d.ts +5 -0
  278. package/build/types/integrations/bullmq/tracer.d.ts.map +1 -0
  279. package/build/types/integrations/bullmq/types.d.ts +72 -0
  280. package/build/types/integrations/bullmq/types.d.ts.map +1 -0
  281. package/build/types/integrations/cron.d.ts.map +1 -1
  282. package/build/types/integrations/express/types.d.ts +1 -0
  283. package/build/types/integrations/express/types.d.ts.map +1 -1
  284. package/build/types/integrations/flue.d.ts +2 -1
  285. package/build/types/integrations/flue.d.ts.map +1 -1
  286. package/build/types/integrations/google-genai.d.ts +5 -4
  287. package/build/types/integrations/google-genai.d.ts.map +1 -1
  288. package/build/types/integrations/groq.d.ts +1 -1
  289. package/build/types/integrations/langchain.d.ts +2 -1
  290. package/build/types/integrations/langchain.d.ts.map +1 -1
  291. package/build/types/integrations/langgraph.d.ts +2 -1
  292. package/build/types/integrations/langgraph.d.ts.map +1 -1
  293. package/build/types/integrations/mistral.d.ts +2 -1
  294. package/build/types/integrations/mistral.d.ts.map +1 -1
  295. package/build/types/integrations/node-cron.d.ts +1 -1
  296. package/build/types/integrations/node-cron.d.ts.map +1 -1
  297. package/build/types/integrations/node-schedule.d.ts.map +1 -1
  298. package/build/types/integrations/openai-compatible.d.ts.map +1 -1
  299. package/build/types/integrations/openai.d.ts +2 -1
  300. package/build/types/integrations/openai.d.ts.map +1 -1
  301. package/build/types/integrations/pi-ai.d.ts +6 -3
  302. package/build/types/integrations/pi-ai.d.ts.map +1 -1
  303. package/build/types/integrations/pi-durable.d.ts +2 -1
  304. package/build/types/integrations/pi-durable.d.ts.map +1 -1
  305. package/build/types/integrations/pino.d.ts +61 -0
  306. package/build/types/integrations/pino.d.ts.map +1 -0
  307. package/build/types/integrations/together-ai.d.ts +1 -1
  308. package/build/types/integrations/typesafe.d.ts +2 -2
  309. package/build/types/integrations/typesafe.d.ts.map +1 -1
  310. package/build/types/integrations/vercel-ai/index.d.ts +3 -3
  311. package/build/types/integrations/vercel-ai/index.d.ts.map +1 -1
  312. package/build/types/integrations/vercel-ai/util.d.ts +2 -1
  313. package/build/types/integrations/vercel-ai/util.d.ts.map +1 -1
  314. package/build/types/integrations/vercel-ai/vercel-ai-dc-subscriber.d.ts +20 -4
  315. package/build/types/integrations/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -1
  316. package/build/types/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.d.ts.map +1 -1
  317. package/build/types/integrations/winston.d.ts +55 -0
  318. package/build/types/integrations/winston.d.ts.map +1 -0
  319. package/build/types/orchestrion/bundler/moduleInjectedTransform.d.ts.map +1 -1
  320. package/build/types/orchestrion/bundler/rollup.d.ts +3 -3
  321. package/build/types/orchestrion/bundler/rollup.d.ts.map +1 -1
  322. package/build/types/orchestrion/channels.d.ts +1 -0
  323. package/build/types/orchestrion/channels.d.ts.map +1 -1
  324. package/build/types/orchestrion/config/google-genai.d.ts +13 -0
  325. package/build/types/orchestrion/config/google-genai.d.ts.map +1 -1
  326. package/build/types/utils/cronMonitoring.d.ts +4 -5
  327. package/build/types/utils/cronMonitoring.d.ts.map +1 -1
  328. package/package.json +3 -3
@@ -10,7 +10,7 @@ const googleGenAiConfig = [
10
10
  channelName: "generate-content",
11
11
  module: {
12
12
  name: "@google/genai",
13
- versionRange: ">=0.10.0 <3",
13
+ versionRange: ">=0.10.0 <4",
14
14
  filePath
15
15
  },
16
16
  functionQuery: {
@@ -22,7 +22,7 @@ const googleGenAiConfig = [
22
22
  channelName: "embed-content",
23
23
  module: {
24
24
  name: "@google/genai",
25
- versionRange: ">=0.10.0 <3",
25
+ versionRange: ">=0.10.0 <4",
26
26
  filePath
27
27
  },
28
28
  functionQuery: {
@@ -35,7 +35,7 @@ const googleGenAiConfig = [
35
35
  channelName: "chat",
36
36
  module: {
37
37
  name: "@google/genai",
38
- versionRange: ">=0.10.0 <3",
38
+ versionRange: ">=0.10.0 <4",
39
39
  filePath
40
40
  },
41
41
  functionQuery: {
@@ -43,13 +43,27 @@ const googleGenAiConfig = [
43
43
  methodName,
44
44
  kind: "Auto"
45
45
  }
46
- })))
46
+ }))),
47
+ ...NODE_DIST_FILES.map((filePath) => ({
48
+ channelName: "decide",
49
+ module: {
50
+ name: "@google/genai",
51
+ versionRange: ">=3.2.0 <4",
52
+ filePath
53
+ },
54
+ functionQuery: {
55
+ className: "GeminiNextGenDecisions",
56
+ methodName: "create",
57
+ kind: "Async"
58
+ }
59
+ }))
47
60
  ];
48
61
  const googleGenAiModuleNames = getModuleNames(googleGenAiConfig);
49
62
  const googleGenAiChannels = {
50
63
  GOOGLE_GENAI_GENERATE_CONTENT: "orchestrion:@google/genai:generate-content",
51
64
  GOOGLE_GENAI_EMBED_CONTENT: "orchestrion:@google/genai:embed-content",
52
- GOOGLE_GENAI_CHAT: "orchestrion:@google/genai:chat"
65
+ GOOGLE_GENAI_CHAT: "orchestrion:@google/genai:chat",
66
+ GOOGLE_GENAI_DECIDE: "orchestrion:@google/genai:decide"
53
67
  };
54
68
  export { googleGenAiChannels, googleGenAiConfig, googleGenAiModuleNames };
55
69
 
@@ -1 +1 @@
1
- {"version":3,"file":"google-genai.js","names":[],"sources":["../../../../src/orchestrion/config/google-genai.ts"],"sourcesContent":["import type { InstrumentationConfig } from '../apmTypes';\n\nimport { getModuleNames } from './module-names';\n\n// `@google/genai` ships one bundled file per module format and the matcher compares `filePath` exactly,\n// so we list every file the `node` export condition resolves to across the supported range: `index.js`\n// (ESM+CJS for <0.15.0, CJS for <1.1.0), `index.mjs` (ESM for >=0.15.0), and `index.cjs` (CJS for >=1.1.0).\n// A file that doesn't exist in a given version simply never matches, so listing all three is safe.\nconst NODE_DIST_FILES = ['dist/node/index.js', 'dist/node/index.mjs', 'dist/node/index.cjs'];\n\nexport const googleGenAiConfig = [\n // `generateContent`/`generateContentStream` are arrow properties assigned in the constructor, not class\n // methods, so they need `expressionName` rather than `className`/`methodName`.\n ...NODE_DIST_FILES.flatMap(filePath =>\n (['generateContent', 'generateContentStream'] as const).map(expressionName => ({\n channelName: 'generate-content',\n module: { name: '@google/genai', versionRange: '>=0.10.0 <3', filePath },\n functionQuery: { expressionName, kind: 'Auto' as const },\n })),\n ),\n // `embedContent` is a real class method in v1 but a constructor-assigned arrow in v2; the\n // `className`/`methodName` selector matches both shapes.\n ...NODE_DIST_FILES.map(filePath => ({\n channelName: 'embed-content',\n module: { name: '@google/genai', versionRange: '>=0.10.0 <3', filePath },\n functionQuery: { className: 'Models', methodName: 'embedContent', kind: 'Auto' as const },\n })),\n // `sendMessage`/`sendMessageStream` internally delegate to `Models.generateContent(Stream)`; the\n // subscriber suppresses that nested `generate-content` event so a chat call yields a single span.\n ...NODE_DIST_FILES.flatMap(filePath =>\n (['sendMessage', 'sendMessageStream'] as const).map(methodName => ({\n channelName: 'chat',\n module: { name: '@google/genai', versionRange: '>=0.10.0 <3', filePath },\n functionQuery: { className: 'Chat', methodName, kind: 'Auto' as const },\n })),\n ),\n] satisfies InstrumentationConfig[];\n\nexport const googleGenAiModuleNames = getModuleNames(googleGenAiConfig);\n\nexport const googleGenAiChannels = {\n GOOGLE_GENAI_GENERATE_CONTENT: 'orchestrion:@google/genai:generate-content',\n GOOGLE_GENAI_EMBED_CONTENT: 'orchestrion:@google/genai:embed-content',\n GOOGLE_GENAI_CHAT: 'orchestrion:@google/genai:chat',\n} as const;\n"],"mappings":";;AAQA,MAAM,kBAAkB;CAAC;CAAsB;CAAuB;AAAqB;AAE3F,MAAa,oBAAoB;CAG/B,GAAG,gBAAgB,SAAQ,aACxB,CAAC,mBAAmB,uBAAuB,CAAC,CAAW,KAAI,oBAAmB;EAC7E,aAAa;EACb,QAAQ;GAAE,MAAM;GAAiB,cAAc;GAAe;EAAS;EACvE,eAAe;GAAE;GAAgB,MAAM;EAAgB;CACzD,EAAE,CACJ;CAGA,GAAG,gBAAgB,KAAI,cAAa;EAClC,aAAa;EACb,QAAQ;GAAE,MAAM;GAAiB,cAAc;GAAe;EAAS;EACvE,eAAe;GAAE,WAAW;GAAU,YAAY;GAAgB,MAAM;EAAgB;CAC1F,EAAE;CAGF,GAAG,gBAAgB,SAAQ,aACxB,CAAC,eAAe,mBAAmB,CAAC,CAAW,KAAI,gBAAe;EACjE,aAAa;EACb,QAAQ;GAAE,MAAM;GAAiB,cAAc;GAAe;EAAS;EACvE,eAAe;GAAE,WAAW;GAAQ;GAAY,MAAM;EAAgB;CACxE,EAAE,CACJ;AACF;AAEA,MAAa,yBAAyB,eAAe,iBAAiB;AAEtE,MAAa,sBAAsB;CACjC,+BAA+B;CAC/B,4BAA4B;CAC5B,mBAAmB;AACrB"}
1
+ {"version":3,"file":"google-genai.js","names":[],"sources":["../../../../src/orchestrion/config/google-genai.ts"],"sourcesContent":["import type { InstrumentationConfig } from '../apmTypes';\n\nimport { getModuleNames } from './module-names';\n\n// `@google/genai` ships one bundled file per module format and the matcher compares `filePath` exactly,\n// so we list every file the `node` export condition resolves to across the supported range: `index.js`\n// (ESM+CJS for <0.15.0, CJS for <1.1.0), `index.mjs` (ESM for >=0.15.0), and `index.cjs` (CJS for >=1.1.0).\n// A file that doesn't exist in a given version simply never matches, so listing all three is safe.\nconst NODE_DIST_FILES = ['dist/node/index.js', 'dist/node/index.mjs', 'dist/node/index.cjs'];\n\nexport const googleGenAiConfig = [\n // `generateContent`/`generateContentStream` are arrow properties assigned in the constructor, not class\n // methods, so they need `expressionName` rather than `className`/`methodName`.\n ...NODE_DIST_FILES.flatMap(filePath =>\n (['generateContent', 'generateContentStream'] as const).map(expressionName => ({\n channelName: 'generate-content',\n module: { name: '@google/genai', versionRange: '>=0.10.0 <4', filePath },\n functionQuery: { expressionName, kind: 'Auto' as const },\n })),\n ),\n // `embedContent` is a real class method in v1 but a constructor-assigned arrow in v2; the\n // `className`/`methodName` selector matches both shapes.\n ...NODE_DIST_FILES.map(filePath => ({\n channelName: 'embed-content',\n module: { name: '@google/genai', versionRange: '>=0.10.0 <4', filePath },\n functionQuery: { className: 'Models', methodName: 'embedContent', kind: 'Auto' as const },\n })),\n // `sendMessage`/`sendMessageStream` internally delegate to `Models.generateContent(Stream)`; the\n // subscriber suppresses that nested `generate-content` event so a chat call yields a single span.\n ...NODE_DIST_FILES.flatMap(filePath =>\n (['sendMessage', 'sendMessageStream'] as const).map(methodName => ({\n channelName: 'chat',\n module: { name: '@google/genai', versionRange: '>=0.10.0 <4', filePath },\n functionQuery: { className: 'Chat', methodName, kind: 'Auto' as const },\n })),\n ),\n // `client.decisions` (`@google/genai` >= 3.2.0) returns typed answers rather than generated content.\n ...NODE_DIST_FILES.map(filePath => ({\n channelName: 'decide',\n module: { name: '@google/genai', versionRange: '>=3.2.0 <4', filePath },\n functionQuery: { className: 'GeminiNextGenDecisions', methodName: 'create', kind: 'Async' as const },\n })),\n] satisfies InstrumentationConfig[];\n\nexport const googleGenAiModuleNames = getModuleNames(googleGenAiConfig);\n\nexport const googleGenAiChannels = {\n GOOGLE_GENAI_GENERATE_CONTENT: 'orchestrion:@google/genai:generate-content',\n GOOGLE_GENAI_EMBED_CONTENT: 'orchestrion:@google/genai:embed-content',\n GOOGLE_GENAI_CHAT: 'orchestrion:@google/genai:chat',\n GOOGLE_GENAI_DECIDE: 'orchestrion:@google/genai:decide',\n} as const;\n"],"mappings":";;AAQA,MAAM,kBAAkB;CAAC;CAAsB;CAAuB;AAAqB;AAE3F,MAAa,oBAAoB;CAG/B,GAAG,gBAAgB,SAAQ,aACxB,CAAC,mBAAmB,uBAAuB,CAAC,CAAW,KAAI,oBAAmB;EAC7E,aAAa;EACb,QAAQ;GAAE,MAAM;GAAiB,cAAc;GAAe;EAAS;EACvE,eAAe;GAAE;GAAgB,MAAM;EAAgB;CACzD,EAAE,CACJ;CAGA,GAAG,gBAAgB,KAAI,cAAa;EAClC,aAAa;EACb,QAAQ;GAAE,MAAM;GAAiB,cAAc;GAAe;EAAS;EACvE,eAAe;GAAE,WAAW;GAAU,YAAY;GAAgB,MAAM;EAAgB;CAC1F,EAAE;CAGF,GAAG,gBAAgB,SAAQ,aACxB,CAAC,eAAe,mBAAmB,CAAC,CAAW,KAAI,gBAAe;EACjE,aAAa;EACb,QAAQ;GAAE,MAAM;GAAiB,cAAc;GAAe;EAAS;EACvE,eAAe;GAAE,WAAW;GAAQ;GAAY,MAAM;EAAgB;CACxE,EAAE,CACJ;CAEA,GAAG,gBAAgB,KAAI,cAAa;EAClC,aAAa;EACb,QAAQ;GAAE,MAAM;GAAiB,cAAc;GAAc;EAAS;EACtE,eAAe;GAAE,WAAW;GAA0B,YAAY;GAAU,MAAM;EAAiB;CACrG,EAAE;AACJ;AAEA,MAAa,yBAAyB,eAAe,iBAAiB;AAEtE,MAAa,sBAAsB;CACjC,+BAA+B;CAC/B,4BAA4B;CAC5B,mBAAmB;CACnB,qBAAqB;AACvB"}
@@ -39,7 +39,7 @@ function detectOrchestrionSetup() {
39
39
  if (!marker.warnedBunRunNotInjected) {
40
40
  marker.warnedBunRunNotInjected = true;
41
41
  consoleSandbox(() => {
42
- console.warn("[Sentry] No diagnostics-channel injection detected. Channel-based integrations will not record spans or capture errors, because Bun cannot instrument modules at runtime. Build your app with `@sentry/bun/plugin` to enable them.");
42
+ console.warn("[Sentry] No diagnostics-channel injection detected. Channel-based integrations will not record spans or capture errors. On Bun 1.4.6 or later, run your app with `bun --preload @sentry/bun/import`. Or build your app with `@sentry/bun/plugin`.");
43
43
  });
44
44
  }
45
45
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"detect.js","names":[],"sources":["../../../src/orchestrion/detect.ts"],"sourcesContent":["import { consoleSandbox, debug, GLOBAL_OBJ } from '@sentry/core';\nimport { isBun } from '../utils/runtime';\n\n/**\n * The module names (e.g. `mysql`, `@hapi/hapi`) orchestrion has already injected\n * into this process — from the runtime `--import` hook (`runtime`) and/or the\n * snippets a bundler transform spliced into each transformed module (`bundler`).\n * Channel-based integrations use it to decide whether to subscribe now (their\n * module is already loaded) or wait for the module-injected event.\n *\n * The `instanceof Set` guard is runtime safety, not typing: a banner from\n * another SDK copy or version may have written a non-Set flag here.\n */\nexport function getOrchestrionInjectedModules(): string[] {\n const { runtime, bundler } = GLOBAL_OBJ.__SENTRY_ORCHESTRION__ ?? {};\n return [...(runtime ?? []), ...(bundler instanceof Set ? bundler : [])];\n}\n\n/**\n * Verifies that the diagnostics channels have been injected either by the\n * runtime `--import` hook (or init-time registration), a bundler plugin, or\n * both, and warns if not. When at least one injector is active, logs for each\n * mechanism whether it hooked (a defined list, even empty, means it did) and\n * which libraries it injected. For the bundler path, the entry banner ensures\n * an empty `Set` at boot; module names arrive as each transformed module is\n * evaluated, so an empty set can also just mean none has loaded yet.\n *\n * Both injectors being active at once is fine: they operate on disjoint module\n * sets (a module is either loaded through Node's loader and transformed by the\n * runtime hook, or inlined by the bundler and transformed by the plugin), so\n * a single module can't be double-wrapped. A hybrid setup, with some deps\n * external and runtime-instrumented, others bundled and plugin-instrumented,\n * is fine.\n */\nexport function detectOrchestrionSetup(): void {\n const marker = GLOBAL_OBJ.__SENTRY_ORCHESTRION__ ?? {};\n const { runtime, bundler, channelIntegrations } = marker;\n\n if (!runtime && !bundler) {\n if (channelIntegrations && isBun()) {\n if (!marker.warnedBunRunNotInjected) {\n marker.warnedBunRunNotInjected = true;\n consoleSandbox(() => {\n // oxlint-disable-next-line no-console\n console.warn(\n '[Sentry] No diagnostics-channel injection detected. Channel-based integrations will not record ' +\n 'spans or capture errors, because Bun cannot instrument modules at runtime. Build your app with ' +\n '`@sentry/bun/plugin` to enable them.',\n );\n });\n }\n return;\n }\n\n debug.warn(\n '[Sentry] No diagnostics-channel injection detected. Channel-based integrations ' +\n 'will not record spans. Make sure the diagnostics channels are injected ' +\n 'via the runtime `--import` hook or a bundler plugin before the instrumented modules load.',\n );\n return;\n }\n\n debug.log(\n runtime\n ? `[Sentry] Runtime hook registered, injected libraries=${JSON.stringify(runtime)}`\n : '[Sentry] Runtime hook not registered',\n );\n debug.log(\n bundler\n ? `[Sentry] Bundler plugin ran, injected libraries=${JSON.stringify(\n bundler instanceof Set ? [...bundler] : bundler,\n )}`\n : '[Sentry] Bundler plugin did not run',\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,gCAA0C;CACxD,MAAM,EAAE,SAAS,YAAY,WAAW,0BAA0B,CAAC;CACnE,OAAO,CAAC,GAAI,WAAW,CAAC,GAAI,GAAI,mBAAmB,MAAM,UAAU,CAAC,CAAE;AACxE;;;;;;;;;;;;;;;;;AAkBA,SAAgB,yBAA+B;CAC7C,MAAM,SAAS,WAAW,0BAA0B,CAAC;CACrD,MAAM,EAAE,SAAS,SAAS,wBAAwB;CAElD,IAAI,CAAC,WAAW,CAAC,SAAS;EACxB,IAAI,uBAAuB,MAAM,GAAG;GAClC,IAAI,CAAC,OAAO,yBAAyB;IACnC,OAAO,0BAA0B;IACjC,qBAAqB;KAEnB,QAAQ,KACN,oOAGF;IACF,CAAC;GACH;GACA;EACF;EAEA,MAAM,KACJ,iPAGF;EACA;CACF;CAEA,MAAM,IACJ,UACI,wDAAwD,KAAK,UAAU,OAAO,MAC9E,sCACN;CACA,MAAM,IACJ,UACI,mDAAmD,KAAK,UACtD,mBAAmB,MAAM,CAAC,GAAG,OAAO,IAAI,OAC1C,MACA,qCACN;AACF"}
1
+ {"version":3,"file":"detect.js","names":[],"sources":["../../../src/orchestrion/detect.ts"],"sourcesContent":["import { consoleSandbox, debug, GLOBAL_OBJ } from '@sentry/core';\nimport { isBun } from '../utils/runtime';\n\n/**\n * The module names (e.g. `mysql`, `@hapi/hapi`) orchestrion has already injected\n * into this process — from the runtime `--import` hook (`runtime`) and/or the\n * snippets a bundler transform spliced into each transformed module (`bundler`).\n * Channel-based integrations use it to decide whether to subscribe now (their\n * module is already loaded) or wait for the module-injected event.\n *\n * The `instanceof Set` guard is runtime safety, not typing: a banner from\n * another SDK copy or version may have written a non-Set flag here.\n */\nexport function getOrchestrionInjectedModules(): string[] {\n const { runtime, bundler } = GLOBAL_OBJ.__SENTRY_ORCHESTRION__ ?? {};\n return [...(runtime ?? []), ...(bundler instanceof Set ? bundler : [])];\n}\n\n/**\n * Verifies that the diagnostics channels have been injected either by the\n * runtime `--import` hook (or init-time registration), a bundler plugin, or\n * both, and warns if not. When at least one injector is active, logs for each\n * mechanism whether it hooked (a defined list, even empty, means it did) and\n * which libraries it injected. For the bundler path, the entry banner ensures\n * an empty `Set` at boot; module names arrive as each transformed module is\n * evaluated, so an empty set can also just mean none has loaded yet.\n *\n * Both injectors being active at once is fine: they operate on disjoint module\n * sets (a module is either loaded through Node's loader and transformed by the\n * runtime hook, or inlined by the bundler and transformed by the plugin), so\n * a single module can't be double-wrapped. A hybrid setup, with some deps\n * external and runtime-instrumented, others bundled and plugin-instrumented,\n * is fine.\n */\nexport function detectOrchestrionSetup(): void {\n const marker = GLOBAL_OBJ.__SENTRY_ORCHESTRION__ ?? {};\n const { runtime, bundler, channelIntegrations } = marker;\n\n if (!runtime && !bundler) {\n if (channelIntegrations && isBun()) {\n if (!marker.warnedBunRunNotInjected) {\n marker.warnedBunRunNotInjected = true;\n consoleSandbox(() => {\n // oxlint-disable-next-line no-console\n console.warn(\n '[Sentry] No diagnostics-channel injection detected. Channel-based integrations will not record ' +\n 'spans or capture errors. On Bun 1.4.6 or later, run your app with `bun --preload @sentry/bun/import`. ' +\n 'Or build your app with `@sentry/bun/plugin`.',\n );\n });\n }\n return;\n }\n\n debug.warn(\n '[Sentry] No diagnostics-channel injection detected. Channel-based integrations ' +\n 'will not record spans. Make sure the diagnostics channels are injected ' +\n 'via the runtime `--import` hook or a bundler plugin before the instrumented modules load.',\n );\n return;\n }\n\n debug.log(\n runtime\n ? `[Sentry] Runtime hook registered, injected libraries=${JSON.stringify(runtime)}`\n : '[Sentry] Runtime hook not registered',\n );\n debug.log(\n bundler\n ? `[Sentry] Bundler plugin ran, injected libraries=${JSON.stringify(\n bundler instanceof Set ? [...bundler] : bundler,\n )}`\n : '[Sentry] Bundler plugin did not run',\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,gCAA0C;CACxD,MAAM,EAAE,SAAS,YAAY,WAAW,0BAA0B,CAAC;CACnE,OAAO,CAAC,GAAI,WAAW,CAAC,GAAI,GAAI,mBAAmB,MAAM,UAAU,CAAC,CAAE;AACxE;;;;;;;;;;;;;;;;;AAkBA,SAAgB,yBAA+B;CAC7C,MAAM,SAAS,WAAW,0BAA0B,CAAC;CACrD,MAAM,EAAE,SAAS,SAAS,wBAAwB;CAElD,IAAI,CAAC,WAAW,CAAC,SAAS;EACxB,IAAI,uBAAuB,MAAM,GAAG;GAClC,IAAI,CAAC,OAAO,yBAAyB;IACnC,OAAO,0BAA0B;IACjC,qBAAqB;KAEnB,QAAQ,KACN,mPAGF;IACF,CAAC;GACH;GACA;EACF;EAEA,MAAM,KACJ,iPAGF;EACA;CACF;CAEA,MAAM,IACJ,UACI,wDAAwD,KAAK,UAAU,OAAO,MAC9E,sCACN;CACA,MAAM,IACJ,UACI,mDAAmD,KAAK,UACtD,mBAAmB,MAAM,CAAC,GAAG,OAAO,IAAI,OAC1C,MACA,qCACN;AACF"}
@@ -1 +1 @@
1
- {"type":"module","version":"11.13.0","sideEffects":false}
1
+ {"type":"module","version":"11.15.0","sideEffects":false}
@@ -36,61 +36,71 @@ function subscribeToScheduleChange(channelName, integrationName, onChange, onSta
36
36
  function shouldMonitorJob(name, job, excludeJobs) {
37
37
  return typeof name === "string" && !!name && typeof job === "function" && !job[MONITORED] && !stringMatchesSomePattern(name, excludeJobs, true);
38
38
  }
39
- const NICKNAMES = {
39
+ const COMMON_NICKNAMES = {
40
40
  "@yearly": "0 0 1 1 *",
41
- "@annually": "0 0 1 1 *",
42
41
  "@monthly": "0 0 1 * *",
43
42
  "@weekly": "0 0 * * 0",
44
43
  "@daily": "0 0 * * *",
45
- "@midnight": "0 0 * * *",
46
- "@hourly": "0 * * * *",
47
- "@minutely": "* * * * *",
48
- "@weekdays": "0 0 * * 1-5",
49
- "@weekends": "0 0 * * 0,6"
44
+ "@hourly": "0 * * * *"
45
+ };
46
+ const NICKNAMES = {
47
+ "node-cron": {
48
+ ...COMMON_NICKNAMES,
49
+ "@annually": "0 0 1 1 *",
50
+ "@midnight": "0 0 * * *"
51
+ },
52
+ cron: {
53
+ ...COMMON_NICKNAMES,
54
+ "@minutely": "* * * * *",
55
+ "@weekdays": "0 0 * * 1-5",
56
+ "@weekends": "0 0 * * 0,6"
57
+ },
58
+ "cron-parser": COMMON_NICKNAMES
50
59
  };
51
60
  const MONTHS = [
52
- "jan",
53
- "feb",
54
- "mar",
55
- "apr",
61
+ "january",
62
+ "february",
63
+ "march",
64
+ "april",
56
65
  "may",
57
- "jun",
58
- "jul",
59
- "aug",
60
- "sep",
61
- "oct",
62
- "nov",
63
- "dec"
66
+ "june",
67
+ "july",
68
+ "august",
69
+ "september",
70
+ "october",
71
+ "november",
72
+ "december"
64
73
  ];
65
74
  const WEEKDAYS = [
66
- "sun",
67
- "mon",
68
- "tue",
69
- "wed",
70
- "thu",
71
- "fri",
72
- "sat"
75
+ "sunday",
76
+ "monday",
77
+ "tuesday",
78
+ "wednesday",
79
+ "thursday",
80
+ "friday",
81
+ "saturday"
73
82
  ];
74
83
  /**
75
84
  * The Sentry monitor config for a cron expression, or `undefined` if Sentry would read it differently.
76
85
  * Without a `timezone`, the server's time zone is used, like the schedulers do.
77
86
  */
78
- function cronExpressionToMonitorConfig(expression, timezone, daySemantics) {
87
+ function cronExpressionToMonitorConfig(expression, timezone, dialect) {
79
88
  const trimmed = expression.trim();
80
- const fields = (NICKNAMES[trimmed.toLowerCase()] || trimmed).split(/\s+/);
89
+ const fields = (NICKNAMES[dialect][trimmed.toLowerCase()] || trimmed).split(/\s+/);
81
90
  if (fields.length === 6 && /^\d+$/.test(fields[0])) fields.shift();
82
- if (fields.length !== 5 || !fields.every((field) => /^[\d*,/a-z-]+$/i.test(field))) return;
83
- const [minute, hour, dayOfMonth, month, dayOfWeekWithNames] = fields;
84
- const dayOfWeek = replaceNames(dayOfWeekWithNames, WEEKDAYS, 0);
85
- if (!isSameDayMatching(dayOfMonth, dayOfWeek, daySemantics)) return;
91
+ if (fields.length !== 5 || !fields.every((field) => /^[\d*,/a-z#-]+$/i.test(field))) return;
92
+ const [minute, hour, dayOfMonth, month, dayOfWeek] = fields;
93
+ const monthNumbers = replaceNames(month, MONTHS, 1, dialect);
94
+ const weekdayNames = replaceNames(dayOfWeek, WEEKDAYS, 0, dialect);
95
+ const weekdayNumbers = dialect === "node-cron" ? endRangesOnSundayAsSeven(weekdayNames) : weekdayNames;
86
96
  const crontab = [
87
97
  minute,
88
98
  hour,
89
99
  dayOfMonth,
90
- replaceNames(month, MONTHS, 1),
91
- endRangesOnSundayAsSeven(dayOfWeek)
100
+ monthNumbers,
101
+ weekdayNumbers
92
102
  ];
93
- if (crontab.some((field) => /[a-z]/i.test(field) || hasReversedRange(field))) return;
103
+ if (crontab.some((field, index) => hasUnsupportedCharacter(field, dialect === "cron-parser" ? CRON_PARSER_DAY_TOKENS[index] : void 0) || hasReversedRange(field) || hasSteppedSingleValueRange(field)) || !isSameDayMatching(dayOfMonth, weekdayNumbers, dialect) || !hasDayInSelectedMonths(dayOfMonth, monthNumbers)) return;
94
104
  const sentryTimezone = toSentryTimezone(typeof timezone === "string" && timezone ? timezone : void 0);
95
105
  if (!sentryTimezone) return;
96
106
  return {
@@ -101,31 +111,93 @@ function cronExpressionToMonitorConfig(expression, timezone, daySemantics) {
101
111
  timezone: sentryTimezone
102
112
  };
103
113
  }
104
- function isSameDayMatching(dayOfMonth, dayOfWeek, daySemantics) {
105
- if (dayOfMonth === "*" || dayOfWeek === "*") return true;
106
- if (daySemantics === "and") return dayOfMonth.startsWith("*") || dayOfWeek.startsWith("*");
107
- return !(dayOfMonth.startsWith("*") || dayOfWeek.startsWith("*") || countValues(dayOfMonth, 1, 31) >= 29 || countValues(dayOfWeek, 0, 7, (day) => day % 7) === 7);
114
+ const CRON_PARSER_DAY_TOKENS = [
115
+ void 0,
116
+ void 0,
117
+ /^L$/,
118
+ void 0,
119
+ /^[0-7](?:L|#[1-5])$/
120
+ ];
121
+ function hasUnsupportedCharacter(field, dayToken) {
122
+ return field.split(",").some((part) => /[a-z#]/i.test(part) && !dayToken?.test(part));
123
+ }
124
+ function isSameDayMatching(dayOfMonth, dayOfWeek, dialect) {
125
+ const monthDays = parseDayField(dayOfMonth, 1, 31);
126
+ const weekdays = parseDayField(dayOfWeek, 0, 7);
127
+ if (!monthDays || !weekdays) return false;
128
+ const sentryNeedsBoth = dayOfMonth.startsWith("*") || dayOfWeek.startsWith("*");
129
+ if (dialect === "cron-parser") return isSameDayMatchingInCronParser(dayOfMonth, dayOfWeek, monthDays, weekdays, sentryNeedsBoth);
130
+ const allMonthDays = monthDays.days === 31;
131
+ const allWeekdays = weekdays.days === 7;
132
+ return allMonthDays && allWeekdays || (dialect === "node-cron" || allMonthDays || allWeekdays) === sentryNeedsBoth;
133
+ }
134
+ function isSameDayMatchingInCronParser(dayOfMonth, dayOfWeek, monthDays, weekdays, sentryNeedsBoth) {
135
+ if (weekdays.cronParserAddsSunday || dayOfWeek.includes("#") && (dayOfMonth !== "*" || dayOfWeek.includes(","))) return false;
136
+ if (dayOfWeek === "*") return true;
137
+ if (dayOfMonth === "*") return weekdays.cronParserValues !== 8 || weekdays.days === 7;
138
+ return !sentryNeedsBoth && monthDays.cronParserValues < 29 && weekdays.cronParserValues !== 8;
139
+ }
140
+ const DAYS_IN_MONTH = [
141
+ 31,
142
+ 29,
143
+ 31,
144
+ 30,
145
+ 31,
146
+ 30,
147
+ 31,
148
+ 31,
149
+ 30,
150
+ 31,
151
+ 30,
152
+ 31
153
+ ];
154
+ function hasDayInSelectedMonths(dayOfMonth, month) {
155
+ const days = parseDayField(dayOfMonth, 1, 31)?.values;
156
+ const months = parseDayField(month, 1, 12)?.values;
157
+ if (!days || !months) return false;
158
+ return !days.size || Math.min(...days) <= Math.max(...[...months].map((m) => DAYS_IN_MONTH[m - 1]));
108
159
  }
109
- function countValues(field, min, max, normalize = (value) => value) {
110
- const values = /* @__PURE__ */ new Set();
160
+ function parseDayField(field, low, high) {
161
+ const days = /* @__PURE__ */ new Set();
162
+ let cronParserValues = 0;
163
+ let cronParserListsSunday = false;
111
164
  for (const part of field.split(",")) {
112
- const match = /^(?:\*|(\d+)(?:-(\d+))?)(?:\/(\d+))?$/.exec(part);
113
- if (!match) continue;
114
- const [, start, end, step] = match;
115
- const first = start === void 0 ? min : Number(start);
116
- const last = Math.min(end !== void 0 ? Number(end) : start !== void 0 && step === void 0 ? first : max, max);
117
- for (let value = first; value <= last; value += Number(step) || 1) values.add(normalize(value));
165
+ if (/^(?:L|[0-7](?:L|#[1-5]))$/.test(part)) {
166
+ cronParserValues++;
167
+ continue;
168
+ }
169
+ const match = /^(?:(\*)|(\d+)(?:-(\d+))?)(?:\/(\d+))?$/.exec(part);
170
+ if (!match) return;
171
+ const [, wildcard, from, to, step] = match;
172
+ const lower = wildcard ? low : Number(from);
173
+ const upper = wildcard || step && !to ? high : Number(to ?? from);
174
+ const increment = Number(step ?? 1);
175
+ if (!increment || lower < low || upper > high || lower > upper) return;
176
+ if (high === 7 && upper === 7 && lower !== 0 && (to || step)) {
177
+ cronParserValues++;
178
+ cronParserListsSunday = true;
179
+ }
180
+ for (let day = lower; day <= upper; day += increment) {
181
+ days.add(high === 7 && day === 7 ? 0 : day);
182
+ cronParserValues++;
183
+ }
118
184
  }
119
- return values.size;
185
+ return {
186
+ values: days,
187
+ days: days.size,
188
+ cronParserValues,
189
+ cronParserAddsSunday: cronParserListsSunday && !days.has(0)
190
+ };
120
191
  }
121
- function replaceNames(field, names, offset) {
192
+ function replaceNames(field, names, offset, dialect) {
122
193
  return field.replace(/[a-z]+/gi, (word) => {
123
- const index = names.indexOf(word.slice(0, 3).toLowerCase());
194
+ const lowerCase = word.toLowerCase();
195
+ const index = names.findIndex((name) => lowerCase === name.slice(0, 3) || dialect === "node-cron" && lowerCase === name);
124
196
  return index === -1 ? word : String(index + offset);
125
197
  });
126
198
  }
127
199
  function endRangesOnSundayAsSeven(field) {
128
- return field.replace(/(\d+)-0(?!\d)/g, (range, start) => Number(start) ? `${start}-7` : range);
200
+ return field.split(",").map((part) => part.replace(/^(\d+)-0(?!\d)/, (range, start) => Number(start) ? `${start}-7` : range)).join(",");
129
201
  }
130
202
  function hasReversedRange(field) {
131
203
  return field.split(",").some((part) => {
@@ -133,6 +205,12 @@ function hasReversedRange(field) {
133
205
  return !!range && Number(range[1]) > Number(range[2]);
134
206
  });
135
207
  }
208
+ function hasSteppedSingleValueRange(field) {
209
+ return field.split(",").some((part) => {
210
+ const range = /^(\d+)-(\d+)\//.exec(part);
211
+ return !!range && Number(range[1]) === Number(range[2]);
212
+ });
213
+ }
136
214
  function toSentryTimezone(timezone) {
137
215
  if (timezone && /^(?:utc|gmt)?[+-]/i.test(timezone)) return;
138
216
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"cronMonitoring.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/utils/cronMonitoring.ts"],"sourcesContent":["import type { MonitorConfig } from '@sentry/core';\nimport {\n addNonEnumerableProperty,\n captureException,\n debug,\n isThenable,\n startNewTrace,\n stringMatchesSomePattern,\n withMonitor,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport * as diagnosticsChannel from './diagnosticsChannel';\n\nexport type AnyFn = (this: unknown, ...args: unknown[]) => unknown;\n\n// Set by `Sentry.cron.instrumentCron`, `instrumentNodeCron`, `instrumentNodeSchedule` and `wrapScheduledJob`, which already\n// send check-ins.\nconst MONITORED = Symbol.for('sentry.cron.monitored');\n\n/**\n * Calls `onJob` with the arguments of each call on a scheduler's job-creation channel, so it can wrap the job.\n * Errors are logged and the job is created unmonitored.\n */\nexport function subscribeToJobCreation(\n channelName: string,\n integrationName: string,\n onJob: (args: unknown[]) => void,\n): void {\n diagnosticsChannel.tracingChannel<{ arguments: unknown[] }>(channelName).start.subscribe(message => {\n try {\n onJob((message as { arguments: unknown[] }).arguments);\n } catch (e) {\n DEBUG_BUILD && debug.error(`[${integrationName}] Failed to set up the cron monitor:`, e);\n }\n });\n}\n\n/** A call on a schedule-change channel: its arguments, the job it was called on, and what it returned. */\nexport interface ScheduleChange {\n arguments: unknown[];\n self?: unknown;\n result?: unknown;\n}\n\n/**\n * Calls `onChange` after each call on a scheduler's schedule-change channel, so it can update the job's monitor config.\n * `onStart` gets the same object before the call. Errors are logged and the job keeps its config.\n */\nexport function subscribeToScheduleChange(\n channelName: string,\n integrationName: string,\n onChange: (change: ScheduleChange) => void,\n onStart?: (change: ScheduleChange) => void,\n): void {\n const channel = diagnosticsChannel.tracingChannel<ScheduleChange>(channelName);\n const handle = (handler: (change: ScheduleChange) => void) => (message: unknown) => {\n try {\n handler(message as ScheduleChange);\n } catch (e) {\n DEBUG_BUILD && debug.error(`[${integrationName}] Failed to update the cron monitor:`, e);\n }\n };\n if (onStart) {\n channel.start.subscribe(handle(onStart));\n }\n channel.end.subscribe(handle(onChange));\n}\n\n/** Whether a job is named, not excluded, and not already monitored by `Sentry.cron.instrument*` or `wrapScheduledJob`. */\nexport function shouldMonitorJob(\n name: unknown,\n job: unknown,\n excludeJobs: Array<string | RegExp> | undefined,\n): name is string {\n return (\n typeof name === 'string' &&\n !!name &&\n typeof job === 'function' &&\n !(job as { [MONITORED]?: boolean })[MONITORED] &&\n !stringMatchesSomePattern(name, excludeJobs, true)\n );\n}\n\nconst NICKNAMES: Record<string, string> = {\n '@yearly': '0 0 1 1 *',\n '@annually': '0 0 1 1 *',\n '@monthly': '0 0 1 * *',\n '@weekly': '0 0 * * 0',\n '@daily': '0 0 * * *',\n '@midnight': '0 0 * * *',\n '@hourly': '0 * * * *',\n '@minutely': '* * * * *',\n '@weekdays': '0 0 * * 1-5',\n '@weekends': '0 0 * * 0,6',\n};\n\nconst MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];\nconst WEEKDAYS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];\n\n/**\n * How a scheduler combines a restricted day-of-month and day-of-week:\n * - `and`: both must match (`node-cron`).\n * - `or`: either matches, unless one is `*` or a full range (`cron-parser`, `cron`).\n */\nexport type DayFieldSemantics = 'and' | 'or';\n\n/**\n * The Sentry monitor config for a cron expression, or `undefined` if Sentry would read it differently.\n * Without a `timezone`, the server's time zone is used, like the schedulers do.\n */\nexport function cronExpressionToMonitorConfig(\n expression: string,\n timezone: unknown,\n daySemantics: DayFieldSemantics,\n): MonitorConfig | undefined {\n const trimmed = expression.trim();\n const fields = (NICKNAMES[trimmed.toLowerCase()] || trimmed).split(/\\s+/);\n\n // Sentry schedules have minute granularity, so only a fixed second can be dropped.\n if (fields.length === 6 && /^\\d+$/.test(fields[0] as string)) {\n fields.shift();\n }\n if (fields.length !== 5 || !fields.every(field => /^[\\d*,/a-z-]+$/i.test(field))) {\n return undefined;\n }\n\n const [minute, hour, dayOfMonth, month, dayOfWeekWithNames] = fields as [string, string, string, string, string];\n const dayOfWeek = replaceNames(dayOfWeekWithNames, WEEKDAYS, 0);\n if (!isSameDayMatching(dayOfMonth, dayOfWeek, daySemantics)) {\n return undefined;\n }\n\n const crontab = [minute, hour, dayOfMonth, replaceNames(month, MONTHS, 1), endRangesOnSundayAsSeven(dayOfWeek)];\n if (crontab.some(field => /[a-z]/i.test(field) || hasReversedRange(field))) {\n return undefined;\n }\n\n const sentryTimezone = toSentryTimezone(typeof timezone === 'string' && timezone ? timezone : undefined);\n if (!sentryTimezone) {\n return undefined;\n }\n\n return { schedule: { type: 'crontab', value: crontab.join(' ') }, timezone: sentryTimezone };\n}\n\n// Sentry requires both day fields to match when one starts with `*`, and either otherwise.\nfunction isSameDayMatching(dayOfMonth: string, dayOfWeek: string, daySemantics: DayFieldSemantics): boolean {\n if (dayOfMonth === '*' || dayOfWeek === '*') {\n return true;\n }\n if (daySemantics === 'and') {\n return dayOfMonth.startsWith('*') || dayOfWeek.startsWith('*');\n }\n // `cron` reads a field that lists every day like `*`. `cron-parser` does so for a day-of-month that lists every day\n // of the current month, and February has 29 there.\n return !(\n dayOfMonth.startsWith('*') ||\n dayOfWeek.startsWith('*') ||\n countValues(dayOfMonth, 1, 31) >= 29 ||\n countValues(dayOfWeek, 0, 7, day => day % 7) === 7\n );\n}\n\nfunction countValues(field: string, min: number, max: number, normalize = (value: number): number => value): number {\n const values = new Set<number>();\n for (const part of field.split(',')) {\n const match = /^(?:\\*|(\\d+)(?:-(\\d+))?)(?:\\/(\\d+))?$/.exec(part);\n if (!match) {\n continue;\n }\n const [, start, end, step] = match;\n const first = start === undefined ? min : Number(start);\n const last = Math.min(\n end !== undefined ? Number(end) : start !== undefined && step === undefined ? first : max,\n max,\n );\n for (let value = first; value <= last; value += Number(step) || 1) {\n values.add(normalize(value));\n }\n }\n return values.size;\n}\n\nfunction replaceNames(field: string, names: string[], offset: number): string {\n return field.replace(/[a-z]+/gi, word => {\n const index = names.indexOf(word.slice(0, 3).toLowerCase());\n return index === -1 ? word : String(index + offset);\n });\n}\n\n// `sat-sun` is `6-0`, which node-cron 4.6+ runs on Saturday and Sunday. Sentry only accepts it as `6-7`.\nfunction endRangesOnSundayAsSeven(field: string): string {\n return field.replace(/(\\d+)-0(?!\\d)/g, (range, start: string) => (Number(start) ? `${start}-7` : range));\n}\n\n// node-cron 4.6+ wraps these around (`22-2` hours), earlier versions swap them, the other schedulers reject them,\n// and so does Sentry.\nfunction hasReversedRange(field: string): boolean {\n return field.split(',').some(part => {\n const range = /^(\\d+)-(\\d+)/.exec(part);\n return !!range && Number(range[1]) > Number(range[2]);\n });\n}\n\nfunction toSentryTimezone(timezone: string | undefined): string | undefined {\n if (timezone && /^(?:utc|gmt)?[+-]/i.test(timezone)) {\n return undefined;\n }\n try {\n const resolved = new Intl.DateTimeFormat('en-US', { timeZone: timezone }).resolvedOptions().timeZone;\n return resolved && resolved !== 'Etc/Unknown' ? resolved : undefined;\n } catch {\n return undefined;\n }\n}\n\nconst monitorConfigs = new WeakMap<AnyFn, MonitorConfig | undefined>();\n\n/**\n * Wraps a scheduled job with check-ins. Errors are captured, because schedulers catch them, and rethrown.\n * Jobs without a monitor config send no check-ins.\n */\nexport function wrapScheduledJob(\n func: AnyFn,\n monitorSlug: string,\n monitorConfig: MonitorConfig | undefined,\n mechanismType: string,\n): AnyFn {\n const captureAndRethrow = (error: unknown): never => {\n captureException(error, { mechanism: { handled: false, type: mechanismType } });\n throw error;\n };\n\n const wrapped = function (this: unknown, ...args: unknown[]): unknown {\n const run = (): unknown => {\n try {\n const result: unknown = func.apply(this, args);\n return isThenable(result) ? result.then(undefined, captureAndRethrow) : result;\n } catch (e) {\n return captureAndRethrow(e);\n }\n };\n const currentConfig = monitorConfigs.get(wrapped);\n return startNewTrace(() => (currentConfig ? withMonitor(monitorSlug, run, currentConfig) : run()));\n };\n monitorConfigs.set(wrapped, monitorConfig);\n addNonEnumerableProperty(wrapped, MONITORED, true);\n return wrapped;\n}\n\n/** Sets the monitor config a job from `wrapScheduledJob` sends on its next runs. Other functions are ignored. */\nexport function updateMonitorConfig(job: unknown, monitorConfig: MonitorConfig | undefined): void {\n if (typeof job === 'function' && monitorConfigs.has(job as AnyFn)) {\n monitorConfigs.set(job as AnyFn, monitorConfig);\n }\n}\n"],"mappings":";;;;AAiBA,MAAM,YAAY,OAAO,IAAI,uBAAuB;;;;;AAMpD,SAAgB,uBACd,aACA,iBACA,OACM;CACNA,eAA4D,WAAW,CAAC,CAAC,MAAM,WAAU,YAAW;EAClG,IAAI;GACF,MAAO,QAAqC,SAAS;EACvD,SAAS,GAAG;GACV,eAAe,MAAM,MAAM,IAAI,gBAAgB,uCAAuC,CAAC;EACzF;CACF,CAAC;AACH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kBAAkB,CAAC;GAC5B;EACF;EACA,MAAM,gBAAgB,eAAe,IAAI,OAAO;EAChD,OAAO,oBAAqB,gBAAgB,YAAY,aAAa,KAAK,aAAa,IAAI,IAAI,CAAE;CACnG;CACA,eAAe,IAAI,SAAS,aAAa;CACzC,yBAAyB,SAAS,WAAW,IAAI;CACjD,OAAO;AACT;;AAGA,SAAgB,oBAAoB,KAAc,eAAgD;CAChG,IAAI,OAAO,QAAQ,cAAc,eAAe,IAAI,GAAY,GAC9D,eAAe,IAAI,KAAc,aAAa;AAElD"}
1
+ {"version":3,"file":"cronMonitoring.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/utils/cronMonitoring.ts"],"sourcesContent":["import type { MonitorConfig } from '@sentry/core';\nimport {\n addNonEnumerableProperty,\n captureException,\n debug,\n isThenable,\n startNewTrace,\n stringMatchesSomePattern,\n withMonitor,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport * as diagnosticsChannel from './diagnosticsChannel';\n\nexport type AnyFn = (this: unknown, ...args: unknown[]) => unknown;\n\n// Set by `Sentry.cron.instrumentCron`, `instrumentNodeCron`, `instrumentNodeSchedule` and `wrapScheduledJob`, which already\n// send check-ins.\nconst MONITORED = Symbol.for('sentry.cron.monitored');\n\n/**\n * Calls `onJob` with the arguments of each call on a scheduler's job-creation channel, so it can wrap the job.\n * Errors are logged and the job is created unmonitored.\n */\nexport function subscribeToJobCreation(\n channelName: string,\n integrationName: string,\n onJob: (args: unknown[]) => void,\n): void {\n diagnosticsChannel.tracingChannel<{ arguments: unknown[] }>(channelName).start.subscribe(message => {\n try {\n onJob((message as { arguments: unknown[] }).arguments);\n } catch (e) {\n DEBUG_BUILD && debug.error(`[${integrationName}] Failed to set up the cron monitor:`, e);\n }\n });\n}\n\n/** A call on a schedule-change channel: its arguments, the job it was called on, and what it returned. */\nexport interface ScheduleChange {\n arguments: unknown[];\n self?: unknown;\n result?: unknown;\n}\n\n/**\n * Calls `onChange` after each call on a scheduler's schedule-change channel, so it can update the job's monitor config.\n * `onStart` gets the same object before the call. Errors are logged and the job keeps its config.\n */\nexport function subscribeToScheduleChange(\n channelName: string,\n integrationName: string,\n onChange: (change: ScheduleChange) => void,\n onStart?: (change: ScheduleChange) => void,\n): void {\n const channel = diagnosticsChannel.tracingChannel<ScheduleChange>(channelName);\n const handle = (handler: (change: ScheduleChange) => void) => (message: unknown) => {\n try {\n handler(message as ScheduleChange);\n } catch (e) {\n DEBUG_BUILD && debug.error(`[${integrationName}] Failed to update the cron monitor:`, e);\n }\n };\n if (onStart) {\n channel.start.subscribe(handle(onStart));\n }\n channel.end.subscribe(handle(onChange));\n}\n\n/** Whether a job is named, not excluded, and not already monitored by `Sentry.cron.instrument*` or `wrapScheduledJob`. */\nexport function shouldMonitorJob(\n name: unknown,\n job: unknown,\n excludeJobs: Array<string | RegExp> | undefined,\n): name is string {\n return (\n typeof name === 'string' &&\n !!name &&\n typeof job === 'function' &&\n !(job as { [MONITORED]?: boolean })[MONITORED] &&\n !stringMatchesSomePattern(name, excludeJobs, true)\n );\n}\n\n/**\n * The library that parses a scheduler's cron expressions: `node-cron`, `cron` (also behind `@nestjs/schedule`), or\n * `cron-parser` 4 or 5 (behind `node-schedule` and BullMQ).\n */\nexport type CronDialect = 'node-cron' | 'cron' | 'cron-parser';\n\nconst COMMON_NICKNAMES: Record<string, string> = {\n '@yearly': '0 0 1 1 *',\n '@monthly': '0 0 1 * *',\n '@weekly': '0 0 * * 0',\n '@daily': '0 0 * * *',\n '@hourly': '0 * * * *',\n};\n\nconst NICKNAMES: Record<CronDialect, Record<string, string>> = {\n 'node-cron': { ...COMMON_NICKNAMES, '@annually': '0 0 1 1 *', '@midnight': '0 0 * * *' },\n cron: { ...COMMON_NICKNAMES, '@minutely': '* * * * *', '@weekdays': '0 0 * * 1-5', '@weekends': '0 0 * * 0,6' },\n 'cron-parser': COMMON_NICKNAMES,\n};\n\nconst MONTHS = [\n 'january',\n 'february',\n 'march',\n 'april',\n 'may',\n 'june',\n 'july',\n 'august',\n 'september',\n 'october',\n 'november',\n 'december',\n];\nconst WEEKDAYS = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];\n\n/**\n * The Sentry monitor config for a cron expression, or `undefined` if Sentry would read it differently.\n * Without a `timezone`, the server's time zone is used, like the schedulers do.\n */\nexport function cronExpressionToMonitorConfig(\n expression: string,\n timezone: unknown,\n dialect: CronDialect,\n): MonitorConfig | undefined {\n const trimmed = expression.trim();\n const fields = (NICKNAMES[dialect][trimmed.toLowerCase()] || trimmed).split(/\\s+/);\n\n // Sentry schedules have minute granularity, so only a fixed second can be dropped.\n if (fields.length === 6 && /^\\d+$/.test(fields[0] as string)) {\n fields.shift();\n }\n if (fields.length !== 5 || !fields.every(field => /^[\\d*,/a-z#-]+$/i.test(field))) {\n return undefined;\n }\n\n const [minute, hour, dayOfMonth, month, dayOfWeek] = fields as [string, string, string, string, string];\n const monthNumbers = replaceNames(month, MONTHS, 1, dialect);\n const weekdayNames = replaceNames(dayOfWeek, WEEKDAYS, 0, dialect);\n const weekdayNumbers = dialect === 'node-cron' ? endRangesOnSundayAsSeven(weekdayNames) : weekdayNames;\n const crontab = [minute, hour, dayOfMonth, monthNumbers, weekdayNumbers];\n if (\n crontab.some(\n (field, index) =>\n hasUnsupportedCharacter(field, dialect === 'cron-parser' ? CRON_PARSER_DAY_TOKENS[index] : undefined) ||\n hasReversedRange(field) ||\n hasSteppedSingleValueRange(field),\n ) ||\n !isSameDayMatching(dayOfMonth, weekdayNumbers, dialect) ||\n !hasDayInSelectedMonths(dayOfMonth, monthNumbers)\n ) {\n return undefined;\n }\n\n const sentryTimezone = toSentryTimezone(typeof timezone === 'string' && timezone ? timezone : undefined);\n if (!sentryTimezone) {\n return undefined;\n }\n\n return { schedule: { type: 'crontab', value: crontab.join(' ') }, timezone: sentryTimezone };\n}\n\n// `cron-parser` reads these like Sentry: `L` is the last day of the month, `5L` the last Friday, `5#2` the second Friday.\nconst CRON_PARSER_DAY_TOKENS = [undefined, undefined, /^L$/, undefined, /^[0-7](?:L|#[1-5])$/];\n\nfunction hasUnsupportedCharacter(field: string, dayToken: RegExp | undefined): boolean {\n return field.split(',').some(part => /[a-z#]/i.test(part) && !dayToken?.test(part));\n}\n\n// Sentry needs both day fields to match when one starts with `*`, and either otherwise.\nfunction isSameDayMatching(dayOfMonth: string, dayOfWeek: string, dialect: CronDialect): boolean {\n const monthDays = parseDayField(dayOfMonth, 1, 31);\n const weekdays = parseDayField(dayOfWeek, 0, 7);\n if (!monthDays || !weekdays) {\n return false;\n }\n const sentryNeedsBoth = dayOfMonth.startsWith('*') || dayOfWeek.startsWith('*');\n if (dialect === 'cron-parser') {\n return isSameDayMatchingInCronParser(dayOfMonth, dayOfWeek, monthDays, weekdays, sentryNeedsBoth);\n }\n // `cron` needs either day field to match, but ignores one that lists every day, like `1-31` or `sun-sat`.\n const allMonthDays = monthDays.days === 31;\n const allWeekdays = weekdays.days === 7;\n const schedulerNeedsBoth = dialect === 'node-cron' || allMonthDays || allWeekdays;\n return (allMonthDays && allWeekdays) || schedulerNeedsBoth === sentryNeedsBoth;\n}\n\n// `cron-parser` ignores a day-of-week with 8 values, and a day-of-month with at least as many values as the month has\n// days (29 in February), duplicates included. Then only the other field has to match, and otherwise either.\nfunction isSameDayMatchingInCronParser(\n dayOfMonth: string,\n dayOfWeek: string,\n monthDays: DayField,\n weekdays: DayField,\n sentryNeedsBoth: boolean,\n): boolean {\n // `cron-parser` 4 ignores a restricted day of month when the day of week has a `#`.\n if (weekdays.cronParserAddsSunday || (dayOfWeek.includes('#') && (dayOfMonth !== '*' || dayOfWeek.includes(',')))) {\n return false;\n }\n if (dayOfWeek === '*') {\n return true;\n }\n if (dayOfMonth === '*') {\n return weekdays.cronParserValues !== 8 || weekdays.days === 7;\n }\n return !sentryNeedsBoth && monthDays.cronParserValues < 29 && weekdays.cronParserValues !== 8;\n}\n\nconst DAYS_IN_MONTH = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n\n// Sentry rejects a day of month that none of the months have, like `31` in `0 9 31 2,4 *`. The schedulers run these on\n// the day of week or not at all.\nfunction hasDayInSelectedMonths(dayOfMonth: string, month: string): boolean {\n const days = parseDayField(dayOfMonth, 1, 31)?.values;\n const months = parseDayField(month, 1, 12)?.values;\n if (!days || !months) {\n return false;\n }\n return !days.size || Math.min(...days) <= Math.max(...[...months].map(m => DAYS_IN_MONTH[m - 1] as number));\n}\n\ninterface DayField {\n values: Set<number>;\n days: number;\n cronParserValues: number;\n cronParserAddsSunday: boolean;\n}\n\nfunction parseDayField(field: string, low: number, high: number): DayField | undefined {\n const days = new Set<number>();\n let cronParserValues = 0;\n let cronParserListsSunday = false;\n for (const part of field.split(',')) {\n // `L`, `5L` and `5#2` stand for one day each. Only the `cron-parser` dialect lets them through.\n if (/^(?:L|[0-7](?:L|#[1-5]))$/.test(part)) {\n cronParserValues++;\n continue;\n }\n const match = /^(?:(\\*)|(\\d+)(?:-(\\d+))?)(?:\\/(\\d+))?$/.exec(part);\n if (!match) {\n return undefined;\n }\n const [, wildcard, from, to, step] = match;\n const lower = wildcard ? low : Number(from);\n const upper = wildcard || (step && !to) ? high : Number(to ?? from);\n const increment = Number(step ?? 1);\n if (!increment || lower < low || upper > high || lower > upper) {\n return undefined;\n }\n // `cron-parser` starts a weekday range that ends on 7 with a Sunday, whatever the step.\n if (high === 7 && upper === 7 && lower !== 0 && (to || step)) {\n cronParserValues++;\n cronParserListsSunday = true;\n }\n for (let day = lower; day <= upper; day += increment) {\n days.add(high === 7 && day === 7 ? 0 : day);\n cronParserValues++;\n }\n }\n return {\n values: days,\n days: days.size,\n cronParserValues,\n cronParserAddsSunday: cronParserListsSunday && !days.has(0),\n };\n}\n\nfunction replaceNames(field: string, names: string[], offset: number, dialect: CronDialect): string {\n return field.replace(/[a-z]+/gi, word => {\n const lowerCase = word.toLowerCase();\n const index = names.findIndex(\n name => lowerCase === name.slice(0, 3) || (dialect === 'node-cron' && lowerCase === name),\n );\n return index === -1 ? word : String(index + offset);\n });\n}\n\n// `sat-sun` is `6-0`, which node-cron 4.6+ runs on Saturday and Sunday. Sentry only accepts it as `6-7`. The other\n// schedulers reject it.\nfunction endRangesOnSundayAsSeven(field: string): string {\n return field\n .split(',')\n .map(part => part.replace(/^(\\d+)-0(?!\\d)/, (range, start: string) => (Number(start) ? `${start}-7` : range)))\n .join(',');\n}\n\n// node-cron 4.6+ wraps these around (`22-2` hours), earlier versions swap them, the other schedulers reject them,\n// and so does Sentry.\nfunction hasReversedRange(field: string): boolean {\n return field.split(',').some(part => {\n const range = /^(\\d+)-(\\d+)/.exec(part);\n return !!range && Number(range[1]) > Number(range[2]);\n });\n}\n\n// The schedulers run `13-13/3` only on the 13th, but Sentry reads it as `13/3`.\nfunction hasSteppedSingleValueRange(field: string): boolean {\n return field.split(',').some(part => {\n const range = /^(\\d+)-(\\d+)\\//.exec(part);\n return !!range && Number(range[1]) === Number(range[2]);\n });\n}\n\nfunction toSentryTimezone(timezone: string | undefined): string | undefined {\n if (timezone && /^(?:utc|gmt)?[+-]/i.test(timezone)) {\n return undefined;\n }\n try {\n const resolved = new Intl.DateTimeFormat('en-US', { timeZone: timezone }).resolvedOptions().timeZone;\n return resolved && resolved !== 'Etc/Unknown' ? resolved : undefined;\n } catch {\n return undefined;\n }\n}\n\nconst monitorConfigs = new WeakMap<AnyFn, MonitorConfig | undefined>();\n\n/**\n * Wraps a scheduled job with check-ins. Errors are captured, because schedulers catch them, and rethrown.\n * Jobs without a monitor config send no check-ins.\n */\nexport function wrapScheduledJob(\n func: AnyFn,\n monitorSlug: string,\n monitorConfig: MonitorConfig | undefined,\n mechanismType: string,\n): AnyFn {\n const captureAndRethrow = (error: unknown): never => {\n captureException(error, { mechanism: { handled: false, type: mechanismType } });\n throw error;\n };\n\n const wrapped = function (this: unknown, ...args: unknown[]): unknown {\n const run = (): unknown => {\n try {\n const result: unknown = func.apply(this, args);\n return isThenable(result) ? result.then(undefined, captureAndRethrow) : result;\n } catch (e) {\n return captureAndRethrow(e);\n }\n };\n const currentConfig = monitorConfigs.get(wrapped);\n return startNewTrace(() => (currentConfig ? withMonitor(monitorSlug, run, currentConfig) : run()));\n };\n monitorConfigs.set(wrapped, monitorConfig);\n addNonEnumerableProperty(wrapped, MONITORED, true);\n return wrapped;\n}\n\n/** Sets the monitor config a job from `wrapScheduledJob` sends on its next runs. Other functions are ignored. */\nexport function updateMonitorConfig(job: unknown, monitorConfig: MonitorConfig | undefined): void {\n if (typeof job === 'function' && monitorConfigs.has(job as AnyFn)) {\n monitorConfigs.set(job as AnyFn, monitorConfig);\n }\n}\n"],"mappings":";;;;AAiBA,MAAM,YAAY,OAAO,IAAI,uBAAuB;;;;;AAMpD,SAAgB,uBACd,aACA,iBACA,OACM;CACNA,eAA4D,WAAW,CAAC,CAAC,MAAM,WAAU,YAAW;EAClG,IAAI;GACF,MAAO,QAAqC,SAAS;EACvD,SAAS,GAAG;GACV,eAAe,MAAM,MAAM,IAAI,gBAAgB,uCAAuC,CAAC;EACzF;CACF,CAAC;AACH;;;;;AAaA,SAAgB,0BACd,aACA,iBACA,UACA,SACM;CACN,MAAM,UAAUA,eAAkD,WAAW;CAC7E,MAAM,UAAU,aAA+C,YAAqB;EAClF,IAAI;GACF,QAAQ,OAAyB;EACnC,SAAS,GAAG;GACV,eAAe,MAAM,MAAM,IAAI,gBAAgB,uCAAuC,CAAC;EACzF;CACF;CACA,IAAI,SACF,QAAQ,MAAM,UAAU,OAAO,OAAO,CAAC;CAEzC,QAAQ,IAAI,UAAU,OAAO,QAAQ,CAAC;AACxC;;AAGA,SAAgB,iBACd,MACA,KACA,aACgB;CAChB,OACE,OAAO,SAAS,YAChB,CAAC,CAAC,QACF,OAAO,QAAQ,cACf,CAAE,IAAkC,cACpC,CAAC,yBAAyB,MAAM,aAAa,IAAI;AAErD;AAQA,MAAM,mBAA2C;CAC/C,WAAW;CACX,YAAY;CACZ,WAAW;CACX,UAAU;CACV,WAAW;AACb;AAEA,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AqB;GACzB,IAAI;IACF,MAAM,SAAkB,KAAK,MAAM,MAAM,IAAI;IAC7C,OAAO,WAAW,MAAM,IAAI,OAAO,KAAK,KAAA,GAAW,iBAAiB,IAAI;GAC1E,SAAS,GAAG;IACV,OAAO,kBAAkB,CAAC;GAC5B;EACF;EACA,MAAM,gBAAgB,eAAe,IAAI,OAAO;EAChD,OAAO,oBAAqB,gBAAgB,YAAY,aAAa,KAAK,aAAa,IAAI,IAAI,CAAE;CACnG;CACA,eAAe,IAAI,SAAS,aAAa;CACzC,yBAAyB,SAAS,WAAW,IAAI;CACjD,OAAO;AACT;;AAGA,SAAgB,oBAAoB,KAAc,eAAgD;CAChG,IAAI,OAAO,QAAQ,cAAc,eAAe,IAAI,GAAY,GAC9D,eAAe,IAAI,KAAc,aAAa;AAElD"}
@@ -1,5 +1,5 @@
1
1
  import type { Span } from '@sentry/core';
2
- import type { AnthropicAiOptions, AnthropicAiResponse } from './types';
2
+ import type { AnthropicAiOptions } from './types';
3
3
  /**
4
4
  * Extract request attributes from method arguments
5
5
  */
@@ -9,10 +9,6 @@ export declare function extractRequestAttributes(args: unknown[], operationName:
9
9
  * This is only recorded if recordInputs is true.
10
10
  */
11
11
  export declare function addPrivateRequestAttributes(span: Span, params: Record<string, unknown>): void;
12
- /**
13
- * Add response attributes to spans
14
- */
15
- export declare function addResponseAttributes(span: Span, response: AnthropicAiResponse, recordOutputs?: boolean): void;
16
12
  /**
17
13
  * Instrument an Anthropic AI client with Sentry tracing
18
14
  * Can be used across Node.js, Cloudflare Workers, and Vercel Edge
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai/anthropic-ai/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAsB,MAAM,cAAc,CAAC;AA8B7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAA2C,MAAM,SAAS,CAAC;AAYhH;;GAEG;AACH,wBAAgB,wBAAwB,CACtC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 @@
1
1
  import type { Span } from '@sentry/core';
2
+ import type { GenAiSpanResult } from '../core/span-hooks';
2
3
  import type { AnthropicAiStreamingEvent } from './types';
3
4
  /**
4
5
  * Instruments an async iterable stream of Anthropic events, updates the span with
5
6
  * streaming attributes and (optionally) the aggregated output text, and yields
6
7
  * each event from the input stream unchanged.
7
8
  */
8
- export declare function instrumentAsyncIterableStream(stream: AsyncIterable<AnthropicAiStreamingEvent>, span: Span, recordOutputs: boolean): AsyncGenerator<AnthropicAiStreamingEvent, void, unknown>;
9
+ export declare function instrumentAsyncIterableStream(stream: AsyncIterable<AnthropicAiStreamingEvent>, span: Span, recordOutputs: boolean, beforeSpanEnd?: (result: GenAiSpanResult<never>) => void): AsyncGenerator<AnthropicAiStreamingEvent, void, unknown>;
9
10
  /**
10
11
  * Instruments a MessageStream by registering event handlers and preserving the original stream API.
11
12
  */
12
13
  export declare function instrumentMessageStream<R extends {
13
14
  on: (...args: unknown[]) => void;
14
15
  aborted?: boolean;
15
- }>(stream: R, span: Span, recordOutputs: boolean, abortSignal?: AbortSignal): R;
16
+ }>(stream: R, span: Span, recordOutputs: boolean, abortSignal?: AbortSignal, beforeSpanEnd?: (result: GenAiSpanResult<never>) => void): R;
16
17
  //# sourceMappingURL=streaming.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../../../src/ai/anthropic-ai/streaming.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAyNzD;;;;GAIG;AACH,wBAAuB,6BAA6B,CAClD,MAAM,EAAE,aAAa,CAAC,yBAAyB,CAAC,EAChD,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,OAAO,GACrB,cAAc,CAAC,yBAAyB,EAAE,IAAI,EAAE,OAAO,CAAC,CA0B1D;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,EACvG,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,OAAO,EACtB,WAAW,CAAC,EAAE,WAAW,GACxB,CAAC,CAsDH"}
1
+ {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../../../src/ai/anthropic-ai/streaming.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AA2NzD;;;;GAIG;AACH,wBAAuB,6BAA6B,CAClD,MAAM,EAAE,aAAa,CAAC,yBAAyB,CAAC,EAChD,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,OAAO,EACtB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,KAAK,IAAI,GACvD,cAAc,CAAC,yBAAyB,EAAE,IAAI,EAAE,OAAO,CAAC,CA4B1D;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,EACvG,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,OAAO,EACtB,WAAW,CAAC,EAAE,WAAW,EACzB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,KAAK,IAAI,GACvD,CAAC,CAsDH"}
@@ -1 +1 @@
1
- {"version":3,"file":"tool-runner.d.ts","sourceRoot":"","sources":["../../../../src/ai/anthropic-ai/tool-runner.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAQlD,kGAAkG;AAClG,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,EACb,gBAAgB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,KAAK,IAAI,EACxE,OAAO,EAAE,kBAAkB,GAC1B,IAAI,CAMN;AAED,yEAAyE;AACzE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAiBvF;AAED,gIAAgI;AAChI,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAc9F"}
1
+ {"version":3,"file":"tool-runner.d.ts","sourceRoot":"","sources":["../../../../src/ai/anthropic-ai/tool-runner.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAuB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAQvE,kGAAkG;AAClG,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,EACb,gBAAgB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,KAAK,IAAI,EACxE,OAAO,EAAE,kBAAkB,GAC1B,IAAI,CAMN;AAED,yEAAyE;AACzE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAiBvF;AAED,gIAAgI;AAChI,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAc9F"}
@@ -1,6 +1,27 @@
1
- import type { GenAiOptions } from '../core/utils';
2
- /** Options for the Anthropic AI integration. */
3
- export type AnthropicAiOptions = GenAiOptions;
1
+ import type { GenAiSpanHooks } from '../core/span-hooks';
2
+ import type { GenAiCallOptions } from '../core/utils';
3
+ /**
4
+ * The call that `recordInputs`/`recordOutputs` decide on, and that the span hooks get: a model call, or a tool
5
+ * call of a tool runner.
6
+ */
7
+ export type AnthropicAiCallInfo = {
8
+ operation: 'chat';
9
+ /** The request params, the first argument of the method (such as `messages.create`) as passed. */
10
+ request: Record<string, unknown> | undefined;
11
+ } | {
12
+ operation: 'execute_tool';
13
+ /** The runnable tool, as passed to the tool runner. */
14
+ tool: {
15
+ name: string;
16
+ };
17
+ /** The input the model called the tool with. */
18
+ input: unknown;
19
+ };
20
+ /**
21
+ * Options for the Anthropic AI integration. `onSpanEnd` gets the response the method resolved with, such as a
22
+ * `Message`, or the result of a tool call; for streams it is `undefined`.
23
+ */
24
+ export type AnthropicAiOptions = GenAiCallOptions<AnthropicAiCallInfo> & GenAiSpanHooks<AnthropicAiCallInfo>;
4
25
  export type Message = {
5
26
  role: 'user' | 'assistant';
6
27
  content: string | unknown[];
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/ai/anthropic-ai/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,gDAAgD;AAChD,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAE9C,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,OAAO,EAAE,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,UAAU,GAAG,iBAAiB,GAAG,MAAM,CAAC;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAGF,MAAM,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O,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,8CAA8C;QAC9C,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,KAAK,CAAC,EAAE;QACN,aAAa,EAAE,MAAM,CAAC;QAEtB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7B,2BAA2B,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5C,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACzC,CAAC;IACF,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,8CAA8C;IAC9C,aAAa,CAAC,EAAE,YAAY,CAAC;CAC9B,CAAC"}
@@ -15,10 +15,9 @@ export declare function getMessagesAttributes(messages: unknown): Record<string,
15
15
  */
16
16
  export declare function mapAnthropicErrorToStatusMessage(errorType: string | undefined): SpanStatusType;
17
17
  /**
18
- * Capture error information from the response
19
- * @see https://docs.anthropic.com/en/api/errors#error-shapes
18
+ * Add response attributes to spans
20
19
  */
21
- export declare function handleResponseError(span: Span, response: AnthropicAiResponse): void;
20
+ export declare function addResponseAttributes(span: Span, response: AnthropicAiResponse, recordOutputs?: boolean): void;
22
21
  /**
23
22
  * Include the system prompt in the messages list, if available
24
23
  */
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/ai/anthropic-ai/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAIzD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAa3F;AAaD;;;GAGG;AACH,wBAAgB,gCAAgC,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,CAK9F;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,mBAAmB,GAAG,IAAI,CAWnF;AAaD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,EAAE,CAiB7E"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/ai/anthropic-ai/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAUzD,OAAO,KAAK,EAAE,mBAAmB,EAAgB,MAAM,SAAS,CAAC;AAEjE;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAIzD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAa3F;AAaD;;;GAGG;AACH,wBAAgB,gCAAgC,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,CAK9F;AA4ED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,mBAAmB,EAAE,aAAa,CAAC,EAAE,OAAO,GAAG,IAAI,CAgB9G;AAaD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,EAAE,CAiB7E"}
@@ -0,0 +1,31 @@
1
+ import type { Span } from '@sentry/core';
2
+ /** How a gen_ai call ended, as passed to {@link GenAiSpanHooks.onSpanEnd}. */
3
+ export interface GenAiSpanResult<TResponse> {
4
+ /** The response as the library returned it. `undefined` for streams and failed calls. */
5
+ response?: TResponse;
6
+ /** Set when the call failed. */
7
+ error?: unknown;
8
+ }
9
+ /**
10
+ * Hooks that let an integration's users add their own attributes to its gen_ai spans. `TCall` is the same
11
+ * call info that `recordInputs`/`recordOutputs` get, and both hooks get the same object.
12
+ *
13
+ * They only run for spans that are recorded. A hook that throws is logged and does not affect the call.
14
+ */
15
+ export interface GenAiSpanHooks<TCall, TResponse = unknown> {
16
+ /**
17
+ * Runs after the span started and the SDK set its request attributes, in the caller's async context, so
18
+ * it can read request-scoped state.
19
+ */
20
+ onSpanStart?: (span: Span, call: TCall) => void;
21
+ /**
22
+ * Runs after the SDK set its response attributes, right before the span ends. That can be in another
23
+ * async context than the call, for example when a stream is consumed later.
24
+ */
25
+ onSpanEnd?: (span: Span, call: TCall, result: GenAiSpanResult<TResponse>) => void;
26
+ }
27
+ /** Runs {@link GenAiSpanHooks.onSpanStart}. */
28
+ export declare function runGenAiSpanStart<TCall>(hooks: Pick<GenAiSpanHooks<TCall>, 'onSpanStart'>, span: Span, call: TCall): void;
29
+ /** Runs {@link GenAiSpanHooks.onSpanEnd}. Call it right before the span ends. */
30
+ export declare function runGenAiSpanEnd<TCall, TResponse>(hooks: GenAiSpanHooks<TCall, TResponse>, span: Span, call: TCall, result: GenAiSpanResult<TResponse>): void;
31
+ //# sourceMappingURL=span-hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"span-hooks.d.ts","sourceRoot":"","sources":["../../../../src/ai/core/span-hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGzC,8EAA8E;AAC9E,MAAM,WAAW,eAAe,CAAC,SAAS;IACxC,yFAAyF;IACzF,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,gCAAgC;IAChC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO;IACxD;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,KAAK,IAAI,CAAC;IAChD;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;CACnF;AAED,+CAA+C;AAC/C,wBAAgB,iBAAiB,CAAC,KAAK,EACrC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,EACjD,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,KAAK,GACV,IAAI,CAKN;AAED,iFAAiF;AACjF,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAC9C,KAAK,EAAE,cAAc,CAAC,KAAK,EAAE,SAAS,CAAC,EACvC,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,KAAK,EACX,MAAM,EAAE,eAAe,CAAC,SAAS,CAAC,GACjC,IAAI,CAKN"}
@@ -0,0 +1,7 @@
1
+ import type { Span } from '@sentry/core';
2
+ /**
3
+ * Sets `gen_ai.response.time_to_first_chunk` on a streamed span, in seconds from the span start.
4
+ * Call it for each received chunk. Only the first call per span records a value.
5
+ */
6
+ export declare function recordTimeToFirstChunk(span: Span): void;
7
+ //# sourceMappingURL=time-to-first-chunk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time-to-first-chunk.d.ts","sourceRoot":"","sources":["../../../../src/ai/core/time-to-first-chunk.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGzC;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAKvD"}