@sentry/core 10.37.0 → 10.39.0-alpha.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 (296) hide show
  1. package/build/cjs/attributes.js.map +1 -1
  2. package/build/cjs/client.js +22 -12
  3. package/build/cjs/client.js.map +1 -1
  4. package/build/cjs/envelope.js +41 -7
  5. package/build/cjs/envelope.js.map +1 -1
  6. package/build/cjs/index.js +131 -79
  7. package/build/cjs/index.js.map +1 -1
  8. package/build/cjs/integration.js +12 -0
  9. package/build/cjs/integration.js.map +1 -1
  10. package/build/cjs/integrations/captureconsole.js +2 -2
  11. package/build/cjs/integrations/captureconsole.js.map +1 -1
  12. package/build/cjs/integrations/eventFilters.js +1 -1
  13. package/build/cjs/integrations/eventFilters.js.map +1 -1
  14. package/build/cjs/integrations/mcp-server/correlation.js +54 -10
  15. package/build/cjs/integrations/mcp-server/correlation.js.map +1 -1
  16. package/build/cjs/integrations/mcp-server/errorCapture.js +2 -2
  17. package/build/cjs/integrations/mcp-server/errorCapture.js.map +1 -1
  18. package/build/cjs/integrations/mcp-server/sessionManagement.js +50 -16
  19. package/build/cjs/integrations/mcp-server/sessionManagement.js.map +1 -1
  20. package/build/cjs/integrations/requestdata.js +72 -6
  21. package/build/cjs/integrations/requestdata.js.map +1 -1
  22. package/build/cjs/integrations/spanStreaming.js +54 -0
  23. package/build/cjs/integrations/spanStreaming.js.map +1 -0
  24. package/build/cjs/integrations/supabase.js +4 -4
  25. package/build/cjs/integrations/supabase.js.map +1 -1
  26. package/build/cjs/metrics/public-api.js +3 -3
  27. package/build/cjs/metrics/public-api.js.map +1 -1
  28. package/build/cjs/scope.js +1 -1
  29. package/build/cjs/scope.js.map +1 -1
  30. package/build/cjs/semanticAttributes.js +84 -0
  31. package/build/cjs/semanticAttributes.js.map +1 -1
  32. package/build/cjs/spans/captureSpan.js +104 -0
  33. package/build/cjs/spans/captureSpan.js.map +1 -0
  34. package/build/cjs/spans/spanBuffer.js +121 -0
  35. package/build/cjs/spans/spanBuffer.js.map +1 -0
  36. package/build/cjs/spans/spanFirstUtils.js +186 -0
  37. package/build/cjs/spans/spanFirstUtils.js.map +1 -0
  38. package/build/cjs/tracing/ai/gen-ai-attributes.js +6 -0
  39. package/build/cjs/tracing/ai/gen-ai-attributes.js.map +1 -1
  40. package/build/cjs/tracing/anthropic-ai/index.js +3 -3
  41. package/build/cjs/tracing/anthropic-ai/index.js.map +1 -1
  42. package/build/cjs/tracing/anthropic-ai/streaming.js +3 -3
  43. package/build/cjs/tracing/anthropic-ai/streaming.js.map +1 -1
  44. package/build/cjs/tracing/anthropic-ai/utils.js +2 -2
  45. package/build/cjs/tracing/anthropic-ai/utils.js.map +1 -1
  46. package/build/cjs/tracing/google-genai/index.js +3 -3
  47. package/build/cjs/tracing/google-genai/index.js.map +1 -1
  48. package/build/cjs/tracing/google-genai/streaming.js +2 -2
  49. package/build/cjs/tracing/google-genai/streaming.js.map +1 -1
  50. package/build/cjs/tracing/langchain/index.js +4 -4
  51. package/build/cjs/tracing/langchain/index.js.map +1 -1
  52. package/build/cjs/tracing/langgraph/index.js +3 -3
  53. package/build/cjs/tracing/langgraph/index.js.map +1 -1
  54. package/build/cjs/tracing/openai/index.js +136 -53
  55. package/build/cjs/tracing/openai/index.js.map +1 -1
  56. package/build/cjs/tracing/openai/streaming.js +2 -2
  57. package/build/cjs/tracing/openai/streaming.js.map +1 -1
  58. package/build/cjs/tracing/sentrySpan.js +32 -0
  59. package/build/cjs/tracing/sentrySpan.js.map +1 -1
  60. package/build/cjs/tracing/trace.js +1 -0
  61. package/build/cjs/tracing/trace.js.map +1 -1
  62. package/build/cjs/tracing/vercel-ai/constants.js +4 -0
  63. package/build/cjs/tracing/vercel-ai/constants.js.map +1 -1
  64. package/build/cjs/tracing/vercel-ai/index.js +14 -0
  65. package/build/cjs/tracing/vercel-ai/index.js.map +1 -1
  66. package/build/cjs/tracing/vercel-ai/utils.js +71 -22
  67. package/build/cjs/tracing/vercel-ai/utils.js.map +1 -1
  68. package/build/cjs/transports/base.js +18 -2
  69. package/build/cjs/transports/base.js.map +1 -1
  70. package/build/cjs/transports/offline.js +16 -17
  71. package/build/cjs/transports/offline.js.map +1 -1
  72. package/build/cjs/trpc.js +3 -3
  73. package/build/cjs/trpc.js.map +1 -1
  74. package/build/cjs/utils/aggregate-errors.js +13 -5
  75. package/build/cjs/utils/aggregate-errors.js.map +1 -1
  76. package/build/cjs/utils/beforeSendSpan.js +36 -0
  77. package/build/cjs/utils/beforeSendSpan.js.map +1 -0
  78. package/build/cjs/utils/envToBool.js +32 -0
  79. package/build/cjs/utils/envToBool.js.map +1 -0
  80. package/build/cjs/utils/exports.js +7 -7
  81. package/build/cjs/utils/exports.js.map +1 -1
  82. package/build/cjs/utils/featureFlags.js +1 -0
  83. package/build/cjs/utils/featureFlags.js.map +1 -1
  84. package/build/cjs/utils/flushIfServerless.js +2 -2
  85. package/build/cjs/utils/flushIfServerless.js.map +1 -1
  86. package/build/cjs/utils/hasSpanStreamingEnabled.js +21 -0
  87. package/build/cjs/utils/hasSpanStreamingEnabled.js.map +1 -0
  88. package/build/cjs/utils/prepareEvent.js +6 -1
  89. package/build/cjs/utils/prepareEvent.js.map +1 -1
  90. package/build/cjs/utils/promisebuffer.js +5 -3
  91. package/build/cjs/utils/promisebuffer.js.map +1 -1
  92. package/build/cjs/utils/scopeData.js +4 -0
  93. package/build/cjs/utils/scopeData.js.map +1 -1
  94. package/build/cjs/utils/sdkMetadata.js +7 -11
  95. package/build/cjs/utils/sdkMetadata.js.map +1 -1
  96. package/build/cjs/utils/should-ignore-span.js +31 -9
  97. package/build/cjs/utils/should-ignore-span.js.map +1 -1
  98. package/build/cjs/utils/spanUtils.js +90 -2
  99. package/build/cjs/utils/spanUtils.js.map +1 -1
  100. package/build/cjs/utils/timer.js +20 -0
  101. package/build/cjs/utils/timer.js.map +1 -0
  102. package/build/cjs/utils/traceData.js +2 -2
  103. package/build/cjs/utils/traceData.js.map +1 -1
  104. package/build/cjs/utils/tracePropagationTargets.js +38 -0
  105. package/build/cjs/utils/tracePropagationTargets.js.map +1 -0
  106. package/build/cjs/utils/version.js +1 -1
  107. package/build/cjs/utils/version.js.map +1 -1
  108. package/build/esm/attributes.js.map +1 -1
  109. package/build/esm/client.js +18 -8
  110. package/build/esm/client.js.map +1 -1
  111. package/build/esm/envelope.js +41 -8
  112. package/build/esm/envelope.js.map +1 -1
  113. package/build/esm/exports.js +2 -2
  114. package/build/esm/feedback.js +1 -1
  115. package/build/esm/index.js +12 -3
  116. package/build/esm/index.js.map +1 -1
  117. package/build/esm/integration.js +12 -1
  118. package/build/esm/integration.js.map +1 -1
  119. package/build/esm/integrations/eventFilters.js +1 -1
  120. package/build/esm/integrations/eventFilters.js.map +1 -1
  121. package/build/esm/integrations/mcp-server/correlation.js +54 -10
  122. package/build/esm/integrations/mcp-server/correlation.js.map +1 -1
  123. package/build/esm/integrations/mcp-server/sessionManagement.js +50 -16
  124. package/build/esm/integrations/mcp-server/sessionManagement.js.map +1 -1
  125. package/build/esm/integrations/moduleMetadata.js +1 -1
  126. package/build/esm/integrations/requestdata.js +72 -6
  127. package/build/esm/integrations/requestdata.js.map +1 -1
  128. package/build/esm/integrations/spanStreaming.js +52 -0
  129. package/build/esm/integrations/spanStreaming.js.map +1 -0
  130. package/build/esm/integrations/third-party-errors-filter.js +1 -1
  131. package/build/esm/logs/internal.js +1 -1
  132. package/build/esm/metrics/public-api.js +3 -3
  133. package/build/esm/metrics/public-api.js.map +1 -1
  134. package/build/esm/package.json +1 -1
  135. package/build/esm/scope.js +1 -1
  136. package/build/esm/scope.js.map +1 -1
  137. package/build/esm/semanticAttributes.js +57 -1
  138. package/build/esm/semanticAttributes.js.map +1 -1
  139. package/build/esm/spans/captureSpan.js +102 -0
  140. package/build/esm/spans/captureSpan.js.map +1 -0
  141. package/build/esm/spans/spanBuffer.js +119 -0
  142. package/build/esm/spans/spanBuffer.js.map +1 -0
  143. package/build/esm/spans/spanFirstUtils.js +182 -0
  144. package/build/esm/spans/spanFirstUtils.js.map +1 -0
  145. package/build/esm/tracing/ai/gen-ai-attributes.js +6 -1
  146. package/build/esm/tracing/ai/gen-ai-attributes.js.map +1 -1
  147. package/build/esm/tracing/measurement.js +1 -1
  148. package/build/esm/tracing/openai/index.js +134 -51
  149. package/build/esm/tracing/openai/index.js.map +1 -1
  150. package/build/esm/tracing/sentrySpan.js +33 -1
  151. package/build/esm/tracing/sentrySpan.js.map +1 -1
  152. package/build/esm/tracing/trace.js +4 -3
  153. package/build/esm/tracing/trace.js.map +1 -1
  154. package/build/esm/tracing/vercel-ai/constants.js +4 -1
  155. package/build/esm/tracing/vercel-ai/constants.js.map +1 -1
  156. package/build/esm/tracing/vercel-ai/index.js +15 -1
  157. package/build/esm/tracing/vercel-ai/index.js.map +1 -1
  158. package/build/esm/tracing/vercel-ai/utils.js +73 -24
  159. package/build/esm/tracing/vercel-ai/utils.js.map +1 -1
  160. package/build/esm/transports/base.js +18 -2
  161. package/build/esm/transports/base.js.map +1 -1
  162. package/build/esm/transports/offline.js +16 -17
  163. package/build/esm/transports/offline.js.map +1 -1
  164. package/build/esm/utils/aggregate-errors.js +13 -5
  165. package/build/esm/utils/aggregate-errors.js.map +1 -1
  166. package/build/esm/utils/beforeSendSpan.js +33 -0
  167. package/build/esm/utils/beforeSendSpan.js.map +1 -0
  168. package/build/esm/utils/envToBool.js +28 -0
  169. package/build/esm/utils/envToBool.js.map +1 -0
  170. package/build/esm/utils/exports.js +7 -7
  171. package/build/esm/utils/exports.js.map +1 -1
  172. package/build/esm/utils/featureFlags.js +1 -0
  173. package/build/esm/utils/featureFlags.js.map +1 -1
  174. package/build/esm/utils/flushIfServerless.js.map +1 -1
  175. package/build/esm/utils/hasSpanStreamingEnabled.js +19 -0
  176. package/build/esm/utils/hasSpanStreamingEnabled.js.map +1 -0
  177. package/build/esm/utils/prepareEvent.js +6 -1
  178. package/build/esm/utils/prepareEvent.js.map +1 -1
  179. package/build/esm/utils/promisebuffer.js +5 -3
  180. package/build/esm/utils/promisebuffer.js.map +1 -1
  181. package/build/esm/utils/scopeData.js +4 -0
  182. package/build/esm/utils/scopeData.js.map +1 -1
  183. package/build/esm/utils/sdkMetadata.js +7 -11
  184. package/build/esm/utils/sdkMetadata.js.map +1 -1
  185. package/build/esm/utils/should-ignore-span.js +31 -9
  186. package/build/esm/utils/should-ignore-span.js.map +1 -1
  187. package/build/esm/utils/spanUtils.js +87 -3
  188. package/build/esm/utils/spanUtils.js.map +1 -1
  189. package/build/esm/utils/timer.js +18 -0
  190. package/build/esm/utils/timer.js.map +1 -0
  191. package/build/esm/utils/tracePropagationTargets.js +36 -0
  192. package/build/esm/utils/tracePropagationTargets.js.map +1 -0
  193. package/build/esm/utils/version.js +1 -1
  194. package/build/esm/utils/version.js.map +1 -1
  195. package/build/types/attributes.d.ts +1 -1
  196. package/build/types/attributes.d.ts.map +1 -1
  197. package/build/types/client.d.ts +40 -2
  198. package/build/types/client.d.ts.map +1 -1
  199. package/build/types/envelope.d.ts +6 -1
  200. package/build/types/envelope.d.ts.map +1 -1
  201. package/build/types/index.d.ts +13 -4
  202. package/build/types/index.d.ts.map +1 -1
  203. package/build/types/integration.d.ts +4 -0
  204. package/build/types/integration.d.ts.map +1 -1
  205. package/build/types/integrations/mcp-server/correlation.d.ts +6 -2
  206. package/build/types/integrations/mcp-server/correlation.d.ts.map +1 -1
  207. package/build/types/integrations/mcp-server/sessionManagement.d.ts +8 -2
  208. package/build/types/integrations/mcp-server/sessionManagement.d.ts.map +1 -1
  209. package/build/types/integrations/requestdata.d.ts.map +1 -1
  210. package/build/types/integrations/spanStreaming.d.ts +11 -0
  211. package/build/types/integrations/spanStreaming.d.ts.map +1 -0
  212. package/build/types/metrics/public-api.d.ts +3 -3
  213. package/build/types/semanticAttributes.d.ts +38 -0
  214. package/build/types/semanticAttributes.d.ts.map +1 -1
  215. package/build/types/spans/captureSpan.d.ts +10 -0
  216. package/build/types/spans/captureSpan.d.ts.map +1 -0
  217. package/build/types/spans/spanBuffer.d.ts +35 -0
  218. package/build/types/spans/spanBuffer.d.ts.map +1 -0
  219. package/build/types/spans/spanFirstUtils.d.ts +20 -0
  220. package/build/types/spans/spanFirstUtils.d.ts.map +1 -0
  221. package/build/types/tracing/ai/gen-ai-attributes.d.ts +4 -0
  222. package/build/types/tracing/ai/gen-ai-attributes.d.ts.map +1 -1
  223. package/build/types/tracing/openai/index.d.ts.map +1 -1
  224. package/build/types/tracing/sentrySpan.d.ts +10 -1
  225. package/build/types/tracing/sentrySpan.d.ts.map +1 -1
  226. package/build/types/tracing/vercel-ai/constants.d.ts +1 -0
  227. package/build/types/tracing/vercel-ai/constants.d.ts.map +1 -1
  228. package/build/types/tracing/vercel-ai/index.d.ts.map +1 -1
  229. package/build/types/tracing/vercel-ai/utils.d.ts +2 -2
  230. package/build/types/tracing/vercel-ai/utils.d.ts.map +1 -1
  231. package/build/types/transports/base.d.ts.map +1 -1
  232. package/build/types/transports/offline.d.ts.map +1 -1
  233. package/build/types/types-hoist/attributes.d.ts +19 -0
  234. package/build/types/types-hoist/attributes.d.ts.map +1 -0
  235. package/build/types/types-hoist/envelope.d.ts +22 -2
  236. package/build/types/types-hoist/envelope.d.ts.map +1 -1
  237. package/build/types/types-hoist/feedback/index.d.ts.map +1 -1
  238. package/build/types/types-hoist/integration.d.ts +7 -0
  239. package/build/types/types-hoist/integration.d.ts.map +1 -1
  240. package/build/types/types-hoist/link.d.ts +2 -2
  241. package/build/types/types-hoist/link.d.ts.map +1 -1
  242. package/build/types/types-hoist/options.d.ts +18 -2
  243. package/build/types/types-hoist/options.d.ts.map +1 -1
  244. package/build/types/types-hoist/span.d.ts +27 -0
  245. package/build/types/types-hoist/span.d.ts.map +1 -1
  246. package/build/types/utils/beforeSendSpan.d.ts +22 -0
  247. package/build/types/utils/beforeSendSpan.d.ts.map +1 -0
  248. package/build/types/utils/envToBool.d.ts +13 -0
  249. package/build/types/utils/envToBool.d.ts.map +1 -0
  250. package/build/types/utils/featureFlags.d.ts.map +1 -1
  251. package/build/types/utils/flushIfServerless.d.ts.map +1 -1
  252. package/build/types/utils/hasSpanStreamingEnabled.d.ts +9 -0
  253. package/build/types/utils/hasSpanStreamingEnabled.d.ts.map +1 -0
  254. package/build/types/utils/prepareEvent.d.ts.map +1 -1
  255. package/build/types/utils/promisebuffer.d.ts.map +1 -1
  256. package/build/types/utils/scopeData.d.ts.map +1 -1
  257. package/build/types/utils/sdkMetadata.d.ts.map +1 -1
  258. package/build/types/utils/should-ignore-span.d.ts +3 -3
  259. package/build/types/utils/should-ignore-span.d.ts.map +1 -1
  260. package/build/types/utils/spanUtils.d.ts +22 -2
  261. package/build/types/utils/spanUtils.d.ts.map +1 -1
  262. package/build/types/utils/timer.d.ts +11 -0
  263. package/build/types/utils/timer.d.ts.map +1 -0
  264. package/build/types/utils/tracePropagationTargets.d.ts +9 -0
  265. package/build/types/utils/tracePropagationTargets.d.ts.map +1 -0
  266. package/build/types-ts3.8/attributes.d.ts +1 -1
  267. package/build/types-ts3.8/client.d.ts +40 -2
  268. package/build/types-ts3.8/envelope.d.ts +6 -1
  269. package/build/types-ts3.8/index.d.ts +13 -4
  270. package/build/types-ts3.8/integration.d.ts +4 -0
  271. package/build/types-ts3.8/integrations/mcp-server/correlation.d.ts +6 -2
  272. package/build/types-ts3.8/integrations/mcp-server/sessionManagement.d.ts +8 -2
  273. package/build/types-ts3.8/integrations/spanStreaming.d.ts +11 -0
  274. package/build/types-ts3.8/metrics/public-api.d.ts +3 -3
  275. package/build/types-ts3.8/semanticAttributes.d.ts +38 -0
  276. package/build/types-ts3.8/spans/captureSpan.d.ts +10 -0
  277. package/build/types-ts3.8/spans/spanBuffer.d.ts +35 -0
  278. package/build/types-ts3.8/spans/spanFirstUtils.d.ts +20 -0
  279. package/build/types-ts3.8/tracing/ai/gen-ai-attributes.d.ts +4 -0
  280. package/build/types-ts3.8/tracing/sentrySpan.d.ts +10 -1
  281. package/build/types-ts3.8/tracing/vercel-ai/constants.d.ts +1 -0
  282. package/build/types-ts3.8/tracing/vercel-ai/utils.d.ts +2 -2
  283. package/build/types-ts3.8/types-hoist/attributes.d.ts +19 -0
  284. package/build/types-ts3.8/types-hoist/envelope.d.ts +22 -2
  285. package/build/types-ts3.8/types-hoist/integration.d.ts +7 -0
  286. package/build/types-ts3.8/types-hoist/link.d.ts +2 -2
  287. package/build/types-ts3.8/types-hoist/options.d.ts +18 -2
  288. package/build/types-ts3.8/types-hoist/span.d.ts +27 -0
  289. package/build/types-ts3.8/utils/beforeSendSpan.d.ts +22 -0
  290. package/build/types-ts3.8/utils/envToBool.d.ts +13 -0
  291. package/build/types-ts3.8/utils/hasSpanStreamingEnabled.d.ts +9 -0
  292. package/build/types-ts3.8/utils/should-ignore-span.d.ts +3 -3
  293. package/build/types-ts3.8/utils/spanUtils.d.ts +22 -2
  294. package/build/types-ts3.8/utils/timer.d.ts +11 -0
  295. package/build/types-ts3.8/utils/tracePropagationTargets.d.ts +9 -0
  296. package/package.json +1 -1
