@sentry/core 10.39.0-alpha.0 → 10.40.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 (193) hide show
  1. package/build/cjs/attributes.js.map +1 -1
  2. package/build/cjs/client.js +7 -13
  3. package/build/cjs/client.js.map +1 -1
  4. package/build/cjs/envelope.js +7 -41
  5. package/build/cjs/envelope.js.map +1 -1
  6. package/build/cjs/exports.js +4 -2
  7. package/build/cjs/exports.js.map +1 -1
  8. package/build/cjs/fetch.js +8 -4
  9. package/build/cjs/fetch.js.map +1 -1
  10. package/build/cjs/index.js +3 -48
  11. package/build/cjs/index.js.map +1 -1
  12. package/build/cjs/integration.js +0 -12
  13. package/build/cjs/integration.js.map +1 -1
  14. package/build/cjs/integrations/eventFilters.js +1 -1
  15. package/build/cjs/integrations/eventFilters.js.map +1 -1
  16. package/build/cjs/integrations/requestdata.js +6 -72
  17. package/build/cjs/integrations/requestdata.js.map +1 -1
  18. package/build/cjs/semanticAttributes.js +0 -84
  19. package/build/cjs/semanticAttributes.js.map +1 -1
  20. package/build/cjs/tracing/langgraph/index.js +1 -1
  21. package/build/cjs/tracing/langgraph/index.js.map +1 -1
  22. package/build/cjs/tracing/sentrySpan.js +0 -32
  23. package/build/cjs/tracing/sentrySpan.js.map +1 -1
  24. package/build/cjs/tracing/trace.js +0 -1
  25. package/build/cjs/tracing/trace.js.map +1 -1
  26. package/build/cjs/tracing/vercel-ai/index.js +0 -1
  27. package/build/cjs/tracing/vercel-ai/index.js.map +1 -1
  28. package/build/cjs/utils/featureFlags.js +0 -1
  29. package/build/cjs/utils/featureFlags.js.map +1 -1
  30. package/build/cjs/utils/misc.js +7 -0
  31. package/build/cjs/utils/misc.js.map +1 -1
  32. package/build/cjs/utils/node-stack-trace.js +11 -2
  33. package/build/cjs/utils/node-stack-trace.js.map +1 -1
  34. package/build/cjs/utils/scopeData.js +0 -4
  35. package/build/cjs/utils/scopeData.js.map +1 -1
  36. package/build/cjs/utils/should-ignore-span.js +9 -31
  37. package/build/cjs/utils/should-ignore-span.js.map +1 -1
  38. package/build/cjs/utils/spanUtils.js +2 -90
  39. package/build/cjs/utils/spanUtils.js.map +1 -1
  40. package/build/cjs/utils/tunnel.js +74 -0
  41. package/build/cjs/utils/tunnel.js.map +1 -0
  42. package/build/cjs/utils/version.js +1 -1
  43. package/build/cjs/utils/version.js.map +1 -1
  44. package/build/cjs/utils/worldwide.js.map +1 -1
  45. package/build/esm/attributes.js.map +1 -1
  46. package/build/esm/client.js +3 -9
  47. package/build/esm/client.js.map +1 -1
  48. package/build/esm/envelope.js +8 -41
  49. package/build/esm/envelope.js.map +1 -1
  50. package/build/esm/exports.js +4 -2
  51. package/build/esm/exports.js.map +1 -1
  52. package/build/esm/fetch.js +8 -4
  53. package/build/esm/fetch.js.map +1 -1
  54. package/build/esm/index.js +5 -11
  55. package/build/esm/index.js.map +1 -1
  56. package/build/esm/integration.js +1 -12
  57. package/build/esm/integration.js.map +1 -1
  58. package/build/esm/integrations/eventFilters.js +1 -1
  59. package/build/esm/integrations/eventFilters.js.map +1 -1
  60. package/build/esm/integrations/requestdata.js +6 -72
  61. package/build/esm/integrations/requestdata.js.map +1 -1
  62. package/build/esm/package.json +1 -1
  63. package/build/esm/semanticAttributes.js +1 -57
  64. package/build/esm/semanticAttributes.js.map +1 -1
  65. package/build/esm/tracing/langgraph/index.js +1 -1
  66. package/build/esm/tracing/langgraph/index.js.map +1 -1
  67. package/build/esm/tracing/sentrySpan.js +1 -33
  68. package/build/esm/tracing/sentrySpan.js.map +1 -1
  69. package/build/esm/tracing/trace.js +0 -1
  70. package/build/esm/tracing/trace.js.map +1 -1
  71. package/build/esm/tracing/vercel-ai/index.js +0 -1
  72. package/build/esm/tracing/vercel-ai/index.js.map +1 -1
  73. package/build/esm/utils/featureFlags.js +0 -1
  74. package/build/esm/utils/featureFlags.js.map +1 -1
  75. package/build/esm/utils/misc.js +7 -1
  76. package/build/esm/utils/misc.js.map +1 -1
  77. package/build/esm/utils/node-stack-trace.js +11 -2
  78. package/build/esm/utils/node-stack-trace.js.map +1 -1
  79. package/build/esm/utils/scopeData.js +0 -4
  80. package/build/esm/utils/scopeData.js.map +1 -1
  81. package/build/esm/utils/should-ignore-span.js +9 -31
  82. package/build/esm/utils/should-ignore-span.js.map +1 -1
  83. package/build/esm/utils/spanUtils.js +3 -87
  84. package/build/esm/utils/spanUtils.js.map +1 -1
  85. package/build/esm/utils/tunnel.js +72 -0
  86. package/build/esm/utils/tunnel.js.map +1 -0
  87. package/build/esm/utils/version.js +1 -1
  88. package/build/esm/utils/version.js.map +1 -1
  89. package/build/esm/utils/worldwide.js.map +1 -1
  90. package/build/types/attributes.d.ts +1 -1
  91. package/build/types/attributes.d.ts.map +1 -1
  92. package/build/types/client.d.ts +2 -40
  93. package/build/types/client.d.ts.map +1 -1
  94. package/build/types/envelope.d.ts +1 -6
  95. package/build/types/envelope.d.ts.map +1 -1
  96. package/build/types/exports.d.ts.map +1 -1
  97. package/build/types/fetch.d.ts.map +1 -1
  98. package/build/types/index.d.ts +7 -12
  99. package/build/types/index.d.ts.map +1 -1
  100. package/build/types/integration.d.ts +0 -4
  101. package/build/types/integration.d.ts.map +1 -1
  102. package/build/types/integrations/requestdata.d.ts.map +1 -1
  103. package/build/types/semanticAttributes.d.ts +0 -38
  104. package/build/types/semanticAttributes.d.ts.map +1 -1
  105. package/build/types/tracing/sentrySpan.d.ts +1 -10
  106. package/build/types/tracing/sentrySpan.d.ts.map +1 -1
  107. package/build/types/tracing/vercel-ai/index.d.ts.map +1 -1
  108. package/build/types/types-hoist/envelope.d.ts +2 -22
  109. package/build/types/types-hoist/envelope.d.ts.map +1 -1
  110. package/build/types/types-hoist/integration.d.ts +0 -7
  111. package/build/types/types-hoist/integration.d.ts.map +1 -1
  112. package/build/types/types-hoist/link.d.ts +2 -2
  113. package/build/types/types-hoist/link.d.ts.map +1 -1
  114. package/build/types/types-hoist/options.d.ts +2 -18
  115. package/build/types/types-hoist/options.d.ts.map +1 -1
  116. package/build/types/types-hoist/span.d.ts +0 -27
  117. package/build/types/types-hoist/span.d.ts.map +1 -1
  118. package/build/types/utils/featureFlags.d.ts.map +1 -1
  119. package/build/types/utils/misc.d.ts +7 -0
  120. package/build/types/utils/misc.d.ts.map +1 -1
  121. package/build/types/utils/node-stack-trace.d.ts.map +1 -1
  122. package/build/types/utils/scopeData.d.ts.map +1 -1
  123. package/build/types/utils/should-ignore-span.d.ts +3 -3
  124. package/build/types/utils/should-ignore-span.d.ts.map +1 -1
  125. package/build/types/utils/spanUtils.d.ts +2 -22
  126. package/build/types/utils/spanUtils.d.ts.map +1 -1
  127. package/build/types/utils/tunnel.d.ts +16 -0
  128. package/build/types/utils/tunnel.d.ts.map +1 -0
  129. package/build/types/utils/worldwide.d.ts +0 -2
  130. package/build/types/utils/worldwide.d.ts.map +1 -1
  131. package/build/types-ts3.8/attributes.d.ts +1 -1
  132. package/build/types-ts3.8/client.d.ts +2 -40
  133. package/build/types-ts3.8/envelope.d.ts +1 -6
  134. package/build/types-ts3.8/index.d.ts +7 -12
  135. package/build/types-ts3.8/integration.d.ts +0 -4
  136. package/build/types-ts3.8/semanticAttributes.d.ts +0 -38
  137. package/build/types-ts3.8/tracing/sentrySpan.d.ts +1 -10
  138. package/build/types-ts3.8/types-hoist/envelope.d.ts +2 -22
  139. package/build/types-ts3.8/types-hoist/integration.d.ts +0 -7
  140. package/build/types-ts3.8/types-hoist/link.d.ts +2 -2
  141. package/build/types-ts3.8/types-hoist/options.d.ts +2 -18
  142. package/build/types-ts3.8/types-hoist/span.d.ts +0 -27
  143. package/build/types-ts3.8/utils/misc.d.ts +7 -0
  144. package/build/types-ts3.8/utils/should-ignore-span.d.ts +3 -3
  145. package/build/types-ts3.8/utils/spanUtils.d.ts +2 -22
  146. package/build/types-ts3.8/utils/tunnel.d.ts +16 -0
  147. package/build/types-ts3.8/utils/worldwide.d.ts +0 -2
  148. package/package.json +2 -3
  149. package/build/cjs/integrations/spanStreaming.js +0 -54
  150. package/build/cjs/integrations/spanStreaming.js.map +0 -1
  151. package/build/cjs/spans/captureSpan.js +0 -104
  152. package/build/cjs/spans/captureSpan.js.map +0 -1
  153. package/build/cjs/spans/spanBuffer.js +0 -121
  154. package/build/cjs/spans/spanBuffer.js.map +0 -1
  155. package/build/cjs/spans/spanFirstUtils.js +0 -186
  156. package/build/cjs/spans/spanFirstUtils.js.map +0 -1
  157. package/build/cjs/utils/beforeSendSpan.js +0 -36
  158. package/build/cjs/utils/beforeSendSpan.js.map +0 -1
  159. package/build/cjs/utils/hasSpanStreamingEnabled.js +0 -21
  160. package/build/cjs/utils/hasSpanStreamingEnabled.js.map +0 -1
  161. package/build/esm/integrations/spanStreaming.js +0 -52
  162. package/build/esm/integrations/spanStreaming.js.map +0 -1
  163. package/build/esm/spans/captureSpan.js +0 -102
  164. package/build/esm/spans/captureSpan.js.map +0 -1
  165. package/build/esm/spans/spanBuffer.js +0 -119
  166. package/build/esm/spans/spanBuffer.js.map +0 -1
  167. package/build/esm/spans/spanFirstUtils.js +0 -182
  168. package/build/esm/spans/spanFirstUtils.js.map +0 -1
  169. package/build/esm/utils/beforeSendSpan.js +0 -33
  170. package/build/esm/utils/beforeSendSpan.js.map +0 -1
  171. package/build/esm/utils/hasSpanStreamingEnabled.js +0 -19
  172. package/build/esm/utils/hasSpanStreamingEnabled.js.map +0 -1
  173. package/build/types/integrations/spanStreaming.d.ts +0 -11
  174. package/build/types/integrations/spanStreaming.d.ts.map +0 -1
  175. package/build/types/spans/captureSpan.d.ts +0 -10
  176. package/build/types/spans/captureSpan.d.ts.map +0 -1
  177. package/build/types/spans/spanBuffer.d.ts +0 -35
  178. package/build/types/spans/spanBuffer.d.ts.map +0 -1
  179. package/build/types/spans/spanFirstUtils.d.ts +0 -20
  180. package/build/types/spans/spanFirstUtils.d.ts.map +0 -1
  181. package/build/types/types-hoist/attributes.d.ts +0 -19
  182. package/build/types/types-hoist/attributes.d.ts.map +0 -1
  183. package/build/types/utils/beforeSendSpan.d.ts +0 -22
  184. package/build/types/utils/beforeSendSpan.d.ts.map +0 -1
  185. package/build/types/utils/hasSpanStreamingEnabled.d.ts +0 -9
  186. package/build/types/utils/hasSpanStreamingEnabled.d.ts.map +0 -1
  187. package/build/types-ts3.8/integrations/spanStreaming.d.ts +0 -11
  188. package/build/types-ts3.8/spans/captureSpan.d.ts +0 -10
  189. package/build/types-ts3.8/spans/spanBuffer.d.ts +0 -35
  190. package/build/types-ts3.8/spans/spanFirstUtils.d.ts +0 -20
  191. package/build/types-ts3.8/types-hoist/attributes.d.ts +0 -19
  192. package/build/types-ts3.8/utils/beforeSendSpan.d.ts +0 -22
  193. package/build/types-ts3.8/utils/hasSpanStreamingEnabled.d.ts +0 -9
