@sentry/core 10.46.0 → 10.48.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 (381) hide show
  1. package/build/cjs/api.js +1 -0
  2. package/build/cjs/api.js.map +1 -1
  3. package/build/cjs/attributes.js +43 -0
  4. package/build/cjs/attributes.js.map +1 -1
  5. package/build/cjs/client.js +13 -6
  6. package/build/cjs/client.js.map +1 -1
  7. package/build/cjs/currentScopes.js +33 -0
  8. package/build/cjs/currentScopes.js.map +1 -1
  9. package/build/cjs/envelope.js +4 -3
  10. package/build/cjs/envelope.js.map +1 -1
  11. package/build/cjs/index.js +50 -13
  12. package/build/cjs/index.js.map +1 -1
  13. package/build/cjs/integration.js +6 -0
  14. package/build/cjs/integration.js.map +1 -1
  15. package/build/cjs/integrations/express/index.js +206 -0
  16. package/build/cjs/integrations/express/index.js.map +1 -0
  17. package/build/cjs/integrations/express/patch-layer.js +251 -0
  18. package/build/cjs/integrations/express/patch-layer.js.map +1 -0
  19. package/build/cjs/integrations/express/request-layer-store.js +25 -0
  20. package/build/cjs/integrations/express/request-layer-store.js.map +1 -0
  21. package/build/cjs/integrations/express/set-sdk-processing-metadata.js +17 -0
  22. package/build/cjs/integrations/express/set-sdk-processing-metadata.js.map +1 -0
  23. package/build/cjs/integrations/express/types.js +17 -0
  24. package/build/cjs/integrations/express/types.js.map +1 -0
  25. package/build/cjs/integrations/express/utils.js +238 -0
  26. package/build/cjs/integrations/express/utils.js.map +1 -0
  27. package/build/cjs/integrations/mcp-server/correlation.js +5 -1
  28. package/build/cjs/integrations/mcp-server/correlation.js.map +1 -1
  29. package/build/cjs/integrations/mcp-server/handlers.js +18 -10
  30. package/build/cjs/integrations/mcp-server/handlers.js.map +1 -1
  31. package/build/cjs/integrations/mcp-server/index.js +2 -1
  32. package/build/cjs/integrations/mcp-server/index.js.map +1 -1
  33. package/build/cjs/integrations/mcp-server/transport.js +1 -1
  34. package/build/cjs/integrations/mcp-server/transport.js.map +1 -1
  35. package/build/cjs/integrations/mcp-server/validation.js +7 -5
  36. package/build/cjs/integrations/mcp-server/validation.js.map +1 -1
  37. package/build/cjs/integrations/spanStreaming.js +48 -0
  38. package/build/cjs/integrations/spanStreaming.js.map +1 -0
  39. package/build/cjs/integrations/supabase.js +1 -1
  40. package/build/cjs/integrations/supabase.js.map +1 -1
  41. package/build/cjs/semanticAttributes.js +35 -3
  42. package/build/cjs/semanticAttributes.js.map +1 -1
  43. package/build/cjs/tracing/ai/gen-ai-attributes.js +9 -79
  44. package/build/cjs/tracing/ai/gen-ai-attributes.js.map +1 -1
  45. package/build/cjs/tracing/ai/utils.js +50 -35
  46. package/build/cjs/tracing/ai/utils.js.map +1 -1
  47. package/build/cjs/tracing/anthropic-ai/constants.js +10 -10
  48. package/build/cjs/tracing/anthropic-ai/constants.js.map +1 -1
  49. package/build/cjs/tracing/anthropic-ai/index.js +18 -20
  50. package/build/cjs/tracing/anthropic-ai/index.js.map +1 -1
  51. package/build/cjs/tracing/anthropic-ai/streaming.js +2 -100
  52. package/build/cjs/tracing/anthropic-ai/streaming.js.map +1 -1
  53. package/build/cjs/tracing/anthropic-ai/utils.js +0 -9
  54. package/build/cjs/tracing/anthropic-ai/utils.js.map +1 -1
  55. package/build/cjs/tracing/dynamicSamplingContext.js +2 -1
  56. package/build/cjs/tracing/dynamicSamplingContext.js.map +1 -1
  57. package/build/cjs/tracing/google-genai/constants.js +9 -12
  58. package/build/cjs/tracing/google-genai/constants.js.map +1 -1
  59. package/build/cjs/tracing/google-genai/index.js +49 -27
  60. package/build/cjs/tracing/google-genai/index.js.map +1 -1
  61. package/build/cjs/tracing/google-genai/streaming.js +2 -23
  62. package/build/cjs/tracing/google-genai/streaming.js.map +1 -1
  63. package/build/cjs/tracing/google-genai/utils.js +0 -25
  64. package/build/cjs/tracing/google-genai/utils.js.map +1 -1
  65. package/build/cjs/tracing/langchain/embeddings.js +132 -0
  66. package/build/cjs/tracing/langchain/embeddings.js.map +1 -0
  67. package/build/cjs/tracing/langchain/index.js.map +1 -1
  68. package/build/cjs/tracing/openai/constants.js +7 -7
  69. package/build/cjs/tracing/openai/constants.js.map +1 -1
  70. package/build/cjs/tracing/openai/index.js +19 -37
  71. package/build/cjs/tracing/openai/index.js.map +1 -1
  72. package/build/cjs/tracing/openai/streaming.js +3 -34
  73. package/build/cjs/tracing/openai/streaming.js.map +1 -1
  74. package/build/cjs/tracing/openai/utils.js +78 -243
  75. package/build/cjs/tracing/openai/utils.js.map +1 -1
  76. package/build/cjs/tracing/sentryNonRecordingSpan.js +7 -0
  77. package/build/cjs/tracing/sentryNonRecordingSpan.js.map +1 -1
  78. package/build/cjs/tracing/sentrySpan.js +39 -0
  79. package/build/cjs/tracing/sentrySpan.js.map +1 -1
  80. package/build/cjs/tracing/spans/beforeSendSpan.js +43 -0
  81. package/build/cjs/tracing/spans/beforeSendSpan.js.map +1 -0
  82. package/build/cjs/tracing/spans/captureSpan.js +126 -0
  83. package/build/cjs/tracing/spans/captureSpan.js.map +1 -0
  84. package/build/cjs/tracing/spans/envelope.js +38 -0
  85. package/build/cjs/tracing/spans/envelope.js.map +1 -0
  86. package/build/cjs/tracing/spans/estimateSize.js +41 -0
  87. package/build/cjs/tracing/spans/estimateSize.js.map +1 -0
  88. package/build/cjs/tracing/spans/hasSpanStreamingEnabled.js +11 -0
  89. package/build/cjs/tracing/spans/hasSpanStreamingEnabled.js.map +1 -0
  90. package/build/cjs/tracing/spans/spanBuffer.js +158 -0
  91. package/build/cjs/tracing/spans/spanBuffer.js.map +1 -0
  92. package/build/cjs/tracing/trace.js +88 -13
  93. package/build/cjs/tracing/trace.js.map +1 -1
  94. package/build/cjs/tracing/vercel-ai/utils.js +1 -4
  95. package/build/cjs/tracing/vercel-ai/utils.js.map +1 -1
  96. package/build/cjs/utils/featureFlags.js +6 -0
  97. package/build/cjs/utils/featureFlags.js.map +1 -1
  98. package/build/cjs/utils/object.js +33 -0
  99. package/build/cjs/utils/object.js.map +1 -1
  100. package/build/cjs/utils/spanUtils.js +116 -13
  101. package/build/cjs/utils/spanUtils.js.map +1 -1
  102. package/build/cjs/utils/stacktrace.js +3 -1
  103. package/build/cjs/utils/stacktrace.js.map +1 -1
  104. package/build/cjs/utils/string.js +3 -0
  105. package/build/cjs/utils/string.js.map +1 -1
  106. package/build/cjs/utils/traceData.js +11 -0
  107. package/build/cjs/utils/traceData.js.map +1 -1
  108. package/build/cjs/utils/version.js +1 -1
  109. package/build/esm/api.js +1 -1
  110. package/build/esm/api.js.map +1 -1
  111. package/build/esm/attributes.js +43 -1
  112. package/build/esm/attributes.js.map +1 -1
  113. package/build/esm/client.js +8 -1
  114. package/build/esm/client.js.map +1 -1
  115. package/build/esm/currentScopes.js +31 -1
  116. package/build/esm/currentScopes.js.map +1 -1
  117. package/build/esm/envelope.js +2 -1
  118. package/build/esm/envelope.js.map +1 -1
  119. package/build/esm/index.js +13 -4
  120. package/build/esm/index.js.map +1 -1
  121. package/build/esm/integration.js +6 -0
  122. package/build/esm/integration.js.map +1 -1
  123. package/build/esm/integrations/express/index.js +202 -0
  124. package/build/esm/integrations/express/index.js.map +1 -0
  125. package/build/esm/integrations/express/patch-layer.js +249 -0
  126. package/build/esm/integrations/express/patch-layer.js.map +1 -0
  127. package/build/esm/integrations/express/request-layer-store.js +22 -0
  128. package/build/esm/integrations/express/request-layer-store.js.map +1 -0
  129. package/build/esm/integrations/express/set-sdk-processing-metadata.js +15 -0
  130. package/build/esm/integrations/express/set-sdk-processing-metadata.js.map +1 -0
  131. package/build/esm/integrations/express/types.js +10 -0
  132. package/build/esm/integrations/express/types.js.map +1 -0
  133. package/build/esm/integrations/express/utils.js +225 -0
  134. package/build/esm/integrations/express/utils.js.map +1 -0
  135. package/build/esm/integrations/mcp-server/correlation.js +5 -1
  136. package/build/esm/integrations/mcp-server/correlation.js.map +1 -1
  137. package/build/esm/integrations/mcp-server/handlers.js +18 -10
  138. package/build/esm/integrations/mcp-server/handlers.js.map +1 -1
  139. package/build/esm/integrations/mcp-server/index.js +2 -1
  140. package/build/esm/integrations/mcp-server/index.js.map +1 -1
  141. package/build/esm/integrations/mcp-server/transport.js +1 -1
  142. package/build/esm/integrations/mcp-server/transport.js.map +1 -1
  143. package/build/esm/integrations/mcp-server/validation.js +7 -5
  144. package/build/esm/integrations/mcp-server/validation.js.map +1 -1
  145. package/build/esm/integrations/spanStreaming.js +46 -0
  146. package/build/esm/integrations/spanStreaming.js.map +1 -0
  147. package/build/esm/integrations/supabase.js +1 -1
  148. package/build/esm/integrations/supabase.js.map +1 -1
  149. package/build/esm/package.json +1 -1
  150. package/build/esm/semanticAttributes.js +26 -4
  151. package/build/esm/semanticAttributes.js.map +1 -1
  152. package/build/esm/tracing/ai/gen-ai-attributes.js +8 -69
  153. package/build/esm/tracing/ai/gen-ai-attributes.js.map +1 -1
  154. package/build/esm/tracing/ai/utils.js +51 -35
  155. package/build/esm/tracing/ai/utils.js.map +1 -1
  156. package/build/esm/tracing/anthropic-ai/constants.js +10 -10
  157. package/build/esm/tracing/anthropic-ai/constants.js.map +1 -1
  158. package/build/esm/tracing/anthropic-ai/index.js +21 -23
  159. package/build/esm/tracing/anthropic-ai/index.js.map +1 -1
  160. package/build/esm/tracing/anthropic-ai/streaming.js +3 -101
  161. package/build/esm/tracing/anthropic-ai/streaming.js.map +1 -1
  162. package/build/esm/tracing/anthropic-ai/utils.js +1 -9
  163. package/build/esm/tracing/anthropic-ai/utils.js.map +1 -1
  164. package/build/esm/tracing/dynamicSamplingContext.js +2 -1
  165. package/build/esm/tracing/dynamicSamplingContext.js.map +1 -1
  166. package/build/esm/tracing/google-genai/constants.js +9 -10
  167. package/build/esm/tracing/google-genai/constants.js.map +1 -1
  168. package/build/esm/tracing/google-genai/index.js +53 -31
  169. package/build/esm/tracing/google-genai/index.js.map +1 -1
  170. package/build/esm/tracing/google-genai/streaming.js +2 -23
  171. package/build/esm/tracing/google-genai/streaming.js.map +1 -1
  172. package/build/esm/tracing/google-genai/utils.js +1 -24
  173. package/build/esm/tracing/google-genai/utils.js.map +1 -1
  174. package/build/esm/tracing/langchain/embeddings.js +129 -0
  175. package/build/esm/tracing/langchain/embeddings.js.map +1 -0
  176. package/build/esm/tracing/langchain/index.js.map +1 -1
  177. package/build/esm/tracing/openai/constants.js +7 -7
  178. package/build/esm/tracing/openai/constants.js.map +1 -1
  179. package/build/esm/tracing/openai/index.js +21 -39
  180. package/build/esm/tracing/openai/index.js.map +1 -1
  181. package/build/esm/tracing/openai/streaming.js +4 -35
  182. package/build/esm/tracing/openai/streaming.js.map +1 -1
  183. package/build/esm/tracing/openai/utils.js +79 -232
  184. package/build/esm/tracing/openai/utils.js.map +1 -1
  185. package/build/esm/tracing/sentryNonRecordingSpan.js +7 -0
  186. package/build/esm/tracing/sentryNonRecordingSpan.js.map +1 -1
  187. package/build/esm/tracing/sentrySpan.js +40 -1
  188. package/build/esm/tracing/sentrySpan.js.map +1 -1
  189. package/build/esm/tracing/spans/beforeSendSpan.js +40 -0
  190. package/build/esm/tracing/spans/beforeSendSpan.js.map +1 -0
  191. package/build/esm/tracing/spans/captureSpan.js +122 -0
  192. package/build/esm/tracing/spans/captureSpan.js.map +1 -0
  193. package/build/esm/tracing/spans/envelope.js +36 -0
  194. package/build/esm/tracing/spans/envelope.js.map +1 -0
  195. package/build/esm/tracing/spans/estimateSize.js +39 -0
  196. package/build/esm/tracing/spans/estimateSize.js.map +1 -0
  197. package/build/esm/tracing/spans/hasSpanStreamingEnabled.js +9 -0
  198. package/build/esm/tracing/spans/hasSpanStreamingEnabled.js.map +1 -0
  199. package/build/esm/tracing/spans/spanBuffer.js +156 -0
  200. package/build/esm/tracing/spans/spanBuffer.js.map +1 -0
  201. package/build/esm/tracing/trace.js +89 -14
  202. package/build/esm/tracing/trace.js.map +1 -1
  203. package/build/esm/tracing/vercel-ai/utils.js +2 -5
  204. package/build/esm/tracing/vercel-ai/utils.js.map +1 -1
  205. package/build/esm/utils/featureFlags.js +6 -0
  206. package/build/esm/utils/featureFlags.js.map +1 -1
  207. package/build/esm/utils/object.js +33 -1
  208. package/build/esm/utils/object.js.map +1 -1
  209. package/build/esm/utils/spanUtils.js +112 -14
  210. package/build/esm/utils/spanUtils.js.map +1 -1
  211. package/build/esm/utils/stacktrace.js +3 -1
  212. package/build/esm/utils/stacktrace.js.map +1 -1
  213. package/build/esm/utils/string.js +3 -0
  214. package/build/esm/utils/string.js.map +1 -1
  215. package/build/esm/utils/traceData.js +12 -1
  216. package/build/esm/utils/traceData.js.map +1 -1
  217. package/build/esm/utils/version.js +1 -1
  218. package/build/types/api.d.ts +1 -0
  219. package/build/types/api.d.ts.map +1 -1
  220. package/build/types/asyncContext/types.d.ts +3 -1
  221. package/build/types/asyncContext/types.d.ts.map +1 -1
  222. package/build/types/attributes.d.ts +5 -0
  223. package/build/types/attributes.d.ts.map +1 -1
  224. package/build/types/client.d.ts +35 -1
  225. package/build/types/client.d.ts.map +1 -1
  226. package/build/types/currentScopes.d.ts +20 -0
  227. package/build/types/currentScopes.d.ts.map +1 -1
  228. package/build/types/envelope.d.ts.map +1 -1
  229. package/build/types/index.d.ts +15 -6
  230. package/build/types/index.d.ts.map +1 -1
  231. package/build/types/integration.d.ts.map +1 -1
  232. package/build/types/integrations/express/index.d.ts +75 -0
  233. package/build/types/integrations/express/index.d.ts.map +1 -0
  234. package/build/types/integrations/express/patch-layer.d.ts +32 -0
  235. package/build/types/integrations/express/patch-layer.d.ts.map +1 -0
  236. package/build/types/integrations/express/request-layer-store.d.ts +32 -0
  237. package/build/types/integrations/express/request-layer-store.d.ts.map +1 -0
  238. package/build/types/integrations/express/set-sdk-processing-metadata.d.ts +35 -0
  239. package/build/types/integrations/express/set-sdk-processing-metadata.d.ts.map +1 -0
  240. package/build/types/integrations/express/types.d.ts +154 -0
  241. package/build/types/integrations/express/types.d.ts.map +1 -0
  242. package/build/types/integrations/express/utils.d.ts +93 -0
  243. package/build/types/integrations/express/utils.d.ts.map +1 -0
  244. package/build/types/integrations/mcp-server/correlation.d.ts +2 -1
  245. package/build/types/integrations/mcp-server/correlation.d.ts.map +1 -1
  246. package/build/types/integrations/mcp-server/handlers.d.ts +9 -4
  247. package/build/types/integrations/mcp-server/handlers.d.ts.map +1 -1
  248. package/build/types/integrations/mcp-server/index.d.ts +2 -1
  249. package/build/types/integrations/mcp-server/index.d.ts.map +1 -1
  250. package/build/types/integrations/mcp-server/types.d.ts +40 -7
  251. package/build/types/integrations/mcp-server/types.d.ts.map +1 -1
  252. package/build/types/integrations/mcp-server/validation.d.ts +4 -1
  253. package/build/types/integrations/mcp-server/validation.d.ts.map +1 -1
  254. package/build/types/integrations/spanStreaming.d.ts +2 -0
  255. package/build/types/integrations/spanStreaming.d.ts.map +1 -0
  256. package/build/types/semanticAttributes.d.ts +23 -3
  257. package/build/types/semanticAttributes.d.ts.map +1 -1
  258. package/build/types/tracing/ai/gen-ai-attributes.d.ts +6 -46
  259. package/build/types/tracing/ai/gen-ai-attributes.d.ts.map +1 -1
  260. package/build/types/tracing/ai/utils.d.ts +34 -9
  261. package/build/types/tracing/ai/utils.d.ts.map +1 -1
  262. package/build/types/tracing/anthropic-ai/constants.d.ts +24 -1
  263. package/build/types/tracing/anthropic-ai/constants.d.ts.map +1 -1
  264. package/build/types/tracing/anthropic-ai/index.d.ts.map +1 -1
  265. package/build/types/tracing/anthropic-ai/streaming.d.ts.map +1 -1
  266. package/build/types/tracing/anthropic-ai/types.d.ts +5 -2
  267. package/build/types/tracing/anthropic-ai/types.d.ts.map +1 -1
  268. package/build/types/tracing/anthropic-ai/utils.d.ts +1 -5
  269. package/build/types/tracing/anthropic-ai/utils.d.ts.map +1 -1
  270. package/build/types/tracing/dynamicSamplingContext.d.ts.map +1 -1
  271. package/build/types/tracing/google-genai/constants.d.ts +22 -3
  272. package/build/types/tracing/google-genai/constants.d.ts.map +1 -1
  273. package/build/types/tracing/google-genai/index.d.ts.map +1 -1
  274. package/build/types/tracing/google-genai/streaming.d.ts.map +1 -1
  275. package/build/types/tracing/google-genai/types.d.ts +6 -2
  276. package/build/types/tracing/google-genai/types.d.ts.map +1 -1
  277. package/build/types/tracing/google-genai/utils.d.ts +0 -9
  278. package/build/types/tracing/google-genai/utils.d.ts.map +1 -1
  279. package/build/types/tracing/index.d.ts +1 -0
  280. package/build/types/tracing/index.d.ts.map +1 -1
  281. package/build/types/tracing/langchain/embeddings.d.ts +27 -0
  282. package/build/types/tracing/langchain/embeddings.d.ts.map +1 -0
  283. package/build/types/tracing/langchain/index.d.ts +1 -0
  284. package/build/types/tracing/langchain/index.d.ts.map +1 -1
  285. package/build/types/tracing/openai/constants.d.ts +14 -1
  286. package/build/types/tracing/openai/constants.d.ts.map +1 -1
  287. package/build/types/tracing/openai/index.d.ts.map +1 -1
  288. package/build/types/tracing/openai/streaming.d.ts.map +1 -1
  289. package/build/types/tracing/openai/types.d.ts +5 -2
  290. package/build/types/tracing/openai/types.d.ts.map +1 -1
  291. package/build/types/tracing/openai/utils.d.ts +4 -63
  292. package/build/types/tracing/openai/utils.d.ts.map +1 -1
  293. package/build/types/tracing/sentryNonRecordingSpan.d.ts +12 -1
  294. package/build/types/tracing/sentryNonRecordingSpan.d.ts.map +1 -1
  295. package/build/types/tracing/sentrySpan.d.ts +10 -1
  296. package/build/types/tracing/sentrySpan.d.ts.map +1 -1
  297. package/build/types/tracing/spans/beforeSendSpan.d.ts +35 -0
  298. package/build/types/tracing/spans/beforeSendSpan.d.ts.map +1 -0
  299. package/build/types/tracing/spans/captureSpan.d.ts +26 -0
  300. package/build/types/tracing/spans/captureSpan.d.ts.map +1 -0
  301. package/build/types/tracing/spans/envelope.d.ts +8 -0
  302. package/build/types/tracing/spans/envelope.d.ts.map +1 -0
  303. package/build/types/tracing/spans/estimateSize.d.ts +12 -0
  304. package/build/types/tracing/spans/estimateSize.d.ts.map +1 -0
  305. package/build/types/tracing/spans/hasSpanStreamingEnabled.d.ts +6 -0
  306. package/build/types/tracing/spans/hasSpanStreamingEnabled.d.ts.map +1 -0
  307. package/build/types/tracing/spans/spanBuffer.d.ts +60 -0
  308. package/build/types/tracing/spans/spanBuffer.d.ts.map +1 -0
  309. package/build/types/tracing/trace.d.ts.map +1 -1
  310. package/build/types/tracing/vercel-ai/utils.d.ts.map +1 -1
  311. package/build/types/types-hoist/envelope.d.ts +22 -2
  312. package/build/types/types-hoist/envelope.d.ts.map +1 -1
  313. package/build/types/types-hoist/integration.d.ts +8 -0
  314. package/build/types/types-hoist/integration.d.ts.map +1 -1
  315. package/build/types/types-hoist/link.d.ts +2 -2
  316. package/build/types/types-hoist/link.d.ts.map +1 -1
  317. package/build/types/types-hoist/options.d.ts +26 -2
  318. package/build/types/types-hoist/options.d.ts.map +1 -1
  319. package/build/types/types-hoist/span.d.ts +35 -0
  320. package/build/types/types-hoist/span.d.ts.map +1 -1
  321. package/build/types/utils/featureFlags.d.ts.map +1 -1
  322. package/build/types/utils/object.d.ts +10 -0
  323. package/build/types/utils/object.d.ts.map +1 -1
  324. package/build/types/utils/spanUtils.d.ts +27 -2
  325. package/build/types/utils/spanUtils.d.ts.map +1 -1
  326. package/build/types/utils/stacktrace.d.ts.map +1 -1
  327. package/build/types/utils/string.d.ts +2 -2
  328. package/build/types/utils/string.d.ts.map +1 -1
  329. package/build/types/utils/traceData.d.ts +4 -0
  330. package/build/types/utils/traceData.d.ts.map +1 -1
  331. package/build/types-ts3.8/api.d.ts +1 -0
  332. package/build/types-ts3.8/asyncContext/types.d.ts +3 -1
  333. package/build/types-ts3.8/attributes.d.ts +5 -0
  334. package/build/types-ts3.8/client.d.ts +35 -1
  335. package/build/types-ts3.8/currentScopes.d.ts +20 -0
  336. package/build/types-ts3.8/index.d.ts +15 -6
  337. package/build/types-ts3.8/integrations/express/index.d.ts +75 -0
  338. package/build/types-ts3.8/integrations/express/patch-layer.d.ts +32 -0
  339. package/build/types-ts3.8/integrations/express/request-layer-store.d.ts +32 -0
  340. package/build/types-ts3.8/integrations/express/set-sdk-processing-metadata.d.ts +35 -0
  341. package/build/types-ts3.8/integrations/express/types.d.ts +154 -0
  342. package/build/types-ts3.8/integrations/express/utils.d.ts +96 -0
  343. package/build/types-ts3.8/integrations/mcp-server/correlation.d.ts +2 -1
  344. package/build/types-ts3.8/integrations/mcp-server/handlers.d.ts +9 -4
  345. package/build/types-ts3.8/integrations/mcp-server/index.d.ts +2 -1
  346. package/build/types-ts3.8/integrations/mcp-server/types.d.ts +40 -7
  347. package/build/types-ts3.8/integrations/mcp-server/validation.d.ts +4 -1
  348. package/build/types-ts3.8/integrations/spanStreaming.d.ts +2 -0
  349. package/build/types-ts3.8/semanticAttributes.d.ts +23 -3
  350. package/build/types-ts3.8/tracing/ai/gen-ai-attributes.d.ts +6 -46
  351. package/build/types-ts3.8/tracing/ai/utils.d.ts +34 -9
  352. package/build/types-ts3.8/tracing/anthropic-ai/constants.d.ts +24 -9
  353. package/build/types-ts3.8/tracing/anthropic-ai/types.d.ts +5 -2
  354. package/build/types-ts3.8/tracing/anthropic-ai/utils.d.ts +1 -5
  355. package/build/types-ts3.8/tracing/google-genai/constants.d.ts +22 -9
  356. package/build/types-ts3.8/tracing/google-genai/types.d.ts +6 -2
  357. package/build/types-ts3.8/tracing/google-genai/utils.d.ts +0 -9
  358. package/build/types-ts3.8/tracing/index.d.ts +1 -0
  359. package/build/types-ts3.8/tracing/langchain/embeddings.d.ts +27 -0
  360. package/build/types-ts3.8/tracing/langchain/index.d.ts +1 -0
  361. package/build/types-ts3.8/tracing/openai/constants.d.ts +14 -6
  362. package/build/types-ts3.8/tracing/openai/types.d.ts +5 -2
  363. package/build/types-ts3.8/tracing/openai/utils.d.ts +4 -63
  364. package/build/types-ts3.8/tracing/sentryNonRecordingSpan.d.ts +12 -1
  365. package/build/types-ts3.8/tracing/sentrySpan.d.ts +10 -1
  366. package/build/types-ts3.8/tracing/spans/beforeSendSpan.d.ts +35 -0
  367. package/build/types-ts3.8/tracing/spans/captureSpan.d.ts +26 -0
  368. package/build/types-ts3.8/tracing/spans/envelope.d.ts +8 -0
  369. package/build/types-ts3.8/tracing/spans/estimateSize.d.ts +12 -0
  370. package/build/types-ts3.8/tracing/spans/hasSpanStreamingEnabled.d.ts +6 -0
  371. package/build/types-ts3.8/tracing/spans/spanBuffer.d.ts +60 -0
  372. package/build/types-ts3.8/types-hoist/envelope.d.ts +22 -2
  373. package/build/types-ts3.8/types-hoist/integration.d.ts +8 -0
  374. package/build/types-ts3.8/types-hoist/link.d.ts +2 -2
  375. package/build/types-ts3.8/types-hoist/options.d.ts +26 -2
  376. package/build/types-ts3.8/types-hoist/span.d.ts +35 -0
  377. package/build/types-ts3.8/utils/object.d.ts +10 -0
  378. package/build/types-ts3.8/utils/spanUtils.d.ts +27 -2
  379. package/build/types-ts3.8/utils/string.d.ts +2 -2
  380. package/build/types-ts3.8/utils/traceData.d.ts +4 -0
  381. package/package.json +1 -1