@@ -0,0 +1,102 @@
1
+ import { getClient } from '../currentScopes.js';
2
+ import { DEBUG_BUILD } from '../debug-build.js';
3
+ import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_SPAN_SOURCE, SEMANTIC_ATTRIBUTE_USER_USERNAME, SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS, SEMANTIC_ATTRIBUTE_USER_EMAIL, SEMANTIC_ATTRIBUTE_USER_ID, SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME, SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID, SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME, SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT, SEMANTIC_ATTRIBUTE_SENTRY_RELEASE } from '../semanticAttributes.js';
4
+ import { getCapturedScopesOnSpan } from '../tracing/utils.js';
5
+ import { isV2BeforeSendSpanCallback } from '../utils/beforeSendSpan.js';
6
+ import { debug } from '../utils/debug-logger.js';
7
+ import { getCombinedScopeData } from '../utils/scopeData.js';
8
+ import { spanToV2JSON, INTERNAL_getSegmentSpan } from '../utils/spanUtils.js';
9
+ import { applyBeforeSendSpanCallback, safeSetSpanJSONAttributes, contextsToAttributes } from './spanFirstUtils.js';
10
+
11
+ /**
12
+ * Captures a span and returns a JSON representation to be enqueued for sending.
13
+ *
14
+ * IMPORTANT: This function converts the span to JSON immediately to avoid writing
15
+ * to an already-ended OTel span instance (which is blocked by the OTel Span class).
16
+ */
17
+ function captureSpan(span, client = getClient()) {
18
+ if (!client) {
19
+ DEBUG_BUILD && debug.warn('No client available to capture span.');
20
+ return;
21
+ }
22
+
23
+ // Convert to JSON FIRST - we cannot write to an already-ended span
24
+ const spanJSON = spanToV2JSON(span);
25
+
26
+ const segmentSpan = INTERNAL_getSegmentSpan(span);
27
+ const serializedSegmentSpan = spanToV2JSON(segmentSpan);
28
+
29
+ const { isolationScope: spanIsolationScope, scope: spanScope } = getCapturedScopesOnSpan(span);
30
+
31
+ const finalScopeData = getCombinedScopeData(spanIsolationScope, spanScope);
32
+
33
+ applyCommonSpanAttributes(spanJSON, serializedSegmentSpan, client, finalScopeData);
34
+
35
+ if (span === segmentSpan) {
36
+ applyScopeToSegmentSpan(spanJSON, finalScopeData);
37
+ client.emit('processSegmentSpan', spanJSON, { scopeData: finalScopeData });
38
+ }
39
+
40
+ // Allow integrations to add additional data to the span JSON
41
+ client.emit('processSpan', spanJSON, { readOnlySpan: span });
42
+
43
+ const beforeSendSpan = client.getOptions().beforeSendSpan;
44
+ const processedSpan = isV2BeforeSendSpanCallback(beforeSendSpan)
45
+ ? applyBeforeSendSpanCallback(spanJSON, beforeSendSpan)
46
+ : spanJSON;
47
+
48
+ // Backfill sentry.span.source from sentry.source for the PoC
49
+ // TODO(v11): Stop sending `sentry.source` attribute and only send `sentry.span.source`
50
+ // probably easiest done by just renaming SEMANTIC_ATTRIBUTE_SENTRY_SOURCE
51
+ if (processedSpan.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]) {
52
+ safeSetSpanJSONAttributes(processedSpan, {
53
+ [SEMANTIC_ATTRIBUTE_SENTRY_SPAN_SOURCE]: processedSpan.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]?.value,
54
+ });
55
+ }
56
+
57
+ const spanWithRef = {
58
+ ...processedSpan,
59
+ _segmentSpan: segmentSpan,
60
+ };
61
+
62
+ client.emit('enqueueSpan', spanWithRef);
63
+ }
64
+
65
+ function applyScopeToSegmentSpan(segmentSpanJSON, scopeData) {
66
+ // TODO: Apply all scope and request data from auto instrumentation (contexts, request) to segment span
67
+ const { contexts } = scopeData;
68
+
69
+ safeSetSpanJSONAttributes(segmentSpanJSON, contextsToAttributes(contexts));
70
+ }
71
+
72
+ function applyCommonSpanAttributes(
73
+ spanJSON,
74
+ serializedSegmentSpan,
75
+ client,
76
+ scopeData,
77
+ ) {
78
+ const sdk = client.getSdkMetadata();
79
+ const { release, environment, sendDefaultPii } = client.getOptions();
80
+
81
+ // avoid overwriting any previously set attributes (from users or potentially our SDK instrumentation)
82
+ safeSetSpanJSONAttributes(spanJSON, {
83
+ [SEMANTIC_ATTRIBUTE_SENTRY_RELEASE]: release,
84
+ [SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT]: environment,
85
+ [SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME]: serializedSegmentSpan.name,
86
+ [SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID]: serializedSegmentSpan.span_id,
87
+ [SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME]: sdk?.sdk?.name,
88
+ [SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION]: sdk?.sdk?.version,
89
+ ...(sendDefaultPii
90
+ ? {
91
+ [SEMANTIC_ATTRIBUTE_USER_ID]: scopeData.user?.id,
92
+ [SEMANTIC_ATTRIBUTE_USER_EMAIL]: scopeData.user?.email,
93
+ [SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: scopeData.user?.ip_address,
94
+ [SEMANTIC_ATTRIBUTE_USER_USERNAME]: scopeData.user?.username,
95
+ }
96
+ : {}),
97
+ ...scopeData.attributes,
98
+ });
99
+ }
100
+
101
+ export { captureSpan };
102
+ //# sourceMappingURL=captureSpan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"captureSpan.js","sources":["../../../src/spans/captureSpan.ts"],"sourcesContent":["import type { Client } from '../client';\nimport { getClient } from '../currentScopes';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { ScopeData } from '../scope';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT,\n SEMANTIC_ATTRIBUTE_SENTRY_RELEASE,\n SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION,\n SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID,\n SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n SEMANTIC_ATTRIBUTE_SENTRY_SPAN_SOURCE,\n SEMANTIC_ATTRIBUTE_USER_EMAIL,\n SEMANTIC_ATTRIBUTE_USER_ID,\n SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS,\n SEMANTIC_ATTRIBUTE_USER_USERNAME,\n} from '../semanticAttributes';\nimport { getCapturedScopesOnSpan } from '../tracing/utils';\nimport type { Span, SpanV2JSON } from '../types-hoist/span';\nimport { isV2BeforeSendSpanCallback } from '../utils/beforeSendSpan';\nimport { debug } from '../utils/debug-logger';\nimport { getCombinedScopeData } from '../utils/scopeData';\nimport { INTERNAL_getSegmentSpan, spanToV2JSON } from '../utils/spanUtils';\nimport { applyBeforeSendSpanCallback, contextsToAttributes, safeSetSpanJSONAttributes } from './spanFirstUtils';\n/**\n * Captures a span and returns a JSON representation to be enqueued for sending.\n *\n * IMPORTANT: This function converts the span to JSON immediately to avoid writing\n * to an already-ended OTel span instance (which is blocked by the OTel Span class).\n */\nexport function captureSpan(span: Span, client = getClient()): void {\n if (!client) {\n DEBUG_BUILD && debug.warn('No client available to capture span.');\n return;\n }\n\n // Convert to JSON FIRST - we cannot write to an already-ended span\n const spanJSON = spanToV2JSON(span);\n\n const segmentSpan = INTERNAL_getSegmentSpan(span);\n const serializedSegmentSpan = spanToV2JSON(segmentSpan);\n\n const { isolationScope: spanIsolationScope, scope: spanScope } = getCapturedScopesOnSpan(span);\n\n const finalScopeData = getCombinedScopeData(spanIsolationScope, spanScope);\n\n applyCommonSpanAttributes(spanJSON, serializedSegmentSpan, client, finalScopeData);\n\n if (span === segmentSpan) {\n applyScopeToSegmentSpan(spanJSON, finalScopeData);\n client.emit('processSegmentSpan', spanJSON, { scopeData: finalScopeData });\n }\n\n // Allow integrations to add additional data to the span JSON\n client.emit('processSpan', spanJSON, { readOnlySpan: span });\n\n const beforeSendSpan = client.getOptions().beforeSendSpan;\n const processedSpan = isV2BeforeSendSpanCallback(beforeSendSpan)\n ? applyBeforeSendSpanCallback(spanJSON, beforeSendSpan)\n : spanJSON;\n\n // Backfill sentry.span.source from sentry.source for the PoC\n // TODO(v11): Stop sending `sentry.source` attribute and only send `sentry.span.source`\n // probably easiest done by just renaming SEMANTIC_ATTRIBUTE_SENTRY_SOURCE\n if (processedSpan.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]) {\n safeSetSpanJSONAttributes(processedSpan, {\n [SEMANTIC_ATTRIBUTE_SENTRY_SPAN_SOURCE]: processedSpan.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]?.value,\n });\n }\n\n const spanWithRef = {\n ...processedSpan,\n _segmentSpan: segmentSpan,\n };\n\n client.emit('enqueueSpan', spanWithRef);\n}\n\nfunction applyScopeToSegmentSpan(segmentSpanJSON: SpanV2JSON, scopeData: ScopeData): void {\n // TODO: Apply all scope and request data from auto instrumentation (contexts, request) to segment span\n const { contexts } = scopeData;\n\n safeSetSpanJSONAttributes(segmentSpanJSON, contextsToAttributes(contexts));\n}\n\nfunction applyCommonSpanAttributes(\n spanJSON: SpanV2JSON,\n serializedSegmentSpan: SpanV2JSON,\n client: Client,\n scopeData: ScopeData,\n): void {\n const sdk = client.getSdkMetadata();\n const { release, environment, sendDefaultPii } = client.getOptions();\n\n // avoid overwriting any previously set attributes (from users or potentially our SDK instrumentation)\n safeSetSpanJSONAttributes(spanJSON, {\n [SEMANTIC_ATTRIBUTE_SENTRY_RELEASE]: release,\n [SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT]: environment,\n [SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME]: serializedSegmentSpan.name,\n [SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID]: serializedSegmentSpan.span_id,\n [SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME]: sdk?.sdk?.name,\n [SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION]: sdk?.sdk?.version,\n ...(sendDefaultPii\n ? {\n [SEMANTIC_ATTRIBUTE_USER_ID]: scopeData.user?.id,\n [SEMANTIC_ATTRIBUTE_USER_EMAIL]: scopeData.user?.email,\n [SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: scopeData.user?.ip_address,\n [SEMANTIC_ATTRIBUTE_USER_USERNAME]: scopeData.user?.username,\n }\n : {}),\n ...scopeData.attributes,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;AAyBA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,WAAW,CAAC,IAAI,EAAQ,MAAA,GAAS,SAAS,EAAE,EAAQ;AACpE,EAAE,IAAI,CAAC,MAAM,EAAE;AACf,IAAI,eAAe,KAAK,CAAC,IAAI,CAAC,sCAAsC,CAAC;AACrE,IAAI;AACJ,EAAE;;AAEF;AACA,EAAE,MAAM,QAAA,GAAW,YAAY,CAAC,IAAI,CAAC;;AAErC,EAAE,MAAM,WAAA,GAAc,uBAAuB,CAA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envelope } from '../envelope.js';
3
+ import { getDynamicSamplingContextFromSpan } from '../tracing/dynamicSamplingContext.js';
4
+ import { debug } from '../utils/debug-logger.js';
5
+
6
+ /**
7
+ * A buffer for span JSON objects that flushes them to Sentry in Span v2 envelopes.
8
+ * Handles interval-based flushing, size thresholds, and graceful shutdown.
9
+ */
10
+ class SpanBuffer {
11
+
12
+ constructor(client, options) {
13
+ this._spanTreeMap = new Map();
14
+ this._client = client;
15
+
16
+ const { maxSpanLimit, flushInterval } = options ?? {};
17
+
18
+ this._maxSpanLimit = maxSpanLimit && maxSpanLimit > 0 && maxSpanLimit <= 1000 ? maxSpanLimit : 1000;
19
+ this._flushInterval = flushInterval && flushInterval > 0 ? flushInterval : 5000;
20
+
21
+ this._flushIntervalId = setInterval(() => {
22
+ this.flush();
23
+ }, this._flushInterval);
24
+
25
+ this._client.on('flush', () => {
26
+ this.flush();
27
+ });
28
+ }
29
+
30
+ /**
31
+ * Add a span to the buffer.
32
+ */
33
+ addSpan(spanJSON) {
34
+ const traceId = spanJSON.trace_id;
35
+ let traceBucket = this._spanTreeMap.get(traceId);
36
+ if (traceBucket) {
37
+ traceBucket.add(spanJSON);
38
+ } else {
39
+ traceBucket = new Set([spanJSON]);
40
+ this._spanTreeMap.set(traceId, traceBucket);
41
+ }
42
+
43
+ if (traceBucket.size >= this._maxSpanLimit) {
44
+ this.flushTrace(traceId);
45
+ this._debounceFlushInterval();
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Flush all buffered traces.
51
+ */
52
+ flush() {
53
+ if (!this._spanTreeMap.size) {
54
+ return;
55
+ }
56
+
57
+ DEBUG_BUILD && debug.log(`Flushing span tree map with ${this._spanTreeMap.size} traces`);
58
+
59
+ this._spanTreeMap.forEach((_, traceId) => {
60
+ this.flushTrace(traceId);
61
+ });
62
+ this._debounceFlushInterval();
63
+ }
64
+
65
+ /**
66
+ * Flush spans of a specific trace.
67
+ * In contrast to {@link SpanBuffer.flush}, this method does not flush all traces, but only the one with the given traceId.
68
+ */
69
+ flushTrace(traceId) {
70
+ const traceBucket = this._spanTreeMap.get(traceId);
71
+ if (!traceBucket) {
72
+ return;
73
+ }
74
+
75
+ if (!traceBucket.size) {
76
+ this._spanTreeMap.delete(traceId);
77
+ return;
78
+ }
79
+
80
+ const firstSpanJSON = traceBucket.values().next().value;
81
+
82
+ const segmentSpan = firstSpanJSON?._segmentSpan;
83
+ if (!segmentSpan) {
84
+ DEBUG_BUILD && debug.warn('No segment span reference found on span JSON, cannot compute DSC');
85
+ this._spanTreeMap.delete(traceId);
86
+ return;
87
+ }
88
+
89
+ const dsc = getDynamicSamplingContextFromSpan(segmentSpan);
90
+
91
+ const cleanedSpans = Array.from(traceBucket).map(spanJSON => {
92
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
93
+ const { _segmentSpan, ...cleanSpanJSON } = spanJSON;
94
+ return cleanSpanJSON;
95
+ });
96
+
97
+ const envelope = createSpanV2Envelope(cleanedSpans, dsc, this._client);
98
+
99
+ DEBUG_BUILD && debug.log(`Sending span envelope for trace ${traceId} with ${cleanedSpans.length} spans`);
100
+
101
+ this._client.sendEnvelope(envelope).then(null, reason => {
102
+ DEBUG_BUILD && debug.error('Error while sending span stream envelope:', reason);
103
+ });
104
+
105
+ this._spanTreeMap.delete(traceId);
106
+ }
107
+
108
+ _debounceFlushInterval() {
109
+ if (this._flushIntervalId) {
110
+ clearInterval(this._flushIntervalId);
111
+ }
112
+ this._flushIntervalId = setInterval(() => {
113
+ this.flush();
114
+ }, this._flushInterval);
115
+ }
116
+ }
117
+
118
+ export { SpanBuffer };
119
+ //# sourceMappingURL=spanBuffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spanBuffer.js","sources":["../../../src/spans/spanBuffer.ts"],"sourcesContent":["import type { Client } from '../client';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { createSpanV2Envelope } from '../envelope';\nimport { getDynamicSamplingContextFromSpan } from '../tracing/dynamicSamplingContext';\nimport type { SpanV2JSON, SpanV2JSONWithSegmentRef } from '../types-hoist/span';\nimport { debug } from '../utils/debug-logger';\n\nexport interface SpanBufferOptions {\n /** Max spans per trace before auto-flush (default: 1000) */\n maxSpanLimit?: number;\n /** Flush interval in ms (default: 5000) */\n flushInterval?: number;\n}\n\n/**\n * A buffer for span JSON objects that flushes them to Sentry in Span v2 envelopes.\n * Handles interval-based flushing, size thresholds, and graceful shutdown.\n */\nexport class SpanBuffer {\n private _spanTreeMap: Map<string, Set<SpanV2JSONWithSegmentRef>>;\n private _flushIntervalId: ReturnType<typeof setInterval> | null;\n private _client: Client;\n private _maxSpanLimit: number;\n private _flushInterval: number;\n\n public constructor(client: Client, options?: SpanBufferOptions) {\n this._spanTreeMap = new Map();\n this._client = client;\n\n const { maxSpanLimit, flushInterval } = options ?? {};\n\n this._maxSpanLimit = maxSpanLimit && maxSpanLimit > 0 && maxSpanLimit <= 1000 ? maxSpanLimit : 1000;\n this._flushInterval = flushInterval && flushInterval > 0 ? flushInterval : 5_000;\n\n this._flushIntervalId = setInterval(() => {\n this.flush();\n }, this._flushInterval);\n\n this._client.on('flush', () => {\n this.flush();\n });\n }\n\n /**\n * Add a span to the buffer.\n */\n public addSpan(spanJSON: SpanV2JSONWithSegmentRef): void {\n const traceId = spanJSON.trace_id;\n let traceBucket = this._spanTreeMap.get(traceId);\n if (traceBucket) {\n traceBucket.add(spanJSON);\n } else {\n traceBucket = new Set([spanJSON]);\n this._spanTreeMap.set(traceId, traceBucket);\n }\n\n if (traceBucket.size >= this._maxSpanLimit) {\n this.flushTrace(traceId);\n this._debounceFlushInterval();\n }\n }\n\n /**\n * Flush all buffered traces.\n */\n public flush(): void {\n if (!this._spanTreeMap.size) {\n return;\n }\n\n DEBUG_BUILD && debug.log(`Flushing span tree map with ${this._spanTreeMap.size} traces`);\n\n this._spanTreeMap.forEach((_, traceId) => {\n this.flushTrace(traceId);\n });\n this._debounceFlushInterval();\n }\n\n /**\n * Flush spans of a specific trace.\n * In contrast to {@link SpanBuffer.flush}, this method does not flush all traces, but only the one with the given traceId.\n */\n public flushTrace(traceId: string): void {\n const traceBucket = this._spanTreeMap.get(traceId);\n if (!traceBucket) {\n return;\n }\n\n if (!traceBucket.size) {\n this._spanTreeMap.delete(traceId);\n return;\n }\n\n const firstSpanJSON = traceBucket.values().next().value;\n\n const segmentSpan = firstSpanJSON?._segmentSpan;\n if (!segmentSpan) {\n DEBUG_BUILD && debug.warn('No segment span reference found on span JSON, cannot compute DSC');\n this._spanTreeMap.delete(traceId);\n return;\n }\n\n const dsc = getDynamicSamplingContextFromSpan(segmentSpan);\n\n const cleanedSpans: SpanV2JSON[] = Array.from(traceBucket).map(spanJSON => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { _segmentSpan, ...cleanSpanJSON } = spanJSON;\n return cleanSpanJSON;\n });\n\n const envelope = createSpanV2Envelope(cleanedSpans, dsc, this._client);\n\n DEBUG_BUILD && debug.log(`Sending span envelope for trace ${traceId} with ${cleanedSpans.length} spans`);\n\n this._client.sendEnvelope(envelope).then(null, reason => {\n DEBUG_BUILD && debug.error('Error while sending span stream envelope:', reason);\n });\n\n this._spanTreeMap.delete(traceId);\n }\n\n private _debounceFlushInterval(): void {\n if (this._flushIntervalId) {\n clearInterval(this._flushIntervalId);\n }\n this._flushIntervalId = setInterval(() => {\n this.flush();\n }, this._flushInterval);\n }\n}\n"],"names":[],"mappings":";;;;;AAcA;AACA;AACA;AACA;AACO,MAAM,UAAA,CAAW;;AAOxB,GAAS,WAAW,CAAC,MAAM,EAAU,OAAO,EAAsB;AAClE,IAAI,IAAI,CAAC,YAAA,GAAe,IAAI,GAAG,EAAE;AACjC,IAAI,IAAI,CAAC,OAAA,GAAU,MAAM;;AAEzB,IAAI,MAAM,EAAE,YAAY,EAAE,aAAA,KAAkB,OAAA,IAAW,EAAE;;AAEzD,IAAI,IAAI,CAAC,aAAA,GAAgB,YAAA,IAAgB,YAAA,GAAe,CAAA,IAAK,gBAAgB,IAAA,GAAO,YAAA,GAAe,IAA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,eAAe,KAAK,CAAC,GAAG,CAAC,CAAC,gCAAgC,EAAE,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;;AAE5G,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU;AAC7D,MAAM,WAAA,IAAe,KAAK,CAAC,KAAK,CAAC,2CAA2C,EAAE,MAAM,CAAC;AACrF,IAAI,CAAC,CAAC;;AAEN,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC;AACrC,EAAE;;AAEF,GAAU,sBAAsB,GAAS;AACzC,IAAI,IAAI,IAAI,CAAC,gBAAgB,EAAE;AAC/B,MAAM,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC;AAC1C,IAAI;AACJ,IAAI,IAAI,CAAC,gBAAA,GAAmB,WAAW,CAAC,MAAM;AAC9C,MAAM,IAAI,CAAC,KAAK,EAAE;AAClB,IAAI,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC;AAC3B,EAAE;AACF;;;;"}
@@ -0,0 +1,182 @@
1
+ import { isAttributeObject, attributeValueToTypedAttributeValue } from '../attributes.js';
2
+ import { isPrimitive } from '../utils/is.js';
3
+ import { showSpanDropWarning } from '../utils/spanUtils.js';
4
+
5
+ /**
6
+ * Only set a span JSON attribute if it is not already set.
7
+ * This is used to safely set attributes on JSON objects without mutating already-ended span instances.
8
+ */
9
+ function safeSetSpanJSONAttributes(
10
+ spanJSON,
11
+ newAttributes,
12
+ ) {
13
+ if (!spanJSON.attributes) {
14
+ spanJSON.attributes = {};
15
+ }
16
+
17
+ const originalAttributes = spanJSON.attributes;
18
+
19
+ Object.keys(newAttributes).forEach(key => {
20
+ if (!originalAttributes?.[key]) {
21
+ setAttributeOnSpanJSONWithMaybeUnit(
22
+ // type-casting here because we ensured above that the attributes object exists
23
+ spanJSON ,
24
+ key,
25
+ newAttributes[key],
26
+ );
27
+ }
28
+ });
29
+ }
30
+
31
+ /**
32
+ * Apply a user-provided beforeSendSpan callback to a span JSON.
33
+ */
34
+ function applyBeforeSendSpanCallback(
35
+ span,
36
+ beforeSendSpan,
37
+ ) {
38
+ const modifedSpan = beforeSendSpan(span);
39
+ if (!modifedSpan) {
40
+ showSpanDropWarning();
41
+ return span;
42
+ }
43
+ return modifedSpan;
44
+ }
45
+
46
+ function setAttributeOnSpanJSONWithMaybeUnit(
47
+ spanJSON,
48
+ attributeKey,
49
+ attributeValue,
50
+ ) {
51
+ const { value, unit } = isAttributeObject(attributeValue)
52
+ ? attributeValue
53
+ : { value: attributeValue, unit: undefined };
54
+ const typedAttributeValue = attributeValueToTypedAttributeValue(value);
55
+
56
+ if (typedAttributeValue && isSupportedSerializableType(value)) {
57
+ spanJSON.attributes[attributeKey] = typedAttributeValue;
58
+ if (unit) {
59
+ spanJSON.attributes[attributeKey].unit = unit;
60
+ }
61
+ }
62
+ }
63
+
64
+ function isSupportedSerializableType(value) {
65
+ return ['string', 'number', 'boolean'].includes(typeof value) || Array.isArray(value);
66
+ }
67
+
68
+ // map of attributes->context keys for those attributes that don't correspond 1:1 to the context key
69
+ const explicitAttributeToContextMapping = {
70
+ 'os.build_id': 'os.build',
71
+ 'app.name': 'app.app_name',
72
+ 'app.identifier': 'app.app_identifier',
73
+ 'app.version': 'app.app_version',
74
+ 'app.memory': 'app.app_memory',
75
+ 'app.start_time': 'app.app_start_time',
76
+ };
77
+
78
+ const knownContexts = [
79
+ // set by `nodeContextIntegration`
80
+ 'app',
81
+ 'os',
82
+ 'device',
83
+ 'culture',
84
+ 'cloud_resource',
85
+ 'runtime',
86
+
87
+ // TODO: These need more thorough checking if they're all setting expected attributes
88
+
89
+ // set by the `instrumentPostgresJs`
90
+ 'postgresjsConnection',
91
+ // set by `ensureIsWrapped`
92
+ 'missing_instrumentation',
93
+ // set by `nodeProfilingIntegration`
94
+ 'profile',
95
+ // set by angular `init`
96
+ 'angular',
97
+ // set by AWS Lambda SDK
98
+ 'aws.lambda',
99
+ 'aws.cloudwatch.logs',
100
+ // set by `instrumentBunServe`
101
+ 'response',
102
+ // set by `trpcMiddleware`
103
+ 'trpc',
104
+ // set by `instrumentSupabaseClient`
105
+ 'supabase',
106
+ // set by `gcp.function.context`
107
+ 'gcp.function.context',
108
+ // set by nextjs SDK
109
+ 'nextjs',
110
+ // set by react SDK `captureReactException`, `init`
111
+ 'react',
112
+ // set by react SDK `createReduxEnhancer`
113
+ 'state',
114
+ // set by `replayIntegration`
115
+ 'Replays',
116
+ // Other information:
117
+ // - no need to handler feature flags `flags` context because it's already added to the active span
118
+ ];
119
+
120
+ /**
121
+ * Converts a context object to a set of attributes.
122
+ * Only includes attributes that are primitives (for now).
123
+ * @param contexts - The context object to convert.
124
+ * @returns The attributes object.
125
+ */
126
+ function contextsToAttributes(contexts) {
127
+ function contextToAttribute(context) {
128
+ return Object.keys(context).reduce(
129
+ (acc, key) => {
130
+ if (!isPrimitive(context[key])) {
131
+ return acc;
132
+ }
133
+ acc[key] = context[key];
134
+ return acc;
135
+ },
136
+ {} ,
137
+ );
138
+ }
139
+
140
+ const contextsWithPrimitiveValues = Object.keys(contexts).reduce((acc, key) => {
141
+ if (!knownContexts.includes(key)) {
142
+ return acc;
143
+ }
144
+ const context = contexts[key];
145
+ if (context) {
146
+ acc[key] = contextToAttribute(context);
147
+ }
148
+ return acc;
149
+ }, {} );
150
+
151
+ const explicitlyMappedAttributes = Object.entries(explicitAttributeToContextMapping).reduce(
152
+ (acc, [attributeKey, contextKey]) => {
153
+ const [contextName, contextValueKey] = contextKey.split('.');
154
+ if (contextName && contextValueKey && contextsWithPrimitiveValues[contextName]?.[contextValueKey]) {
155
+ acc[attributeKey] = contextsWithPrimitiveValues[contextName]?.[contextValueKey];
156
+ // now we delete this key from `contextsWithPrimitiveValues` so we don't include it in the next step
157
+ delete contextsWithPrimitiveValues[contextName]?.[contextValueKey];
158
+ }
159
+ return acc;
160
+ },
161
+ {} ,
162
+ );
163
+
164
+ return {
165
+ ...explicitlyMappedAttributes,
166
+ ...Object.entries(contextsWithPrimitiveValues).reduce(
167
+ (acc, [contextName, contextObj]) => {
168
+ contextObj &&
169
+ Object.entries(contextObj).forEach(([key, value]) => {
170
+ if (value) {
171
+ acc[`${contextName}.${key}`] = value;
172
+ }
173
+ });
174
+ return acc;
175
+ },
176
+ {} ,
177
+ ),
178
+ };
179
+ }
180
+
181
+ export { applyBeforeSendSpanCallback, contextsToAttributes, safeSetSpanJSONAttributes };
182
+ //# sourceMappingURL=spanFirstUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spanFirstUtils.js","sources":["../../../src/spans/spanFirstUtils.ts"],"sourcesContent":["import type { RawAttributes } from '../attributes';\nimport { attributeValueToTypedAttributeValue, isAttributeObject } from '../attributes';\nimport type { Context, Contexts } from '../types-hoist/context';\nimport type { SpanV2JSON } from '../types-hoist/span';\nimport { isPrimitive } from '../utils/is';\nimport { showSpanDropWarning } from '../utils/spanUtils';\n\n/**\n * Only set a span JSON attribute if it is not already set.\n * This is used to safely set attributes on JSON objects without mutating already-ended span instances.\n */\nexport function safeSetSpanJSONAttributes(\n spanJSON: SpanV2JSON,\n newAttributes: RawAttributes<Record<string, unknown>>,\n): void {\n if (!spanJSON.attributes) {\n spanJSON.attributes = {};\n }\n\n const originalAttributes = spanJSON.attributes;\n\n Object.keys(newAttributes).forEach(key => {\n if (!originalAttributes?.[key]) {\n setAttributeOnSpanJSONWithMaybeUnit(\n // type-casting here because we ensured above that the attributes object exists\n spanJSON as SpanV2JSON & Required<Pick<SpanV2JSON, 'attributes'>>,\n key,\n newAttributes[key],\n );\n }\n });\n}\n\n/**\n * Apply a user-provided beforeSendSpan callback to a span JSON.\n */\nexport function applyBeforeSendSpanCallback(\n span: SpanV2JSON,\n beforeSendSpan: (span: SpanV2JSON) => SpanV2JSON,\n): SpanV2JSON {\n const modifedSpan = beforeSendSpan(span);\n if (!modifedSpan) {\n showSpanDropWarning();\n return span;\n }\n return modifedSpan;\n}\n\nfunction setAttributeOnSpanJSONWithMaybeUnit(\n spanJSON: SpanV2JSON & Required<Pick<SpanV2JSON, 'attributes'>>,\n attributeKey: string,\n attributeValue: unknown,\n): void {\n const { value, unit } = isAttributeObject(attributeValue)\n ? attributeValue\n : { value: attributeValue, unit: undefined };\n const typedAttributeValue = attributeValueToTypedAttributeValue(value);\n\n if (typedAttributeValue && isSupportedSerializableType(value)) {\n spanJSON.attributes[attributeKey] = typedAttributeValue;\n if (unit) {\n spanJSON.attributes[attributeKey].unit = unit;\n }\n }\n}\n\nfunction isSupportedSerializableType(value: unknown): boolean {\n return ['string', 'number', 'boolean'].includes(typeof value) || Array.isArray(value);\n}\n\n// map of attributes->context keys for those attributes that don't correspond 1:1 to the context key\nconst explicitAttributeToContextMapping = {\n 'os.build_id': 'os.build',\n 'app.name': 'app.app_name',\n 'app.identifier': 'app.app_identifier',\n 'app.version': 'app.app_version',\n 'app.memory': 'app.app_memory',\n 'app.start_time': 'app.app_start_time',\n};\n\nconst knownContexts = [\n // set by `nodeContextIntegration`\n 'app',\n 'os',\n 'device',\n 'culture',\n 'cloud_resource',\n 'runtime',\n\n // TODO: These need more thorough checking if they're all setting expected attributes\n\n // set by the `instrumentPostgresJs`\n 'postgresjsConnection',\n // set by `ensureIsWrapped`\n 'missing_instrumentation',\n // set by `nodeProfilingIntegration`\n 'profile',\n // set by angular `init`\n 'angular',\n // set by AWS Lambda SDK\n 'aws.lambda',\n 'aws.cloudwatch.logs',\n // set by `instrumentBunServe`\n 'response',\n // set by `trpcMiddleware`\n 'trpc',\n // set by `instrumentSupabaseClient`\n 'supabase',\n // set by `gcp.function.context`\n 'gcp.function.context',\n // set by nextjs SDK\n 'nextjs',\n // set by react SDK `captureReactException`, `init`\n 'react',\n // set by react SDK `createReduxEnhancer`\n 'state',\n // set by `replayIntegration`\n 'Replays',\n // Other information:\n // - no need to handler feature flags `flags` context because it's already added to the active span\n];\n\n/**\n * Converts a context object to a set of attributes.\n * Only includes attributes that are primitives (for now).\n * @param contexts - The context object to convert.\n * @returns The attributes object.\n */\nexport function contextsToAttributes(contexts: Contexts): RawAttributes<Record<string, unknown>> {\n function contextToAttribute(context: Context): Context {\n return Object.keys(context).reduce(\n (acc, key) => {\n if (!isPrimitive(context[key])) {\n return acc;\n }\n acc[key] = context[key];\n return acc;\n },\n {} as Record<string, unknown>,\n );\n }\n\n const contextsWithPrimitiveValues = Object.keys(contexts).reduce((acc, key) => {\n if (!knownContexts.includes(key)) {\n return acc;\n }\n const context = contexts[key];\n if (context) {\n acc[key] = contextToAttribute(context);\n }\n return acc;\n }, {} as Contexts);\n\n const explicitlyMappedAttributes = Object.entries(explicitAttributeToContextMapping).reduce(\n (acc, [attributeKey, contextKey]) => {\n const [contextName, contextValueKey] = contextKey.split('.');\n if (contextName && contextValueKey && contextsWithPrimitiveValues[contextName]?.[contextValueKey]) {\n acc[attributeKey] = contextsWithPrimitiveValues[contextName]?.[contextValueKey];\n // now we delete this key from `contextsWithPrimitiveValues` so we don't include it in the next step\n delete contextsWithPrimitiveValues[contextName]?.[contextValueKey];\n }\n return acc;\n },\n {} as Record<string, unknown>,\n );\n\n return {\n ...explicitlyMappedAttributes,\n ...Object.entries(contextsWithPrimitiveValues).reduce(\n (acc, [contextName, contextObj]) => {\n contextObj &&\n Object.entries(contextObj).forEach(([key, value]) => {\n if (value) {\n acc[`${contextName}.${key}`] = value;\n }\n });\n return acc;\n },\n {} as Record<string, unknown>,\n ),\n };\n}\n"],"names":[],"mappings":";;;;AAOA;AACA;AACA;AACA;AACO,SAAS,yBAAyB;AACzC,EAAE,QAAQ;AACV,EAAE,aAAa;AACf,EAAQ;AACR,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE;AAC5B,IAAI,QAAQ,CAAC,UAAA,GAAa,EAAE;AAC5B,EAAE;;AAEF,EAAE,MAAM,kBAAA,GAAqB,QAAQ,CAAC,UAAU;;AAEhD,EAAE,MAAM,CAAC,IAAI,CAAC,aAAa,C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O,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;AAC/D,YAAY,IAAI,KAAK,EAAE;AACvB,cAAc,GAAG,CAAC,CAAC,EAAA,WAAA,CAAA,CAAA,EAAA,GAAA,CAAA,CAAA,CAAA,GAAA,KAAA;AACA,YAAA;AACA,UAAA,CAAA,CAAA;AACA,QAAA,OAAA,GAAA;AACA,MAAA,CAAA;AACA,MAAA,EAAA;AACA,KAAA;AACA,GAAA;AACA;;;;"}
@@ -229,6 +229,11 @@ const GEN_AI_EMBED_DO_EMBED_OPERATION_ATTRIBUTE = 'gen_ai.embed';
229
229
  */
230
230
  const GEN_AI_EMBED_MANY_DO_EMBED_OPERATION_ATTRIBUTE = 'gen_ai.embed_many';
231
231
 
232
+ /**
233
+ * The span operation name for reranking
234
+ */
235
+ const GEN_AI_RERANK_DO_RERANK_OPERATION_ATTRIBUTE = 'gen_ai.rerank';
236
+
232
237
  /**
233
238
  * The span operation name for executing a tool
234
239
  */
@@ -310,5 +315,5 @@ const OPENAI_OPERATIONS = {
310
315
  */
311
316
  const ANTHROPIC_AI_RESPONSE_TIMESTAMP_ATTRIBUTE = 'anthropic.response.timestamp';
312
317
 
313
- export { ANTHROPIC_AI_RESPONSE_TIMESTAMP_ATTRIBUTE, GEN_AI_AGENT_NAME_ATTRIBUTE, GEN_AI_CONVERSATION_ID_ATTRIBUTE, GEN_AI_EMBEDDINGS_INPUT_ATTRIBUTE, GEN_AI_EMBED_DO_EMBED_OPERATION_ATTRIBUTE, GEN_AI_EMBED_MANY_DO_EMBED_OPERATION_ATTRIBUTE, GEN_AI_EXECUTE_TOOL_OPERATION_ATTRIBUTE, GEN_AI_GENERATE_OBJECT_DO_GENERATE_OPERATION_ATTRIBUTE, GEN_AI_GENERATE_TEXT_DO_GENERATE_OPERATION_ATTRIBUTE, GEN_AI_INPUT_MESSAGES_ATTRIBUTE, GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE, GEN_AI_INVOKE_AGENT_OPERATION_ATTRIBUTE, GEN_AI_OPERATION_NAME_ATTRIBUTE, GEN_AI_PIPELINE_NAME_ATTRIBUTE, GEN_AI_PROMPT_ATTRIBUTE, GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE, GEN_AI_REQUEST_DIMENSIONS_ATTRIBUTE, GEN_AI_REQUEST_ENCODING_FORMAT_ATTRIBUTE, GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE, GEN_AI_REQUEST_MAX_TOKENS_ATTRIBUTE, GEN_AI_REQUEST_MODEL_ATTRIBUTE, GEN_AI_REQUEST_PRESENCE_PENALTY_ATTRIBUTE, GEN_AI_REQUEST_STREAM_ATTRIBUTE, GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE, GEN_AI_REQUEST_TOP_K_ATTRIBUTE, GEN_AI_REQUEST_TOP_P_ATTRIBUTE, GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE, GEN_AI_RESPONSE_ID_ATTRIBUTE, GEN_AI_RESPONSE_MODEL_ATTRIBUTE, GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE, GEN_AI_RESPONSE_STREAMING_ATTRIBUTE, GEN_AI_RESPONSE_TEXT_ATTRIBUTE, GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE, GEN_AI_STREAM_OBJECT_DO_STREAM_OPERATION_ATTRIBUTE, GEN_AI_STREAM_TEXT_DO_STREAM_OPERATION_ATTRIBUTE, GEN_AI_SYSTEM_ATTRIBUTE, GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE, GEN_AI_TOOL_CALL_ID_ATTRIBUTE, GEN_AI_TOOL_INPUT_ATTRIBUTE, GEN_AI_TOOL_NAME_ATTRIBUTE, GEN_AI_TOOL_OUTPUT_ATTRIBUTE, GEN_AI_TOOL_TYPE_ATTRIBUTE, GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE, GEN_AI_USAGE_INPUT_TOKENS_CACHE_WRITE_ATTRIBUTE, GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE, OPENAI_OPERATIONS, OPENAI_RESPONSE_ID_ATTRIBUTE, OPENAI_RESPONSE_MODEL_ATTRIBUTE, OPENAI_RESPONSE_TIMESTAMP_ATTRIBUTE, OPENAI_USAGE_COMPLETION_TOKENS_ATTRIBUTE, OPENAI_USAGE_PROMPT_TOKENS_ATTRIBUTE };
318
+ export { ANTHROPIC_AI_RESPONSE_TIMESTAMP_ATTRIBUTE, GEN_AI_AGENT_NAME_ATTRIBUTE, GEN_AI_CONVERSATION_ID_ATTRIBUTE, GEN_AI_EMBEDDINGS_INPUT_ATTRIBUTE, GEN_AI_EMBED_DO_EMBED_OPERATION_ATTRIBUTE, GEN_AI_EMBED_MANY_DO_EMBED_OPERATION_ATTRIBUTE, GEN_AI_EXECUTE_TOOL_OPERATION_ATTRIBUTE, GEN_AI_GENERATE_OBJECT_DO_GENERATE_OPERATION_ATTRIBUTE, GEN_AI_GENERATE_TEXT_DO_GENERATE_OPERATION_ATTRIBUTE, GEN_AI_INPUT_MESSAGES_ATTRIBUTE, GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE, GEN_AI_INVOKE_AGENT_OPERATION_ATTRIBUTE, GEN_AI_OPERATION_NAME_ATTRIBUTE, GEN_AI_PIPELINE_NAME_ATTRIBUTE, GEN_AI_PROMPT_ATTRIBUTE, GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE, GEN_AI_REQUEST_DIMENSIONS_ATTRIBUTE, GEN_AI_REQUEST_ENCODING_FORMAT_ATTRIBUTE, GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE, GEN_AI_REQUEST_MAX_TOKENS_ATTRIBUTE, GEN_AI_REQUEST_MODEL_ATTRIBUTE, GEN_AI_REQUEST_PRESENCE_PENALTY_ATTRIBUTE, GEN_AI_REQUEST_STREAM_ATTRIBUTE, GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE, GEN_AI_REQUEST_TOP_K_ATTRIBUTE, GEN_AI_REQUEST_TOP_P_ATTRIBUTE, GEN_AI_RERANK_DO_RERANK_OPERATION_ATTRIBUTE, GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE, GEN_AI_RESPONSE_ID_ATTRIBUTE, GEN_AI_RESPONSE_MODEL_ATTRIBUTE, GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE, GEN_AI_RESPONSE_STREAMING_ATTRIBUTE, GEN_AI_RESPONSE_TEXT_ATTRIBUTE, GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE, GEN_AI_STREAM_OBJECT_DO_STREAM_OPERATION_ATTRIBUTE, GEN_AI_STREAM_TEXT_DO_STREAM_OPERATION_ATTRIBUTE, GEN_AI_SYSTEM_ATTRIBUTE, GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE, GEN_AI_TOOL_CALL_ID_ATTRIBUTE, GEN_AI_TOOL_INPUT_ATTRIBUTE, GEN_AI_TOOL_NAME_ATTRIBUTE, GEN_AI_TOOL_OUTPUT_ATTRIBUTE, GEN_AI_TOOL_TYPE_ATTRIBUTE, GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE, GEN_AI_USAGE_INPUT_TOKENS_CACHE_WRITE_ATTRIBUTE, GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE, GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE, OPENAI_OPERATIONS, OPENAI_RESPONSE_ID_ATTRIBUTE, OPENAI_RESPONSE_MODEL_ATTRIBUTE, OPENAI_RESPONSE_TIMESTAMP_ATTRIBUTE, OPENAI_USAGE_COMPLETION_TOKENS_ATTRIBUTE, OPENAI_USAGE_PROMPT_TOKENS_ATTRIBUTE };
314
319
  //# sourceMappingURL=gen-ai-attributes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gen-ai-attributes.js","sources":["../../../../src/tracing/ai/gen-ai-attributes.ts"],"sourcesContent":["/**\n * OpenAI Integration Telemetry Attributes\n * Based on OpenTelemetry Semantic Conventions for Generative AI\n * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/\n */\n\n// =============================================================================\n// OPENTELEMETRY SEMANTIC CONVENTIONS FOR GENAI\n// =============================================================================\n\n/**\n * The input messages sent to the model\n */\nexport const GEN_AI_PROMPT_ATTRIBUTE = 'gen_ai.prompt';\n\n/**\n * The Generative AI system being used\n * For OpenAI, this should always be \"openai\"\n */\nexport const GEN_AI_SYSTEM_ATTRIBUTE = 'gen_ai.system';\n\n/**\n * The name of the model as requested\n * Examples: \"gpt-4\", \"gpt-3.5-turbo\"\n */\nexport const GEN_AI_REQUEST_MODEL_ATTRIBUTE = 'gen_ai.request.model';\n\n/**\n * Whether streaming was enabled for the request\n */\nexport const GEN_AI_REQUEST_STREAM_ATTRIBUTE = 'gen_ai.request.stream';\n\n/**\n * The temperature setting for the model request\n */\nexport const GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE = 'gen_ai.request.temperature';\n\n/**\n * The maximum number of tokens requested\n */\nexport const GEN_AI_REQUEST_MAX_TOKENS_ATTRIBUTE = 'gen_ai.request.max_tokens';\n\n/**\n * The frequency penalty setting for the model request\n */\nexport const GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE = 'gen_ai.request.frequency_penalty';\n\n/**\n * The presence penalty setting for the model request\n */\nexport const GEN_AI_REQUEST_PRESENCE_PENALTY_ATTRIBUTE = 'gen_ai.request.presence_penalty';\n\n/**\n * The top_p (nucleus sampling) setting for the model request\n */\nexport const GEN_AI_REQUEST_TOP_P_ATTRIBUTE = 'gen_ai.request.top_p';\n\n/**\n * The top_k setting for the model request\n */\nexport const GEN_AI_REQUEST_TOP_K_ATTRIBUTE = 'gen_ai.request.top_k';\n\n/**\n * Stop sequences for the model request\n */\nexport const GEN_AI_REQUEST_STOP_SEQUENCES_ATTRIBUTE = 'gen_ai.request.stop_sequences';\n\n/**\n * The encoding format for the model request\n */\nexport const GEN_AI_REQUEST_ENCODING_FORMAT_ATTRIBUTE = 'gen_ai.request.encoding_format';\n\n/**\n * The dimensions for the model request\n */\nexport const GEN_AI_REQUEST_DIMENSIONS_ATTRIBUTE = 'gen_ai.request.dimensions';\n\n/**\n * Array of reasons why the model stopped generating tokens\n */\nexport const GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE = 'gen_ai.response.finish_reasons';\n\n/**\n * The name of the model that generated the response\n */\nexport const GEN_AI_RESPONSE_MODEL_ATTRIBUTE = 'gen_ai.response.model';\n\n/**\n * The unique identifier for the response\n */\nexport const GEN_AI_RESPONSE_ID_ATTRIBUTE = 'gen_ai.response.id';\n\n/**\n * The reason why the model stopped generating tokens\n */\nexport const GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE = 'gen_ai.response.stop_reason';\n\n/**\n * The number of tokens used in the prompt\n */\nexport const GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE = 'gen_ai.usage.input_tokens';\n\n/**\n * The number of tokens used in the response\n */\nexport const GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE = 'gen_ai.usage.output_tokens';\n\n/**\n * The total number of tokens used (input + output)\n */\nexport const GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE = 'gen_ai.usage.total_tokens';\n\n/**\n * The operation name\n */\nexport const GEN_AI_OPERATION_NAME_ATTRIBUTE = 'gen_ai.operation.name';\n\n/**\n * Original length of messages array, used to indicate truncations had occured\n */\nexport const GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE = 'sentry.sdk_meta.gen_ai.input.messages.original_length';\n\n/**\n * The prompt messages\n * Only recorded when recordInputs is enabled\n */\nexport const GEN_AI_INPUT_MESSAGES_ATTRIBUTE = 'gen_ai.input.messages';\n\n/**\n * The system instructions extracted from system messages\n * Only recorded when recordInputs is enabled\n * According to OpenTelemetry spec: https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-system-instructions\n */\nexport const GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE = 'gen_ai.system_instructions';\n\n/**\n * The response text\n * Only recorded when recordOutputs is enabled\n */\nexport const GEN_AI_RESPONSE_TEXT_ATTRIBUTE = 'gen_ai.response.text';\n\n/**\n * The available tools from incoming request\n * Only recorded when recordInputs is enabled\n */\nexport const GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE = 'gen_ai.request.available_tools';\n\n/**\n * Whether the response is a streaming response\n */\nexport const GEN_AI_RESPONSE_STREAMING_ATTRIBUTE = 'gen_ai.response.streaming';\n\n/**\n * The tool calls from the response\n * Only recorded when recordOutputs is enabled\n */\nexport const GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE = 'gen_ai.response.tool_calls';\n\n/**\n * The agent name\n */\nexport const GEN_AI_AGENT_NAME_ATTRIBUTE = 'gen_ai.agent.name';\n\n/**\n * The pipeline name\n */\nexport const GEN_AI_PIPELINE_NAME_ATTRIBUTE = 'gen_ai.pipeline.name';\n\n/**\n * The conversation ID for linking messages across API calls\n * For OpenAI Assistants API: thread_id\n * For LangGraph: configurable.thread_id\n */\nexport const GEN_AI_CONVERSATION_ID_ATTRIBUTE = 'gen_ai.conversation.id';\n\n/**\n * The number of cache creation input tokens used\n */\nexport const GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS_ATTRIBUTE = 'gen_ai.usage.cache_creation_input_tokens';\n\n/**\n * The number of cache read input tokens used\n */\nexport const GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS_ATTRIBUTE = 'gen_ai.usage.cache_read_input_tokens';\n\n/**\n * The number of cache write input tokens used\n */\nexport const GEN_AI_USAGE_INPUT_TOKENS_CACHE_WRITE_ATTRIBUTE = 'gen_ai.usage.input_tokens.cache_write';\n\n/**\n * The number of cached input tokens that were used\n */\nexport const GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE = 'gen_ai.usage.input_tokens.cached';\n\n/**\n * The span operation name for invoking an agent\n */\nexport const GEN_AI_INVOKE_AGENT_OPERATION_ATTRIBUTE = 'gen_ai.invoke_agent';\n\n/**\n * The span operation name for generating text\n */\nexport const GEN_AI_GENERATE_TEXT_DO_GENERATE_OPERATION_ATTRIBUTE = 'gen_ai.generate_text';\n\n/**\n * The span operation name for streaming text\n */\nexport const GEN_AI_STREAM_TEXT_DO_STREAM_OPERATION_ATTRIBUTE = 'gen_ai.stream_text';\n\n/**\n * The span operation name for generating object\n */\nexport const GEN_AI_GENERATE_OBJECT_DO_GENERATE_OPERATION_ATTRIBUTE = 'gen_ai.generate_object';\n\n/**\n * The span operation name for streaming object\n */\nexport const GEN_AI_STREAM_OBJECT_DO_STREAM_OPERATION_ATTRIBUTE = 'gen_ai.stream_object';\n\n/**\n * The embeddings input\n * Only recorded when recordInputs is enabled\n */\nexport const GEN_AI_EMBEDDINGS_INPUT_ATTRIBUTE = 'gen_ai.embeddings.input';\n\n/**\n * The span operation name for embedding\n */\nexport const GEN_AI_EMBED_DO_EMBED_OPERATION_ATTRIBUTE = 'gen_ai.embed';\n\n/**\n * The span operation name for embedding many\n */\nexport const GEN_AI_EMBED_MANY_DO_EMBED_OPERATION_ATTRIBUTE = 'gen_ai.embed_many';\n\n/**\n * The span operation name for executing a tool\n */\nexport const GEN_AI_EXECUTE_TOOL_OPERATION_ATTRIBUTE = 'gen_ai.execute_tool';\n\n/**\n * The tool name for tool call spans\n */\nexport const GEN_AI_TOOL_NAME_ATTRIBUTE = 'gen_ai.tool.name';\n\n/**\n * The tool call ID\n */\nexport const GEN_AI_TOOL_CALL_ID_ATTRIBUTE = 'gen_ai.tool.call.id';\n\n/**\n * The tool type (e.g., 'function')\n */\nexport const GEN_AI_TOOL_TYPE_ATTRIBUTE = 'gen_ai.tool.type';\n\n/**\n * The tool input/arguments\n */\nexport const GEN_AI_TOOL_INPUT_ATTRIBUTE = 'gen_ai.tool.input';\n\n/**\n * The tool output/result\n */\nexport const GEN_AI_TOOL_OUTPUT_ATTRIBUTE = 'gen_ai.tool.output';\n\n// =============================================================================\n// OPENAI-SPECIFIC ATTRIBUTES\n// =============================================================================\n\n/**\n * The response ID from OpenAI\n */\nexport const OPENAI_RESPONSE_ID_ATTRIBUTE = 'openai.response.id';\n\n/**\n * The response model from OpenAI\n */\nexport const OPENAI_RESPONSE_MODEL_ATTRIBUTE = 'openai.response.model';\n\n/**\n * The response timestamp from OpenAI (ISO string)\n */\nexport const OPENAI_RESPONSE_TIMESTAMP_ATTRIBUTE = 'openai.response.timestamp';\n\n/**\n * The number of completion tokens used\n */\nexport const OPENAI_USAGE_COMPLETION_TOKENS_ATTRIBUTE = 'openai.usage.completion_tokens';\n\n/**\n * The number of prompt tokens used\n */\nexport const OPENAI_USAGE_PROMPT_TOKENS_ATTRIBUTE = 'openai.usage.prompt_tokens';\n\n// =============================================================================\n// OPENAI OPERATIONS\n// =============================================================================\n\n/**\n * OpenAI API operations following OpenTelemetry semantic conventions\n * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/#llm-request-spans\n */\nexport const OPENAI_OPERATIONS = {\n CHAT: 'chat',\n EMBEDDINGS: 'embeddings',\n} as const;\n\n// =============================================================================\n// ANTHROPIC AI OPERATIONS\n// =============================================================================\n\n/**\n * The response timestamp from Anthropic AI (ISO string)\n */\nexport const ANTHROPIC_AI_RESPONSE_TIMESTAMP_ATTRIBUTE = 'anthropic.response.timestamp';\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA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AU,EAAE,YAAY;AAC1B,CAAA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACO,MAAM,yCAAA,GAA4C;;;;"}
1
+ {"version":3,"file":"gen-ai-attributes.js","sources":["../../../../src/tracing/ai/gen-ai-attributes.ts"],"sourcesContent":["/**\n * OpenAI Integration Telemetry Attributes\n * Based on OpenTelemetry Semantic Conventions for Generative AI\n * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/\n */\n\n// =============================================================================\n// OPENTELEMETRY SEMANTIC CONVENTIONS FOR GENAI\n// =============================================================================\n\n/**\n * The input messages sent to the model\n */\nexport const GEN_AI_PROMPT_ATTRIBUTE = 'gen_ai.prompt';\n\n/**\n * The Generative AI system being used\n * For OpenAI, this should always be \"openai\"\n */\nexport const GEN_AI_SYSTEM_ATTRIBUTE = 'gen_ai.system';\n\n/**\n * The name of the model as requested\n * Examples: \"gpt-4\", \"gpt-3.5-turbo\"\n */\nexport const GEN_AI_REQUEST_MODEL_ATTRIBUTE = 'gen_ai.request.model';\n\n/**\n * Whether streaming was enabled for the request\n */\nexport const GEN_AI_REQUEST_STREAM_ATTRIBUTE = 'gen_ai.request.stream';\n\n/**\n * The temperature setting for the model request\n */\nexport const GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE = 'gen_ai.request.temperature';\n\n/**\n * The maximum number of tokens requested\n */\nexport const GEN_AI_REQUEST_MAX_TOKENS_ATTRIBUTE = 'gen_ai.request.max_tokens';\n\n/**\n * The frequency penalty setting for the model request\n */\nexport const GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE = 'gen_ai.request.frequency_penalty';\n\n/**\n * The presence penalty setting for the model request\n */\nexport const GEN_AI_REQUEST_PRESENCE_PENALTY_ATTRIBUTE = 'gen_ai.request.presence_penalty';\n\n/**\n * The top_p (nucleus sampling) setting for the model request\n */\nexport const GEN_AI_REQUEST_TOP_P_ATTRIBUTE = 'gen_ai.request.top_p';\n\n/**\n * The top_k setting for the model request\n */\nexport const GEN_AI_REQUEST_TOP_K_ATTRIBUTE = 'gen_ai.request.top_k';\n\n/**\n * Stop sequences for the model request\n */\nexport const GEN_AI_REQUEST_STOP_SEQUENCES_ATTRIBUTE = 'gen_ai.request.stop_sequences';\n\n/**\n * The encoding format for the model request\n */\nexport const GEN_AI_REQUEST_ENCODING_FORMAT_ATTRIBUTE = 'gen_ai.request.encoding_format';\n\n/**\n * The dimensions for the model request\n */\nexport const GEN_AI_REQUEST_DIMENSIONS_ATTRIBUTE = 'gen_ai.request.dimensions';\n\n/**\n * Array of reasons why the model stopped generating tokens\n */\nexport const GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE = 'gen_ai.response.finish_reasons';\n\n/**\n * The name of the model that generated the response\n */\nexport const GEN_AI_RESPONSE_MODEL_ATTRIBUTE = 'gen_ai.response.model';\n\n/**\n * The unique identifier for the response\n */\nexport const GEN_AI_RESPONSE_ID_ATTRIBUTE = 'gen_ai.response.id';\n\n/**\n * The reason why the model stopped generating tokens\n */\nexport const GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE = 'gen_ai.response.stop_reason';\n\n/**\n * The number of tokens used in the prompt\n */\nexport const GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE = 'gen_ai.usage.input_tokens';\n\n/**\n * The number of tokens used in the response\n */\nexport const GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE = 'gen_ai.usage.output_tokens';\n\n/**\n * The total number of tokens used (input + output)\n */\nexport const GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE = 'gen_ai.usage.total_tokens';\n\n/**\n * The operation name\n */\nexport const GEN_AI_OPERATION_NAME_ATTRIBUTE = 'gen_ai.operation.name';\n\n/**\n * Original length of messages array, used to indicate truncations had occured\n */\nexport const GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE = 'sentry.sdk_meta.gen_ai.input.messages.original_length';\n\n/**\n * The prompt messages\n * Only recorded when recordInputs is enabled\n */\nexport const GEN_AI_INPUT_MESSAGES_ATTRIBUTE = 'gen_ai.input.messages';\n\n/**\n * The system instructions extracted from system messages\n * Only recorded when recordInputs is enabled\n * According to OpenTelemetry spec: https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-system-instructions\n */\nexport const GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE = 'gen_ai.system_instructions';\n\n/**\n * The response text\n * Only recorded when recordOutputs is enabled\n */\nexport const GEN_AI_RESPONSE_TEXT_ATTRIBUTE = 'gen_ai.response.text';\n\n/**\n * The available tools from incoming request\n * Only recorded when recordInputs is enabled\n */\nexport const GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE = 'gen_ai.request.available_tools';\n\n/**\n * Whether the response is a streaming response\n */\nexport const GEN_AI_RESPONSE_STREAMING_ATTRIBUTE = 'gen_ai.response.streaming';\n\n/**\n * The tool calls from the response\n * Only recorded when recordOutputs is enabled\n */\nexport const GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE = 'gen_ai.response.tool_calls';\n\n/**\n * The agent name\n */\nexport const GEN_AI_AGENT_NAME_ATTRIBUTE = 'gen_ai.agent.name';\n\n/**\n * The pipeline name\n */\nexport const GEN_AI_PIPELINE_NAME_ATTRIBUTE = 'gen_ai.pipeline.name';\n\n/**\n * The conversation ID for linking messages across API calls\n * For OpenAI Assistants API: thread_id\n * For LangGraph: configurable.thread_id\n */\nexport const GEN_AI_CONVERSATION_ID_ATTRIBUTE = 'gen_ai.conversation.id';\n\n/**\n * The number of cache creation input tokens used\n */\nexport const GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS_ATTRIBUTE = 'gen_ai.usage.cache_creation_input_tokens';\n\n/**\n * The number of cache read input tokens used\n */\nexport const GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS_ATTRIBUTE = 'gen_ai.usage.cache_read_input_tokens';\n\n/**\n * The number of cache write input tokens used\n */\nexport const GEN_AI_USAGE_INPUT_TOKENS_CACHE_WRITE_ATTRIBUTE = 'gen_ai.usage.input_tokens.cache_write';\n\n/**\n * The number of cached input tokens that were used\n */\nexport const GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE = 'gen_ai.usage.input_tokens.cached';\n\n/**\n * The span operation name for invoking an agent\n */\nexport const GEN_AI_INVOKE_AGENT_OPERATION_ATTRIBUTE = 'gen_ai.invoke_agent';\n\n/**\n * The span operation name for generating text\n */\nexport const GEN_AI_GENERATE_TEXT_DO_GENERATE_OPERATION_ATTRIBUTE = 'gen_ai.generate_text';\n\n/**\n * The span operation name for streaming text\n */\nexport const GEN_AI_STREAM_TEXT_DO_STREAM_OPERATION_ATTRIBUTE = 'gen_ai.stream_text';\n\n/**\n * The span operation name for generating object\n */\nexport const GEN_AI_GENERATE_OBJECT_DO_GENERATE_OPERATION_ATTRIBUTE = 'gen_ai.generate_object';\n\n/**\n * The span operation name for streaming object\n */\nexport const GEN_AI_STREAM_OBJECT_DO_STREAM_OPERATION_ATTRIBUTE = 'gen_ai.stream_object';\n\n/**\n * The embeddings input\n * Only recorded when recordInputs is enabled\n */\nexport const GEN_AI_EMBEDDINGS_INPUT_ATTRIBUTE = 'gen_ai.embeddings.input';\n\n/**\n * The span operation name for embedding\n */\nexport const GEN_AI_EMBED_DO_EMBED_OPERATION_ATTRIBUTE = 'gen_ai.embed';\n\n/**\n * The span operation name for embedding many\n */\nexport const GEN_AI_EMBED_MANY_DO_EMBED_OPERATION_ATTRIBUTE = 'gen_ai.embed_many';\n\n/**\n * The span operation name for reranking\n */\nexport const GEN_AI_RERANK_DO_RERANK_OPERATION_ATTRIBUTE = 'gen_ai.rerank';\n\n/**\n * The span operation name for executing a tool\n */\nexport const GEN_AI_EXECUTE_TOOL_OPERATION_ATTRIBUTE = 'gen_ai.execute_tool';\n\n/**\n * The tool name for tool call spans\n */\nexport const GEN_AI_TOOL_NAME_ATTRIBUTE = 'gen_ai.tool.name';\n\n/**\n * The tool call ID\n */\nexport const GEN_AI_TOOL_CALL_ID_ATTRIBUTE = 'gen_ai.tool.call.id';\n\n/**\n * The tool type (e.g., 'function')\n */\nexport const GEN_AI_TOOL_TYPE_ATTRIBUTE = 'gen_ai.tool.type';\n\n/**\n * The tool input/arguments\n */\nexport const GEN_AI_TOOL_INPUT_ATTRIBUTE = 'gen_ai.tool.input';\n\n/**\n * The tool output/result\n */\nexport const GEN_AI_TOOL_OUTPUT_ATTRIBUTE = 'gen_ai.tool.output';\n\n// =============================================================================\n// OPENAI-SPECIFIC ATTRIBUTES\n// =============================================================================\n\n/**\n * The response ID from OpenAI\n */\nexport const OPENAI_RESPONSE_ID_ATTRIBUTE = 'openai.response.id';\n\n/**\n * The response model from OpenAI\n */\nexport const OPENAI_RESPONSE_MODEL_ATTRIBUTE = 'openai.response.model';\n\n/**\n * The response timestamp from OpenAI (ISO string)\n */\nexport const OPENAI_RESPONSE_TIMESTAMP_ATTRIBUTE = 'openai.response.timestamp';\n\n/**\n * The number of completion tokens used\n */\nexport const OPENAI_USAGE_COMPLETION_TOKENS_ATTRIBUTE = 'openai.usage.completion_tokens';\n\n/**\n * The number of prompt tokens used\n */\nexport const OPENAI_USAGE_PROMPT_TOKENS_ATTRIBUTE = 'openai.usage.prompt_tokens';\n\n// =============================================================================\n// OPENAI OPERATIONS\n// =============================================================================\n\n/**\n * OpenAI API operations following OpenTelemetry semantic conventions\n * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/#llm-request-spans\n */\nexport const OPENAI_OPERATIONS = {\n CHAT: 'chat',\n EMBEDDINGS: 'embeddings',\n} as const;\n\n// =============================================================================\n// ANTHROPIC AI OPERATIONS\n// =============================================================================\n\n/**\n * The response timestamp from Anthropic AI (ISO string)\n */\nexport const ANTHROPIC_AI_RESPONSE_TIMESTAMP_ATTRIBUTE = 'anthropic.response.timestamp';\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACO,MAAM,uBAAA,GAA0B;;AAEvC;AACA;AACA;AACA;AAC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AAEA;AACA;AACA;;AAEA;AACA;AACA;AACO,MAAM,yCAAA,GAA4C;;;;"}
@@ -1,7 +1,7 @@
1
1
  import { DEBUG_BUILD } from '../debug-build.js';
2
2
  import { SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT, SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE } from '../semanticAttributes.js';
3
3
  import { debug } from '../utils/debug-logger.js';
4
- import { getActiveSpan, getRootSpan } from '../utils/spanUtils.js';
4
+ import { getRootSpan, getActiveSpan } from '../utils/spanUtils.js';
5
5
 
6
6
  /**
7
7
  * Adds a measurement to the active transaction on the current global scope. You can optionally pass in a different span