@@ -1,4 +1,3 @@
1
- import { Attributes } from '../attributes';
2
1
  import { SpanLink, SpanLinkJSON } from './link';
3
2
  import { Measurements } from './measurement';
4
3
  import { HrTime } from './opentelemetry';
@@ -18,32 +17,6 @@ export type SpanAttributes = Partial<{
18
17
  }> & Record<string, SpanAttributeValue | undefined>;
19
18
  /** This type is aligned with the OpenTelemetry TimeInput type. */
20
19
  export type SpanTimeInput = HrTime | number | Date;
21
- /**
22
- * JSON representation of a v2 span, as it should be sent to Sentry.
23
- */
24
- export interface SpanV2JSON {
25
- trace_id: string;
26
- parent_span_id?: string;
27
- span_id: string;
28
- name: string;
29
- start_timestamp: number;
30
- end_timestamp: number;
31
- status: 'ok' | 'error';
32
- is_segment: boolean;
33
- attributes?: Attributes;
34
- links?: SpanLinkJSON<Attributes>[];
35
- }
36
- /**
37
- * A SpanV2JSON with an attached reference to the segment span.
38
- * This reference is used to compute dynamic sampling context before sending.
39
- * The reference MUST be removed before sending the span envelope.
40
- */
41
- export interface SpanV2JSONWithSegmentRef extends SpanV2JSON {
42
- _segmentSpan: Span;
43
- }
44
- export type SerializedSpanContainer = {
45
- items: Array<SpanV2JSON>;
46
- };
47
20
  /** A JSON representation of a span. */