@@ -1,94 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const genAiAttributes = require('../ai/gen-ai-attributes.js');
4
- const constants = require('./constants.js');
5
-
6
- /**
7
- * Maps OpenAI method paths to OpenTelemetry semantic convention operation names
8
- * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/#llm-request-spans
9
- */
10
- function getOperationName(methodPath) {
11
- if (methodPath.includes('chat.completions')) {
12
- return genAiAttributes.OPENAI_OPERATIONS.CHAT;
13
- }
14
- if (methodPath.includes('responses')) {
15
- return genAiAttributes.OPENAI_OPERATIONS.CHAT;
16
- }
17
- if (methodPath.includes('embeddings')) {
18
- return genAiAttributes.OPENAI_OPERATIONS.EMBEDDINGS;
19
- }
20
- if (methodPath.includes('conversations')) {
21
- return genAiAttributes.OPENAI_OPERATIONS.CHAT;
22
- }
23
- return methodPath.split('.').pop() || 'unknown';
24
- }
25
-
26
- /**
27
- * Get the span operation for OpenAI methods
28
- * Following Sentry's convention: "gen_ai.{operation_name}"
29
- */
30
- function getSpanOperation(methodPath) {
31
- return `gen_ai.${getOperationName(methodPath)}`;
32
- }
33
-
34
- /**
35
- * Check if a method path should be instrumented
36
- */
37
- function shouldInstrument(methodPath) {
38
- return constants.INSTRUMENTED_METHODS.includes(methodPath );
39
- }
40
-
41
- /**
42
- * Check if response is a Chat Completion object
43
- */
44
- function isChatCompletionResponse(response) {
45
- return (
46
- response !== null &&
47
- typeof response === 'object' &&
48
- 'object' in response &&
49
- (response ).object === 'chat.completion'
50
- );
51
- }
52
-
53
- /**
54
- * Check if response is a Responses API object
55
- */
56
- function isResponsesApiResponse(response) {
57
- return (
58
- response !== null &&
59
- typeof response === 'object' &&
60
- 'object' in response &&
61
- (response ).object === 'response'
62
- );
63
- }
64
-
65
- /**
66
- * Check if response is an Embeddings API object
67
- */
68
- function isEmbeddingsResponse(response) {
69
- if (response === null || typeof response !== 'object' || !('object' in response)) {
70
- return false;
71
- }
72
- const responseObject = response ;
73
- return (
74
- responseObject.object === 'list' &&
75
- typeof responseObject.model === 'string' &&
76
- responseObject.model.toLowerCase().includes('embedding')
77
- );
78
- }
79
-
80
- /**
81
- * Check if response is a Conversations API object
82
- * @see https://platform.openai.com/docs/api-reference/conversations
83
- */
84
- function isConversationResponse(response) {
85
- return (
86
- response !== null &&
87
- typeof response === 'object' &&
88
- 'object' in response &&
89
- (response ).object === 'conversation'
90
- );
91
- }
92
4
 
