@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
@@ -16,20 +16,16 @@ const version = require('./version.js');
16
16
  * @param names list of package names
17
17
  */
18
18
  function applySdkMetadata(options, name, names = [name], source = 'npm') {
19
- const metadata = options._metadata || {};
19
+ const sdk = ((options._metadata = options._metadata || {}).sdk = options._metadata.sdk || {});
20
20
 
21
- if (!metadata.sdk) {
22
- metadata.sdk = {
23
- name: `sentry.javascript.${name}`,
24
- packages: names.map(name => ({
25
- name: `${source}:@sentry/${name}`,
26
- version: version.SDK_VERSION,
27
- })),
21
+ if (!sdk.name) {
22
+ sdk.name = `sentry.javascript.${name}`;
23
+ sdk.packages = names.map(name => ({
24
+ name: `${source}:@sentry/${name}`,
28
25
  version: version.SDK_VERSION,
29
- };
26
+ }));
27
+ sdk.version = version.SDK_VERSION;
30
28
  }
31
-
32
- options._metadata = metadata;
33
29
  }
34
30
 
35
31
  exports.applySdkMetadata = applySdkMetadata;
@@ -1 +1 @@
1
- {"version":3,"file":"sdkMetadata.js","sources":["../../../src/utils/sdkMetadata.ts"],"sourcesContent":["import type { CoreOptions } from '../types-hoist/options';\nimport { SDK_VERSION } from '../utils/version';\n\n/**\n * A builder for the SDK metadata in the options for the SDK initialization.\n *\n * Note: This function is identical to `buildMetadata` in Remix and NextJS and SvelteKit.\n * We don't extract it for bundle size reasons.\n * @see https://github.com/getsentry/sentry-javascript/pull/7404\n * @see https://github.com/getsentry/sentry-javascript/pull/4196\n *\n * If you make changes to this function consider updating the others as well.\n *\n * @param options SDK options object that gets mutated\n * @param names list of package names\n */\nexport function applySdkMetadata(options: CoreOptions, name: string, names = [name], source = 'npm'): void {\n const metadata = options._metadata || {};\n\n if (!metadata.sdk) {\n metadata.sdk = {\n name: `sentry.javascript.${name}`,\n packages: names.map(name => ({\n name: `${source}:@sentry/${name}`,\n version: SDK_VERSION,\n })),\n version: SDK_VERSION,\n };\n }\n\n options._metadata = metadata;\n}\n"],"names":["SDK_VERSION"],"mappings":";;;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,gBAAgB,CAAC,OAAO,EAAe,IAAI,EAAU,KAAA,GAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,KAAK,EAAQ;AAC3G,EAAE,MAAM,WAAW,OAAO,CAAC,SAAA,IAAa,EAAE;;AAE1C,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE;AACrB,IAAI,QAAQ,CAAC,GAAA,GAAM;AACnB,MAAM,IAAI,EAAE,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAA;AACA,MAAA,QAAA,EAAA,KAAA,CAAA,GAAA,CAAA,IAAA,KAAA;AACA,QAAA,IAAA,EAAA,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,IAAA,CAAA,CAAA;AACA,QAAA,OAAA,EAAAA,mBAAA;AACA,OAAA,CAAA,CAAA;AACA,MAAA,OAAA,EAAAA,mBAAA;AACA,KAAA;AACA,EAAA;;AAEA,EAAA,OAAA,CAAA,SAAA,GAAA,QAAA;AACA;;;;"}
1
+ {"version":3,"file":"sdkMetadata.js","sources":["../../../src/utils/sdkMetadata.ts"],"sourcesContent":["import type { CoreOptions } from '../types-hoist/options';\nimport { SDK_VERSION } from '../utils/version';\n\n/**\n * A builder for the SDK metadata in the options for the SDK initialization.\n *\n * Note: This function is identical to `buildMetadata` in Remix and NextJS and SvelteKit.\n * We don't extract it for bundle size reasons.\n * @see https://github.com/getsentry/sentry-javascript/pull/7404\n * @see https://github.com/getsentry/sentry-javascript/pull/4196\n *\n * If you make changes to this function consider updating the others as well.\n *\n * @param options SDK options object that gets mutated\n * @param names list of package names\n */\nexport function applySdkMetadata(options: CoreOptions, name: string, names = [name], source = 'npm'): void {\n const sdk = ((options._metadata = options._metadata || {}).sdk = options._metadata.sdk || {});\n\n if (!sdk.name) {\n sdk.name = `sentry.javascript.${name}`;\n sdk.packages = names.map(name => ({\n name: `${source}:@sentry/${name}`,\n version: SDK_VERSION,\n }));\n sdk.version = SDK_VERSION;\n }\n}\n"],"names":["SDK_VERSION"],"mappings":";;;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,gBAAgB,CAAC,OAAO,EAAe,IAAI,EAAU,KAAA,GAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,KAAK,EAAQ;AAC3G,EAAE,MAAM,GAAA,IAAO,CAAC,OAAO,CAAC,SAAA,GAAY,OAAO,CAAC,SAAA,IAAa,EAAE,EAAE,GAAA,GAAM,OAAO,CAAC,SAAS,CAAC,GAAA,IAAO,EAAE,CAAC;;AAE/F,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;AACjB,IAAI,GAAG,CAAC,IAAA,GAAO,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAA;AACA,IAAA,GAAA,CAAA,QAAA,GAAA,KAAA,CAAA,GAAA,CAAA,IAAA,KAAA;AACA,MAAA,IAAA,EAAA,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,IAAA,CAAA,CAAA;AACA,MAAA,OAAA,EAAAA,mBAAA;AACA,KAAA,CAAA,CAAA;AACA,IAAA,GAAA,CAAA,OAAA,GAAAA,mBAAA;AACA,EAAA;AACA;;;;"}
@@ -1,11 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const debugBuild = require('../debug-build.js');
4
+ const semanticAttributes = require('../semanticAttributes.js');
4
5
  const debugLogger = require('./debug-logger.js');
5
6
  const string = require('./string.js');
6
7
 
7
- function logIgnoredSpan(droppedSpan) {
8
- debugLogger.debug.log(`Ignoring span ${droppedSpan.op} - ${droppedSpan.description} because it matches \`ignoreSpans\`.`);
8
+ function logIgnoredSpan(spanName, spanOp) {
9
+ debugLogger.debug.log(`Ignoring span ${spanOp ? `${spanOp} - ` : ''}${spanName} because it matches \`ignoreSpans\`.`);
9
10
  }
10
11
 
11
12
  /**
@@ -15,14 +16,32 @@ function shouldIgnoreSpan(
15
16
  span,
16
17
  ignoreSpans,
17
18
  ) {
18
- if (!ignoreSpans?.length || !span.description) {
19
+ if (!ignoreSpans?.length) {
20
+ return false;
21
+ }
22
+
23
+ const { spanName, spanOp: spanOpAttributeOrString } =
24
+ 'description' in span
25
+ ? { spanName: span.description, spanOp: span.op }
26
+ : 'name' in span
27
+ ? { spanName: span.name, spanOp: span.attributes?.[semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_OP] }
28
+ : { spanName: '', spanOp: '' };
29
+
30
+ const spanOp =
31
+ typeof spanOpAttributeOrString === 'string'
32
+ ? spanOpAttributeOrString
33
+ : spanOpAttributeOrString?.type === 'string'
34
+ ? spanOpAttributeOrString.value
35
+ : undefined;
36
+
37
+ if (!spanName) {
19
38
  return false;
20
39
  }
21
40
 
22
41
  for (const pattern of ignoreSpans) {
23
42
  if (isStringOrRegExp(pattern)) {
24
- if (string.isMatchingPattern(span.description, pattern)) {
25
- debugBuild.DEBUG_BUILD && logIgnoredSpan(span);
43
+ if (string.isMatchingPattern(spanName, pattern)) {
44
+ debugBuild.DEBUG_BUILD && logIgnoredSpan(spanName, spanOp);
26
45
  return true;
27
46
  }
28
47
  continue;
@@ -32,15 +51,15 @@ function shouldIgnoreSpan(
32
51
  continue;
33
52
  }
34
53
 
35
- const nameMatches = pattern.name ? string.isMatchingPattern(span.description, pattern.name) : true;
36
- const opMatches = pattern.op ? span.op && string.isMatchingPattern(span.op, pattern.op) : true;
54
+ const nameMatches = pattern.name ? string.isMatchingPattern(spanName, pattern.name) : true;
55
+ const opMatches = pattern.op ? spanOp && string.isMatchingPattern(spanOp, pattern.op) : true;
37
56
 
38
57
  // This check here is only correct because we can guarantee that we ran `isMatchingPattern`
39
58
  // for at least one of `nameMatches` and `opMatches`. So in contrary to how this looks,
40
59
  // not both op and name actually have to match. This is the most efficient way to check
41
60
  // for all combinations of name and op patterns.
42
61
  if (nameMatches && opMatches) {
43
- debugBuild.DEBUG_BUILD && logIgnoredSpan(span);
62
+ debugBuild.DEBUG_BUILD && logIgnoredSpan(spanName, spanOp);
44
63
  return true;
45
64
  }
46
65
  }
@@ -52,7 +71,10 @@ function shouldIgnoreSpan(
52
71
  * Takes a list of spans, and a span that was dropped, and re-parents the child spans of the dropped span to the parent of the dropped span, if possible.
53
72
  * This mutates the spans array in place!
54
73
  */
55
- function reparentChildSpans(spans, dropSpan) {
74
+ function reparentChildSpans(
75
+ spans,
76
+ dropSpan,
77
+ ) {
56
78
  const droppedSpanParentId = dropSpan.parent_span_id;
57
79
  const droppedSpanId = dropSpan.span_id;
58
80
 
@@ -1 +1 @@
1
- {"version":3,"file":"should-ignore-span.js","sources":["../../../src/utils/should-ignore-span.ts"],"sourcesContent":["import { DEBUG_BUILD } from '../debug-build';\nimport type { ClientOptions } from '../types-hoist/options';\nimport type { SpanJSON } from '../types-hoist/span';\nimport { debug } from './debug-logger';\nimport { isMatchingPattern } from './string';\n\nfunction logIgnoredSpan(droppedSpan: Pick<SpanJSON, 'description' | 'op'>): void {\n debug.log(`Ignoring span ${droppedSpan.op} - ${droppedSpan.description} because it matches \\`ignoreSpans\\`.`);\n}\n\n/**\n * Check if a span should be ignored based on the ignoreSpans configuration.\n */\nexport function shouldIgnoreSpan(\n span: Pick<SpanJSON, 'description' | 'op'>,\n ignoreSpans: Required<ClientOptions>['ignoreSpans'],\n): boolean {\n if (!ignoreSpans?.length || !span.description) {\n return false;\n }\n\n for (const pattern of ignoreSpans) {\n if (isStringOrRegExp(pattern)) {\n if (isMatchingPattern(span.description, pattern)) {\n DEBUG_BUILD && logIgnoredSpan(span);\n return true;\n }\n continue;\n }\n\n if (!pattern.name && !pattern.op) {\n continue;\n }\n\n const nameMatches = pattern.name ? isMatchingPattern(span.description, pattern.name) : true;\n const opMatches = pattern.op ? span.op && isMatchingPattern(span.op, pattern.op) : true;\n\n // This check here is only correct because we can guarantee that we ran `isMatchingPattern`\n // for at least one of `nameMatches` and `opMatches`. So in contrary to how this looks,\n // not both op and name actually have to match. This is the most efficient way to check\n // for all combinations of name and op patterns.\n if (nameMatches && opMatches) {\n DEBUG_BUILD && logIgnoredSpan(span);\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Takes a list of spans, and a span that was dropped, and re-parents the child spans of the dropped span to the parent of the dropped span, if possible.\n * This mutates the spans array in place!\n */\nexport function reparentChildSpans(spans: SpanJSON[], dropSpan: SpanJSON): void {\n const droppedSpanParentId = dropSpan.parent_span_id;\n const droppedSpanId = dropSpan.span_id;\n\n // This should generally not happen, as we do not apply this on root spans\n // but to be safe, we just bail in this case\n if (!droppedSpanParentId) {\n return;\n }\n\n for (const span of spans) {\n if (span.parent_span_id === droppedSpanId) {\n span.parent_span_id = droppedSpanParentId;\n }\n }\n}\n\nfunction isStringOrRegExp(value: unknown): value is string | RegExp {\n return typeof value === 'string' || value instanceof RegExp;\n}\n"],"names":["debug","isMatchingPattern","DEBUG_BUILD"],"mappings":";;;;;;AAMA,SAAS,cAAc,CAAC,WAAW,EAA8C;AACjF,EAAEA,iBAAK,CAAC,GAAG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QAAQ,EAAkB;AAChF,EAAE,MAAM,mBAAA,GAAsB,QAAQ,CAAC,cAAc;AACrD,EAAE,MAAM,aAAA,GAAgB,QAAQ,CAAC,OAAO;;AAExC;AACA;AACA,EAAE,IAAI,CAAC,mBAAmB,EAAE;AAC5B,IAAI;AACJ,EAAE;;AAEF,EAAE,KAAK,MAAM,IAAA,IAAQ,KAAK,EAAE;AAC5B,IAAI,IAAI,IAAI,CAAC,cAAA,KAAmB,aAAa,EAAE;AAC/C,MAAM,IAAI,CAAC,cAAA,GAAiB,mBAAmB;AAC/C,IAAI;AACJ,EAAE;AACF;;AAEA,SAAS,gBAAgB,CAAC,KAAK,EAAqC;AACpE,EAAE,OAAO,OAAO,KAAA,KAAU,YAAY,KAAA,YAAiB,MAAM;AAC7D;;;;;"}
1
+ {"version":3,"file":"should-ignore-span.js","sources":["../../../src/utils/should-ignore-span.ts"],"sourcesContent":["import { DEBUG_BUILD } from '../debug-build';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_OP } from '../semanticAttributes';\nimport type { ClientOptions } from '../types-hoist/options';\nimport type { SpanJSON, SpanV2JSON } from '../types-hoist/span';\nimport { debug } from './debug-logger';\nimport { isMatchingPattern } from './string';\n\nfunction logIgnoredSpan(spanName: string, spanOp: string | undefined): void {\n debug.log(`Ignoring span ${spanOp ? `${spanOp} - ` : ''}${spanName} because it matches \\`ignoreSpans\\`.`);\n}\n\n/**\n * Check if a span should be ignored based on the ignoreSpans configuration.\n */\nexport function shouldIgnoreSpan(\n span: Pick<SpanJSON, 'description' | 'op'> | Pick<SpanV2JSON, 'name' | 'attributes'>,\n ignoreSpans: Required<ClientOptions>['ignoreSpans'],\n): boolean {\n if (!ignoreSpans?.length) {\n return false;\n }\n\n const { spanName, spanOp: spanOpAttributeOrString } =\n 'description' in span\n ? { spanName: span.description, spanOp: span.op }\n : 'name' in span\n ? { spanName: span.name, spanOp: span.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_OP] }\n : { spanName: '', spanOp: '' };\n\n const spanOp =\n typeof spanOpAttributeOrString === 'string'\n ? spanOpAttributeOrString\n : spanOpAttributeOrString?.type === 'string'\n ? spanOpAttributeOrString.value\n : undefined;\n\n if (!spanName) {\n return false;\n }\n\n for (const pattern of ignoreSpans) {\n if (isStringOrRegExp(pattern)) {\n if (isMatchingPattern(spanName, pattern)) {\n DEBUG_BUILD && logIgnoredSpan(spanName, spanOp);\n return true;\n }\n continue;\n }\n\n if (!pattern.name && !pattern.op) {\n continue;\n }\n\n const nameMatches = pattern.name ? isMatchingPattern(spanName, pattern.name) : true;\n const opMatches = pattern.op ? spanOp && isMatchingPattern(spanOp, pattern.op) : true;\n\n // This check here is only correct because we can guarantee that we ran `isMatchingPattern`\n // for at least one of `nameMatches` and `opMatches`. So in contrary to how this looks,\n // not both op and name actually have to match. This is the most efficient way to check\n // for all combinations of name and op patterns.\n if (nameMatches && opMatches) {\n DEBUG_BUILD && logIgnoredSpan(spanName, spanOp);\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Takes a list of spans, and a span that was dropped, and re-parents the child spans of the dropped span to the parent of the dropped span, if possible.\n * This mutates the spans array in place!\n */\nexport function reparentChildSpans(\n spans: Pick<SpanV2JSON, 'parent_span_id' | 'span_id'>[],\n dropSpan: Pick<SpanV2JSON, 'parent_span_id' | 'span_id'>,\n): void {\n const droppedSpanParentId = dropSpan.parent_span_id;\n const droppedSpanId = dropSpan.span_id;\n\n // This should generally not happen, as we do not apply this on root spans\n // but to be safe, we just bail in this case\n if (!droppedSpanParentId) {\n return;\n }\n\n for (const span of spans) {\n if (span.parent_span_id === droppedSpanId) {\n span.parent_span_id = droppedSpanParentId;\n }\n }\n}\n\nfunction isStringOrRegExp(value: unknown): value is string | RegExp {\n return typeof value === 'string' || value instanceof RegExp;\n}\n"],"names":["debug","SEMANTIC_ATTRIBUTE_SENTRY_OP","isMatchingPattern","DEBUG_BUILD"],"mappings":";;;;;;;AAOA,SAAS,cAAc,CAAC,QAAQ,EAAU,MAAM,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CAAA,OAAA,CAAA,EAAA,EAAA;AACA,MAAA;AACA,IAAA;;AAEA,IAAA,MAAA,WAAA,GAAA,OAAA,CAAA,IAAA,GAAAD,wBAAA,CAAA,QAAA,EAAA,OAAA,CAAA,IAAA,CAAA,GAAA,IAAA;AACA,IAAA,MAAA,SAAA,GAAA,OAAA,CAAA,EAAA,GAAA,MAAA,IAAAA,wBAAA,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,CAAA,GAAA,IAAA;;AAEA;AACA;AACA;AACA;AACA,IAAA,IAAA,WAAA,IAAA,SAAA,EAAA;AACA,MAAAC,sBAAA,IAAA,cAAA,CAAA,QAAA,EAAA,MAAA,CAAA;AACA,MAAA,OAAA,IAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,OAAA,KAAA;AACA;;AAEA;AACA;AACA;AACA;AACA,SAAA,kBAAA;AACA,EAAA,KAAA;AACA,EAAA,QAAA;AACA,EAAA;AACA,EAAA,MAAA,mBAAA,GAAA,QAAA,CAAA,cAAA;AACA,EAAA,MAAA,aAAA,GAAA,QAAA,CAAA,OAAA;;AAEA;AACA;AACA,EAAA,IAAA,CAAA,mBAAA,EAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,KAAA,MAAA,IAAA,IAAA,KAAA,EAAA;AACA,IAAA,IAAA,IAAA,CAAA,cAAA,KAAA,aAAA,EAAA;AACA,MAAA,IAAA,CAAA,cAAA,GAAA,mBAAA;AACA,IAAA;AACA,EAAA;AACA;;AAEA,SAAA,gBAAA,CAAA,KAAA,EAAA;AACA,EAAA,OAAA,OAAA,KAAA,KAAA,QAAA,IAAA,KAAA,YAAA,MAAA;AACA;;;;;"}
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const index = require('../asyncContext/index.js');
4
+ const attributes = require('../attributes.js');
4
5
  const carrier = require('../carrier.js');
5
6
  const currentScopes = require('../currentScopes.js');
6
7
  const semanticAttributes = require('../semanticAttributes.js');
@@ -84,7 +85,7 @@ function spanToTraceparentHeader(span) {
84
85
  * If the links array is empty, it returns `undefined` so the empty value can be dropped before it's sent.
85
86
  */
86
87
  function convertSpanLinksForEnvelope(links) {
87
- if (links && links.length > 0) {
88
+ if (links?.length) {
88
89
  return links.map(({ context: { spanId, traceId, traceFlags, ...restContext }, attributes }) => ({
89
90
  span_id: spanId,
90
91
  trace_id: traceId,
@@ -96,6 +97,24 @@ function convertSpanLinksForEnvelope(links) {
96
97
  return undefined;
97
98
  }
98
99
  }
100
+ /**
101
+ *
102
+ * @param links
103
+ * @returns
104
+ */
105
+ function getV2SpanLinks(links) {
106
+ if (links?.length) {
107
+ return links.map(({ context: { spanId, traceId, traceFlags, ...restContext }, attributes: attributes$1 }) => ({
108
+ span_id: spanId,
109
+ trace_id: traceId,
110
+ sampled: traceFlags === TRACE_FLAG_SAMPLED,
111
+ ...(attributes$1 && { attributes: attributes.serializeAttributes(attributes$1) }),
112
+ ...restContext,
113
+ }));
114
+ } else {
115
+ return undefined;
116
+ }
117
+ }
99
118
 
100
119
  /**
101
120
  * Convert a span time input into a timestamp in seconds.
@@ -179,6 +198,59 @@ function spanToJSON(span) {
179
198
  };
180
199
  }
181
200
 
201
+ /**
202
+ * Convert a span to a SpanV2JSON representation.
203
+ * @returns
204
+ */
205
+ function spanToV2JSON(span) {
206
+ if (spanIsSentrySpan(span)) {
207
+ return span.getSpanV2JSON();
208
+ }
209
+
210
+ const { spanId: span_id, traceId: trace_id } = span.spanContext();
211
+
212
+ // Handle a span from @opentelemetry/sdk-base-trace's `Span` class
213
+ if (spanIsOpenTelemetrySdkTraceBaseSpan(span)) {
214
+ const { attributes: attributes$1, startTime, name, endTime, status, links } = span;
215
+
216
+ // In preparation for the next major of OpenTelemetry, we want to support
217
+ // looking up the parent span id according to the new API
218
+ // In OTel v1, the parent span id is accessed as `parentSpanId`
219
+ // In OTel v2, the parent span id is accessed as `spanId` on the `parentSpanContext`
220
+ const parentSpanId =
221
+ 'parentSpanId' in span
222
+ ? span.parentSpanId
223
+ : 'parentSpanContext' in span
224
+ ? (span.parentSpanContext )?.spanId
225
+ : undefined;
226
+
227
+ return {
228
+ name,
229
+ span_id,
230
+ trace_id,
231
+ parent_span_id: parentSpanId,
232
+ start_timestamp: spanTimeInputToSeconds(startTime),
233
+ end_timestamp: spanTimeInputToSeconds(endTime),
234
+ is_segment: span === INTERNAL_getSegmentSpan(span),
235
+ status: getV2StatusMessage(status),
236
+ attributes: attributes.serializeAttributes(attributes$1),
237
+ links: getV2SpanLinks(links),
238
+ };
239
+ }
240
+
241
+ // Finally, as a fallback, at least we have `spanContext()`....
242
+ // This should not actually happen in reality, but we need to handle it for type safety.
243
+ return {
244
+ span_id,
245
+ trace_id,
246
+ start_timestamp: 0,
247
+ name: '',
248
+ end_timestamp: 0,
249
+ status: 'ok',
250
+ is_segment: span === INTERNAL_getSegmentSpan(span),
251
+ };
252
+ }
253
+
182
254
  function spanIsOpenTelemetrySdkTraceBaseSpan(span) {
183
255
  const castSpan = span ;
184
256
  return !!castSpan.attributes && !!castSpan.startTime && !!castSpan.name && !!castSpan.endTime && !!castSpan.status;
@@ -220,6 +292,13 @@ function getStatusMessage(status) {
220
292
  return status.message || 'internal_error';
221
293
  }
222
294
 
295
+ /**
296
+ * Convert the various statuses to the ones expected by Sentry ('ok' is default)
297
+ */
298
+ function getV2StatusMessage(status) {
299
+ return !status || status.code === spanstatus.SPAN_STATUS_OK || status.code === spanstatus.SPAN_STATUS_UNSET ? 'ok' : 'error';
300
+ }
301
+
223
302
  const CHILD_SPANS_FIELD = '_sentryChildSpans';
224
303
  const ROOT_SPAN_FIELD = '_sentryRootSpan';
225
304
 
@@ -276,7 +355,12 @@ function getSpanDescendants(span) {
276
355
  /**
277
356
  * Returns the root span of a given span.
278
357
  */
279
- function getRootSpan(span) {
358
+ const getRootSpan = INTERNAL_getSegmentSpan;
359
+
360
+ /**
361
+ * Returns the segment span of a given span.
362
+ */
363
+ function INTERNAL_getSegmentSpan(span) {
280
364
  return span[ROOT_SPAN_FIELD] || span;
281
365
  }
282
366
 
@@ -332,6 +416,7 @@ function updateSpanName(span, name) {
332
416
  });
333
417
  }
334
418
 
419
+ exports.INTERNAL_getSegmentSpan = INTERNAL_getSegmentSpan;
335
420
  exports.TRACE_FLAG_NONE = TRACE_FLAG_NONE;
336
421
  exports.TRACE_FLAG_SAMPLED = TRACE_FLAG_SAMPLED;
337
422
  exports.addChildSpanToSpan = addChildSpanToSpan;
@@ -340,6 +425,8 @@ exports.getActiveSpan = getActiveSpan;
340
425
  exports.getRootSpan = getRootSpan;
341
426
  exports.getSpanDescendants = getSpanDescendants;
342
427
  exports.getStatusMessage = getStatusMessage;
428
+ exports.getV2SpanLinks = getV2SpanLinks;
429
+ exports.getV2StatusMessage = getV2StatusMessage;
343
430
  exports.removeChildSpanFromSpan = removeChildSpanFromSpan;
344
431
  exports.showSpanDropWarning = showSpanDropWarning;
345
432
  exports.spanIsSampled = spanIsSampled;
@@ -349,5 +436,6 @@ exports.spanToTraceContext = spanToTraceContext;
349
436
  exports.spanToTraceHeader = spanToTraceHeader;
350
437
  exports.spanToTraceparentHeader = spanToTraceparentHeader;
351
438
  exports.spanToTransactionTraceContext = spanToTransactionTraceContext;
439
+ exports.spanToV2JSON = spanToV2JSON;
352
440
  exports.updateSpanName = updateSpanName;
353
441
  //# sourceMappingURL=spanUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"spanUtils.js","sources":["../../../src/utils/spanUtils.ts"],"sourcesContent":["import { getAsyncContextStrategy } from '../asyncContext';\nimport { getMainCarrier } from '../carrier';\nimport { getCurrentScope } from '../currentScopes';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n} from '../semanticAttributes';\nimport type { SentrySpan } from '../tracing/sentrySpan';\nimport { SPAN_STATUS_OK, SPAN_STATUS_UNSET } from '../tracing/spanstatus';\nimport { getCapturedScopesOnSpan } from '../tracing/utils';\nimport type { TraceContext } from '../types-hoist/context';\nimport type { SpanLink, SpanLinkJSON } from '../types-hoist/link';\nimport type { Span, SpanAttributes, SpanJSON, SpanOrigin, SpanTimeInput } from '../types-hoist/span';\nimport type { SpanStatus } from '../types-hoist/spanStatus';\nimport { addNonEnumerableProperty } from '../utils/object';\nimport { generateSpanId } from '../utils/propagationContext';\nimport { timestampInSeconds } from '../utils/time';\nimport { generateSentryTraceHeader, generateTraceparentHeader } from '../utils/tracing';\nimport { consoleSandbox } from './debug-logger';\nimport { _getSpanForScope } from './spanOnScope';\n\n// These are aligned with OpenTelemetry trace flags\nexport const TRACE_FLAG_NONE = 0x0;\nexport const TRACE_FLAG_SAMPLED = 0x1;\n\nlet hasShownSpanDropWarning = false;\n\n/**\n * Convert a span to a trace context, which can be sent as the `trace` context in an event.\n * By default, this will only include trace_id, span_id & parent_span_id.\n * If `includeAllData` is true, it will also include data, op, status & origin.\n */\nexport function spanToTransactionTraceContext(span: Span): TraceContext {\n const { spanId: span_id, traceId: trace_id } = span.spanContext();\n const { data, op, parent_span_id, status, origin, links } = spanToJSON(span);\n\n return {\n parent_span_id,\n span_id,\n trace_id,\n data,\n op,\n status,\n origin,\n links,\n };\n}\n\n/**\n * Convert a span to a trace context, which can be sent as the `trace` context in a non-transaction event.\n */\nexport function spanToTraceContext(span: Span): TraceContext {\n const { spanId, traceId: trace_id, isRemote } = span.spanContext();\n\n // If the span is remote, we use a random/virtual span as span_id to the trace context,\n // and the remote span as parent_span_id\n const parent_span_id = isRemote ? spanId : spanToJSON(span).parent_span_id;\n const scope = getCapturedScopesOnSpan(span).scope;\n\n const span_id = isRemote ? scope?.getPropagationContext().propagationSpanId || generateSpanId() : spanId;\n\n return {\n parent_span_id,\n span_id,\n trace_id,\n };\n}\n\n/**\n * Convert a Span to a Sentry trace header.\n */\nexport function spanToTraceHeader(span: Span): string {\n const { traceId, spanId } = span.spanContext();\n const sampled = spanIsSampled(span);\n return generateSentryTraceHeader(traceId, spanId, sampled);\n}\n\n/**\n * Convert a Span to a W3C traceparent header.\n */\nexport function spanToTraceparentHeader(span: Span): string {\n const { traceId, spanId } = span.spanContext();\n const sampled = spanIsSampled(span);\n return generateTraceparentHeader(traceId, spanId, sampled);\n}\n\n/**\n * Converts the span links array to a flattened version to be sent within an envelope.\n *\n * If the links array is empty, it returns `undefined` so the empty value can be dropped before it's sent.\n */\nexport function convertSpanLinksForEnvelope(links?: SpanLink[]): SpanLinkJSON[] | undefined {\n if (links && links.length > 0) {\n return links.map(({ context: { spanId, traceId, traceFlags, ...restContext }, attributes }) => ({\n span_id: spanId,\n trace_id: traceId,\n sampled: traceFlags === TRACE_FLAG_SAMPLED,\n attributes,\n ...restContext,\n }));\n } else {\n return undefined;\n }\n}\n\n/**\n * Convert a span time input into a timestamp in seconds.\n */\nexport function spanTimeInputToSeconds(input: SpanTimeInput | undefined): number {\n if (typeof input === 'number') {\n return ensureTimestampInSeconds(input);\n }\n\n if (Array.isArray(input)) {\n // See {@link HrTime} for the array-based time format\n return input[0] + input[1] / 1e9;\n }\n\n if (input instanceof Date) {\n return ensureTimestampInSeconds(input.getTime());\n }\n\n return timestampInSeconds();\n}\n\n/**\n * Converts a timestamp to second, if it was in milliseconds, or keeps it as second.\n */\nfunction ensureTimestampInSeconds(timestamp: number): number {\n const isMs = timestamp > 9999999999;\n return isMs ? timestamp / 1000 : timestamp;\n}\n\n/**\n * Convert a span to a JSON representation.\n */\n// Note: Because of this, we currently have a circular type dependency (which we opted out of in package.json).\n// This is not avoidable as we need `spanToJSON` in `spanUtils.ts`, which in turn is needed by `span.ts` for backwards compatibility.\n// And `spanToJSON` needs the Span class from `span.ts` to check here.\nexport function spanToJSON(span: Span): SpanJSON {\n if (spanIsSentrySpan(span)) {\n return span.getSpanJSON();\n }\n\n const { spanId: span_id, traceId: trace_id } = span.spanContext();\n\n // Handle a span from @opentelemetry/sdk-base-trace's `Span` class\n if (spanIsOpenTelemetrySdkTraceBaseSpan(span)) {\n const { attributes, startTime, name, endTime, status, links } = span;\n\n // In preparation for the next major of OpenTelemetry, we want to support\n // looking up the parent span id according to the new API\n // In OTel v1, the parent span id is accessed as `parentSpanId`\n // In OTel v2, the parent span id is accessed as `spanId` on the `parentSpanContext`\n const parentSpanId =\n 'parentSpanId' in span\n ? span.parentSpanId\n : 'parentSpanContext' in span\n ? (span.parentSpanContext as { spanId?: string } | undefined)?.spanId\n : undefined;\n\n return {\n span_id,\n trace_id,\n data: attributes,\n description: name,\n parent_span_id: parentSpanId,\n start_timestamp: spanTimeInputToSeconds(startTime),\n // This is [0,0] by default in OTEL, in which case we want to interpret this as no end time\n timestamp: spanTimeInputToSeconds(endTime) || undefined,\n status: getStatusMessage(status),\n op: attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP],\n origin: attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined,\n links: convertSpanLinksForEnvelope(links),\n };\n }\n\n // Finally, at least we have `spanContext()`....\n // This should not actually happen in reality, but we need to handle it for type safety.\n return {\n span_id,\n trace_id,\n start_timestamp: 0,\n data: {},\n };\n}\n\nfunction spanIsOpenTelemetrySdkTraceBaseSpan(span: Span): span is OpenTelemetrySdkTraceBaseSpan {\n const castSpan = span as Partial<OpenTelemetrySdkTraceBaseSpan>;\n return !!castSpan.attributes && !!castSpan.startTime && !!castSpan.name && !!castSpan.endTime && !!castSpan.status;\n}\n\n/** Exported only for tests. */\nexport interface OpenTelemetrySdkTraceBaseSpan extends Span {\n attributes: SpanAttributes;\n startTime: SpanTimeInput;\n name: string;\n status: SpanStatus;\n endTime: SpanTimeInput;\n parentSpanId?: string;\n links?: SpanLink[];\n}\n\n/**\n * Sadly, due to circular dependency checks we cannot actually import the Span class here and check for instanceof.\n * :( So instead we approximate this by checking if it has the `getSpanJSON` method.\n */\nfunction spanIsSentrySpan(span: Span): span is SentrySpan {\n return typeof (span as SentrySpan).getSpanJSON === 'function';\n}\n\n/**\n * Returns true if a span is sampled.\n * In most cases, you should just use `span.isRecording()` instead.\n * However, this has a slightly different semantic, as it also returns false if the span is finished.\n * So in the case where this distinction is important, use this method.\n */\nexport function spanIsSampled(span: Span): boolean {\n // We align our trace flags with the ones OpenTelemetry use\n // So we also check for sampled the same way they do.\n const { traceFlags } = span.spanContext();\n return traceFlags === TRACE_FLAG_SAMPLED;\n}\n\n/** Get the status message to use for a JSON representation of a span. */\nexport function getStatusMessage(status: SpanStatus | undefined): string | undefined {\n if (!status || status.code === SPAN_STATUS_UNSET) {\n return undefined;\n }\n\n if (status.code === SPAN_STATUS_OK) {\n return 'ok';\n }\n\n return status.message || 'internal_error';\n}\n\nconst CHILD_SPANS_FIELD = '_sentryChildSpans';\nconst ROOT_SPAN_FIELD = '_sentryRootSpan';\n\ntype SpanWithPotentialChildren = Span & {\n [CHILD_SPANS_FIELD]?: Set<Span>;\n [ROOT_SPAN_FIELD]?: Span;\n};\n\n/**\n * Adds an opaque child span reference to a span.\n */\nexport function addChildSpanToSpan(span: SpanWithPotentialChildren, childSpan: Span): void {\n // We store the root span reference on the child span\n // We need this for `getRootSpan()` to work\n const rootSpan = span[ROOT_SPAN_FIELD] || span;\n addNonEnumerableProperty(childSpan as SpanWithPotentialChildren, ROOT_SPAN_FIELD, rootSpan);\n\n // We store a list of child spans on the parent span\n // We need this for `getSpanDescendants()` to work\n if (span[CHILD_SPANS_FIELD]) {\n span[CHILD_SPANS_FIELD].add(childSpan);\n } else {\n addNonEnumerableProperty(span, CHILD_SPANS_FIELD, new Set([childSpan]));\n }\n}\n\n/** This is only used internally by Idle Spans. */\nexport function removeChildSpanFromSpan(span: SpanWithPotentialChildren, childSpan: Span): void {\n if (span[CHILD_SPANS_FIELD]) {\n span[CHILD_SPANS_FIELD].delete(childSpan);\n }\n}\n\n/**\n * Returns an array of the given span and all of its descendants.\n */\nexport function getSpanDescendants(span: SpanWithPotentialChildren): Span[] {\n const resultSet = new Set<Span>();\n\n function addSpanChildren(span: SpanWithPotentialChildren): void {\n // This exit condition is required to not infinitely loop in case of a circular dependency.\n if (resultSet.has(span)) {\n return;\n // We want to ignore unsampled spans (e.g. non recording spans)\n } else if (spanIsSampled(span)) {\n resultSet.add(span);\n const childSpans = span[CHILD_SPANS_FIELD] ? Array.from(span[CHILD_SPANS_FIELD]) : [];\n for (const childSpan of childSpans) {\n addSpanChildren(childSpan);\n }\n }\n }\n\n addSpanChildren(span);\n\n return Array.from(resultSet);\n}\n\n/**\n * Returns the root span of a given span.\n */\nexport function getRootSpan(span: SpanWithPotentialChildren): Span {\n return span[ROOT_SPAN_FIELD] || span;\n}\n\n/**\n * Returns the currently active span.\n */\nexport function getActiveSpan(): Span | undefined {\n const carrier = getMainCarrier();\n const acs = getAsyncContextStrategy(carrier);\n if (acs.getActiveSpan) {\n return acs.getActiveSpan();\n }\n\n return _getSpanForScope(getCurrentScope());\n}\n\n/**\n * Logs a warning once if `beforeSendSpan` is used to drop spans.\n */\nexport function showSpanDropWarning(): void {\n if (!hasShownSpanDropWarning) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly or use `ignoreSpans`.',\n );\n });\n hasShownSpanDropWarning = true;\n }\n}\n\n/**\n * Updates the name of the given span and ensures that the span name is not\n * overwritten by the Sentry SDK.\n *\n * Use this function instead of `span.updateName()` if you want to make sure that\n * your name is kept. For some spans, for example root `http.server` spans the\n * Sentry SDK would otherwise overwrite the span name with a high-quality name\n * it infers when the span ends.\n *\n * Use this function in server code or when your span is started on the server\n * and on the client (browser). If you only update a span name on the client,\n * you can also use `span.updateName()` the SDK does not overwrite the name.\n *\n * @param span - The span to update the name of.\n * @param name - The name to set on the span.\n */\nexport function updateSpanName(span: Span, name: string): void {\n span.updateName(name);\n span.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',\n [SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: name,\n });\n}\n"],"names":["getCapturedScopesOnSpan","generateSpanId","generateSentryTraceHeader","generateTraceparentHeader","timestampInSeconds","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SPAN_STATUS_UNSET","SPAN_STATUS_OK","addNonEnumerableProperty","carrier","getMainCarrier","getAsyncContextStrategy","_getSpanForScope","getCurrentScope","consoleSandbox","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME"],"mappings":";;;;;;;;;;;;;;;AAuBA;AACO,MAAM,eAAA,GAAkB;AACxB,MAAM,kBAAA,GAAqB;;AAElC,IAAI,uBAAA,GAA0B,KAAK;;AAEnC;AACA;AACA;AACA;AACA;AACO,SAAS,6BAA6B,CAAC,IAAI,EAAsB;AACxE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAA,KAAa,IAAI,CAAC,WAAW,EAAE;AACnE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,KAAA,EAAM,GAAI,UAAU,CAAC,IAAI,CAAC;;AAE9E,EAAE,OAAO;AACT,IAAI,cAAc;AAClB,IAAI,OAAO;AACX,IAAI,QAAQ;AACZ,IAAI,IAAI;AACR,IAAI,EAAE;AACN,IAAI,MAAM;AACV,IAAI,MAAM;AACV,IAAI,KAAK;AACT,GAAG;AACH;;AAEA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,IAAI,EAAsB;AAC7D,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAA,KAAa,IAAI,CAAC,WAAW,EAAE;;AAEpE;AACA;AACA,EAAE,MAAM,cAAA,GAAiB,QAAA,GAAW,MAAA,GAAS,UAAU,CAAC,IAAI,CAAC,CAAC,cA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O;AACP,IAAI,CAAC,CAAC;AACN,IAAI,uBAAA,GAA0B,IAAI;AAClC,EAAE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,IAAI,EAAQ,IAAI,EAAgB;AAC/D,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;AACvB,EAAE,IAAI,CAAC,aAAa,CAAC;AACrB,IAAI,CAACC,mDAAgC,GAAG,QAAQ;AAChD,IAAI,CAACC,6DAA0C,GAAG,IAAI;AACtD,GAAG,CAAC;AACJ;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"spanUtils.js","sources":["../../../src/utils/spanUtils.ts"],"sourcesContent":["import { getAsyncContextStrategy } from '../asyncContext';\nimport type { Attributes } from '../attributes';\nimport { serializeAttributes } from '../attributes';\nimport { getMainCarrier } from '../carrier';\nimport { getCurrentScope } from '../currentScopes';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n} from '../semanticAttributes';\nimport type { SentrySpan } from '../tracing/sentrySpan';\nimport { SPAN_STATUS_OK, SPAN_STATUS_UNSET } from '../tracing/spanstatus';\nimport { getCapturedScopesOnSpan } from '../tracing/utils';\nimport type { TraceContext } from '../types-hoist/context';\nimport type { SpanLink, SpanLinkJSON } from '../types-hoist/link';\nimport type { Span, SpanAttributes, SpanJSON, SpanOrigin, SpanTimeInput, SpanV2JSON } from '../types-hoist/span';\nimport type { SpanStatus } from '../types-hoist/spanStatus';\nimport { addNonEnumerableProperty } from '../utils/object';\nimport { generateSpanId } from '../utils/propagationContext';\nimport { timestampInSeconds } from '../utils/time';\nimport { generateSentryTraceHeader, generateTraceparentHeader } from '../utils/tracing';\nimport { consoleSandbox } from './debug-logger';\nimport { _getSpanForScope } from './spanOnScope';\n\n// These are aligned with OpenTelemetry trace flags\nexport const TRACE_FLAG_NONE = 0x0;\nexport const TRACE_FLAG_SAMPLED = 0x1;\n\nlet hasShownSpanDropWarning = false;\n\n/**\n * Convert a span to a trace context, which can be sent as the `trace` context in an event.\n * By default, this will only include trace_id, span_id & parent_span_id.\n * If `includeAllData` is true, it will also include data, op, status & origin.\n */\nexport function spanToTransactionTraceContext(span: Span): TraceContext {\n const { spanId: span_id, traceId: trace_id } = span.spanContext();\n const { data, op, parent_span_id, status, origin, links } = spanToJSON(span);\n\n return {\n parent_span_id,\n span_id,\n trace_id,\n data,\n op,\n status,\n origin,\n links,\n };\n}\n\n/**\n * Convert a span to a trace context, which can be sent as the `trace` context in a non-transaction event.\n */\nexport function spanToTraceContext(span: Span): TraceContext {\n const { spanId, traceId: trace_id, isRemote } = span.spanContext();\n\n // If the span is remote, we use a random/virtual span as span_id to the trace context,\n // and the remote span as parent_span_id\n const parent_span_id = isRemote ? spanId : spanToJSON(span).parent_span_id;\n const scope = getCapturedScopesOnSpan(span).scope;\n\n const span_id = isRemote ? scope?.getPropagationContext().propagationSpanId || generateSpanId() : spanId;\n\n return {\n parent_span_id,\n span_id,\n trace_id,\n };\n}\n\n/**\n * Convert a Span to a Sentry trace header.\n */\nexport function spanToTraceHeader(span: Span): string {\n const { traceId, spanId } = span.spanContext();\n const sampled = spanIsSampled(span);\n return generateSentryTraceHeader(traceId, spanId, sampled);\n}\n\n/**\n * Convert a Span to a W3C traceparent header.\n */\nexport function spanToTraceparentHeader(span: Span): string {\n const { traceId, spanId } = span.spanContext();\n const sampled = spanIsSampled(span);\n return generateTraceparentHeader(traceId, spanId, sampled);\n}\n\n/**\n * Converts the span links array to a flattened version to be sent within an envelope.\n *\n * If the links array is empty, it returns `undefined` so the empty value can be dropped before it's sent.\n */\nexport function convertSpanLinksForEnvelope(links?: SpanLink[]): SpanLinkJSON[] | undefined {\n if (links?.length) {\n return links.map(({ context: { spanId, traceId, traceFlags, ...restContext }, attributes }) => ({\n span_id: spanId,\n trace_id: traceId,\n sampled: traceFlags === TRACE_FLAG_SAMPLED,\n attributes,\n ...restContext,\n }));\n } else {\n return undefined;\n }\n}\n/**\n *\n * @param links\n * @returns\n */\nexport function getV2SpanLinks(links?: SpanLink[]): SpanLinkJSON<Attributes>[] | undefined {\n if (links?.length) {\n return links.map(({ context: { spanId, traceId, traceFlags, ...restContext }, attributes }) => ({\n span_id: spanId,\n trace_id: traceId,\n sampled: traceFlags === TRACE_FLAG_SAMPLED,\n ...(attributes && { attributes: serializeAttributes(attributes) }),\n ...restContext,\n }));\n } else {\n return undefined;\n }\n}\n\n/**\n * Convert a span time input into a timestamp in seconds.\n */\nexport function spanTimeInputToSeconds(input: SpanTimeInput | undefined): number {\n if (typeof input === 'number') {\n return ensureTimestampInSeconds(input);\n }\n\n if (Array.isArray(input)) {\n // See {@link HrTime} for the array-based time format\n return input[0] + input[1] / 1e9;\n }\n\n if (input instanceof Date) {\n return ensureTimestampInSeconds(input.getTime());\n }\n\n return timestampInSeconds();\n}\n\n/**\n * Converts a timestamp to second, if it was in milliseconds, or keeps it as second.\n */\nfunction ensureTimestampInSeconds(timestamp: number): number {\n const isMs = timestamp > 9999999999;\n return isMs ? timestamp / 1000 : timestamp;\n}\n\n/**\n * Convert a span to a JSON representation.\n */\n// Note: Because of this, we currently have a circular type dependency (which we opted out of in package.json).\n// This is not avoidable as we need `spanToJSON` in `spanUtils.ts`, which in turn is needed by `span.ts` for backwards compatibility.\n// And `spanToJSON` needs the Span class from `span.ts` to check here.\nexport function spanToJSON(span: Span): SpanJSON {\n if (spanIsSentrySpan(span)) {\n return span.getSpanJSON();\n }\n\n const { spanId: span_id, traceId: trace_id } = span.spanContext();\n\n // Handle a span from @opentelemetry/sdk-base-trace's `Span` class\n if (spanIsOpenTelemetrySdkTraceBaseSpan(span)) {\n const { attributes, startTime, name, endTime, status, links } = span;\n\n // In preparation for the next major of OpenTelemetry, we want to support\n // looking up the parent span id according to the new API\n // In OTel v1, the parent span id is accessed as `parentSpanId`\n // In OTel v2, the parent span id is accessed as `spanId` on the `parentSpanContext`\n const parentSpanId =\n 'parentSpanId' in span\n ? span.parentSpanId\n : 'parentSpanContext' in span\n ? (span.parentSpanContext as { spanId?: string } | undefined)?.spanId\n : undefined;\n\n return {\n span_id,\n trace_id,\n data: attributes,\n description: name,\n parent_span_id: parentSpanId,\n start_timestamp: spanTimeInputToSeconds(startTime),\n // This is [0,0] by default in OTEL, in which case we want to interpret this as no end time\n timestamp: spanTimeInputToSeconds(endTime) || undefined,\n status: getStatusMessage(status),\n op: attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP],\n origin: attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined,\n links: convertSpanLinksForEnvelope(links),\n };\n }\n\n // Finally, at least we have `spanContext()`....\n // This should not actually happen in reality, but we need to handle it for type safety.\n return {\n span_id,\n trace_id,\n start_timestamp: 0,\n data: {},\n };\n}\n\n/**\n * Convert a span to a SpanV2JSON representation.\n * @returns\n */\nexport function spanToV2JSON(span: Span): SpanV2JSON {\n if (spanIsSentrySpan(span)) {\n return span.getSpanV2JSON();\n }\n\n const { spanId: span_id, traceId: trace_id } = span.spanContext();\n\n // Handle a span from @opentelemetry/sdk-base-trace's `Span` class\n if (spanIsOpenTelemetrySdkTraceBaseSpan(span)) {\n const { attributes, startTime, name, endTime, status, links } = span;\n\n // In preparation for the next major of OpenTelemetry, we want to support\n // looking up the parent span id according to the new API\n // In OTel v1, the parent span id is accessed as `parentSpanId`\n // In OTel v2, the parent span id is accessed as `spanId` on the `parentSpanContext`\n const parentSpanId =\n 'parentSpanId' in span\n ? span.parentSpanId\n : 'parentSpanContext' in span\n ? (span.parentSpanContext as { spanId?: string } | undefined)?.spanId\n : undefined;\n\n return {\n name,\n span_id,\n trace_id,\n parent_span_id: parentSpanId,\n start_timestamp: spanTimeInputToSeconds(startTime),\n end_timestamp: spanTimeInputToSeconds(endTime),\n is_segment: span === INTERNAL_getSegmentSpan(span),\n status: getV2StatusMessage(status),\n attributes: serializeAttributes(attributes),\n links: getV2SpanLinks(links),\n };\n }\n\n // Finally, as a fallback, at least we have `spanContext()`....\n // This should not actually happen in reality, but we need to handle it for type safety.\n return {\n span_id,\n trace_id,\n start_timestamp: 0,\n name: '',\n end_timestamp: 0,\n status: 'ok',\n is_segment: span === INTERNAL_getSegmentSpan(span),\n };\n}\n\nfunction spanIsOpenTelemetrySdkTraceBaseSpan(span: Span): span is OpenTelemetrySdkTraceBaseSpan {\n const castSpan = span as Partial<OpenTelemetrySdkTraceBaseSpan>;\n return !!castSpan.attributes && !!castSpan.startTime && !!castSpan.name && !!castSpan.endTime && !!castSpan.status;\n}\n\n/** Exported only for tests. */\nexport interface OpenTelemetrySdkTraceBaseSpan extends Span {\n attributes: SpanAttributes;\n startTime: SpanTimeInput;\n name: string;\n status: SpanStatus;\n endTime: SpanTimeInput;\n parentSpanId?: string;\n links?: SpanLink[];\n}\n\n/**\n * Sadly, due to circular dependency checks we cannot actually import the Span class here and check for instanceof.\n * :( So instead we approximate this by checking if it has the `getSpanJSON` method.\n */\nfunction spanIsSentrySpan(span: Span): span is SentrySpan {\n return typeof (span as SentrySpan).getSpanJSON === 'function';\n}\n\n/**\n * Returns true if a span is sampled.\n * In most cases, you should just use `span.isRecording()` instead.\n * However, this has a slightly different semantic, as it also returns false if the span is finished.\n * So in the case where this distinction is important, use this method.\n */\nexport function spanIsSampled(span: Span): boolean {\n // We align our trace flags with the ones OpenTelemetry use\n // So we also check for sampled the same way they do.\n const { traceFlags } = span.spanContext();\n return traceFlags === TRACE_FLAG_SAMPLED;\n}\n\n/** Get the status message to use for a JSON representation of a span. */\nexport function getStatusMessage(status: SpanStatus | undefined): string | undefined {\n if (!status || status.code === SPAN_STATUS_UNSET) {\n return undefined;\n }\n\n if (status.code === SPAN_STATUS_OK) {\n return 'ok';\n }\n\n return status.message || 'internal_error';\n}\n\n/**\n * Convert the various statuses to the ones expected by Sentry ('ok' is default)\n */\nexport function getV2StatusMessage(status: SpanStatus | undefined): 'ok' | 'error' {\n return !status || status.code === SPAN_STATUS_OK || status.code === SPAN_STATUS_UNSET ? 'ok' : 'error';\n}\n\nconst CHILD_SPANS_FIELD = '_sentryChildSpans';\nconst ROOT_SPAN_FIELD = '_sentryRootSpan';\n\ntype SpanWithPotentialChildren = Span & {\n [CHILD_SPANS_FIELD]?: Set<Span>;\n [ROOT_SPAN_FIELD]?: Span;\n};\n\n/**\n * Adds an opaque child span reference to a span.\n */\nexport function addChildSpanToSpan(span: SpanWithPotentialChildren, childSpan: Span): void {\n // We store the root span reference on the child span\n // We need this for `getRootSpan()` to work\n const rootSpan = span[ROOT_SPAN_FIELD] || span;\n addNonEnumerableProperty(childSpan as SpanWithPotentialChildren, ROOT_SPAN_FIELD, rootSpan);\n\n // We store a list of child spans on the parent span\n // We need this for `getSpanDescendants()` to work\n if (span[CHILD_SPANS_FIELD]) {\n span[CHILD_SPANS_FIELD].add(childSpan);\n } else {\n addNonEnumerableProperty(span, CHILD_SPANS_FIELD, new Set([childSpan]));\n }\n}\n\n/** This is only used internally by Idle Spans. */\nexport function removeChildSpanFromSpan(span: SpanWithPotentialChildren, childSpan: Span): void {\n if (span[CHILD_SPANS_FIELD]) {\n span[CHILD_SPANS_FIELD].delete(childSpan);\n }\n}\n\n/**\n * Returns an array of the given span and all of its descendants.\n */\nexport function getSpanDescendants(span: SpanWithPotentialChildren): Span[] {\n const resultSet = new Set<Span>();\n\n function addSpanChildren(span: SpanWithPotentialChildren): void {\n // This exit condition is required to not infinitely loop in case of a circular dependency.\n if (resultSet.has(span)) {\n return;\n // We want to ignore unsampled spans (e.g. non recording spans)\n } else if (spanIsSampled(span)) {\n resultSet.add(span);\n const childSpans = span[CHILD_SPANS_FIELD] ? Array.from(span[CHILD_SPANS_FIELD]) : [];\n for (const childSpan of childSpans) {\n addSpanChildren(childSpan);\n }\n }\n }\n\n addSpanChildren(span);\n\n return Array.from(resultSet);\n}\n\n/**\n * Returns the root span of a given span.\n */\nexport const getRootSpan = INTERNAL_getSegmentSpan;\n\n/**\n * Returns the segment span of a given span.\n */\nexport function INTERNAL_getSegmentSpan(span: SpanWithPotentialChildren): Span {\n return span[ROOT_SPAN_FIELD] || span;\n}\n\n/**\n * Returns the currently active span.\n */\nexport function getActiveSpan(): Span | undefined {\n const carrier = getMainCarrier();\n const acs = getAsyncContextStrategy(carrier);\n if (acs.getActiveSpan) {\n return acs.getActiveSpan();\n }\n\n return _getSpanForScope(getCurrentScope());\n}\n\n/**\n * Logs a warning once if `beforeSendSpan` is used to drop spans.\n */\nexport function showSpanDropWarning(): void {\n if (!hasShownSpanDropWarning) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly or use `ignoreSpans`.',\n );\n });\n hasShownSpanDropWarning = true;\n }\n}\n\n/**\n * Updates the name of the given span and ensures that the span name is not\n * overwritten by the Sentry SDK.\n *\n * Use this function instead of `span.updateName()` if you want to make sure that\n * your name is kept. For some spans, for example root `http.server` spans the\n * Sentry SDK would otherwise overwrite the span name with a high-quality name\n * it infers when the span ends.\n *\n * Use this function in server code or when your span is started on the server\n * and on the client (browser). If you only update a span name on the client,\n * you can also use `span.updateName()` the SDK does not overwrite the name.\n *\n * @param span - The span to update the name of.\n * @param name - The name to set on the span.\n */\nexport function updateSpanName(span: Span, name: string): void {\n span.updateName(name);\n span.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',\n [SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: name,\n });\n}\n"],"names":["getCapturedScopesOnSpan","generateSpanId","generateSentryTraceHeader","generateTraceparentHeader","attributes","serializeAttributes","timestampInSeconds","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SPAN_STATUS_UNSET","SPAN_STATUS_OK","addNonEnumerableProperty","carrier","getMainCarrier","getAsyncContextStrategy","_getSpanForScope","getCurrentScope","consoleSandbox","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME"],"mappings":";;;;;;;;;;;;;;;;AAyBA;AACO,MAAM,eAAA,GAAkB;AACxB,MAAM,kBAAA,GAAqB;;AAElC,IAAI,uBAAA,GAA0B,KAAK;;AAEnC;AACA;AACA;AACA;AACA;AACO,SAAS,6BAA6B,CAAC,IAAI,EAAsB;AACxE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAA,KAAa,IAAI,CAAC,WAAW,EAAE;AACnE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,KAAA,EAAM,GAAI,UAAU,CAAC,IAAI,CAAC;;AAE9E,EAAE,OAAO;AACT,IAAI,cAAc;AAClB,IAAI,OAAO;AACX,IAAI,QAAQ;AACZ,IAAI,IAAI;AACR,IAAI,EAAE;AACN,IAAI,MAAM;AACV,IAAI,MAAM;AACV,IAAI,KAAK;AACT,GAAG;AACH;;AAEA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,IAAI,EAAsB;AAC7D,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAA,KAAa,IAAI,CAAC,WAAW,EAAE;;AAEpE;AACA;AACA,EAAE,MAAM,cAAA,GAAiB,QAAA,GAAW,MAAA,GAAS,UAAU,CAAC,IAAI,CAAC,CAAC,cAAc;AAC5E,EAAE,MAAM,QAAQA,6BAAuB,CAAC,IAAI,CAAC,CAAC,KAAK;;AAEnD,EAAE,MAAM,OAAA,GAAU,QAAA,GAAW,KAAK,EAAE,qBAAqB,EAAE,CAAC,iBAAA,IAAqBC,iCAAc,EAAC,GAAI,MAAM;;AAE1G,EAAE,OAAO;AACT,IAAI,cAAc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AAE3B;AACA;AACA;AACO,SAAS,uBAAuB,CAAC,IAAI,EAAmC;AAC/E,EAAE,OAAO,IAAI,CAAC,eAAe,CAAA,IAAK,IAAI;AACtC;;AAEA;AACA;AACA;AACO,SAAS,aAAa,GAAqB;AAClD,EAAE,MAAMC,SAAA,GAAUC,sBAAc,EAAE;AAClC,EAAE,MAAM,GAAA,GAAMC,6BAAuB,CAACF,SAAO,CAAC;AAC9C,EAAE,IAAI,GAAG,CAAC,aAAa,EAAE;AACzB,IAAI,OAAO,GAAG,CAAC,aAAa,EAAE;AAC9B,EAAE;;AAEF,EAAE,OAAOG,4BAAgB,CAACC,6BAAe,EAAE,CAAC;AAC5C;;AAEA;AACA;AACA;AACO,SAAS,mBAAmB,GAAS;AAC5C,EAAE,IAAI,CAAC,uBAAuB,EAAE;AAChC,IAAIC,0BAAc,CAAC,MAAM;AACzB;AACA,MAAM,OAAO,CAAC,IAAI;AAClB,QAAQ,0JAA0J;AAClK,OAAO;AACP,IAAI,CAAC,CAAC;AACN,IAAI,uBAAA,GAA0B,IAAI;AAClC,EAAE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,IAAI,EAAQ,IAAI,EAAgB;AAC/D,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;AACvB,EAAE,IAAI,CAAC,aAAa,CAAC;AACrB,IAAI,CAACC,mDAAgC,GAAG,QAAQ;AAChD,IAAI,CAACC,6DAA0C,GAAG,IAAI;AACtD,GAAG,CAAC;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,20 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ /**
4
+ * Calls `unref` on a timer, if the method is available on @param timer.
5
+ *
6
+ * `unref()` is used to allow processes to exit immediately, even if the timer
7
+ * is still running and hasn't resolved yet.
8
+ *
9
+ * Use this in places where code can run on browser or server, since browsers
10
+ * do not support `unref`.
11
+ */
12
+ function safeUnref(timer) {
13
+ if (typeof timer === 'object' && typeof timer.unref === 'function') {
14
+ timer.unref();
15
+ }
16
+ return timer;
17
+ }
18
+
19
+ exports.safeUnref = safeUnref;
20
+ //# sourceMappingURL=timer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.js","sources":["../../../src/utils/timer.ts"],"sourcesContent":["/**\n * Calls `unref` on a timer, if the method is available on @param timer.\n *\n * `unref()` is used to allow processes to exit immediately, even if the timer\n * is still running and hasn't resolved yet.\n *\n * Use this in places where code can run on browser or server, since browsers\n * do not support `unref`.\n */\nexport function safeUnref(timer: ReturnType<typeof setTimeout>): ReturnType<typeof setTimeout> {\n if (typeof timer === 'object' && typeof timer.unref === 'function') {\n timer.unref();\n }\n return timer;\n}\n"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,SAAS,CAAC,KAAK,EAAgE;AAC/F,EAAE,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,OAAO,KAAK,CAAC,KAAA,KAAU,UAAU,EAAE;AACtE,IAAI,KAAK,CAAC,KAAK,EAAE;AACjB,EAAE;AACF,EAAE,OAAO,KAAK;AACd;;;;"}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
3
  const index = require('../asyncContext/index.js');
4
4
  const carrier = require('../carrier.js');
5
5
  const currentScopes = require('../currentScopes.js');
6
- const exports$1 = require('../exports.js');
6
+ const _exports = require('../exports.js');
7
7
  const debugLogger = require('./debug-logger.js');
8
8
  const spanUtils = require('./spanUtils.js');
9
9
  const dynamicSamplingContext = require('../tracing/dynamicSamplingContext.js');
@@ -28,7 +28,7 @@ function getTraceData(
28
28
  options = {},
29
29
  ) {
30
30
  const client = options.client || currentScopes.getClient();
31
- if (!exports$1.isEnabled() || !client) {
31
+ if (!_exports.isEnabled() || !client) {
32
32
  return {};
33
33
  }
34
34
 
@@ -1 +1 @@
1
- {"version":3,"file":"traceData.js","sources":["../../../src/utils/traceData.ts"],"sourcesContent":["import { getAsyncContextStrategy } from '../asyncContext';\nimport { getMainCarrier } from '../carrier';\nimport type { Client } from '../client';\nimport { getClient, getCurrentScope } from '../currentScopes';\nimport { isEnabled } from '../exports';\nimport type { Scope } from '../scope';\nimport { getDynamicSamplingContextFromScope, getDynamicSamplingContextFromSpan } from '../tracing';\nimport type { Span } from '../types-hoist/span';\nimport type { SerializedTraceData } from '../types-hoist/tracing';\nimport { dynamicSamplingContextToSentryBaggageHeader } from './baggage';\nimport { debug } from './debug-logger';\nimport { getActiveSpan, spanToTraceHeader, spanToTraceparentHeader } from './spanUtils';\nimport { generateSentryTraceHeader, generateTraceparentHeader, TRACEPARENT_REGEXP } from './tracing';\n\n/**\n * Extracts trace propagation data from the current span or from the client's scope (via transaction or propagation\n * context) and serializes it to `sentry-trace` and `baggage` values. These values can be used to propagate\n * a trace via our tracing Http headers or Html `<meta>` tags.\n *\n * This function also applies some validation to the generated sentry-trace and baggage values to ensure that\n * only valid strings are returned.\n *\n * If (@param options.propagateTraceparent) is `true`, the function will also generate a `traceparent` value,\n * following the W3C traceparent header format.\n *\n * @returns an object with the tracing data values. The object keys are the name of the tracing key to be used as header\n * or meta tag name.\n */\nexport function getTraceData(\n options: { span?: Span; scope?: Scope; client?: Client; propagateTraceparent?: boolean } = {},\n): SerializedTraceData {\n const client = options.client || getClient();\n if (!isEnabled() || !client) {\n return {};\n }\n\n const carrier = getMainCarrier();\n const acs = getAsyncContextStrategy(carrier);\n if (acs.getTraceData) {\n return acs.getTraceData(options);\n }\n\n const scope = options.scope || getCurrentScope();\n const span = options.span || getActiveSpan();\n const sentryTrace = span ? spanToTraceHeader(span) : scopeToTraceHeader(scope);\n const dsc = span ? getDynamicSamplingContextFromSpan(span) : getDynamicSamplingContextFromScope(client, scope);\n const baggage = dynamicSamplingContextToSentryBaggageHeader(dsc);\n\n const isValidSentryTraceHeader = TRACEPARENT_REGEXP.test(sentryTrace);\n if (!isValidSentryTraceHeader) {\n debug.warn('Invalid sentry-trace data. Cannot generate trace data');\n return {};\n }\n\n const traceData: SerializedTraceData = {\n 'sentry-trace': sentryTrace,\n baggage,\n };\n\n if (options.propagateTraceparent) {\n traceData.traceparent = span ? spanToTraceparentHeader(span) : scopeToTraceparentHeader(scope);\n }\n\n return traceData;\n}\n\n/**\n * Get a sentry-trace header value for the given scope.\n */\nfunction scopeToTraceHeader(scope: Scope): string {\n const { traceId, sampled, propagationSpanId } = scope.getPropagationContext();\n return generateSentryTraceHeader(traceId, propagationSpanId, sampled);\n}\n\nfunction scopeToTraceparentHeader(scope: Scope): string {\n const { traceId, sampled, propagationSpanId } = scope.getPropagationContext();\n return generateTraceparentHeader(traceId, propagationSpanId, sampled);\n}\n"],"names":["getClient","isEnabled","carrier","getMainCarrier","getAsyncContextStrategy","getCurrentScope","getActiveSpan","spanToTraceHeader","getDynamicSamplingContextFromSpan","getDynamicSamplingContextFromScope","baggage","dynamicSamplingContextToSentryBaggageHeader","TRACEPARENT_REGEXP","debug","spanToTraceparentHeader","generateSentryTraceHeader","generateTraceparentHeader"],"mappings":";;;;;;;;;;;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,YAAY;AAC5B,EAAE,OAAO,GAAoF,EAAE;AAC/F,EAAuB;AACvB,EAAE,MAAM,SAAS,OAAO,CAAC,MAAA,IAAUA,uBAAS,EAAE;AAC9C,EAAE,IAAI,CAACC,mBAAS,EAAC,IAAK,CAAC,MAAM,EAAE;AAC/B,IAAI,OAAO,EAAE;AACb,EAAE;;AAEF,EAAE,MAAMC,SAAA,GAAUC,sBAAc,EAAE;AAClC,EAAE,MAAM,GAAA,GAAMC,6BAAuB,CAACF,SAAO,CAAC;AAC9C,EAAE,IAAI,GAAG,CAAC,YAAY,EAAE;AACxB,IAAI,OAAO,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC;AACpC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AK,CAAC,qBAAqB,EAAE;AAC/E,EAAE,OAAOC,iCAAyB,CAAC,OAAO,EAAE,iBAAiB,EAAE,OAAO,CAAC;AACvE;;;;"}
1
+ {"version":3,"file":"traceData.js","sources":["../../../src/utils/traceData.ts"],"sourcesContent":["import { getAsyncContextStrategy } from '../asyncContext';\nimport { getMainCarrier } from '../carrier';\nimport type { Client } from '../client';\nimport { getClient, getCurrentScope } from '../currentScopes';\nimport { isEnabled } from '../exports';\nimport type { Scope } from '../scope';\nimport { getDynamicSamplingContextFromScope, getDynamicSamplingContextFromSpan } from '../tracing';\nimport type { Span } from '../types-hoist/span';\nimport type { SerializedTraceData } from '../types-hoist/tracing';\nimport { dynamicSamplingContextToSentryBaggageHeader } from './baggage';\nimport { debug } from './debug-logger';\nimport { getActiveSpan, spanToTraceHeader, spanToTraceparentHeader } from './spanUtils';\nimport { generateSentryTraceHeader, generateTraceparentHeader, TRACEPARENT_REGEXP } from './tracing';\n\n/**\n * Extracts trace propagation data from the current span or from the client's scope (via transaction or propagation\n * context) and serializes it to `sentry-trace` and `baggage` values. These values can be used to propagate\n * a trace via our tracing Http headers or Html `<meta>` tags.\n *\n * This function also applies some validation to the generated sentry-trace and baggage values to ensure that\n * only valid strings are returned.\n *\n * If (@param options.propagateTraceparent) is `true`, the function will also generate a `traceparent` value,\n * following the W3C traceparent header format.\n *\n * @returns an object with the tracing data values. The object keys are the name of the tracing key to be used as header\n * or meta tag name.\n */\nexport function getTraceData(\n options: { span?: Span; scope?: Scope; client?: Client; propagateTraceparent?: boolean } = {},\n): SerializedTraceData {\n const client = options.client || getClient();\n if (!isEnabled() || !client) {\n return {};\n }\n\n const carrier = getMainCarrier();\n const acs = getAsyncContextStrategy(carrier);\n if (acs.getTraceData) {\n return acs.getTraceData(options);\n }\n\n const scope = options.scope || getCurrentScope();\n const span = options.span || getActiveSpan();\n const sentryTrace = span ? spanToTraceHeader(span) : scopeToTraceHeader(scope);\n const dsc = span ? getDynamicSamplingContextFromSpan(span) : getDynamicSamplingContextFromScope(client, scope);\n const baggage = dynamicSamplingContextToSentryBaggageHeader(dsc);\n\n const isValidSentryTraceHeader = TRACEPARENT_REGEXP.test(sentryTrace);\n if (!isValidSentryTraceHeader) {\n debug.warn('Invalid sentry-trace data. Cannot generate trace data');\n return {};\n }\n\n const traceData: SerializedTraceData = {\n 'sentry-trace': sentryTrace,\n baggage,\n };\n\n if (options.propagateTraceparent) {\n traceData.traceparent = span ? spanToTraceparentHeader(span) : scopeToTraceparentHeader(scope);\n }\n\n return traceData;\n}\n\n/**\n * Get a sentry-trace header value for the given scope.\n */\nfunction scopeToTraceHeader(scope: Scope): string {\n const { traceId, sampled, propagationSpanId } = scope.getPropagationContext();\n return generateSentryTraceHeader(traceId, propagationSpanId, sampled);\n}\n\nfunction scopeToTraceparentHeader(scope: Scope): string {\n const { traceId, sampled, propagationSpanId } = scope.getPropagationContext();\n return generateTraceparentHeader(traceId, propagationSpanId, sampled);\n}\n"],"names":["getClient","isEnabled","carrier","getMainCarrier","getAsyncContextStrategy","getCurrentScope","getActiveSpan","spanToTraceHeader","getDynamicSamplingContextFromSpan","getDynamicSamplingContextFromScope","baggage","dynamicSamplingContextToSentryBaggageHeader","TRACEPARENT_REGEXP","debug","spanToTraceparentHeader","generateSentryTraceHeader","generateTraceparentHeader"],"mappings":";;;;;;;;;;;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,YAAY;AAC5B,EAAE,OAAO,GAAoF,EAAE;AAC/F,EAAuB;AACvB,EAAE,MAAM,SAAS,OAAO,CAAC,MAAA,IAAUA,uBAAS,EAAE;AAC9C,EAAE,IAAI,CAACC,kBAAS,EAAC,IAAK,CAAC,MAAM,EAAE;AAC/B,IAAI,OAAO,EAAE;AACb,EAAE;;AAEF,EAAE,MAAMC,SAAA,GAAUC,sBAAc,EAAE;AAClC,EAAE,MAAM,GAAA,GAAMC,6BAAuB,CAACF,SAAO,CAAC;AAC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wBAAwB,CAAC,KAAK,EAAiB;AACxD,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,iBAAA,EAAkB,GAAI,KAAK,CAAC,qBAAqB,EAAE;AAC/E,EAAE,OAAOC,iCAAyB,CAAC,OAAO,EAAE,iBAAiB,EAAE,OAAO,CAAC;AACvE;;;;"}
@@ -0,0 +1,38 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const debugBuild = require('../debug-build.js');
4
+ const debugLogger = require('./debug-logger.js');
5
+ const string = require('./string.js');
6
+
7
+ const NOT_PROPAGATED_MESSAGE =
8
+ '[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:';
9
+
10
+ /**
11
+ * Check if a given URL should be propagated to or not.
12
+ * If no url is defined, or no trace propagation targets are defined, this will always return `true`.
13
+ * You can also optionally provide a decision map, to cache decisions and avoid repeated regex lookups.
14
+ */
15
+ function shouldPropagateTraceForUrl(
16
+ url,
17
+ tracePropagationTargets,
18
+ decisionMap,
19
+ ) {
20
+ if (typeof url !== 'string' || !tracePropagationTargets) {
21
+ return true;
22
+ }
23
+
24
+ const cachedDecision = decisionMap?.get(url);
25
+ if (cachedDecision !== undefined) {
26
+ debugBuild.DEBUG_BUILD && !cachedDecision && debugLogger.debug.log(NOT_PROPAGATED_MESSAGE, url);
27
+ return cachedDecision;
28
+ }
29
+
30
+ const decision = string.stringMatchesSomePattern(url, tracePropagationTargets);
31
+ decisionMap?.set(url, decision);
32
+
33
+ debugBuild.DEBUG_BUILD && !decision && debugLogger.debug.log(NOT_PROPAGATED_MESSAGE, url);
34
+ return decision;
35
+ }
36
+
37
+ exports.shouldPropagateTraceForUrl = shouldPropagateTraceForUrl;
38
+ //# sourceMappingURL=tracePropagationTargets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracePropagationTargets.js","sources":["../../../src/utils/tracePropagationTargets.ts"],"sourcesContent":["import { DEBUG_BUILD } from '../debug-build';\nimport type { CoreOptions as Options } from '../types-hoist/options';\nimport { debug } from './debug-logger';\nimport type { LRUMap } from './lru';\nimport { stringMatchesSomePattern } from './string';\n\nconst NOT_PROPAGATED_MESSAGE =\n '[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:';\n\n/**\n * Check if a given URL should be propagated to or not.\n * If no url is defined, or no trace propagation targets are defined, this will always return `true`.\n * You can also optionally provide a decision map, to cache decisions and avoid repeated regex lookups.\n */\nexport function shouldPropagateTraceForUrl(\n url: string | undefined,\n tracePropagationTargets: Options['tracePropagationTargets'],\n decisionMap?: LRUMap<string, boolean>,\n): boolean {\n if (typeof url !== 'string' || !tracePropagationTargets) {\n return true;\n }\n\n const cachedDecision = decisionMap?.get(url);\n if (cachedDecision !== undefined) {\n DEBUG_BUILD && !cachedDecision && debug.log(NOT_PROPAGATED_MESSAGE, url);\n return cachedDecision;\n }\n\n const decision = stringMatchesSomePattern(url, tracePropagationTargets);\n decisionMap?.set(url, decision);\n\n DEBUG_BUILD && !decision && debug.log(NOT_PROPAGATED_MESSAGE, url);\n return decision;\n}\n"],"names":["DEBUG_BUILD","debug","stringMatchesSomePattern"],"mappings":";;;;;;AAMA,MAAM,sBAAA;AACN,EAAE,+FAA+F;;AAEjG;AACA;AACA;AACA;AACA;AACO,SAAS,0BAA0B;AAC1C,EAAE,GAAG;AACL,EAAE,uBAAuB;AACzB,EAAE,WAAW;AACb,EAAW;AACX,EAAE,IAAI,OAAO,GAAA,KAAQ,QAAA,IAAY,CAAC,uBAAuB,EAAE;AAC3D,IAAI,OAAO,IAAI;AACf,EAAE;;AAEF,EAAE,MAAM,iBAAiB,WAAW,EAAE,GAAG,CAAC,GAAG,CAAC;AAC9C,EAAE,IAAI,cAAA,KAAmB,SAAS,EAAE;AACpC,IAAIA,sBAAA,IAAe,CAAC,cAAA,IAAkBC,iBAAK,CAAC,GAAG,CAAC,sBAAsB,EAAE,GAAG,CAAC;AAC5E,IAAI,OAAO,cAAc;AACzB,EAAE;;AAEF,EAAE,MAAM,WAAWC,+BAAwB,CAAC,GAAG,EAAE,uBAAuB,CAAC;AACzE,EAAE,WAAW,EAAE,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC;;AAEjC,EAAEF,sBAAA,IAAe,CAAC,QAAA,IAAYC,iBAAK,CAAC,GAAG,CAAC,sBAAsB,EAAE,GAAG,CAAC;AACpE,EAAE,OAAO,QAAQ;AACjB;;;;"}
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  // This is a magic string replaced by rollup
4
4
 
5
- const SDK_VERSION = "10.37.0" ;
5
+ const SDK_VERSION = "10.39.0-alpha.0" ;
6
6
 
7
7
  exports.SDK_VERSION = SDK_VERSION;
8
8
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sources":["../../../src/utils/version.ts"],"sourcesContent":["// This is a magic string replaced by rollup\ndeclare const __SENTRY_SDK_VERSION__: string;\n\nexport const SDK_VERSION = typeof __SENTRY_SDK_VERSION__ === 'string' ? __SENTRY_SDK_VERSION__ : '0.0.0-unknown.0';\n"],"names":[],"mappings":";;AAAA;;AAGO,MAAM,WAAA,GAA2D,SAAA;;;;"}
1
+ {"version":3,"file":"version.js","sources":["../../../src/utils/version.ts"],"sourcesContent":["// This is a magic string replaced by rollup\ndeclare const __SENTRY_SDK_VERSION__: string;\n\nexport const SDK_VERSION = typeof __SENTRY_SDK_VERSION__ === 'string' ? __SENTRY_SDK_VERSION__ : '0.0.0-unknown.0';\n"],"names":[],"mappings":";;AAAA;;AAGO,MAAM,WAAA,GAA2D,iBAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.js","sources":["../../src/attributes.ts"],"sourcesContent":["import type { DurationUnit, FractionUnit, InformationUnit } from './types-hoist/measurement';\n\nexport type RawAttributes<T> = T & ValidatedAttributes<T>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RawAttribute<T> = T extends { value: any } | { unit: any } ? AttributeObject : T;\n\nexport type Attributes = Record<string, TypedAttributeValue>;\n\nexport type AttributeValueType = string | number | boolean | Array<string> | Array<number> | Array<boolean>;\n\ntype AttributeTypeMap = {\n string: string;\n integer: number;\n double: number;\n boolean: boolean;\n 'string[]': Array<string>;\n 'integer[]': Array<number>;\n 'double[]': Array<number>;\n 'boolean[]': Array<boolean>;\n};\n\n/* Generates a type from the AttributeTypeMap like:\n | { value: string; type: 'string' }\n | { value: number; type: 'integer' }\n | { value: number; type: 'double' }\n */\ntype AttributeUnion = {\n [K in keyof AttributeTypeMap]: {\n value: AttributeTypeMap[K];\n type: K;\n };\n}[keyof AttributeTypeMap];\n\nexport type TypedAttributeValue = AttributeUnion & { unit?: AttributeUnit };\n\nexport type AttributeObject = {\n value: unknown;\n unit?: AttributeUnit;\n};\n\n// Unfortunately, we loose type safety if we did something like Exclude<MeasurementUnit, string>\n// so therefore we unionize between the three supported unit categories.\ntype AttributeUnit = DurationUnit | InformationUnit | FractionUnit;\n\n/* If an attribute has either a 'value' or 'unit' property, we use the ValidAttributeObject type. */\nexport type ValidatedAttributes<T> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [K in keyof T]: T[K] extends { value: any } | { unit: any } ? AttributeObject : unknown;\n};\n\n/**\n * Type-guard: The attribute object has the shape the official attribute object (value, type, unit).\n * https://develop.sentry.dev/sdk/telemetry/scopes/#setting-attributes\n */\nexport function isAttributeObject(maybeObj: unknown): maybeObj is AttributeObject {\n return (\n typeof maybeObj === 'object' &&\n maybeObj != null &&\n !Array.isArray(maybeObj) &&\n Object.keys(maybeObj).includes('value')\n );\n}\n\n/**\n * Converts an attribute value to a typed attribute value.\n *\n * For now, we intentionally only support primitive values and attribute objects with primitive values.\n * If @param useFallback is true, we stringify non-primitive values to a string attribute value. Otherwise\n * we return `undefined` for unsupported values.\n *\n * @param value - The value of the passed attribute.\n * @param useFallback - If true, unsupported values will be stringified to a string attribute value.\n * Defaults to false. In this case, `undefined` is returned for unsupported values.\n * @returns The typed attribute.\n */\nexport function attributeValueToTypedAttributeValue(\n rawValue: unknown,\n useFallback?: boolean | 'skip-undefined',\n): TypedAttributeValue | void {\n const { value, unit } = isAttributeObject(rawValue) ? rawValue : { value: rawValue, unit: undefined };\n const attributeValue = getTypedAttributeValue(value);\n const checkedUnit = unit && typeof unit === 'string' ? { unit } : {};\n if (attributeValue) {\n return { ...attributeValue, ...checkedUnit };\n }\n\n if (!useFallback || (useFallback === 'skip-undefined' && value === undefined)) {\n return;\n }\n\n // Fallback: stringify the value\n // TODO(v11): be smarter here and use String constructor if stringify fails\n // (this is a breaking change for already existing attribute values)\n let stringValue = '';\n try {\n stringValue = JSON.stringify(value) ?? '';\n } catch {\n // Do nothing\n }\n return {\n value: stringValue,\n type: 'string',\n ...checkedUnit,\n };\n}\n\n/**\n * Serializes raw attributes to typed attributes as expected in our envelopes.\n *\n * @param attributes The raw attributes to serialize.\n * @param fallback If true, unsupported values will be stringified to a string attribute value.\n * Defaults to false. In this case, `undefined` is returned for unsupported values.\n *\n * @returns The serialized attributes.\n */\nexport function serializeAttributes<T>(\n attributes: RawAttributes<T> | undefined,\n fallback: boolean | 'skip-undefined' = false,\n): Attributes {\n const serializedAttributes: Attributes = {};\n for (const [key, value] of Object.entries(attributes ?? {})) {\n const typedValue = attributeValueToTypedAttributeValue(value, fallback);\n if (typedValue) {\n serializedAttributes[key] = typedValue;\n }\n }\n return serializedAttributes;\n}\n\n/**\n * NOTE: We intentionally do not return anything for non-primitive values:\n * - array support will come in the future but if we stringify arrays now,\n * sending arrays (unstringified) later will be a subtle breaking change.\n * - Objects are not supported yet and product support is still TBD.\n * - We still keep the type signature for TypedAttributeValue wider to avoid a\n * breaking change once we add support for non-primitive values.\n * - Once we go back to supporting arrays and stringifying all other values,\n * we already implemented the serialization logic here:\n * https://github.com/getsentry/sentry-javascript/pull/18165\n */\nfunction getTypedAttributeValue(value: unknown): TypedAttributeValue | void {\n const primitiveType =\n typeof value === 'string'\n ? 'string'\n : typeof value === 'boolean'\n ? 'boolean'\n : typeof value === 'number' && !Number.isNaN(value)\n ? Number.isInteger(value)\n ? 'integer'\n : 'double'\n : null;\n if (primitiveType) {\n // @ts-expect-error - TS complains because {@link TypedAttributeValue} is strictly typed to\n // avoid setting the wrong `type` on the attribute value.\n // In this case, getPrimitiveType already does the check but TS doesn't know that.\n // The \"clean\" alternative is to return an object per `typeof value` case\n // but that would require more bundle size\n // Therefore, we ignore it.\n return { value, type: primitiveType };\n }\n}\n"],"names":[],"mappings":"AAkDA;AACA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,QAAQ,EAAwC;AAClF,EAAE;AACF,IAAI,OAAO,QAAA,KAAa,QAAA;AACxB,IAAI,QAAA,IAAY,IAAA;AAChB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAA;AAC3B,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO;AAC1C;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,mCAAmC;AACnD,EAAE,QAAQ;AACV,EAAE,WAAW;AACb,EAA8B;AAC9B,EAAE,MAAM,EAAE,KAAK,EAAE,MAAK,GAAI,iBAAiB,CAAC,QAAQ,CAAA,GAAI,QAAA,GAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAA,EAAW;AACvG,EAAE,MAAM,cAAA,GAAiB,sBAAsB,CAAC,KAAK,CAAC;AACtD,EAAE,MAAM,WAAA,GAAc,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,GAAW,EAAE,IAAA,EAAK,GAAI,EAAE;AACtE,EAAE,IAAI,cAAc,EAAE;AACtB,IAAI,OAAO,EAAE,GAAG,cAAc,EAAE,GAAG,aAAa;AAChD,EAAE;;AAEF,EAAE,IAAI,CAAC,WAAA,KAAgB,WAAA,KAAgB,gBAAA,IAAoB,KAAA,KAAU,SAAS,CAAC,EAAE;AACjF,IAAI;AACJ,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KAAK,EAAE,IAAI,EAAE,eAAe;AACzC,EAAE;AACF;;;;"}
1
+ {"version":3,"file":"attributes.js","sources":["../../src/attributes.ts"],"sourcesContent":["import type { DurationUnit, FractionUnit, InformationUnit } from './types-hoist/measurement';\n\nexport type RawAttributes<T> = T & ValidatedAttributes<T>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RawAttribute<T> = T extends { value: any } | { unit: any } ? AttributeObject : T;\n\nexport type Attributes = Record<string, TypedAttributeValue>;\n\nexport type AttributeValueType = string | number | boolean | Array<string> | Array<number> | Array<boolean>;\n\ntype AttributeTypeMap = {\n string: string;\n integer: number;\n double: number;\n boolean: boolean;\n 'string[]': Array<string>;\n 'integer[]': Array<number>;\n 'double[]': Array<number>;\n 'boolean[]': Array<boolean>;\n};\n\n/* Generates a type from the AttributeTypeMap like:\n | { value: string; type: 'string' }\n | { value: number; type: 'integer' }\n | { value: number; type: 'double' }\n */\ntype AttributeUnion = {\n [K in keyof AttributeTypeMap]: {\n value: AttributeTypeMap[K];\n type: K;\n };\n}[keyof AttributeTypeMap];\n\nexport type TypedAttributeValue = AttributeUnion & { unit?: AttributeUnit };\n\nexport type AttributeObject = {\n value: unknown;\n unit?: AttributeUnit;\n};\n\n// Unfortunately, we loose type safety if we did something like Exclude<MeasurementUnit, string>\n// so therefore we unionize between the three supported unit categories.\nexport type AttributeUnit = DurationUnit | InformationUnit | FractionUnit;\n\n/* If an attribute has either a 'value' or 'unit' property, we use the ValidAttributeObject type. */\nexport type ValidatedAttributes<T> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [K in keyof T]: T[K] extends { value: any } | { unit: any } ? AttributeObject : unknown;\n};\n\n/**\n * Type-guard: The attribute object has the shape the official attribute object (value, type, unit).\n * https://develop.sentry.dev/sdk/telemetry/scopes/#setting-attributes\n */\nexport function isAttributeObject(maybeObj: unknown): maybeObj is AttributeObject {\n return (\n typeof maybeObj === 'object' &&\n maybeObj != null &&\n !Array.isArray(maybeObj) &&\n Object.keys(maybeObj).includes('value')\n );\n}\n\n/**\n * Converts an attribute value to a typed attribute value.\n *\n * For now, we intentionally only support primitive values and attribute objects with primitive values.\n * If @param useFallback is true, we stringify non-primitive values to a string attribute value. Otherwise\n * we return `undefined` for unsupported values.\n *\n * @param value - The value of the passed attribute.\n * @param useFallback - If true, unsupported values will be stringified to a string attribute value.\n * Defaults to false. In this case, `undefined` is returned for unsupported values.\n * @returns The typed attribute.\n */\nexport function attributeValueToTypedAttributeValue(\n rawValue: unknown,\n useFallback?: boolean | 'skip-undefined',\n): TypedAttributeValue | void {\n const { value, unit } = isAttributeObject(rawValue) ? rawValue : { value: rawValue, unit: undefined };\n const attributeValue = getTypedAttributeValue(value);\n const checkedUnit = unit && typeof unit === 'string' ? { unit } : {};\n if (attributeValue) {\n return { ...attributeValue, ...checkedUnit };\n }\n\n if (!useFallback || (useFallback === 'skip-undefined' && value === undefined)) {\n return;\n }\n\n // Fallback: stringify the value\n // TODO(v11): be smarter here and use String constructor if stringify fails\n // (this is a breaking change for already existing attribute values)\n let stringValue = '';\n try {\n stringValue = JSON.stringify(value) ?? '';\n } catch {\n // Do nothing\n }\n return {\n value: stringValue,\n type: 'string',\n ...checkedUnit,\n };\n}\n\n/**\n * Serializes raw attributes to typed attributes as expected in our envelopes.\n *\n * @param attributes The raw attributes to serialize.\n * @param fallback If true, unsupported values will be stringified to a string attribute value.\n * Defaults to false. In this case, `undefined` is returned for unsupported values.\n *\n * @returns The serialized attributes.\n */\nexport function serializeAttributes<T>(\n attributes: RawAttributes<T> | undefined,\n fallback: boolean | 'skip-undefined' = false,\n): Attributes {\n const serializedAttributes: Attributes = {};\n for (const [key, value] of Object.entries(attributes ?? {})) {\n const typedValue = attributeValueToTypedAttributeValue(value, fallback);\n if (typedValue) {\n serializedAttributes[key] = typedValue;\n }\n }\n return serializedAttributes;\n}\n\n/**\n * NOTE: We intentionally do not return anything for non-primitive values:\n * - array support will come in the future but if we stringify arrays now,\n * sending arrays (unstringified) later will be a subtle breaking change.\n * - Objects are not supported yet and product support is still TBD.\n * - We still keep the type signature for TypedAttributeValue wider to avoid a\n * breaking change once we add support for non-primitive values.\n * - Once we go back to supporting arrays and stringifying all other values,\n * we already implemented the serialization logic here:\n * https://github.com/getsentry/sentry-javascript/pull/18165\n */\nfunction getTypedAttributeValue(value: unknown): TypedAttributeValue | void {\n const primitiveType =\n typeof value === 'string'\n ? 'string'\n : typeof value === 'boolean'\n ? 'boolean'\n : typeof value === 'number' && !Number.isNaN(value)\n ? Number.isInteger(value)\n ? 'integer'\n : 'double'\n : null;\n if (primitiveType) {\n // @ts-expect-error - TS complains because {@link TypedAttributeValue} is strictly typed to\n // avoid setting the wrong `type` on the attribute value.\n // In this case, getPrimitiveType already does the check but TS doesn't know that.\n // The \"clean\" alternative is to return an object per `typeof value` case\n // but that would require more bundle size\n // Therefore, we ignore it.\n return { value, type: primitiveType };\n }\n}\n"],"names":[],"mappings":"AAkDA;AACA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,QAAQ,EAAwC;AAClF,EAAE;AACF,IAAI,OAAO,QAAA,KAAa,QAAA;AACxB,IAAI,QAAA,IAAY,IAAA;AAChB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAA;AAC3B,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO;AAC1C;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,mCAAmC;AACnD,EAAE,QAAQ;AACV,EAAE,WAAW;AACb,EAA8B;AAC9B,EAAE,MAAM,EAAE,KAAK,EAAE,MAAK,GAAI,iBAAiB,CAAC,QAAQ,CAAA,GAAI,QAAA,GAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAA,EAAW;AACvG,EAAE,MAAM,cAAA,GAAiB,sBAAsB,CAAC,KAAK,CAAC;AACtD,EAAE,MAAM,WAAA,GAAc,IAAA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