48
21
  export interface SpanJSON {
49
22
  data: SpanAttributes;
@@ -76,5 +76,12 @@ export declare function addContextToFrame(lines: string[], frame: StackFrame, li
76
76
  * @returns `true` if the exception has already been captured, `false` if not (with the side effect of marking it seen)
77
77
  */
78
78
  export declare function checkOrSetAlreadyCaught(exception: unknown): boolean;
79
+ /**
80
+ * Checks whether we've already captured the given exception (note: not an identical exception - the very object).
81
+ * It is considered already captured if it has the `__sentry_captured__` property set to `true`.
82
+ *
83
+ * @internal Only considered for internal usage
84
+ */
85
+ export declare function isAlreadyCaptured(exception: unknown): boolean | void;
79
86
  export {};
80
87
  //# sourceMappingURL=misc.d.ts.map
@@ -1,12 +1,12 @@
1
1
  import { ClientOptions } from '../types-hoist/options';
2
- import { SpanJSON, SpanV2JSON } from '../types-hoist/span';
2
+ import { SpanJSON } from '../types-hoist/span';
3
3
  /**
4
4
  * Check if a span should be ignored based on the ignoreSpans configuration.
5
5
  */
6
- export declare function shouldIgnoreSpan(span: Pick<SpanJSON, 'description' | 'op'> | Pick<SpanV2JSON, 'name' | 'attributes'>, ignoreSpans: Required<ClientOptions>['ignoreSpans']): boolean;
6
+ export declare function shouldIgnoreSpan(span: Pick<SpanJSON, 'description' | 'op'>, ignoreSpans: Required<ClientOptions>['ignoreSpans']): boolean;
7
7
  /**
8
8
  * 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.
9
9
  * This mutates the spans array in place!
10
10
  */
11
- export declare function reparentChildSpans(spans: Pick<SpanV2JSON, 'parent_span_id' | 'span_id'>[], dropSpan: Pick<SpanV2JSON, 'parent_span_id' | 'span_id'>): void;
11
+ export declare function reparentChildSpans(spans: SpanJSON[], dropSpan: SpanJSON): void;
12
12
  //# sourceMappingURL=should-ignore-span.d.ts.map
@@ -1,7 +1,6 @@
1
- import { Attributes } from '../attributes';
2
1
  import { TraceContext } from '../types-hoist/context';
3
2
  import { SpanLink, SpanLinkJSON } from '../types-hoist/link';
4
- import { Span, SpanAttributes, SpanJSON, SpanTimeInput, SpanV2JSON } from '../types-hoist/span';
3
+ import { Span, SpanAttributes, SpanJSON, SpanTimeInput } from '../types-hoist/span';
5
4
  import { SpanStatus } from '../types-hoist/spanStatus';
6
5
  export declare const TRACE_FLAG_NONE = 0;
7
6
  export declare const TRACE_FLAG_SAMPLED = 1;
@@ -29,12 +28,6 @@ export declare function spanToTraceparentHeader(span: Span): string;
29
28
  * If the links array is empty, it returns `undefined` so the empty value can be dropped before it's sent.
30
29
  */
31
30
  export declare function convertSpanLinksForEnvelope(links?: SpanLink[]): SpanLinkJSON[] | undefined;
32
- /**
33
- *
34
- * @param links
35
- * @returns
36
- */
37
- export declare function getV2SpanLinks(links?: SpanLink[]): SpanLinkJSON<Attributes>[] | undefined;
38
31
  /**
39
32
  * Convert a span time input into a timestamp in seconds.
40
33
  */
@@ -43,11 +36,6 @@ export declare function spanTimeInputToSeconds(input: SpanTimeInput | undefined)
43
36
  * Convert a span to a JSON representation.
44
37
  */
45
38
  export declare function spanToJSON(span: Span): SpanJSON;
46
- /**
47
- * Convert a span to a SpanV2JSON representation.
48
- * @returns
49
- */
50
- export declare function spanToV2JSON(span: Span): SpanV2JSON;
51
39
  /** Exported only for tests. */
52
40
  export interface OpenTelemetrySdkTraceBaseSpan extends Span {
53
41
  attributes: SpanAttributes;
@@ -67,10 +55,6 @@ export interface OpenTelemetrySdkTraceBaseSpan extends Span {
67
55
  export declare function spanIsSampled(span: Span): boolean;
68
56
  /** Get the status message to use for a JSON representation of a span. */
69
57
  export declare function getStatusMessage(status: SpanStatus | undefined): string | undefined;
70
- /**
71
- * Convert the various statuses to the ones expected by Sentry ('ok' is default)
72
- */
73
- export declare function getV2StatusMessage(status: SpanStatus | undefined): 'ok' | 'error';
74
58
  declare const CHILD_SPANS_FIELD = "_sentryChildSpans";
75
59
  declare const ROOT_SPAN_FIELD = "_sentryRootSpan";
76
60
  type SpanWithPotentialChildren = Span & {
@@ -90,11 +74,7 @@ export declare function getSpanDescendants(span: SpanWithPotentialChildren): Spa
90
74
  /**
91
75
  * Returns the root span of a given span.
92
76
  */
93
- export declare const getRootSpan: typeof INTERNAL_getSegmentSpan;
94
- /**
95
- * Returns the segment span of a given span.
96
- */
97
- export declare function INTERNAL_getSegmentSpan(span: SpanWithPotentialChildren): Span;
77
+ export declare function getRootSpan(span: SpanWithPotentialChildren): Span;
98
78
  /**
99
79
  * Returns the currently active span.
100
80
  */
@@ -0,0 +1,16 @@
1
+ export interface HandleTunnelRequestOptions {
2
+ /** Incoming request containing the Sentry envelope as its body */
3
+ request: Request;
4
+ /** Pre-parsed array of allowed DSN strings */
5
+ allowedDsns: Array<string>;
6
+ }
7
+ /**
8
+ * Core Sentry tunnel handler - framework agnostic.
9
+ *
10
+ * Validates the envelope DSN against allowed DSNs, then forwards the
11
+ * envelope to the Sentry ingest endpoint.
12
+ *
13
+ * @returns A `Response` — either the upstream Sentry response on success, or an error response.
14
+ */
15
+ export declare function handleTunnelRequest(options: HandleTunnelRequestOptions): Promise<Response>;
16
+ //# sourceMappingURL=tunnel.d.ts.map
@@ -53,8 +53,6 @@ export type InternalGlobal = {
53
53
  */
54
54
  _sentryModuleMetadata?: Record<string, any>;
55
55
  _sentryEsmLoaderHookRegistered?: boolean;
56
- _sentryInjectLoaderHookRegister?: () => void;
57
- _sentryInjectLoaderHookRegistered?: boolean;
58
56
  } & Carrier;
59
57
  /** Get's the global object for the current JavaScript runtime */
60
58
  export declare const GLOBAL_OBJ: InternalGlobal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/core",
3
- "version": "10.39.0-alpha.0",
3
+ "version": "10.40.0",
4
4
  "description": "Base implementation for all Sentry JavaScript SDKs",
5
5
  "repository": "git://github.com/getsentry/sentry-javascript.git",
6
6
  "homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/core",
@@ -45,10 +45,9 @@
45
45
  "build:types": "run-s build:types:core build:types:downlevel",
46
46
  "build:types:core": "tsc -p tsconfig.types.json",
47
47
  "build:types:downlevel": "yarn downlevel-dts build/types build/types-ts3.8 --to ts3.8",
48
- "build:watch": "run-p build:transpile:watch build:types:watch",
48
+ "build:watch": "run-p build:transpile:watch",
49
49
  "build:dev:watch": "yarn build:watch",
50
50
  "build:transpile:watch": "rollup -c rollup.npm.config.mjs --watch",
51
- "build:types:watch": "tsc -p tsconfig.types.json --watch",
52
51
  "build:tarball": "npm pack",
53
52
  "circularDepCheck": "madge --circular src/index.ts",
54
53
  "clean": "rimraf build coverage sentry-core-*.tgz",
@@ -1,54 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- const debugBuild = require('../debug-build.js');
4
- const integration = require('../integration.js');
5
- const captureSpan = require('../spans/captureSpan.js');
6
- const spanBuffer = require('../spans/spanBuffer.js');
7
- const beforeSendSpan = require('../utils/beforeSendSpan.js');
8
- const debugLogger = require('../utils/debug-logger.js');
9
-
10
- const INTEGRATION_NAME = 'SpanStreaming';
11
-
12
- const _spanStreamingIntegration = ((options) => {
13
- return {
14
- name: INTEGRATION_NAME,
15
- setup(client) {
16
- const clientOptions = client.getOptions();
17
- const beforeSendSpan$1 = clientOptions.beforeSendSpan;
18
-
19
- const initialMessage = 'spanStreamingIntegration requires';
20
- const fallbackMsg = 'Falling back to static trace lifecycle.';
21
-
22
- if (clientOptions.traceLifecycle !== 'stream') {
23
- client.getOptions().traceLifecycle = 'static';
24
- debugBuild.DEBUG_BUILD && debugLogger.debug.warn(`${initialMessage} \`traceLifecycle\` to be set to "stream"! ${fallbackMsg}`);
25
- return;
26
- }
27
-
28
- if (beforeSendSpan$1 && !beforeSendSpan.isV2BeforeSendSpanCallback(beforeSendSpan$1)) {
29
- client.getOptions().traceLifecycle = 'static';
30
- debugBuild.DEBUG_BUILD &&
31
- debugLogger.debug.warn(`${initialMessage} a beforeSendSpan callback using \`withStreamSpan\`! ${fallbackMsg}`);
32
- return;
33
- }
34
-
35
- const buffer = new spanBuffer.SpanBuffer(client, options);
36
-
37
- client.on('enqueueSpan', spanJSON => {
38
- buffer.addSpan(spanJSON);
39
- });
40
-
41
- client.on('afterSpanEnd', span => {
42
- captureSpan.captureSpan(span, client);
43
- });
44
- },
45
- };
46
- }) ;
47
-
48
- /**
49
- * Span streaming integration used by server runtime SDKs.
50
- */
51
- const spanStreamingIntegration = integration.defineIntegration(_spanStreamingIntegration);
52
-
53
- exports.spanStreamingIntegration = spanStreamingIntegration;
54
- //# sourceMappingURL=spanStreaming.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spanStreaming.js","sources":["../../../src/integrations/spanStreaming.ts"],"sourcesContent":["import { DEBUG_BUILD } from '../debug-build';\nimport { defineIntegration } from '../integration';\nimport { captureSpan } from '../spans/captureSpan';\nimport { SpanBuffer } from '../spans/spanBuffer';\nimport type { IntegrationFn } from '../types-hoist/integration';\nimport { isV2BeforeSendSpanCallback } from '../utils/beforeSendSpan';\nimport { debug } from '../utils/debug-logger';\n\nexport interface ServerSpanStreamingOptions {\n /** Max spans per envelope batch (default: 1000) */\n maxSpanLimit?: number;\n /** Flush interval in ms (default: 5000) */\n flushInterval?: number;\n}\n\nconst INTEGRATION_NAME = 'SpanStreaming';\n\nconst _spanStreamingIntegration = ((options?: ServerSpanStreamingOptions) => {\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n const clientOptions = client.getOptions();\n const beforeSendSpan = clientOptions.beforeSendSpan;\n\n const initialMessage = 'spanStreamingIntegration requires';\n const fallbackMsg = 'Falling back to static trace lifecycle.';\n\n if (clientOptions.traceLifecycle !== 'stream') {\n client.getOptions().traceLifecycle = 'static';\n DEBUG_BUILD && debug.warn(`${initialMessage} \\`traceLifecycle\\` to be set to \"stream\"! ${fallbackMsg}`);\n return;\n }\n\n if (beforeSendSpan && !isV2BeforeSendSpanCallback(beforeSendSpan)) {\n client.getOptions().traceLifecycle = 'static';\n DEBUG_BUILD &&\n debug.warn(`${initialMessage} a beforeSendSpan callback using \\`withStreamSpan\\`! ${fallbackMsg}`);\n return;\n }\n\n const buffer = new SpanBuffer(client, options);\n\n client.on('enqueueSpan', spanJSON => {\n buffer.addSpan(spanJSON);\n });\n\n client.on('afterSpanEnd', span => {\n captureSpan(span, client);\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Span streaming integration used by server runtime SDKs.\n */\nexport const spanStreamingIntegration = defineIntegration(_spanStreamingIntegration);\n"],"names":["beforeSendSpan","DEBUG_BUILD","debug","isV2BeforeSendSpanCallback","SpanBuffer","captureSpan","defineIntegration"],"mappings":";;;;;;;;;AAeA,MAAM,gBAAA,GAAmB,eAAe;;AAExC,MAAM,6BAA6B,CAAC,OAAO,KAAkC;AAC7E,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB,MAAM,MAAM,aAAA,GAAgB,MAAM,CAAC,UAAU,EAAE;AAC/C,MAAM,MAAMA,gBAAA,GAAiB,aAAa,CAAC,cAAc;;AAEzD,MAAM,MAAM,cAAA,GAAiB,mCAAmC;AAChE,MAAM,MAAM,WAAA,GAAc,yCAAyC;;AAEnE,MAAM,IAAI,aAAa,CAAC,cAAA,KAAmB,QAAQ,EAAE;AACrD,QAAQ,MAAM,CAAC,UAAU,EAAE,CAAC,cAAA,GAAiB,QAAQ;AACrD,QAAQC,0BAAeC,iBAAK,CAAC,IAAI,CAAC,CAAC,EAAA,cAAA,CAAA,2CAAA,EAAA,WAAA,CAAA,CAAA,CAAA;AACA,QAAA;AACA,MAAA;;AAEA,MAAA,IAAAF,gBAAA,IAAA,CAAAG,yCAAA,CAAAH,gBAAA,CAAA,EAAA;AACA,QAAA,MAAA,CAAA,UAAA,EAAA,CAAA,cAAA,GAAA,QAAA;AACA,QAAAC,sBAAA;AACA,UAAAC,iBAAA,CAAA,IAAA,CAAA,CAAA,EAAA,cAAA,CAAA,qDAAA,EAAA,WAAA,CAAA,CAAA,CAAA;AACA,QAAA;AACA,MAAA;;AAEA,MAAA,MAAA,MAAA,GAAA,IAAAE,qBAAA,CAAA,MAAA,EAAA,OAAA,CAAA;;AAEA,MAAA,MAAA,CAAA,EAAA,CAAA,aAAA,EAAA,QAAA,IAAA;AACA,QAAA,MAAA,CAAA,OAAA,CAAA,QAAA,CAAA;AACA,MAAA,CAAA,CAAA;;AAEA,MAAA,MAAA,CAAA,EAAA,CAAA,cAAA,EAAA,IAAA,IAAA;AACA,QAAAC,uBAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AACA,MAAA,CAAA,CAAA;AACA,IAAA,CAAA;AACA,GAAA;AACA,CAAA,CAAA;;AAEA;AACA;AACA;AACA,MAAA,wBAAA,GAAAC,6BAAA,CAAA,yBAAA;;;;"}
@@ -1,104 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- const currentScopes = require('../currentScopes.js');
4
- const debugBuild = require('../debug-build.js');
5
- const semanticAttributes = require('../semanticAttributes.js');
6
- const utils = require('../tracing/utils.js');
7
- const beforeSendSpan = require('../utils/beforeSendSpan.js');
8
- const debugLogger = require('../utils/debug-logger.js');
9
- const scopeData = require('../utils/scopeData.js');
10
- const spanUtils = require('../utils/spanUtils.js');
11
- const spanFirstUtils = require('./spanFirstUtils.js');
12
-
13
- /**
14
- * Captures a span and returns a JSON representation to be enqueued for sending.
15
- *
16
- * IMPORTANT: This function converts the span to JSON immediately to avoid writing
17
- * to an already-ended OTel span instance (which is blocked by the OTel Span class).
18
- */
19
- function captureSpan(span, client = currentScopes.getClient()) {
20
- if (!client) {
21
- debugBuild.DEBUG_BUILD && debugLogger.debug.warn('No client available to capture span.');
22
- return;
23
- }
24
-
25
- // Convert to JSON FIRST - we cannot write to an already-ended span
26
- const spanJSON = spanUtils.spanToV2JSON(span);
27
-
28
- const segmentSpan = spanUtils.INTERNAL_getSegmentSpan(span);
29
- const serializedSegmentSpan = spanUtils.spanToV2JSON(segmentSpan);
30
-
31
- const { isolationScope: spanIsolationScope, scope: spanScope } = utils.getCapturedScopesOnSpan(span);
32
-
33
- const finalScopeData = scopeData.getCombinedScopeData(spanIsolationScope, spanScope);
34
-
35
- applyCommonSpanAttributes(spanJSON, serializedSegmentSpan, client, finalScopeData);
36
-
37
- if (span === segmentSpan) {
38
- applyScopeToSegmentSpan(spanJSON, finalScopeData);
39
- client.emit('processSegmentSpan', spanJSON, { scopeData: finalScopeData });
40
- }
41
-
42
- // Allow integrations to add additional data to the span JSON
43
- client.emit('processSpan', spanJSON, { readOnlySpan: span });
44
-
45
- const beforeSendSpan$1 = client.getOptions().beforeSendSpan;
46
- const processedSpan = beforeSendSpan.isV2BeforeSendSpanCallback(beforeSendSpan$1)
47
- ? spanFirstUtils.applyBeforeSendSpanCallback(spanJSON, beforeSendSpan$1)
48
- : spanJSON;
49
-
50
- // Backfill sentry.span.source from sentry.source for the PoC
51
- // TODO(v11): Stop sending `sentry.source` attribute and only send `sentry.span.source`
52
- // probably easiest done by just renaming SEMANTIC_ATTRIBUTE_SENTRY_SOURCE
53
- if (processedSpan.attributes?.[semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]) {
54
- spanFirstUtils.safeSetSpanJSONAttributes(processedSpan, {
55
- [semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_SPAN_SOURCE]: processedSpan.attributes?.[semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]?.value,
56
- });
57
- }
58
-
59
- const spanWithRef = {
60
- ...processedSpan,
61
- _segmentSpan: segmentSpan,
62
- };
63
-
64
- client.emit('enqueueSpan', spanWithRef);
65
- }
66
-
67
- function applyScopeToSegmentSpan(segmentSpanJSON, scopeData) {
68
- // TODO: Apply all scope and request data from auto instrumentation (contexts, request) to segment span
69
- const { contexts } = scopeData;
70
-
71
- spanFirstUtils.safeSetSpanJSONAttributes(segmentSpanJSON, spanFirstUtils.contextsToAttributes(contexts));
72
- }
73
-
74
- function applyCommonSpanAttributes(
75
- spanJSON,
76
- serializedSegmentSpan,
77
- client,
78
- scopeData,
79
- ) {
80
- const sdk = client.getSdkMetadata();
81
- const { release, environment, sendDefaultPii } = client.getOptions();
82
-
83
- // avoid overwriting any previously set attributes (from users or potentially our SDK instrumentation)
84
- spanFirstUtils.safeSetSpanJSONAttributes(spanJSON, {
85
- [semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_RELEASE]: release,
86
- [semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT]: environment,
87
- [semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME]: serializedSegmentSpan.name,
88
- [semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID]: serializedSegmentSpan.span_id,
89
- [semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME]: sdk?.sdk?.name,
90
- [semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION]: sdk?.sdk?.version,
91
- ...(sendDefaultPii
92
- ? {
93
- [semanticAttributes.SEMANTIC_ATTRIBUTE_USER_ID]: scopeData.user?.id,
94
- [semanticAttributes.SEMANTIC_ATTRIBUTE_USER_EMAIL]: scopeData.user?.email,
95
- [semanticAttributes.SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: scopeData.user?.ip_address,
96
- [semanticAttributes.SEMANTIC_ATTRIBUTE_USER_USERNAME]: scopeData.user?.username,
97
- }
98
- : {}),
99
- ...scopeData.attributes,
100
- });
101
- }
102
-
103
- exports.captureSpan = captureSpan;
104
- //# sourceMappingURL=captureSpan.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"captureSpan.js","sources":["../../../src/spans/captureSpan.ts"],"sourcesContent":["import type { Client } from '../client';\nimport { getClient } from '../currentScopes';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { ScopeData } from '../scope';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT,\n SEMANTIC_ATTRIBUTE_SENTRY_RELEASE,\n SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION,\n SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID,\n SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n SEMANTIC_ATTRIBUTE_SENTRY_SPAN_SOURCE,\n SEMANTIC_ATTRIBUTE_USER_EMAIL,\n SEMANTIC_ATTRIBUTE_USER_ID,\n SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS,\n SEMANTIC_ATTRIBUTE_USER_USERNAME,\n} from '../semanticAttributes';\nimport { getCapturedScopesOnSpan } from '../tracing/utils';\nimport type { Span, SpanV2JSON } from '../types-hoist/span';\nimport { isV2BeforeSendSpanCallback } from '../utils/beforeSendSpan';\nimport { debug } from '../utils/debug-logger';\nimport { getCombinedScopeData } from '../utils/scopeData';\nimport { INTERNAL_getSegmentSpan, spanToV2JSON } from '../utils/spanUtils';\nimport { applyBeforeSendSpanCallback, contextsToAttributes, safeSetSpanJSONAttributes } from './spanFirstUtils';\n/**\n * Captures a span and returns a JSON representation to be enqueued for sending.\n *\n * IMPORTANT: This function converts the span to JSON immediately to avoid writing\n * to an already-ended OTel span instance (which is blocked by the OTel Span class).\n */\nexport function captureSpan(span: Span, client = getClient()): void {\n if (!client) {\n DEBUG_BUILD && debug.warn('No client available to capture span.');\n return;\n }\n\n // Convert to JSON FIRST - we cannot write to an already-ended span\n const spanJSON = spanToV2JSON(span);\n\n const segmentSpan = INTERNAL_getSegmentSpan(span);\n const serializedSegmentSpan = spanToV2JSON(segmentSpan);\n\n const { isolationScope: spanIsolationScope, scope: spanScope } = getCapturedScopesOnSpan(span);\n\n const finalScopeData = getCombinedScopeData(spanIsolationScope, spanScope);\n\n applyCommonSpanAttributes(spanJSON, serializedSegmentSpan, client, finalScopeData);\n\n if (span === segmentSpan) {\n applyScopeToSegmentSpan(spanJSON, finalScopeData);\n client.emit('processSegmentSpan', spanJSON, { scopeData: finalScopeData });\n }\n\n // Allow integrations to add additional data to the span JSON\n client.emit('processSpan', spanJSON, { readOnlySpan: span });\n\n const beforeSendSpan = client.getOptions().beforeSendSpan;\n const processedSpan = isV2BeforeSendSpanCallback(beforeSendSpan)\n ? applyBeforeSendSpanCallback(spanJSON, beforeSendSpan)\n : spanJSON;\n\n // Backfill sentry.span.source from sentry.source for the PoC\n // TODO(v11): Stop sending `sentry.source` attribute and only send `sentry.span.source`\n // probably easiest done by just renaming SEMANTIC_ATTRIBUTE_SENTRY_SOURCE\n if (processedSpan.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]) {\n safeSetSpanJSONAttributes(processedSpan, {\n [SEMANTIC_ATTRIBUTE_SENTRY_SPAN_SOURCE]: processedSpan.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]?.value,\n });\n }\n\n const spanWithRef = {\n ...processedSpan,\n _segmentSpan: segmentSpan,\n };\n\n client.emit('enqueueSpan', spanWithRef);\n}\n\nfunction applyScopeToSegmentSpan(segmentSpanJSON: SpanV2JSON, scopeData: ScopeData): void {\n // TODO: Apply all scope and request data from auto instrumentation (contexts, request) to segment span\n const { contexts } = scopeData;\n\n safeSetSpanJSONAttributes(segmentSpanJSON, contextsToAttributes(contexts));\n}\n\nfunction applyCommonSpanAttributes(\n spanJSON: SpanV2JSON,\n serializedSegmentSpan: SpanV2JSON,\n client: Client,\n scopeData: ScopeData,\n): void {\n const sdk = client.getSdkMetadata();\n const { release, environment, sendDefaultPii } = client.getOptions();\n\n // avoid overwriting any previously set attributes (from users or potentially our SDK instrumentation)\n safeSetSpanJSONAttributes(spanJSON, {\n [SEMANTIC_ATTRIBUTE_SENTRY_RELEASE]: release,\n [SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT]: environment,\n [SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME]: serializedSegmentSpan.name,\n [SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID]: serializedSegmentSpan.span_id,\n [SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME]: sdk?.sdk?.name,\n [SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION]: sdk?.sdk?.version,\n ...(sendDefaultPii\n ? {\n [SEMANTIC_ATTRIBUTE_USER_ID]: scopeData.user?.id,\n [SEMANTIC_ATTRIBUTE_USER_EMAIL]: scopeData.user?.email,\n [SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: scopeData.user?.ip_address,\n [SEMANTIC_ATTRIBUTE_USER_USERNAME]: scopeData.user?.username,\n }\n : {}),\n ...scopeData.attributes,\n });\n}\n"],"names":["getClient","DEBUG_BUILD","debug","spanToV2JSON","INTERNAL_getSegmentSpan","getCapturedScopesOnSpan","getCombinedScopeData","beforeSendSpan","isV2BeforeSendSpanCallback","applyBeforeSendSpanCallback","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","safeSetSpanJSONAttributes","SEMANTIC_ATTRIBUTE_SENTRY_SPAN_SOURCE","contextsToAttributes","SEMANTIC_ATTRIBUTE_SENTRY_RELEASE","SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT","SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME","SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID","SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME","SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION","SEMANTIC_ATTRIBUTE_USER_ID","SEMANTIC_ATTRIBUTE_USER_EMAIL","SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS","SEMANTIC_ATTRIBUTE_USER_USERNAME"],"mappings":";;;;;;;;;;;;AAyBA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,WAAW,CAAC,IAAI,EAAQ,MAAA,GAASA,uBAAS,EAAE,EAAQ;AACpE,EAAE,IAAI,CAAC,MAAM,EAAE;AACf,IAAIC,0BAAeC,iBAAK,CAAC,IAAI,CAAC,sCAAsC,CAAC;AACrE,IAAI;AACJ,EAAE;;AAEF;AACA,EAAE,MAAM,QAAA,GA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AAG,CAAC;AACJ;;;;"}
@@ -1,121 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- const debugBuild = require('../debug-build.js');
4
- const envelope = require('../envelope.js');
5
- const dynamicSamplingContext = require('../tracing/dynamicSamplingContext.js');
6
- const debugLogger = require('../utils/debug-logger.js');
7
-
8
- /**
9
- * A buffer for span JSON objects that flushes them to Sentry in Span v2 envelopes.
10
- * Handles interval-based flushing, size thresholds, and graceful shutdown.
11
- */
12
- class SpanBuffer {
13
-
14
- constructor(client, options) {
15
- this._spanTreeMap = new Map();
16
- this._client = client;
17
-
18
- const { maxSpanLimit, flushInterval } = options ?? {};
19
-
20
- this._maxSpanLimit = maxSpanLimit && maxSpanLimit > 0 && maxSpanLimit <= 1000 ? maxSpanLimit : 1000;
21
- this._flushInterval = flushInterval && flushInterval > 0 ? flushInterval : 5000;
22
-
23
- this._flushIntervalId = setInterval(() => {
24
- this.flush();
25
- }, this._flushInterval);
26
-
27
- this._client.on('flush', () => {
28
- this.flush();
29
- });
30
- }
31
-
32
- /**
33
- * Add a span to the buffer.
34
- */
35
- addSpan(spanJSON) {
36
- const traceId = spanJSON.trace_id;
37
- let traceBucket = this._spanTreeMap.get(traceId);
38
- if (traceBucket) {
39
- traceBucket.add(spanJSON);
40
- } else {
41
- traceBucket = new Set([spanJSON]);
42
- this._spanTreeMap.set(traceId, traceBucket);
43
- }
44
-
45
- if (traceBucket.size >= this._maxSpanLimit) {
46
- this.flushTrace(traceId);
47
- this._debounceFlushInterval();
48
- }
49
- }
50
-
51
- /**
52
- * Flush all buffered traces.
53
- */
54
- flush() {
55
- if (!this._spanTreeMap.size) {
56
- return;
57
- }
58
-
59
- debugBuild.DEBUG_BUILD && debugLogger.debug.log(`Flushing span tree map with ${this._spanTreeMap.size} traces`);
60
-
61
- this._spanTreeMap.forEach((_, traceId) => {
62
- this.flushTrace(traceId);
63
- });
64
- this._debounceFlushInterval();
65
- }
66
-
67
- /**
68
- * Flush spans of a specific trace.
69
- * In contrast to {@link SpanBuffer.flush}, this method does not flush all traces, but only the one with the given traceId.
70
- */
71
- flushTrace(traceId) {
72
- const traceBucket = this._spanTreeMap.get(traceId);
73
- if (!traceBucket) {
74
- return;
75
- }
76
-
77
- if (!traceBucket.size) {
78
- this._spanTreeMap.delete(traceId);
79
- return;
80
- }
81
-
82
- const firstSpanJSON = traceBucket.values().next().value;
83
-
84
- const segmentSpan = firstSpanJSON?._segmentSpan;
85
- if (!segmentSpan) {
86
- debugBuild.DEBUG_BUILD && debugLogger.debug.warn('No segment span reference found on span JSON, cannot compute DSC');
87
- this._spanTreeMap.delete(traceId);
88
- return;
89
- }
90
-
91
- const dsc = dynamicSamplingContext.getDynamicSamplingContextFromSpan(segmentSpan);
92
-
93
- const cleanedSpans = Array.from(traceBucket).map(spanJSON => {
94
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
95
- const { _segmentSpan, ...cleanSpanJSON } = spanJSON;
96
- return cleanSpanJSON;
97
- });
98
-
99
- const envelope$1 = envelope.createSpanV2Envelope(cleanedSpans, dsc, this._client);
100
-
101
- debugBuild.DEBUG_BUILD && debugLogger.debug.log(`Sending span envelope for trace ${traceId} with ${cleanedSpans.length} spans`);
102
-
103
- this._client.sendEnvelope(envelope$1).then(null, reason => {
104
- debugBuild.DEBUG_BUILD && debugLogger.debug.error('Error while sending span stream envelope:', reason);
105
- });
106
-
107
- this._spanTreeMap.delete(traceId);
108
- }
109
-
110
- _debounceFlushInterval() {
111
- if (this._flushIntervalId) {
112
- clearInterval(this._flushIntervalId);
113
- }
114
- this._flushIntervalId = setInterval(() => {
115
- this.flush();
116
- }, this._flushInterval);
117
- }
118
- }
119
-
120
- exports.SpanBuffer = SpanBuffer;
121
- //# sourceMappingURL=spanBuffer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spanBuffer.js","sources":["../../../src/spans/spanBuffer.ts"],"sourcesContent":["import type { Client } from '../client';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { createSpanV2Envelope } from '../envelope';\nimport { getDynamicSamplingContextFromSpan } from '../tracing/dynamicSamplingContext';\nimport type { SpanV2JSON, SpanV2JSONWithSegmentRef } from '../types-hoist/span';\nimport { debug } from '../utils/debug-logger';\n\nexport interface SpanBufferOptions {\n /** Max spans per trace before auto-flush (default: 1000) */\n maxSpanLimit?: number;\n /** Flush interval in ms (default: 5000) */\n flushInterval?: number;\n}\n\n/**\n * A buffer for span JSON objects that flushes them to Sentry in Span v2 envelopes.\n * Handles interval-based flushing, size thresholds, and graceful shutdown.\n */\nexport class SpanBuffer {\n private _spanTreeMap: Map<string, Set<SpanV2JSONWithSegmentRef>>;\n private _flushIntervalId: ReturnType<typeof setInterval> | null;\n private _client: Client;\n private _maxSpanLimit: number;\n private _flushInterval: number;\n\n public constructor(client: Client, options?: SpanBufferOptions) {\n this._spanTreeMap = new Map();\n this._client = client;\n\n const { maxSpanLimit, flushInterval } = options ?? {};\n\n this._maxSpanLimit = maxSpanLimit && maxSpanLimit > 0 && maxSpanLimit <= 1000 ? maxSpanLimit : 1000;\n this._flushInterval = flushInterval && flushInterval > 0 ? flushInterval : 5_000;\n\n this._flushIntervalId = setInterval(() => {\n this.flush();\n }, this._flushInterval);\n\n this._client.on('flush', () => {\n this.flush();\n });\n }\n\n /**\n * Add a span to the buffer.\n */\n public addSpan(spanJSON: SpanV2JSONWithSegmentRef): void {\n const traceId = spanJSON.trace_id;\n let traceBucket = this._spanTreeMap.get(traceId);\n if (traceBucket) {\n traceBucket.add(spanJSON);\n } else {\n traceBucket = new Set([spanJSON]);\n this._spanTreeMap.set(traceId, traceBucket);\n }\n\n if (traceBucket.size >= this._maxSpanLimit) {\n this.flushTrace(traceId);\n this._debounceFlushInterval();\n }\n }\n\n /**\n * Flush all buffered traces.\n */\n public flush(): void {\n if (!this._spanTreeMap.size) {\n return;\n }\n\n DEBUG_BUILD && debug.log(`Flushing span tree map with ${this._spanTreeMap.size} traces`);\n\n this._spanTreeMap.forEach((_, traceId) => {\n this.flushTrace(traceId);\n });\n this._debounceFlushInterval();\n }\n\n /**\n * Flush spans of a specific trace.\n * In contrast to {@link SpanBuffer.flush}, this method does not flush all traces, but only the one with the given traceId.\n */\n public flushTrace(traceId: string): void {\n const traceBucket = this._spanTreeMap.get(traceId);\n if (!traceBucket) {\n return;\n }\n\n if (!traceBucket.size) {\n this._spanTreeMap.delete(traceId);\n return;\n }\n\n const firstSpanJSON = traceBucket.values().next().value;\n\n const segmentSpan = firstSpanJSON?._segmentSpan;\n if (!segmentSpan) {\n DEBUG_BUILD && debug.warn('No segment span reference found on span JSON, cannot compute DSC');\n this._spanTreeMap.delete(traceId);\n return;\n }\n\n const dsc = getDynamicSamplingContextFromSpan(segmentSpan);\n\n const cleanedSpans: SpanV2JSON[] = Array.from(traceBucket).map(spanJSON => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { _segmentSpan, ...cleanSpanJSON } = spanJSON;\n return cleanSpanJSON;\n });\n\n const envelope = createSpanV2Envelope(cleanedSpans, dsc, this._client);\n\n DEBUG_BUILD && debug.log(`Sending span envelope for trace ${traceId} with ${cleanedSpans.length} spans`);\n\n this._client.sendEnvelope(envelope).then(null, reason => {\n DEBUG_BUILD && debug.error('Error while sending span stream envelope:', reason);\n });\n\n this._spanTreeMap.delete(traceId);\n }\n\n private _debounceFlushInterval(): void {\n if (this._flushIntervalId) {\n clearInterval(this._flushIntervalId);\n }\n this._flushIntervalId = setInterval(() => {\n this.flush();\n }, this._flushInterval);\n }\n}\n"],"names":["DEBUG_BUILD","debug","getDynamicSamplingContextFromSpan","envelope","createSpanV2Envelope"],"mappings":";;;;;;;AAcA;AACA;AACA;AACA;AACO,MAAM,UAAA,CAAW;;AAOxB,GAAS,WAAW,CAAC,MAAM,EAAU,OAAO,EAAsB;AAClE,IAAI,IAAI,CAAC,YAAA,GAAe,IAAI,GAAG,EAAE;AACjC,IAAI,IAAI,CAAC,OAAA,GAAU,MAAM;;AAEzB,IAAI,MAAM,EAAE,YAAY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