93
5
  /**
94
6
  * Check if streaming event is from the Responses API
@@ -116,173 +28,108 @@ function isChatCompletionChunk(event) {
116
28
  }
117
29
 
118
30
  /**
119
- * Add attributes for Chat Completion responses
31
+ * Add response attributes to a span using duck-typing.
32
+ * Works for Chat Completions, Responses API, Embeddings, and Conversations API responses.
120
33
  */
121
- function addChatCompletionAttributes(
122
- span,
123
- response,
124
- recordOutputs,
125
- ) {
126
- setCommonResponseAttributes(span, response.id, response.model, response.created);
127
- if (response.usage) {
128
- setTokenUsageAttributes(
129
- span,
130
- response.usage.prompt_tokens,
131
- response.usage.completion_tokens,
132
- response.usage.total_tokens,
133
- );
34
+ function addResponseAttributes(span, result, recordOutputs) {
35
+ if (!result || typeof result !== 'object') return;
36
+
37
+ const response = result ;
38
+ const attrs = {};
39
+
40
+ // Response ID
41
+ if (typeof response.id === 'string') {
42
+ attrs[genAiAttributes.GEN_AI_RESPONSE_ID_ATTRIBUTE] = response.id;
43
+ }
44
+
45
+ // Response model
46
+ if (typeof response.model === 'string') {
47
+ attrs[genAiAttributes.GEN_AI_RESPONSE_MODEL_ATTRIBUTE] = response.model;
134
48
  }
49
+
50
+ // Conversation ID (conversation objects use id as conversation link)
51
+ if (response.object === 'conversation' && typeof response.id === 'string') {
52
+ attrs[genAiAttributes.GEN_AI_CONVERSATION_ID_ATTRIBUTE] = response.id;
53
+ }
54
+
55
+ // Token usage — supports both naming conventions (chat: prompt_tokens/completion_tokens, responses: input_tokens/output_tokens)
56
+ if (response.usage && typeof response.usage === 'object') {
57
+ const usage = response.usage ;
58
+
59
+ const inputTokens = usage.prompt_tokens ?? usage.input_tokens;
60
+ if (typeof inputTokens === 'number') {
61
+ attrs[genAiAttributes.GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] = inputTokens;
62
+ }
63
+
64
+ const outputTokens = usage.completion_tokens ?? usage.output_tokens;
65
+ if (typeof outputTokens === 'number') {
66
+ attrs[genAiAttributes.GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE] = outputTokens;
67
+ }
68
+
69
+ if (typeof usage.total_tokens === 'number') {
70
+ attrs[genAiAttributes.GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE] = usage.total_tokens;
71
+ }
72
+ }
73
+
74
+ // Finish reasons from choices (chat completions)
135
75
  if (Array.isArray(response.choices)) {
136
- const finishReasons = response.choices
76
+ const choices = response.choices ;
77
+ const finishReasons = choices
137
78
  .map(choice => choice.finish_reason)
138
- .filter((reason) => reason !== null);
79
+ .filter((reason) => typeof reason === 'string');
139
80
  if (finishReasons.length > 0) {
140
- span.setAttributes({
141
- [genAiAttributes.GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE]: JSON.stringify(finishReasons),
142
- });
81
+ attrs[genAiAttributes.GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE] = JSON.stringify(finishReasons);
143
82
  }
144
83
 
145
- // Extract tool calls from all choices (only if recordOutputs is true)
146
84
  if (recordOutputs) {
147
- const toolCalls = response.choices
148
- .map(choice => choice.message?.tool_calls)
85
+ // Response text from choices
86
+ const responseTexts = choices.map(choice => {
87
+ const message = choice.message ;
88
+ return (message?.content ) || '';
89
+ });
90
+ attrs[genAiAttributes.GEN_AI_RESPONSE_TEXT_ATTRIBUTE] = JSON.stringify(responseTexts);
91
+
92
+ // Tool calls from choices
93
+ const toolCalls = choices
94
+ .map(choice => {
95
+ const message = choice.message ;
96
+ return message?.tool_calls;
97
+ })
149
98
  .filter(calls => Array.isArray(calls) && calls.length > 0)
150
99
  .flat();
151
100
 
152
101
  if (toolCalls.length > 0) {
153
- span.setAttributes({
154
- [genAiAttributes.GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE]: JSON.stringify(toolCalls),
155
- });
102
+ attrs[genAiAttributes.GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE] = JSON.stringify(toolCalls);
156
103
  }
157
104
  }
158
105
  }
159
- }
160
106
 
161
- /**
162
- * Add attributes for Responses API responses
163
- */
164
- function addResponsesApiAttributes(span, response, recordOutputs) {
165
- setCommonResponseAttributes(span, response.id, response.model, response.created_at);
166
- if (response.status) {
167
- span.setAttributes({
168
- [genAiAttributes.GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE]: JSON.stringify([response.status]),
169
- });
170
- }
171
- if (response.usage) {
172
- setTokenUsageAttributes(
173
- span,
174
- response.usage.input_tokens,
175
- response.usage.output_tokens,
176
- response.usage.total_tokens,
177
- );
107
+ // Finish reason from status (responses API)
108
+ if (typeof response.status === 'string') {
109
+ // Only set if not already set from choices
110
+ if (!attrs[genAiAttributes.GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE]) {
111
+ attrs[genAiAttributes.GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE] = JSON.stringify([response.status]);
112
+ }
178
113
  }
179
114
 
180
- // Extract function calls from output (only if recordOutputs is true)
181
115
  if (recordOutputs) {
182
- const responseWithOutput = response ;
183
- if (Array.isArray(responseWithOutput.output) && responseWithOutput.output.length > 0) {
184
- // Filter for function_call type objects in the output array
185
- const functionCalls = responseWithOutput.output.filter(
186
- (item) =>
187
- // oxlint-disable-next-line typescript/prefer-optional-chain
188
- typeof item === 'object' && item !== null && (item ).type === 'function_call',
189
- );
116
+ // Response text from output_text (responses API)
117
+ if (typeof response.output_text === 'string' && !attrs[genAiAttributes.GEN_AI_RESPONSE_TEXT_ATTRIBUTE]) {
118
+ attrs[genAiAttributes.GEN_AI_RESPONSE_TEXT_ATTRIBUTE] = response.output_text;
119
+ }
190
120
 
121
+ // Tool calls from output array (responses API)
122
+ if (Array.isArray(response.output) && response.output.length > 0 && !attrs[genAiAttributes.GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE]) {
123
+ const functionCalls = (response.output ).filter(
124
+ item => item?.type === 'function_call',
125
+ );
191
126
  if (functionCalls.length > 0) {
192
- span.setAttributes({
193
- [genAiAttributes.GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE]: JSON.stringify(functionCalls),
194
- });
127
+ attrs[genAiAttributes.GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE] = JSON.stringify(functionCalls);
195
128
  }
196
129
  }
197
130
  }
198
- }
199
-
200
- /**
201
- * Add attributes for Embeddings API responses
202
- */
203
- function addEmbeddingsAttributes(span, response) {
204
- span.setAttributes({
205
- [genAiAttributes.OPENAI_RESPONSE_MODEL_ATTRIBUTE]: response.model,
206
- [genAiAttributes.GEN_AI_RESPONSE_MODEL_ATTRIBUTE]: response.model,
207
- });
208
-
209
- if (response.usage) {
210
- setTokenUsageAttributes(span, response.usage.prompt_tokens, undefined, response.usage.total_tokens);
211
- }
212
- }
213
-
214
- /**
215
- * Add attributes for Conversations API responses
216
- * @see https://platform.openai.com/docs/api-reference/conversations
217
- */
218
- function addConversationAttributes(span, response) {
219
- const { id, created_at } = response;
220
-
221
- span.setAttributes({
222
- [genAiAttributes.OPENAI_RESPONSE_ID_ATTRIBUTE]: id,
223
- [genAiAttributes.GEN_AI_RESPONSE_ID_ATTRIBUTE]: id,
224
- // The conversation id is used to link messages across API calls
225
- [genAiAttributes.GEN_AI_CONVERSATION_ID_ATTRIBUTE]: id,
226
- });
227
-
228
- if (created_at) {
229
- span.setAttributes({
230
- [genAiAttributes.OPENAI_RESPONSE_TIMESTAMP_ATTRIBUTE]: new Date(created_at * 1000).toISOString(),
231
- });
232
- }
233
- }
234
131
 
235
- /**
236
- * Set token usage attributes
237
- * @param span - The span to add attributes to
238
- * @param promptTokens - The number of prompt tokens
239
- * @param completionTokens - The number of completion tokens
240
- * @param totalTokens - The number of total tokens
241
- */
242
- function setTokenUsageAttributes(
243
- span,
244
- promptTokens,
245
- completionTokens,
246
- totalTokens,
247
- ) {
248
- if (promptTokens !== undefined) {
249
- span.setAttributes({
250
- [genAiAttributes.OPENAI_USAGE_PROMPT_TOKENS_ATTRIBUTE]: promptTokens,
251
- [genAiAttributes.GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE]: promptTokens,
252
- });
253
- }
254
- if (completionTokens !== undefined) {
255
- span.setAttributes({
256
- [genAiAttributes.OPENAI_USAGE_COMPLETION_TOKENS_ATTRIBUTE]: completionTokens,
257
- [genAiAttributes.GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE]: completionTokens,
258
- });
259
- }
260
- if (totalTokens !== undefined) {
261
- span.setAttributes({
262
- [genAiAttributes.GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE]: totalTokens,
263
- });
264
- }
265
- }
266
-
267
- /**
268
- * Set common response attributes
269
- * @param span - The span to add attributes to
270
- * @param id - The response id
271
- * @param model - The response model
272
- * @param timestamp - The response timestamp
273
- */
274
- function setCommonResponseAttributes(span, id, model, timestamp) {
275
- span.setAttributes({
276
- [genAiAttributes.OPENAI_RESPONSE_ID_ATTRIBUTE]: id,
277
- [genAiAttributes.GEN_AI_RESPONSE_ID_ATTRIBUTE]: id,
278
- });
279
- span.setAttributes({
280
- [genAiAttributes.OPENAI_RESPONSE_MODEL_ATTRIBUTE]: model,
281
- [genAiAttributes.GEN_AI_RESPONSE_MODEL_ATTRIBUTE]: model,
282
- });
283
- span.setAttributes({
284
- [genAiAttributes.OPENAI_RESPONSE_TIMESTAMP_ATTRIBUTE]: new Date(timestamp * 1000).toISOString(),
285
- });
132
+ span.setAttributes(attrs);
286
133
  }
287
134
 
288
135
  /**
@@ -327,20 +174,8 @@ function extractRequestParameters(params) {
327
174
  return attributes;
328
175
  }
329
176
 
330
- exports.addChatCompletionAttributes = addChatCompletionAttributes;
331
- exports.addConversationAttributes = addConversationAttributes;
332
- exports.addEmbeddingsAttributes = addEmbeddingsAttributes;
333
- exports.addResponsesApiAttributes = addResponsesApiAttributes;
177
+ exports.addResponseAttributes = addResponseAttributes;
334
178
  exports.extractRequestParameters = extractRequestParameters;
335
- exports.getOperationName = getOperationName;
336
- exports.getSpanOperation = getSpanOperation;
337
179
  exports.isChatCompletionChunk = isChatCompletionChunk;
338
- exports.isChatCompletionResponse = isChatCompletionResponse;
339
- exports.isConversationResponse = isConversationResponse;
340
- exports.isEmbeddingsResponse = isEmbeddingsResponse;
341
- exports.isResponsesApiResponse = isResponsesApiResponse;
342
180
  exports.isResponsesApiStreamEvent = isResponsesApiStreamEvent;
343
- exports.setCommonResponseAttributes = setCommonResponseAttributes;
344
- exports.setTokenUsageAttributes = setTokenUsageAttributes;
345
- exports.shouldInstrument = shouldInstrument;
346
181
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../../src/tracing/openai/utils.ts"],"sourcesContent":["import type { Span } from '../../types-hoist/span';\nimport {\n GEN_AI_CONVERSATION_ID_ATTRIBUTE,\n GEN_AI_REQUEST_DIMENSIONS_ATTRIBUTE,\n GEN_AI_REQUEST_ENCODING_FORMAT_ATTRIBUTE,\n GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE,\n GEN_AI_REQUEST_MODEL_ATTRIBUTE,\n GEN_AI_REQUEST_PRESENCE_PENALTY_ATTRIBUTE,\n GEN_AI_REQUEST_STREAM_ATTRIBUTE,\n GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE,\n GEN_AI_REQUEST_TOP_P_ATTRIBUTE,\n GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE,\n GEN_AI_RESPONSE_ID_ATTRIBUTE,\n GEN_AI_RESPONSE_MODEL_ATTRIBUTE,\n GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,\n OPENAI_OPERATIONS,\n OPENAI_RESPONSE_ID_ATTRIBUTE,\n OPENAI_RESPONSE_MODEL_ATTRIBUTE,\n OPENAI_RESPONSE_TIMESTAMP_ATTRIBUTE,\n OPENAI_USAGE_COMPLETION_TOKENS_ATTRIBUTE,\n OPENAI_USAGE_PROMPT_TOKENS_ATTRIBUTE,\n} from '../ai/gen-ai-attributes';\nimport { INSTRUMENTED_METHODS } from './constants';\nimport type {\n ChatCompletionChunk,\n InstrumentedMethod,\n OpenAiChatCompletionObject,\n OpenAIConversationObject,\n OpenAICreateEmbeddingsObject,\n OpenAIResponseObject,\n ResponseStreamingEvent,\n} from './types';\n\n/**\n * Maps OpenAI method paths to OpenTelemetry semantic convention operation names\n * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/#llm-request-spans\n */\nexport function getOperationName(methodPath: string): string {\n if (methodPath.includes('chat.completions')) {\n return OPENAI_OPERATIONS.CHAT;\n }\n if (methodPath.includes('responses')) {\n return OPENAI_OPERATIONS.CHAT;\n }\n if (methodPath.includes('embeddings')) {\n return OPENAI_OPERATIONS.EMBEDDINGS;\n }\n if (methodPath.includes('conversations')) {\n return OPENAI_OPERATIONS.CHAT;\n }\n return methodPath.split('.').pop() || 'unknown';\n}\n\n/**\n * Get the span operation for OpenAI methods\n * Following Sentry's convention: \"gen_ai.{operation_name}\"\n */\nexport function getSpanOperation(methodPath: string): string {\n return `gen_ai.${getOperationName(methodPath)}`;\n}\n\n/**\n * Check if a method path should be instrumented\n */\nexport function shouldInstrument(methodPath: string): methodPath is InstrumentedMethod {\n return INSTRUMENTED_METHODS.includes(methodPath as InstrumentedMethod);\n}\n\n/**\n * Check if response is a Chat Completion object\n */\nexport function isChatCompletionResponse(response: unknown): response is OpenAiChatCompletionObject {\n return (\n response !== null &&\n typeof response === 'object' &&\n 'object' in response &&\n (response as Record<string, unknown>).object === 'chat.completion'\n );\n}\n\n/**\n * Check if response is a Responses API object\n */\nexport function isResponsesApiResponse(response: unknown): response is OpenAIResponseObject {\n return (\n response !== null &&\n typeof response === 'object' &&\n 'object' in response &&\n (response as Record<string, unknown>).object === 'response'\n );\n}\n\n/**\n * Check if response is an Embeddings API object\n */\nexport function isEmbeddingsResponse(response: unknown): response is OpenAICreateEmbeddingsObject {\n if (response === null || typeof response !== 'object' || !('object' in response)) {\n return false;\n }\n const responseObject = response as Record<string, unknown>;\n return (\n responseObject.object === 'list' &&\n typeof responseObject.model === 'string' &&\n responseObject.model.toLowerCase().includes('embedding')\n );\n}\n\n/**\n * Check if response is a Conversations API object\n * @see https://platform.openai.com/docs/api-reference/conversations\n */\nexport function isConversationResponse(response: unknown): response is OpenAIConversationObject {\n return (\n response !== null &&\n typeof response === 'object' &&\n 'object' in response &&\n (response as Record<string, unknown>).object === 'conversation'\n );\n}\n\n/**\n * Check if streaming event is from the Responses API\n */\nexport function isResponsesApiStreamEvent(event: unknown): event is ResponseStreamingEvent {\n return (\n event !== null &&\n typeof event === 'object' &&\n 'type' in event &&\n typeof (event as Record<string, unknown>).type === 'string' &&\n ((event as Record<string, unknown>).type as string).startsWith('response.')\n );\n}\n\n/**\n * Check if streaming event is a chat completion chunk\n */\nexport function isChatCompletionChunk(event: unknown): event is ChatCompletionChunk {\n return (\n event !== null &&\n typeof event === 'object' &&\n 'object' in event &&\n (event as Record<string, unknown>).object === 'chat.completion.chunk'\n );\n}\n\n/**\n * Add attributes for Chat Completion responses\n */\nexport function addChatCompletionAttributes(\n span: Span,\n response: OpenAiChatCompletionObject,\n recordOutputs?: boolean,\n): void {\n setCommonResponseAttributes(span, response.id, response.model, response.created);\n if (response.usage) {\n setTokenUsageAttributes(\n span,\n response.usage.prompt_tokens,\n response.usage.completion_tokens,\n response.usage.total_tokens,\n );\n }\n if (Array.isArray(response.choices)) {\n const finishReasons = response.choices\n .map(choice => choice.finish_reason)\n .filter((reason): reason is string => reason !== null);\n if (finishReasons.length > 0) {\n span.setAttributes({\n [GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE]: JSON.stringify(finishReasons),\n });\n }\n\n // Extract tool calls from all choices (only if recordOutputs is true)\n if (recordOutputs) {\n const toolCalls = response.choices\n .map(choice => choice.message?.tool_calls)\n .filter(calls => Array.isArray(calls) && calls.length > 0)\n .flat();\n\n if (toolCalls.length > 0) {\n span.setAttributes({\n [GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE]: JSON.stringify(toolCalls),\n });\n }\n }\n }\n}\n\n/**\n * Add attributes for Responses API responses\n */\nexport function addResponsesApiAttributes(span: Span, response: OpenAIResponseObject, recordOutputs?: boolean): void {\n setCommonResponseAttributes(span, response.id, response.model, response.created_at);\n if (response.status) {\n span.setAttributes({\n [GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE]: JSON.stringify([response.status]),\n });\n }\n if (response.usage) {\n setTokenUsageAttributes(\n span,\n response.usage.input_tokens,\n response.usage.output_tokens,\n response.usage.total_tokens,\n );\n }\n\n // Extract function calls from output (only if recordOutputs is true)\n if (recordOutputs) {\n const responseWithOutput = response as OpenAIResponseObject & { output?: unknown[] };\n if (Array.isArray(responseWithOutput.output) && responseWithOutput.output.length > 0) {\n // Filter for function_call type objects in the output array\n const functionCalls = responseWithOutput.output.filter(\n (item): unknown =>\n // oxlint-disable-next-line typescript/prefer-optional-chain\n typeof item === 'object' && item !== null && (item as Record<string, unknown>).type === 'function_call',\n );\n\n if (functionCalls.length > 0) {\n span.setAttributes({\n [GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE]: JSON.stringify(functionCalls),\n });\n }\n }\n }\n}\n\n/**\n * Add attributes for Embeddings API responses\n */\nexport function addEmbeddingsAttributes(span: Span, response: OpenAICreateEmbeddingsObject): void {\n span.setAttributes({\n [OPENAI_RESPONSE_MODEL_ATTRIBUTE]: response.model,\n [GEN_AI_RESPONSE_MODEL_ATTRIBUTE]: response.model,\n });\n\n if (response.usage) {\n setTokenUsageAttributes(span, response.usage.prompt_tokens, undefined, response.usage.total_tokens);\n }\n}\n\n/**\n * Add attributes for Conversations API responses\n * @see https://platform.openai.com/docs/api-reference/conversations\n */\nexport function addConversationAttributes(span: Span, response: OpenAIConversationObject): void {\n const { id, created_at } = response;\n\n span.setAttributes({\n [OPENAI_RESPONSE_ID_ATTRIBUTE]: id,\n [GEN_AI_RESPONSE_ID_ATTRIBUTE]: id,\n // The conversation id is used to link messages across API calls\n [GEN_AI_CONVERSATION_ID_ATTRIBUTE]: id,\n });\n\n if (created_at) {\n span.setAttributes({\n [OPENAI_RESPONSE_TIMESTAMP_ATTRIBUTE]: new Date(created_at * 1000).toISOString(),\n });\n }\n}\n\n/**\n * Set token usage attributes\n * @param span - The span to add attributes to\n * @param promptTokens - The number of prompt tokens\n * @param completionTokens - The number of completion tokens\n * @param totalTokens - The number of total tokens\n */\nexport function setTokenUsageAttributes(\n span: Span,\n promptTokens?: number,\n completionTokens?: number,\n totalTokens?: number,\n): void {\n if (promptTokens !== undefined) {\n span.setAttributes({\n [OPENAI_USAGE_PROMPT_TOKENS_ATTRIBUTE]: promptTokens,\n [GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE]: promptTokens,\n });\n }\n if (completionTokens !== undefined) {\n span.setAttributes({\n [OPENAI_USAGE_COMPLETION_TOKENS_ATTRIBUTE]: completionTokens,\n [GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE]: completionTokens,\n });\n }\n if (totalTokens !== undefined) {\n span.setAttributes({\n [GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE]: totalTokens,\n });\n }\n}\n\n/**\n * Set common response attributes\n * @param span - The span to add attributes to\n * @param id - The response id\n * @param model - The response model\n * @param timestamp - The response timestamp\n */\nexport function setCommonResponseAttributes(span: Span, id: string, model: string, timestamp: number): void {\n span.setAttributes({\n [OPENAI_RESPONSE_ID_ATTRIBUTE]: id,\n [GEN_AI_RESPONSE_ID_ATTRIBUTE]: id,\n });\n span.setAttributes({\n [OPENAI_RESPONSE_MODEL_ATTRIBUTE]: model,\n [GEN_AI_RESPONSE_MODEL_ATTRIBUTE]: model,\n });\n span.setAttributes({\n [OPENAI_RESPONSE_TIMESTAMP_ATTRIBUTE]: new Date(timestamp * 1000).toISOString(),\n });\n}\n\n/**\n * Extract conversation ID from request parameters\n * Supports both Conversations API and previous_response_id chaining\n * @see https://platform.openai.com/docs/guides/conversation-state\n */\nfunction extractConversationId(params: Record<string, unknown>): string | undefined {\n // Conversations API: conversation parameter (e.g., \"conv_...\")\n if ('conversation' in params && typeof params.conversation === 'string') {\n return params.conversation;\n }\n // Responses chaining: previous_response_id links to parent response\n if ('previous_response_id' in params && typeof params.previous_response_id === 'string') {\n return params.previous_response_id;\n }\n return undefined;\n}\n\n/**\n * Extract request parameters including model settings and conversation context\n */\nexport function extractRequestParameters(params: Record<string, unknown>): Record<string, unknown> {\n const attributes: Record<string, unknown> = {\n [GEN_AI_REQUEST_MODEL_ATTRIBUTE]: params.model ?? 'unknown',\n };\n\n if ('temperature' in params) attributes[GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE] = params.temperature;\n if ('top_p' in params) attributes[GEN_AI_REQUEST_TOP_P_ATTRIBUTE] = params.top_p;\n if ('frequency_penalty' in params) attributes[GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE] = params.frequency_penalty;\n if ('presence_penalty' in params) attributes[GEN_AI_REQUEST_PRESENCE_PENALTY_ATTRIBUTE] = params.presence_penalty;\n if ('stream' in params) attributes[GEN_AI_REQUEST_STREAM_ATTRIBUTE] = params.stream;\n if ('encoding_format' in params) attributes[GEN_AI_REQUEST_ENCODING_FORMAT_ATTRIBUTE] = params.encoding_format;\n if ('dimensions' in params) attributes[GEN_AI_REQUEST_DIMENSIONS_ATTRIBUTE] = params.dimensions;\n\n // Capture conversation ID for linking messages across API calls\n const conversationId = extractConversationId(params);\n if (conversationId) {\n attributes[GEN_AI_CONVERSATION_ID_ATTRIBUTE] = conversationId;\n }\n\n return attributes;\n}\n"],"names":["OPENAI_OPERATIONS","INSTRUMENTED_METHODS","GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE","GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE","OPENAI_RESPONSE_MODEL_ATTRIBUTE","GEN_AI_RESPONSE_MODEL_ATTRIBUTE","OPENAI_RESPONSE_ID_ATTRIBUTE","GEN_AI_RESPONSE_ID_ATTRIBUTE","GEN_AI_CONVERSATION_ID_ATTRIBUTE","OPENAI_RESPONSE_TIMESTAMP_ATTRIBUTE","OPENAI_USAGE_PROMPT_TOKENS_ATTRIBUTE","GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE","OPENAI_USAGE_COMPLETION_TOKENS_ATTRIBUTE","GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE","GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE","GEN_AI_REQUEST_MODEL_ATTRIBUTE","GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE","GEN_AI_REQUEST_TOP_P_ATTRIBUTE","GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE","GEN_AI_REQUEST_PRESENCE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OAAA,MAAA,CAAA,oBAAA;AACA,EAAA;AACA,EAAA,OAAA,SAAA;AACA;;AAEA;AACA;AACA;AACA,SAAA,wBAAA,CAAA,MAAA,EAAA;AACA,EAAA,MAAA,UAAA,GAAA;AACA,IAAA,CAAAM,8CAAA,GAAA,MAAA,CAAA,KAAA,IAAA,SAAA;AACA,GAAA;;AAEA,EAAA,IAAA,aAAA,IAAA,MAAA,EAAA,UAAA,CAAAC,oDAAA,CAAA,GAAA,MAAA,CAAA,WAAA;AACA,EAAA,IAAA,OAAA,IAAA,MAAA,EAAA,UAAA,CAAAC,8CAAA,CAAA,GAAA,MAAA,CAAA,KAAA;AACA,EAAA,IAAA,mBAAA,IAAA,MAAA,EAAA,UAAA,CAAAC,0DAAA,CAAA,GAAA,MAAA,CAAA,iBAAA;AACA,EAAA,IAAA,kBAAA,IAAA,MAAA,EAAA,UAAA,CAAAC,yDAAA,CAAA,GAAA,MAAA,CAAA,gBAAA;AACA,EAAA,IAAA,QAAA,IAAA,MAAA,EAAA,UAAA,CAAAC,+CAAA,CAAA,GAAA,MAAA,CAAA,MAAA;AACA,EAAA,IAAA,iBAAA,IAAA,MAAA,EAAA,UAAA,CAAAC,wDAAA,CAAA,GAAA,MAAA,CAAA,eAAA;AACA,EAAA,IAAA,YAAA,IAAA,MAAA,EAAA,UAAA,CAAAC,mDAAA,CAAA,GAAA,MAAA,CAAA,UAAA;;AAEA;AACA,EAAA,MAAA,cAAA,GAAA,qBAAA,CAAA,MAAA,CAAA;AACA,EAAA,IAAA,cAAA,EAAA;AACA,IAAA,UAAA,CAAAd,gDAAA,CAAA,GAAA,cAAA;AACA,EAAA;;AAEA,EAAA,OAAA,UAAA;AACA;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../../src/tracing/openai/utils.ts"],"sourcesContent":["import type { Span } from '../../types-hoist/span';\nimport type { SpanAttributeValue } from '../../types-hoist/span';\nimport {\n GEN_AI_CONVERSATION_ID_ATTRIBUTE,\n GEN_AI_REQUEST_DIMENSIONS_ATTRIBUTE,\n GEN_AI_REQUEST_ENCODING_FORMAT_ATTRIBUTE,\n GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE,\n GEN_AI_REQUEST_MODEL_ATTRIBUTE,\n GEN_AI_REQUEST_PRESENCE_PENALTY_ATTRIBUTE,\n GEN_AI_REQUEST_STREAM_ATTRIBUTE,\n GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE,\n GEN_AI_REQUEST_TOP_P_ATTRIBUTE,\n GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE,\n GEN_AI_RESPONSE_ID_ATTRIBUTE,\n GEN_AI_RESPONSE_MODEL_ATTRIBUTE,\n GEN_AI_RESPONSE_TEXT_ATTRIBUTE,\n GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE,\n GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,\n GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,\n} from '../ai/gen-ai-attributes';\nimport type { ChatCompletionChunk, ResponseStreamingEvent } from './types';\n\n/**\n * Check if streaming event is from the Responses API\n */\nexport function isResponsesApiStreamEvent(event: unknown): event is ResponseStreamingEvent {\n return (\n event !== null &&\n typeof event === 'object' &&\n 'type' in event &&\n typeof (event as Record<string, unknown>).type === 'string' &&\n ((event as Record<string, unknown>).type as string).startsWith('response.')\n );\n}\n\n/**\n * Check if streaming event is a chat completion chunk\n */\nexport function isChatCompletionChunk(event: unknown): event is ChatCompletionChunk {\n return (\n event !== null &&\n typeof event === 'object' &&\n 'object' in event &&\n (event as Record<string, unknown>).object === 'chat.completion.chunk'\n );\n}\n\n/**\n * Add response attributes to a span using duck-typing.\n * Works for Chat Completions, Responses API, Embeddings, and Conversations API responses.\n */\nexport function addResponseAttributes(span: Span, result: unknown, recordOutputs?: boolean): void {\n if (!result || typeof result !== 'object') return;\n\n const response = result as Record<string, unknown>;\n const attrs: Record<string, SpanAttributeValue> = {};\n\n // Response ID\n if (typeof response.id === 'string') {\n attrs[GEN_AI_RESPONSE_ID_ATTRIBUTE] = response.id;\n }\n\n // Response model\n if (typeof response.model === 'string') {\n attrs[GEN_AI_RESPONSE_MODEL_ATTRIBUTE] = response.model;\n }\n\n // Conversation ID (conversation objects use id as conversation link)\n if (response.object === 'conversation' && typeof response.id === 'string') {\n attrs[GEN_AI_CONVERSATION_ID_ATTRIBUTE] = response.id;\n }\n\n // Token usage — supports both naming conventions (chat: prompt_tokens/completion_tokens, responses: input_tokens/output_tokens)\n if (response.usage && typeof response.usage === 'object') {\n const usage = response.usage as Record<string, unknown>;\n\n const inputTokens = usage.prompt_tokens ?? usage.input_tokens;\n if (typeof inputTokens === 'number') {\n attrs[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE] = inputTokens;\n }\n\n const outputTokens = usage.completion_tokens ?? usage.output_tokens;\n if (typeof outputTokens === 'number') {\n attrs[GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE] = outputTokens;\n }\n\n if (typeof usage.total_tokens === 'number') {\n attrs[GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE] = usage.total_tokens;\n }\n }\n\n // Finish reasons from choices (chat completions)\n if (Array.isArray(response.choices)) {\n const choices = response.choices as Array<Record<string, unknown>>;\n const finishReasons = choices\n .map(choice => choice.finish_reason)\n .filter((reason): reason is string => typeof reason === 'string');\n if (finishReasons.length > 0) {\n attrs[GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE] = JSON.stringify(finishReasons);\n }\n\n if (recordOutputs) {\n // Response text from choices\n const responseTexts = choices.map(choice => {\n const message = choice.message as Record<string, unknown> | undefined;\n return (message?.content as string) || '';\n });\n attrs[GEN_AI_RESPONSE_TEXT_ATTRIBUTE] = JSON.stringify(responseTexts);\n\n // Tool calls from choices\n const toolCalls = choices\n .map(choice => {\n const message = choice.message as Record<string, unknown> | undefined;\n return message?.tool_calls;\n })\n .filter(calls => Array.isArray(calls) && calls.length > 0)\n .flat();\n\n if (toolCalls.length > 0) {\n attrs[GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE] = JSON.stringify(toolCalls);\n }\n }\n }\n\n // Finish reason from status (responses API)\n if (typeof response.status === 'string') {\n // Only set if not already set from choices\n if (!attrs[GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE]) {\n attrs[GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE] = JSON.stringify([response.status]);\n }\n }\n\n if (recordOutputs) {\n // Response text from output_text (responses API)\n if (typeof response.output_text === 'string' && !attrs[GEN_AI_RESPONSE_TEXT_ATTRIBUTE]) {\n attrs[GEN_AI_RESPONSE_TEXT_ATTRIBUTE] = response.output_text;\n }\n\n // Tool calls from output array (responses API)\n if (Array.isArray(response.output) && response.output.length > 0 && !attrs[GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE]) {\n const functionCalls = (response.output as Array<Record<string, unknown>>).filter(\n item => item?.type === 'function_call',\n );\n if (functionCalls.length > 0) {\n attrs[GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE] = JSON.stringify(functionCalls);\n }\n }\n }\n\n span.setAttributes(attrs);\n}\n\n/**\n * Extract conversation ID from request parameters\n * Supports both Conversations API and previous_response_id chaining\n * @see https://platform.openai.com/docs/guides/conversation-state\n */\nfunction extractConversationId(params: Record<string, unknown>): string | undefined {\n // Conversations API: conversation parameter (e.g., \"conv_...\")\n if ('conversation' in params && typeof params.conversation === 'string') {\n return params.conversation;\n }\n // Responses chaining: previous_response_id links to parent response\n if ('previous_response_id' in params && typeof params.previous_response_id === 'string') {\n return params.previous_response_id;\n }\n return undefined;\n}\n\n/**\n * Extract request parameters including model settings and conversation context\n */\nexport function extractRequestParameters(params: Record<string, unknown>): Record<string, unknown> {\n const attributes: Record<string, unknown> = {\n [GEN_AI_REQUEST_MODEL_ATTRIBUTE]: params.model ?? 'unknown',\n };\n\n if ('temperature' in params) attributes[GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE] = params.temperature;\n if ('top_p' in params) attributes[GEN_AI_REQUEST_TOP_P_ATTRIBUTE] = params.top_p;\n if ('frequency_penalty' in params) attributes[GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE] = params.frequency_penalty;\n if ('presence_penalty' in params) attributes[GEN_AI_REQUEST_PRESENCE_PENALTY_ATTRIBUTE] = params.presence_penalty;\n if ('stream' in params) attributes[GEN_AI_REQUEST_STREAM_ATTRIBUTE] = params.stream;\n if ('encoding_format' in params) attributes[GEN_AI_REQUEST_ENCODING_FORMAT_ATTRIBUTE] = params.encoding_format;\n if ('dimensions' in params) attributes[GEN_AI_REQUEST_DIMENSIONS_ATTRIBUTE] = params.dimensions;\n\n // Capture conversation ID for linking messages across API calls\n const conversationId = extractConversationId(params);\n if (conversationId) {\n attributes[GEN_AI_CONVERSATION_ID_ATTRIBUTE] = conversationId;\n }\n\n return attributes;\n}\n"],"names":["GEN_AI_RESPONSE_ID_ATTRIBUTE","GEN_AI_RESPONSE_MODEL_ATTRIBUTE","GEN_AI_CONVERSATION_ID_ATTRIBUTE","GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE","GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE","GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE","GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE","GEN_AI_RESPONSE_TEXT_ATTRIBUTE","GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE","GEN_AI_REQUEST_MODEL_ATTRIBUTE","GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE","GEN_AI_REQUEST_TOP_P_ATTRIBUTE","GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE","GEN_AI_REQUEST_PRESENCE_PENALTY_ATTRIBUTE","GEN_AI_REQUEST_STREAM_ATTRIBUTE","GEN_AI_REQUEST_ENCODING_FORMAT_ATTRIBUTE","GEN_AI_REQUEST_DI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AsB,MAAM,EAAE,UAAU,CAACC,yDAAyC,CAAA,GAAI,MAAM,CAAC,gBAAgB;AACnH,EAAE,IAAI,QAAA,IAAY,MAAM,EAAE,UAAU,CAACC,+CAA+B,CAAA,GAAI,MAAM,CAAC,MAAM;AACrF,EAAE,IAAI,iBAAA,IAAqB,MAAM,EAAE,UAAU,CAACC,wDAAwC,CAAA,GAAI,MAAM,CAAC,eAAe;AAChH,EAAE,IAAI,YAAA,IAAgB,MAAM,EAAE,UAAU,CAACC,mDAAmC,CAAA,GAAI,MAAM,CAAC,UAAU;;AAEjG;AACA,EAAE,MAAM,cAAA,GAAiB,qBAAqB,CAAC,MAAM,CAAC;AACtD,EAAE,IAAI,cAAc,EAAE;AACtB,IAAI,UAAU,CAACd,gDAAgC,CAAA,GAAI,cAAc;AACjE,EAAE;;AAEF,EAAE,OAAO,UAAU;AACnB;;;;;;;"}
@@ -8,9 +8,16 @@ const spanUtils = require('../utils/spanUtils.js');
8
8
  */
9
9
  class SentryNonRecordingSpan {
10
10
 
11
+ /**
12
+ * Reason why this span was dropped, if applicable ('ignored' or 'sample_rate').
13
+ * Used to propagate the correct client report outcome to descendant spans
14
+ * when span streaming is enabled.
15
+ */
16
+
11
17
  constructor(spanContext = {}) {
12
18
  this._traceId = spanContext.traceId || propagationContext.generateTraceId();
13
19
  this._spanId = spanContext.spanId || propagationContext.generateSpanId();
20
+ this.dropReason = spanContext.dropReason;
14
21
  }
15
22
 
16
23
  /** @inheritdoc */
@@ -1 +1 @@
1
- {"version":3,"file":"sentryNonRecordingSpan.js","sources":["../../../src/tracing/sentryNonRecordingSpan.ts"],"sourcesContent":["import type {\n SentrySpanArguments,\n Span,\n SpanAttributes,\n SpanAttributeValue,\n SpanContextData,\n SpanTimeInput,\n} from '../types-hoist/span';\nimport type { SpanStatus } from '../types-hoist/spanStatus';\nimport { generateSpanId, generateTraceId } from '../utils/propagationContext';\nimport { TRACE_FLAG_NONE } from '../utils/spanUtils';\n\n/**\n * A Sentry Span that is non-recording, meaning it will not be sent to Sentry.\n */\nexport class SentryNonRecordingSpan implements Span {\n private _traceId: string;\n private _spanId: string;\n\n public constructor(spanContext: SentrySpanArguments = {}) {\n this._traceId = spanContext.traceId || generateTraceId();\n this._spanId = spanContext.spanId || generateSpanId();\n }\n\n /** @inheritdoc */\n public spanContext(): SpanContextData {\n return {\n spanId: this._spanId,\n traceId: this._traceId,\n traceFlags: TRACE_FLAG_NONE,\n };\n }\n\n /** @inheritdoc */\n public end(_timestamp?: SpanTimeInput): void {}\n\n /** @inheritdoc */\n public setAttribute(_key: string, _value: SpanAttributeValue | undefined): this {\n return this;\n }\n\n /** @inheritdoc */\n public setAttributes(_values: SpanAttributes): this {\n return this;\n }\n\n /** @inheritdoc */\n public setStatus(_status: SpanStatus): this {\n return this;\n }\n\n /** @inheritdoc */\n public updateName(_name: string): this {\n return this;\n }\n\n /** @inheritdoc */\n public isRecording(): boolean {\n return false;\n }\n\n /** @inheritdoc */\n public addEvent(\n _name: string,\n _attributesOrStartTime?: SpanAttributes | SpanTimeInput,\n _startTime?: SpanTimeInput,\n ): this {\n return this;\n }\n\n /** @inheritDoc */\n public addLink(_link: unknown): this {\n return this;\n }\n\n /** @inheritDoc */\n public addLinks(_links: unknown[]): this {\n return this;\n }\n\n /**\n * This should generally not be used,\n * but we need it for being compliant with the OTEL Span interface.\n *\n * @hidden\n * @internal\n */\n public recordException(_exception: unknown, _time?: number | undefined): void {\n // noop\n }\n}\n"],"names":["generateTraceId","generateSpanId","TRACE_FLAG_NONE"],"mappings":";;;;;AAYA;AACA;AACA;AACO,MAAM,wBAAuC;;AAIpD,GAAS,WAAW,CAAC,WAAW,GAAwB,EAAE,EAAE;AAC5D,IAAI,IAAI,CAAC,QAAA,GAAW,WAAW,CAAC,OAAA,IAAWA,kCAAe,EAAE;AAC5D,IAAI,IAAI,CAAC,OAAA,GAAU,WAAW,CAAC,MAAA,IAAUC,iCAAc,EAAE;AACzD,EAAE;;AAEF;AACA,GAAS,WAAW,GAAoB;AACxC,IAAI,OAAO;AACX,MAAM,MAAM,EAAE,IAAI,CAAC,OAAO;AAC1B,MAAM,OAAO,EAAE,IAAI,CAAC,QAAQ;AAC5B,MAAM,UAAU,EAAEC,yBAAe;AACjC,KAAK;AACL,EAAE;;AAEF;AACA,GAAS,GAAG,CAAC,UAAU,EAAwB,CAAC;;AAEhD;AACA,GAAS,YAAY,CAAC,IAAI,EAAU,MAAM,EAAwC;AAClF,IAAI,OAAO,IAAI;AACf,EAAE;;AAEF;AACA,GAAS,aAAa,CAAC,OAAO,EAAwB;AACtD,IAAI,OAAO,IAAI;AACf,EAAE;;AAEF;AACA,GAAS,SAAS,CAAC,OAAO,EAAoB;AAC9C,IAAI,OAAO,IAAI;AACf,EAAE;;AAEF;AACA,GAAS,UAAU,CAAC,KAAK,EAAgB;AACzC,IAAI,OAAO,IAAI;AACf,EAAE;;AAEF;AACA,GAAS,WAAW,GAAY;AAChC,IAAI,OAAO,KAAK;AAChB,EAAE;;AAEF;AACA,GAAS,QAAQ;AACjB,IAAI,KAAK;AACT,IAAI,sBAAsB;AAC1B,IAAI,UAAU;AACd,IAAU;AACV,IAAI,OAAO,IAAI;AACf,EAAE;;AAEF;AACA,GAAS,OAAO,CAAC,KAAK,EAAiB;AACvC,IAAI,OAAO,IAAI;AACf,EAAE;;AAEF;AACA,GAAS,QAAQ,CAAC,MAAM,EAAmB;AAC3C,IAAI,OAAO,IAAI;AACf,EAAE;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAS,eAAe,CAAC,UAAU,EAAW,KAAK,EAA6B;AAChF;AACA,EAAE;AACF;;;;"}
1
+ {"version":3,"file":"sentryNonRecordingSpan.js","sources":["../../../src/tracing/sentryNonRecordingSpan.ts"],"sourcesContent":["import type { EventDropReason } from '../types-hoist/clientreport';\nimport type {\n SentrySpanArguments,\n Span,\n SpanAttributes,\n SpanAttributeValue,\n SpanContextData,\n SpanTimeInput,\n} from '../types-hoist/span';\nimport type { SpanStatus } from '../types-hoist/spanStatus';\nimport { generateSpanId, generateTraceId } from '../utils/propagationContext';\nimport { TRACE_FLAG_NONE } from '../utils/spanUtils';\n\ninterface SentryNonRecordingSpanArguments extends SentrySpanArguments {\n dropReason?: EventDropReason;\n}\n\n/**\n * A Sentry Span that is non-recording, meaning it will not be sent to Sentry.\n */\nexport class SentryNonRecordingSpan implements Span {\n private _traceId: string;\n private _spanId: string;\n\n /**\n * Reason why this span was dropped, if applicable ('ignored' or 'sample_rate').\n * Used to propagate the correct client report outcome to descendant spans\n * when span streaming is enabled.\n */\n public dropReason?: EventDropReason;\n\n public constructor(spanContext: SentryNonRecordingSpanArguments = {}) {\n this._traceId = spanContext.traceId || generateTraceId();\n this._spanId = spanContext.spanId || generateSpanId();\n this.dropReason = spanContext.dropReason;\n }\n\n /** @inheritdoc */\n public spanContext(): SpanContextData {\n return {\n spanId: this._spanId,\n traceId: this._traceId,\n traceFlags: TRACE_FLAG_NONE,\n };\n }\n\n /** @inheritdoc */\n public end(_timestamp?: SpanTimeInput): void {}\n\n /** @inheritdoc */\n public setAttribute(_key: string, _value: SpanAttributeValue | undefined): this {\n return this;\n }\n\n /** @inheritdoc */\n public setAttributes(_values: SpanAttributes): this {\n return this;\n }\n\n /** @inheritdoc */\n public setStatus(_status: SpanStatus): this {\n return this;\n }\n\n /** @inheritdoc */\n public updateName(_name: string): this {\n return this;\n }\n\n /** @inheritdoc */\n public isRecording(): boolean {\n return false;\n }\n\n /** @inheritdoc */\n public addEvent(\n _name: string,\n _attributesOrStartTime?: SpanAttributes | SpanTimeInput,\n _startTime?: SpanTimeInput,\n ): this {\n return this;\n }\n\n /** @inheritDoc */\n public addLink(_link: unknown): this {\n return this;\n }\n\n /** @inheritDoc */\n public addLinks(_links: unknown[]): this {\n return this;\n }\n\n /**\n * This should generally not be used,\n * but we need it for being compliant with the OTEL Span interface.\n *\n * @hidden\n * @internal\n */\n public recordException(_exception: unknown, _time?: number | undefined): void {\n // noop\n }\n}\n"],"names":["generateTraceId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Q,CAAC,MAAM,EAAmB;AAC3C,IAAI,OAAO,IAAI;AACf,EAAE;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAS,eAAe,CAAC,UAAU,EAAW,KAAK,EAA6B;AAChF;AACA,EAAE;AACF;;;;"}
@@ -11,8 +11,11 @@ const time = require('../utils/time.js');
11
11
  const dynamicSamplingContext = require('./dynamicSamplingContext.js');
12
12
  const logSpans = require('./logSpans.js');
13
13
  const measurement = require('./measurement.js');
14
+ const hasSpanStreamingEnabled = require('./spans/hasSpanStreamingEnabled.js');
14
15
  const utils = require('./utils.js');
15
16
 
17
+ /* eslint-disable max-lines */
18
+
16
19
  const MAX_SPAN_COUNT = 1000;
17
20
 
18
21
  /**
@@ -203,6 +206,30 @@ class SentrySpan {
203
206
  };
204
207
  }
205
208
 
209
+ /**
210
+ * Get {@link StreamedSpanJSON} representation of this span.
211
+ *
212
+ * @hidden
213
+ * @internal This method is purely for internal purposes and should not be used outside
214
+ * of SDK code. If you need to get a JSON representation of a span,
215
+ * use `spanToStreamedSpanJSON(span)` instead.
216
+ */
217
+ getStreamedSpanJSON() {
218
+ return {
219
+ name: this._name ?? '',
220
+ span_id: this._spanId,
221
+ trace_id: this._traceId,
222
+ parent_span_id: this._parentSpanId,
223
+ start_timestamp: this._startTime,
224
+ // just in case _endTime is not set, we use the start time (i.e. duration 0)
225
+ end_timestamp: this._endTime ?? this._startTime,
226
+ is_segment: this._isStandaloneSpan || this === spanUtils.getRootSpan(this),
227
+ status: spanUtils.getSimpleStatusMessage(this._status),
228
+ attributes: this._attributes,
229
+ links: spanUtils.getStreamedSpanLinks(this._links),
230
+ };
231
+ }
232
+
206
233
  /** @inheritdoc */
207
234
  isRecording() {
208
235
  return !this._endTime && !!this._sampled;
@@ -249,6 +276,14 @@ class SentrySpan {
249
276
  const client = currentScopes.getClient();
250
277
  if (client) {
251
278
  client.emit('spanEnd', this);
279
+ // Guarding sending standalone v1 spans as v2 streamed spans for now.
280
+ // Otherwise they'd be sent once as v1 spans and again as streamed spans.
281
+ // We'll migrate CLS and LCP spans to streamed spans in a later PR and
282
+ // INP spans in the next major of the SDK. At that point, we can fully remove
283
+ // standalone v1 spans <3
284
+ if (!this._isStandaloneSpan) {
285
+ client.emit('afterSpanEnd', this);
286
+ }
252
287
  }
253
288
 
254
289
  // A segment span is basically the root span of a local span tree.
@@ -272,6 +307,10 @@ class SentrySpan {
272
307
  }
273
308
  }
274
309
  return;
310
+ } else if (client && hasSpanStreamingEnabled.hasSpanStreamingEnabled(client)) {
311
+ // TODO (spans): Remove standalone span custom logic in favor of sending simple v2 web vital spans
312
+ client.emit('afterSegmentSpanEnd', this);
313
+ return;
275
314
  }
276
315
 
277
316
  const transactionEvent = this._convertSpanToTransaction();