@sentry/opentelemetry 7.105.0 → 8.0.0-alpha.1

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 (130) hide show
  1. package/README.md +8 -14
  2. package/cjs/asyncContextStrategy.js +87 -19
  3. package/cjs/asyncContextStrategy.js.map +1 -1
  4. package/cjs/constants.js +14 -0
  5. package/cjs/constants.js.map +1 -1
  6. package/cjs/contextManager.js +37 -15
  7. package/cjs/contextManager.js.map +1 -1
  8. package/cjs/custom/client.js +0 -28
  9. package/cjs/custom/client.js.map +1 -1
  10. package/cjs/custom/getCurrentHub.js +106 -0
  11. package/cjs/custom/getCurrentHub.js.map +1 -0
  12. package/cjs/custom/hub.js +3 -136
  13. package/cjs/custom/hub.js.map +1 -1
  14. package/cjs/custom/transaction.js +3 -32
  15. package/cjs/custom/transaction.js.map +1 -1
  16. package/cjs/index.js +7 -7
  17. package/cjs/index.js.map +1 -1
  18. package/cjs/propagator.js +39 -12
  19. package/cjs/propagator.js.map +1 -1
  20. package/cjs/sampler.js +0 -1
  21. package/cjs/sampler.js.map +1 -1
  22. package/cjs/semanticAttributes.js +0 -9
  23. package/cjs/semanticAttributes.js.map +1 -1
  24. package/cjs/setupEventContextTrace.js +12 -7
  25. package/cjs/setupEventContextTrace.js.map +1 -1
  26. package/cjs/spanExporter.js +69 -58
  27. package/cjs/spanExporter.js.map +1 -1
  28. package/cjs/spanProcessor.js +14 -19
  29. package/cjs/spanProcessor.js.map +1 -1
  30. package/cjs/trace.js +120 -23
  31. package/cjs/trace.js.map +1 -1
  32. package/cjs/utils/addOriginToSpan.js +2 -2
  33. package/cjs/utils/addOriginToSpan.js.map +1 -1
  34. package/cjs/utils/contextData.js +38 -0
  35. package/cjs/utils/contextData.js.map +1 -1
  36. package/cjs/utils/dynamicSamplingContext.js +64 -0
  37. package/cjs/utils/dynamicSamplingContext.js.map +1 -0
  38. package/cjs/utils/spanData.js +23 -23
  39. package/cjs/utils/spanData.js.map +1 -1
  40. package/esm/asyncContextStrategy.js +89 -18
  41. package/esm/asyncContextStrategy.js.map +1 -1
  42. package/esm/constants.js +10 -1
  43. package/esm/constants.js.map +1 -1
  44. package/esm/contextManager.js +36 -17
  45. package/esm/contextManager.js.map +1 -1
  46. package/esm/custom/client.js +0 -28
  47. package/esm/custom/client.js.map +1 -1
  48. package/esm/custom/getCurrentHub.js +101 -0
  49. package/esm/custom/getCurrentHub.js.map +1 -0
  50. package/esm/custom/hub.js +4 -133
  51. package/esm/custom/hub.js.map +1 -1
  52. package/esm/custom/transaction.js +4 -32
  53. package/esm/custom/transaction.js.map +1 -1
  54. package/esm/index.js +6 -5
  55. package/esm/index.js.map +1 -1
  56. package/esm/propagator.js +42 -15
  57. package/esm/propagator.js.map +1 -1
  58. package/esm/sampler.js +0 -1
  59. package/esm/sampler.js.map +1 -1
  60. package/esm/semanticAttributes.js +0 -9
  61. package/esm/semanticAttributes.js.map +1 -1
  62. package/esm/setupEventContextTrace.js +14 -9
  63. package/esm/setupEventContextTrace.js.map +1 -1
  64. package/esm/spanExporter.js +70 -59
  65. package/esm/spanExporter.js.map +1 -1
  66. package/esm/spanProcessor.js +10 -15
  67. package/esm/spanProcessor.js.map +1 -1
  68. package/esm/trace.js +122 -26
  69. package/esm/trace.js.map +1 -1
  70. package/esm/utils/addOriginToSpan.js +2 -2
  71. package/esm/utils/addOriginToSpan.js.map +1 -1
  72. package/esm/utils/contextData.js +36 -2
  73. package/esm/utils/contextData.js.map +1 -1
  74. package/esm/utils/dynamicSamplingContext.js +59 -0
  75. package/esm/utils/dynamicSamplingContext.js.map +1 -0
  76. package/esm/utils/spanData.js +22 -20
  77. package/esm/utils/spanData.js.map +1 -1
  78. package/package.json +5 -5
  79. package/types/asyncContextStrategy.d.ts.map +1 -1
  80. package/types/constants.d.ts +5 -0
  81. package/types/constants.d.ts.map +1 -1
  82. package/types/contextManager.d.ts +1 -1
  83. package/types/contextManager.d.ts.map +1 -1
  84. package/types/custom/client.d.ts.map +1 -1
  85. package/types/custom/getCurrentHub.d.ts +7 -0
  86. package/types/custom/getCurrentHub.d.ts.map +1 -0
  87. package/types/custom/hub.d.ts +2 -33
  88. package/types/custom/hub.d.ts.map +1 -1
  89. package/types/custom/transaction.d.ts +1 -10
  90. package/types/custom/transaction.d.ts.map +1 -1
  91. package/types/index.d.ts +6 -5
  92. package/types/index.d.ts.map +1 -1
  93. package/types/propagator.d.ts.map +1 -1
  94. package/types/semanticAttributes.d.ts +0 -9
  95. package/types/semanticAttributes.d.ts.map +1 -1
  96. package/types/setupEventContextTrace.d.ts.map +1 -1
  97. package/types/spanExporter.d.ts.map +1 -1
  98. package/types/spanProcessor.d.ts +1 -5
  99. package/types/spanProcessor.d.ts.map +1 -1
  100. package/types/trace.d.ts +14 -3
  101. package/types/trace.d.ts.map +1 -1
  102. package/types/types.d.ts +7 -12
  103. package/types/types.d.ts.map +1 -1
  104. package/types/utils/addOriginToSpan.d.ts.map +1 -1
  105. package/types/utils/contextData.d.ts +22 -1
  106. package/types/utils/contextData.d.ts.map +1 -1
  107. package/types/utils/dynamicSamplingContext.d.ts +11 -0
  108. package/types/utils/dynamicSamplingContext.d.ts.map +1 -0
  109. package/types/utils/spanData.d.ts +14 -8
  110. package/types/utils/spanData.d.ts.map +1 -1
  111. package/types-ts3.8/constants.d.ts +5 -0
  112. package/types-ts3.8/contextManager.d.ts +1 -1
  113. package/types-ts3.8/custom/getCurrentHub.d.ts +7 -0
  114. package/types-ts3.8/custom/hub.d.ts +2 -33
  115. package/types-ts3.8/custom/transaction.d.ts +1 -10
  116. package/types-ts3.8/index.d.ts +6 -5
  117. package/types-ts3.8/semanticAttributes.d.ts +0 -9
  118. package/types-ts3.8/spanProcessor.d.ts +1 -5
  119. package/types-ts3.8/trace.d.ts +14 -3
  120. package/types-ts3.8/types.d.ts +7 -12
  121. package/types-ts3.8/utils/contextData.d.ts +22 -1
  122. package/types-ts3.8/utils/dynamicSamplingContext.d.ts +11 -0
  123. package/types-ts3.8/utils/spanData.d.ts +14 -8
  124. package/cjs/custom/scope.js +0 -202
  125. package/cjs/custom/scope.js.map +0 -1
  126. package/esm/custom/scope.js +0 -200
  127. package/esm/custom/scope.js.map +0 -1
  128. package/types/custom/scope.d.ts +0 -42
  129. package/types/custom/scope.d.ts.map +0 -1
  130. package/types-ts3.8/custom/scope.d.ts +0 -42
@@ -1 +1 @@
1
- {"version":3,"file":"setupEventContextTrace.js","sources":["../../src/setupEventContextTrace.ts"],"sourcesContent":["import type { Client } from '@sentry/types';\n\nimport { getActiveSpan } from './utils/getActiveSpan';\nimport { spanHasParentId } from './utils/spanTypes';\n\n/** Ensure the `trace` context is set on all events. */\nexport function setupEventContextTrace(client: Client): void {\n if (!client.addEventProcessor) {\n return;\n }\n\n client.addEventProcessor(event => {\n const span = getActiveSpan();\n if (!span) {\n return event;\n }\n\n const spanContext = span.spanContext();\n\n // If event has already set `trace` context, use that one.\n event.contexts = {\n trace: {\n trace_id: spanContext.traceId,\n span_id: spanContext.spanId,\n parent_span_id: spanHasParentId(span) ? span.parentSpanId : undefined,\n },\n ...event.contexts,\n };\n\n return event;\n });\n}\n"],"names":[],"mappings":";;;AAKA;AACO,SAAS,sBAAsB,CAAC,MAAM,EAAgB;AAC7D,EAAE,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE;AACjC,IAAI,OAAM;AACV,GAAE;AACF;AACA,EAAE,MAAM,CAAC,iBAAiB,CAAC,SAAS;AACpC,IAAI,MAAM,IAAA,GAAO,aAAa,EAAE,CAAA;AAChC,IAAI,IAAI,CAAC,IAAI,EAAE;AACf,MAAM,OAAO,KAAK,CAAA;AAClB,KAAI;AACJ;AACA,IAAI,MAAM,WAAY,GAAE,IAAI,CAAC,WAAW,EAAE,CAAA;AAC1C;AACA;AACA,IAAI,KAAK,CAAC,QAAA,GAAW;AACrB,MAAM,KAAK,EAAE;AACb,QAAQ,QAAQ,EAAE,WAAW,CAAC,OAAO;AACrC,QAAQ,OAAO,EAAE,WAAW,CAAC,MAAM;AACnC,QAAQ,cAAc,EAAE,eAAe,CAAC,IAAI,CAAE,GAAE,IAAI,CAAC,YAAa,GAAE,SAAS;AAC7E,OAAO;AACP,MAAM,GAAG,KAAK,CAAC,QAAQ;AACvB,KAAK,CAAA;AACL;AACA,IAAI,OAAO,KAAK,CAAA;AAChB,GAAG,CAAC,CAAA;AACJ;;;;"}
1
+ {"version":3,"file":"setupEventContextTrace.js","sources":["../../src/setupEventContextTrace.ts"],"sourcesContent":["import type { Client } from '@sentry/types';\nimport { dropUndefinedKeys } from '@sentry/utils';\n\nimport { getActiveSpan, getRootSpan } from './utils/getActiveSpan';\nimport { spanHasName, spanHasParentId } from './utils/spanTypes';\n\n/** Ensure the `trace` context is set on all events. */\nexport function setupEventContextTrace(client: Client): void {\n client.addEventProcessor(event => {\n const span = getActiveSpan();\n // For transaction events, this is handled separately\n // Because the active span may not be the span that is actually the transaction event\n if (!span || event.type === 'transaction') {\n return event;\n }\n\n const spanContext = span.spanContext();\n\n // If event has already set `trace` context, use that one.\n event.contexts = {\n trace: dropUndefinedKeys({\n trace_id: spanContext.traceId,\n span_id: spanContext.spanId,\n parent_span_id: spanHasParentId(span) ? span.parentSpanId : undefined,\n }),\n ...event.contexts,\n };\n\n const rootSpan = getRootSpan(span);\n const transactionName = spanHasName(rootSpan) ? rootSpan.name : undefined;\n if (transactionName) {\n event.tags = { transaction: transactionName, ...event.tags };\n }\n\n return event;\n });\n}\n"],"names":[],"mappings":";;;;AAMA;AACO,SAAS,sBAAsB,CAAC,MAAM,EAAgB;AAC7D,EAAE,MAAM,CAAC,iBAAiB,CAAC,SAAS;AACpC,IAAI,MAAM,IAAA,GAAO,aAAa,EAAE,CAAA;AAChC;AACA;AACA,IAAI,IAAI,CAAC,IAAK,IAAG,KAAK,CAAC,IAAA,KAAS,aAAa,EAAE;AAC/C,MAAM,OAAO,KAAK,CAAA;AAClB,KAAI;AACJ;AACA,IAAI,MAAM,WAAY,GAAE,IAAI,CAAC,WAAW,EAAE,CAAA;AAC1C;AACA;AACA,IAAI,KAAK,CAAC,QAAA,GAAW;AACrB,MAAM,KAAK,EAAE,iBAAiB,CAAC;AAC/B,QAAQ,QAAQ,EAAE,WAAW,CAAC,OAAO;AACrC,QAAQ,OAAO,EAAE,WAAW,CAAC,MAAM;AACnC,QAAQ,cAAc,EAAE,eAAe,CAAC,IAAI,CAAE,GAAE,IAAI,CAAC,YAAa,GAAE,SAAS;AAC7E,OAAO,CAAC;AACR,MAAM,GAAG,KAAK,CAAC,QAAQ;AACvB,KAAK,CAAA;AACL;AACA,IAAI,MAAM,QAAS,GAAE,WAAW,CAAC,IAAI,CAAC,CAAA;AACtC,IAAI,MAAM,eAAA,GAAkB,WAAW,CAAC,QAAQ,CAAE,GAAE,QAAQ,CAAC,IAAK,GAAE,SAAS,CAAA;AAC7E,IAAI,IAAI,eAAe,EAAE;AACzB,MAAM,KAAK,CAAC,IAAK,GAAE,EAAE,WAAW,EAAE,eAAe,EAAE,GAAG,KAAK,CAAC,MAAM,CAAA;AAClE,KAAI;AACJ;AACA,IAAI,OAAO,KAAK,CAAA;AAChB,GAAG,CAAC,CAAA;AACJ;;;;"}
@@ -1,18 +1,18 @@
1
1
  import { SpanKind } from '@opentelemetry/api';
2
2
  import { ExportResultCode } from '@opentelemetry/core';
3
3
  import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
4
- import { flush, getCurrentScope, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE } from '@sentry/core';
5
- import { logger } from '@sentry/utils';
6
- import { getCurrentHub } from './custom/hub.js';
4
+ import { getCurrentHub, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core';
5
+ import { logger, dropUndefinedKeys, addNonEnumerableProperty } from '@sentry/utils';
7
6
  import { startTransaction } from './custom/transaction.js';
8
7
  import { DEBUG_BUILD } from './debug-build.js';
9
8
  import { InternalSentrySemanticAttributes } from './semanticAttributes.js';
10
9
  import { convertOtelTimeToSeconds } from './utils/convertOtelTimeToSeconds.js';
10
+ import { getDynamicSamplingContextFromSpan } from './utils/dynamicSamplingContext.js';
11
11
  import { getRequestSpanData } from './utils/getRequestSpanData.js';
12
12
  import { groupSpansWithParents } from './utils/groupSpansWithParents.js';
13
13
  import { mapStatus } from './utils/mapStatus.js';
14
14
  import { parseSpanDescription } from './utils/parseSpanDescription.js';
15
- import { getSpanFinishScope, getSpanScope, getSpanHub, getSpanMetadata } from './utils/spanData.js';
15
+ import { getSpanHub, getSpanMetadata, getSpanScopes } from './utils/spanData.js';
16
16
 
17
17
  /**
18
18
  * A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.
@@ -63,14 +63,17 @@ class SentrySpanExporter {
63
63
 
64
64
  /** @inheritDoc */
65
65
  shutdown() {
66
+ const forceFlush = this.forceFlush();
66
67
  this._stopped = true;
67
68
  this._finishedSpans = [];
68
- return this.forceFlush();
69
+ return forceFlush;
69
70
  }
70
71
 
71
72
  /** @inheritDoc */
72
- async forceFlush() {
73
- await flush();
73
+ forceFlush() {
74
+ return new Promise(resolve => {
75
+ this.export(this._finishedSpans, () => resolve());
76
+ });
74
77
  }
75
78
  }
76
79
 
@@ -98,10 +101,7 @@ function maybeSend(spans) {
98
101
  createAndFinishSpanForOtelSpan(child, transaction, remaining);
99
102
  });
100
103
 
101
- // Now finish the transaction, which will send it together with all the spans
102
- // We make sure to use the finish scope
103
- const scope = getScopeForTransactionFinish(span);
104
- transaction.finishWithScope(convertOtelTimeToSeconds(span.endTime), scope);
104
+ transaction.end(span.endTime);
105
105
  });
106
106
 
107
107
  return Array.from(remaining)
@@ -109,17 +109,6 @@ function maybeSend(spans) {
109
109
  .filter((span) => !!span);
110
110
  }
111
111
 
112
- function getScopeForTransactionFinish(span) {
113
- // The finish scope should normally always be there (and it is already a clone),
114
- // but for the sake of type safety we fall back to a clone of the current scope
115
- const scope = getSpanFinishScope(span) || getCurrentScope().clone();
116
- scope.setContext('otel', {
117
- attributes: removeSentryAttributes(span.attributes),
118
- resource: span.resource.attributes,
119
- });
120
- return scope;
121
- }
122
-
123
112
  function getCompletedRootNodes(nodes) {
124
113
  return nodes.filter((node) => !!node.span && !node.parentNode);
125
114
  }
@@ -132,15 +121,15 @@ function shouldCleanupSpan(span, maxStartTimeOffsetSeconds) {
132
121
  function parseSpan(span) {
133
122
  const attributes = span.attributes;
134
123
 
135
- const origin = attributes[InternalSentrySemanticAttributes.ORIGIN] ;
136
- const op = attributes[InternalSentrySemanticAttributes.OP] ;
137
- const source = attributes[InternalSentrySemanticAttributes.SOURCE] ;
124
+ const origin = attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] ;
125
+ const op = attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] ;
126
+ const source = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] ;
138
127
 
139
128
  return { origin, op, source };
140
129
  }
141
130
 
142
131
  function createTransactionForOtelSpan(span) {
143
- const scope = getSpanScope(span);
132
+ // eslint-disable-next-line deprecation/deprecation
144
133
  const hub = getSpanHub(span) || getCurrentHub();
145
134
  const spanContext = span.spanContext();
146
135
  const spanId = spanContext.spanId;
@@ -148,10 +137,21 @@ function createTransactionForOtelSpan(span) {
148
137
  const parentSpanId = span.parentSpanId;
149
138
 
150
139
  const parentSampled = span.attributes[InternalSentrySemanticAttributes.PARENT_SAMPLED] ;
151
- const dynamicSamplingContext = scope ? scope.getPropagationContext().dsc : undefined;
152
140
 
153
- const { op, description, tags, data, origin, source } = getSpanData(span);
141
+ const { op, description, data, origin, source } = getSpanData(span);
154
142
  const metadata = getSpanMetadata(span);
143
+ const capturedSpanScopes = getSpanScopes(span);
144
+
145
+ const sampleRate = span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] ;
146
+
147
+ const attributes = {
148
+ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
149
+ [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,
150
+ ...data,
151
+ ...removeSentryAttributes(span.attributes),
152
+ };
153
+
154
+ const dynamicSamplingContext = getDynamicSamplingContextFromSpan(span);
155
155
 
156
156
  const transaction = startTransaction(hub, {
157
157
  spanId,
@@ -160,20 +160,39 @@ function createTransactionForOtelSpan(span) {
160
160
  parentSampled,
161
161
  name: description,
162
162
  op,
163
- instrumenter: 'otel',
164
- status: mapStatus(span),
165
163
  startTimestamp: convertOtelTimeToSeconds(span.startTime),
166
164
  metadata: {
167
- dynamicSamplingContext,
168
- source,
169
- sampleRate: span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] ,
165
+ ...dropUndefinedKeys({
166
+ dynamicSamplingContext,
167
+ sampleRate,
168
+ }),
170
169
  ...metadata,
171
170
  },
172
- data: removeSentryAttributes(data),
171
+ attributes,
173
172
  origin,
174
- tags,
175
173
  sampled: true,
176
- }) ;
174
+ });
175
+
176
+ transaction.setStatus(mapStatus(span));
177
+
178
+ // We currently don't want to write this to the scope because it would mutate it.
179
+ // In the future we will likely have some sort of transaction payload factory where we can pass this context in directly
180
+ // eslint-disable-next-line deprecation/deprecation
181
+ transaction.setContext('otel', {
182
+ attributes: removeSentryAttributes(span.attributes),
183
+ resource: span.resource.attributes,
184
+ });
185
+
186
+ if (capturedSpanScopes) {
187
+ // Ensure the `transaction` tag is correctly set on the transaction event
188
+ const scope = capturedSpanScopes.scope.clone();
189
+ scope.addEventProcessor(event => {
190
+ event.tags = { transaction: description, ...event.tags };
191
+ return event;
192
+ });
193
+
194
+ setCapturedScopesOnTransaction(transaction, scope, capturedSpanScopes.isolationScope);
195
+ }
177
196
 
178
197
  return transaction;
179
198
  }
@@ -195,21 +214,19 @@ function createAndFinishSpanForOtelSpan(node, sentryParentSpan, remaining) {
195
214
  const spanId = span.spanContext().spanId;
196
215
  const { attributes } = span;
197
216
 
198
- const { op, description, tags, data, origin } = getSpanData(span);
217
+ const { op, description, data, origin } = getSpanData(span);
199
218
  const allData = { ...removeSentryAttributes(attributes), ...data };
200
219
 
201
220
  // eslint-disable-next-line deprecation/deprecation
202
221
  const sentrySpan = sentryParentSpan.startChild({
203
- description,
222
+ name: description,
204
223
  op,
205
224
  data: allData,
206
- status: mapStatus(span),
207
- instrumenter: 'otel',
208
225
  startTimestamp: convertOtelTimeToSeconds(span.startTime),
209
226
  spanId,
210
227
  origin,
211
- tags,
212
- });
228
+ }) ;
229
+ sentrySpan.setStatus(mapStatus(span));
213
230
 
214
231
  node.children.forEach(child => {
215
232
  createAndFinishSpanForOtelSpan(child, sentrySpan, remaining);
@@ -227,7 +244,6 @@ function getSpanData(span)
227
244
  const op = definedOp || inferredOp;
228
245
  const source = definedSource || inferredSource;
229
246
 
230
- const tags = getTags(span);
231
247
  const data = { ...inferredData, ...getData(span) };
232
248
 
233
249
  return {
@@ -235,7 +251,6 @@ function getSpanData(span)
235
251
  description,
236
252
  source,
237
253
  origin,
238
- tags,
239
254
  data,
240
255
  };
241
256
  }
@@ -249,27 +264,12 @@ function removeSentryAttributes(data) {
249
264
 
250
265
  /* eslint-disable @typescript-eslint/no-dynamic-delete */
251
266
  delete cleanedData[InternalSentrySemanticAttributes.PARENT_SAMPLED];
252
- delete cleanedData[InternalSentrySemanticAttributes.ORIGIN];
253
- delete cleanedData[InternalSentrySemanticAttributes.OP];
254
- delete cleanedData[InternalSentrySemanticAttributes.SOURCE];
255
267
  delete cleanedData[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];
256
268
  /* eslint-enable @typescript-eslint/no-dynamic-delete */
257
269
 
258
270
  return cleanedData;
259
271
  }
260
272
 
261
- function getTags(span) {
262
- const attributes = span.attributes;
263
- const tags = {};
264
-
265
- if (attributes[SemanticAttributes.HTTP_STATUS_CODE]) {
266
- const statusCode = attributes[SemanticAttributes.HTTP_STATUS_CODE] ;
267
- tags['http.status_code'] = `${statusCode}`;
268
- }
269
-
270
- return tags;
271
- }
272
-
273
273
  function getData(span) {
274
274
  const attributes = span.attributes;
275
275
  const data = {
@@ -297,5 +297,16 @@ function getData(span) {
297
297
  return data;
298
298
  }
299
299
 
300
+ const SCOPE_ON_START_SPAN_FIELD = '_sentryScope';
301
+ const ISOLATION_SCOPE_ON_START_SPAN_FIELD = '_sentryIsolationScope';
302
+
303
+ /** Sets the scope and isolation scope to be used for when the transaction is finished. */
304
+ function setCapturedScopesOnTransaction(span, scope, isolationScope) {
305
+ if (span) {
306
+ addNonEnumerableProperty(span, ISOLATION_SCOPE_ON_START_SPAN_FIELD, isolationScope);
307
+ addNonEnumerableProperty(span, SCOPE_ON_START_SPAN_FIELD, scope);
308
+ }
309
+ }
310
+
300
311
  export { SentrySpanExporter };
301
312
  //# sourceMappingURL=spanExporter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"spanExporter.js","sources":["../../src/spanExporter.ts"],"sourcesContent":["import { SpanKind } from '@opentelemetry/api';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { ExportResultCode } from '@opentelemetry/core';\nimport type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, flush, getCurrentScope } from '@sentry/core';\nimport type { Scope, Span as SentrySpan, SpanOrigin, TransactionSource } from '@sentry/types';\nimport { logger } from '@sentry/utils';\n\nimport { getCurrentHub } from './custom/hub';\nimport type { OpenTelemetryTransaction } from './custom/transaction';\nimport { startTransaction } from './custom/transaction';\nimport { DEBUG_BUILD } from './debug-build';\nimport { InternalSentrySemanticAttributes } from './semanticAttributes';\nimport { convertOtelTimeToSeconds } from './utils/convertOtelTimeToSeconds';\nimport { getRequestSpanData } from './utils/getRequestSpanData';\nimport type { SpanNode } from './utils/groupSpansWithParents';\nimport { groupSpansWithParents } from './utils/groupSpansWithParents';\nimport { mapStatus } from './utils/mapStatus';\nimport { parseSpanDescription } from './utils/parseSpanDescription';\nimport { getSpanFinishScope, getSpanHub, getSpanMetadata, getSpanScope } from './utils/spanData';\n\ntype SpanNodeCompleted = SpanNode & { span: ReadableSpan };\n\n/**\n * A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.\n */\nexport class SentrySpanExporter implements SpanExporter {\n private _finishedSpans: ReadableSpan[];\n private _stopped: boolean;\n\n public constructor() {\n this._stopped = false;\n this._finishedSpans = [];\n }\n\n /** @inheritDoc */\n public export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {\n if (this._stopped) {\n return resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Exporter has been stopped'),\n });\n }\n\n const openSpanCount = this._finishedSpans.length;\n const newSpanCount = spans.length;\n\n this._finishedSpans.push(...spans);\n\n const remainingSpans = maybeSend(this._finishedSpans);\n\n const remainingOpenSpanCount = remainingSpans.length;\n const sentSpanCount = openSpanCount + newSpanCount - remainingOpenSpanCount;\n\n DEBUG_BUILD &&\n logger.log(`SpanExporter exported ${sentSpanCount} spans, ${remainingOpenSpanCount} unsent spans remaining`);\n\n this._finishedSpans = remainingSpans.filter(span => {\n const shouldDrop = shouldCleanupSpan(span, 5 * 60);\n DEBUG_BUILD &&\n shouldDrop &&\n logger.log(\n `SpanExporter dropping span ${span.name} (${\n span.spanContext().spanId\n }) because it is pending for more than 5 minutes.`,\n );\n return !shouldDrop;\n });\n\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n /** @inheritDoc */\n public shutdown(): Promise<void> {\n this._stopped = true;\n this._finishedSpans = [];\n return this.forceFlush();\n }\n\n /** @inheritDoc */\n public async forceFlush(): Promise<void> {\n await flush();\n }\n}\n\n/**\n * Send the given spans, but only if they are part of a finished transaction.\n *\n * Returns the unsent spans.\n * Spans remain unsent when their parent span is not yet finished.\n * This will happen regularly, as child spans are generally finished before their parents.\n * But it _could_ also happen because, for whatever reason, a parent span was lost.\n * In this case, we'll eventually need to clean this up.\n */\nfunction maybeSend(spans: ReadableSpan[]): ReadableSpan[] {\n const grouped = groupSpansWithParents(spans);\n const remaining = new Set(grouped);\n\n const rootNodes = getCompletedRootNodes(grouped);\n\n rootNodes.forEach(root => {\n remaining.delete(root);\n const span = root.span;\n const transaction = createTransactionForOtelSpan(span);\n\n root.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, transaction, remaining);\n });\n\n // Now finish the transaction, which will send it together with all the spans\n // We make sure to use the finish scope\n const scope = getScopeForTransactionFinish(span);\n transaction.finishWithScope(convertOtelTimeToSeconds(span.endTime), scope);\n });\n\n return Array.from(remaining)\n .map(node => node.span)\n .filter((span): span is ReadableSpan => !!span);\n}\n\nfunction getScopeForTransactionFinish(span: ReadableSpan): Scope {\n // The finish scope should normally always be there (and it is already a clone),\n // but for the sake of type safety we fall back to a clone of the current scope\n const scope = getSpanFinishScope(span) || getCurrentScope().clone();\n scope.setContext('otel', {\n attributes: removeSentryAttributes(span.attributes),\n resource: span.resource.attributes,\n });\n return scope;\n}\n\nfunction getCompletedRootNodes(nodes: SpanNode[]): SpanNodeCompleted[] {\n return nodes.filter((node): node is SpanNodeCompleted => !!node.span && !node.parentNode);\n}\n\nfunction shouldCleanupSpan(span: ReadableSpan, maxStartTimeOffsetSeconds: number): boolean {\n const cutoff = Date.now() / 1000 - maxStartTimeOffsetSeconds;\n return convertOtelTimeToSeconds(span.startTime) < cutoff;\n}\n\nfunction parseSpan(span: ReadableSpan): { op?: string; origin?: SpanOrigin; source?: TransactionSource } {\n const attributes = span.attributes;\n\n const origin = attributes[InternalSentrySemanticAttributes.ORIGIN] as SpanOrigin | undefined;\n const op = attributes[InternalSentrySemanticAttributes.OP] as string | undefined;\n const source = attributes[InternalSentrySemanticAttributes.SOURCE] as TransactionSource | undefined;\n\n return { origin, op, source };\n}\n\nfunction createTransactionForOtelSpan(span: ReadableSpan): OpenTelemetryTransaction {\n const scope = getSpanScope(span);\n const hub = getSpanHub(span) || getCurrentHub();\n const spanContext = span.spanContext();\n const spanId = spanContext.spanId;\n const traceId = spanContext.traceId;\n const parentSpanId = span.parentSpanId;\n\n const parentSampled = span.attributes[InternalSentrySemanticAttributes.PARENT_SAMPLED] as boolean | undefined;\n const dynamicSamplingContext = scope ? scope.getPropagationContext().dsc : undefined;\n\n const { op, description, tags, data, origin, source } = getSpanData(span);\n const metadata = getSpanMetadata(span);\n\n const transaction = startTransaction(hub, {\n spanId,\n traceId,\n parentSpanId,\n parentSampled,\n name: description,\n op,\n instrumenter: 'otel',\n status: mapStatus(span),\n startTimestamp: convertOtelTimeToSeconds(span.startTime),\n metadata: {\n dynamicSamplingContext,\n source,\n sampleRate: span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] as number | undefined,\n ...metadata,\n },\n data: removeSentryAttributes(data),\n origin,\n tags,\n sampled: true,\n }) as OpenTelemetryTransaction;\n\n return transaction;\n}\n\nfunction createAndFinishSpanForOtelSpan(node: SpanNode, sentryParentSpan: SentrySpan, remaining: Set<SpanNode>): void {\n remaining.delete(node);\n const span = node.span;\n\n const shouldDrop = !span;\n\n // If this span should be dropped, we still want to create spans for the children of this\n if (shouldDrop) {\n node.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, sentryParentSpan, remaining);\n });\n return;\n }\n\n const spanId = span.spanContext().spanId;\n const { attributes } = span;\n\n const { op, description, tags, data, origin } = getSpanData(span);\n const allData = { ...removeSentryAttributes(attributes), ...data };\n\n // eslint-disable-next-line deprecation/deprecation\n const sentrySpan = sentryParentSpan.startChild({\n description,\n op,\n data: allData,\n status: mapStatus(span),\n instrumenter: 'otel',\n startTimestamp: convertOtelTimeToSeconds(span.startTime),\n spanId,\n origin,\n tags,\n });\n\n node.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, sentrySpan, remaining);\n });\n\n sentrySpan.end(convertOtelTimeToSeconds(span.endTime));\n}\n\nfunction getSpanData(span: ReadableSpan): {\n tags: Record<string, string>;\n data: Record<string, unknown>;\n op?: string;\n description: string;\n source?: TransactionSource;\n origin?: SpanOrigin;\n} {\n const { op: definedOp, source: definedSource, origin } = parseSpan(span);\n const { op: inferredOp, description, source: inferredSource, data: inferredData } = parseSpanDescription(span);\n\n const op = definedOp || inferredOp;\n const source = definedSource || inferredSource;\n\n const tags = getTags(span);\n const data = { ...inferredData, ...getData(span) };\n\n return {\n op,\n description,\n source,\n origin,\n tags,\n data,\n };\n}\n\n/**\n * Remove custom `sentry.` attribtues we do not need to send.\n * These are more carrier attributes we use inside of the SDK, we do not need to send them to the API.\n */\nfunction removeSentryAttributes(data: Record<string, unknown>): Record<string, unknown> {\n const cleanedData = { ...data };\n\n /* eslint-disable @typescript-eslint/no-dynamic-delete */\n delete cleanedData[InternalSentrySemanticAttributes.PARENT_SAMPLED];\n delete cleanedData[InternalSentrySemanticAttributes.ORIGIN];\n delete cleanedData[InternalSentrySemanticAttributes.OP];\n delete cleanedData[InternalSentrySemanticAttributes.SOURCE];\n delete cleanedData[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];\n /* eslint-enable @typescript-eslint/no-dynamic-delete */\n\n return cleanedData;\n}\n\nfunction getTags(span: ReadableSpan): Record<string, string> {\n const attributes = span.attributes;\n const tags: Record<string, string> = {};\n\n if (attributes[SemanticAttributes.HTTP_STATUS_CODE]) {\n const statusCode = attributes[SemanticAttributes.HTTP_STATUS_CODE] as string | number;\n tags['http.status_code'] = `${statusCode}`;\n }\n\n return tags;\n}\n\nfunction getData(span: ReadableSpan): Record<string, unknown> {\n const attributes = span.attributes;\n const data: Record<string, unknown> = {\n 'otel.kind': SpanKind[span.kind],\n };\n\n if (attributes[SemanticAttributes.HTTP_STATUS_CODE]) {\n const statusCode = attributes[SemanticAttributes.HTTP_STATUS_CODE] as string;\n data['http.response.status_code'] = statusCode;\n }\n\n const requestData = getRequestSpanData(span);\n\n if (requestData.url) {\n data.url = requestData.url;\n }\n\n if (requestData['http.query']) {\n data['http.query'] = requestData['http.query'].slice(1);\n }\n if (requestData['http.fragment']) {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;AACA,GAAA;AACA;AACA,EAAA,OAAA,IAAA,CAAA;AACA,CAAA;AACA;AACA,SAAA,OAAA,CAAA,IAAA,EAAA;AACA,EAAA,MAAA,UAAA,GAAA,IAAA,CAAA,UAAA,CAAA;AACA,EAAA,MAAA,IAAA,GAAA;AACA,IAAA,WAAA,EAAA,QAAA,CAAA,IAAA,CAAA,IAAA,CAAA;AACA,GAAA,CAAA;AACA;AACA,EAAA,IAAA,UAAA,CAAA,kBAAA,CAAA,gBAAA,CAAA,EAAA;AACA,IAAA,MAAA,UAAA,GAAA,UAAA,CAAA,kBAAA,CAAA,gBAAA,CAAA,EAAA;AACA,IAAA,IAAA,CAAA,2BAAA,CAAA,GAAA,UAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,MAAA,WAAA,GAAA,kBAAA,CAAA,IAAA,CAAA,CAAA;AACA;AACA,EAAA,IAAA,WAAA,CAAA,GAAA,EAAA;AACA,IAAA,IAAA,CAAA,GAAA,GAAA,WAAA,CAAA,GAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,IAAA,WAAA,CAAA,YAAA,CAAA,EAAA;AACA,IAAA,IAAA,CAAA,YAAA,CAAA,GAAA,WAAA,CAAA,YAAA,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA;AACA,GAAA;AACA,EAAA,IAAA,WAAA,CAAA,eAAA,CAAA,EAAA;AACA,IAAA,IAAA,CAAA,eAAA,CAAA,GAAA,WAAA,CAAA,eAAA,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,IAAA,CAAA;AACA;;;;"}
1
+ {"version":3,"file":"spanExporter.js","sources":["../../src/spanExporter.ts"],"sourcesContent":["import { SpanKind } from '@opentelemetry/api';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { ExportResultCode } from '@opentelemetry/core';\nimport type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport type { SentrySpan, Transaction } from '@sentry/core';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n getCurrentHub,\n} from '@sentry/core';\nimport type { Scope, SpanOrigin, TransactionSource } from '@sentry/types';\nimport { addNonEnumerableProperty, dropUndefinedKeys, logger } from '@sentry/utils';\nimport { startTransaction } from './custom/transaction';\n\nimport { DEBUG_BUILD } from './debug-build';\nimport { InternalSentrySemanticAttributes } from './semanticAttributes';\nimport { convertOtelTimeToSeconds } from './utils/convertOtelTimeToSeconds';\nimport { getDynamicSamplingContextFromSpan } from './utils/dynamicSamplingContext';\nimport { getRequestSpanData } from './utils/getRequestSpanData';\nimport type { SpanNode } from './utils/groupSpansWithParents';\nimport { groupSpansWithParents } from './utils/groupSpansWithParents';\nimport { mapStatus } from './utils/mapStatus';\nimport { parseSpanDescription } from './utils/parseSpanDescription';\nimport { getSpanHub, getSpanMetadata, getSpanScopes } from './utils/spanData';\n\ntype SpanNodeCompleted = SpanNode & { span: ReadableSpan };\n\n/**\n * A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.\n */\nexport class SentrySpanExporter implements SpanExporter {\n private _finishedSpans: ReadableSpan[];\n private _stopped: boolean;\n\n public constructor() {\n this._stopped = false;\n this._finishedSpans = [];\n }\n\n /** @inheritDoc */\n public export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {\n if (this._stopped) {\n return resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Exporter has been stopped'),\n });\n }\n\n const openSpanCount = this._finishedSpans.length;\n const newSpanCount = spans.length;\n\n this._finishedSpans.push(...spans);\n\n const remainingSpans = maybeSend(this._finishedSpans);\n\n const remainingOpenSpanCount = remainingSpans.length;\n const sentSpanCount = openSpanCount + newSpanCount - remainingOpenSpanCount;\n\n DEBUG_BUILD &&\n logger.log(`SpanExporter exported ${sentSpanCount} spans, ${remainingOpenSpanCount} unsent spans remaining`);\n\n this._finishedSpans = remainingSpans.filter(span => {\n const shouldDrop = shouldCleanupSpan(span, 5 * 60);\n DEBUG_BUILD &&\n shouldDrop &&\n logger.log(\n `SpanExporter dropping span ${span.name} (${\n span.spanContext().spanId\n }) because it is pending for more than 5 minutes.`,\n );\n return !shouldDrop;\n });\n\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n /** @inheritDoc */\n public shutdown(): Promise<void> {\n const forceFlush = this.forceFlush();\n this._stopped = true;\n this._finishedSpans = [];\n return forceFlush;\n }\n\n /** @inheritDoc */\n public forceFlush(): Promise<void> {\n return new Promise(resolve => {\n this.export(this._finishedSpans, () => resolve());\n });\n }\n}\n\n/**\n * Send the given spans, but only if they are part of a finished transaction.\n *\n * Returns the unsent spans.\n * Spans remain unsent when their parent span is not yet finished.\n * This will happen regularly, as child spans are generally finished before their parents.\n * But it _could_ also happen because, for whatever reason, a parent span was lost.\n * In this case, we'll eventually need to clean this up.\n */\nfunction maybeSend(spans: ReadableSpan[]): ReadableSpan[] {\n const grouped = groupSpansWithParents(spans);\n const remaining = new Set(grouped);\n\n const rootNodes = getCompletedRootNodes(grouped);\n\n rootNodes.forEach(root => {\n remaining.delete(root);\n const span = root.span;\n const transaction = createTransactionForOtelSpan(span);\n\n root.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, transaction, remaining);\n });\n\n transaction.end(span.endTime);\n });\n\n return Array.from(remaining)\n .map(node => node.span)\n .filter((span): span is ReadableSpan => !!span);\n}\n\nfunction getCompletedRootNodes(nodes: SpanNode[]): SpanNodeCompleted[] {\n return nodes.filter((node): node is SpanNodeCompleted => !!node.span && !node.parentNode);\n}\n\nfunction shouldCleanupSpan(span: ReadableSpan, maxStartTimeOffsetSeconds: number): boolean {\n const cutoff = Date.now() / 1000 - maxStartTimeOffsetSeconds;\n return convertOtelTimeToSeconds(span.startTime) < cutoff;\n}\n\nfunction parseSpan(span: ReadableSpan): { op?: string; origin?: SpanOrigin; source?: TransactionSource } {\n const attributes = span.attributes;\n\n const origin = attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined;\n const op = attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] as string | undefined;\n const source = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] as TransactionSource | undefined;\n\n return { origin, op, source };\n}\n\nfunction createTransactionForOtelSpan(span: ReadableSpan): Transaction {\n // eslint-disable-next-line deprecation/deprecation\n const hub = getSpanHub(span) || getCurrentHub();\n const spanContext = span.spanContext();\n const spanId = spanContext.spanId;\n const traceId = spanContext.traceId;\n const parentSpanId = span.parentSpanId;\n\n const parentSampled = span.attributes[InternalSentrySemanticAttributes.PARENT_SAMPLED] as boolean | undefined;\n\n const { op, description, data, origin, source } = getSpanData(span);\n const metadata = getSpanMetadata(span);\n const capturedSpanScopes = getSpanScopes(span);\n\n const sampleRate = span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] as number | undefined;\n\n const attributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,\n ...data,\n ...removeSentryAttributes(span.attributes),\n };\n\n const dynamicSamplingContext = getDynamicSamplingContextFromSpan(span);\n\n const transaction = startTransaction(hub, {\n spanId,\n traceId,\n parentSpanId,\n parentSampled,\n name: description,\n op,\n startTimestamp: convertOtelTimeToSeconds(span.startTime),\n metadata: {\n ...dropUndefinedKeys({\n dynamicSamplingContext,\n sampleRate,\n }),\n ...metadata,\n },\n attributes,\n origin,\n sampled: true,\n });\n\n transaction.setStatus(mapStatus(span));\n\n // We currently don't want to write this to the scope because it would mutate it.\n // In the future we will likely have some sort of transaction payload factory where we can pass this context in directly\n // eslint-disable-next-line deprecation/deprecation\n transaction.setContext('otel', {\n attributes: removeSentryAttributes(span.attributes),\n resource: span.resource.attributes,\n });\n\n if (capturedSpanScopes) {\n // Ensure the `transaction` tag is correctly set on the transaction event\n const scope = capturedSpanScopes.scope.clone();\n scope.addEventProcessor(event => {\n event.tags = { transaction: description, ...event.tags };\n return event;\n });\n\n setCapturedScopesOnTransaction(transaction, scope, capturedSpanScopes.isolationScope);\n }\n\n return transaction;\n}\n\nfunction createAndFinishSpanForOtelSpan(node: SpanNode, sentryParentSpan: SentrySpan, remaining: Set<SpanNode>): void {\n remaining.delete(node);\n const span = node.span;\n\n const shouldDrop = !span;\n\n // If this span should be dropped, we still want to create spans for the children of this\n if (shouldDrop) {\n node.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, sentryParentSpan, remaining);\n });\n return;\n }\n\n const spanId = span.spanContext().spanId;\n const { attributes } = span;\n\n const { op, description, data, origin } = getSpanData(span);\n const allData = { ...removeSentryAttributes(attributes), ...data };\n\n // eslint-disable-next-line deprecation/deprecation\n const sentrySpan = sentryParentSpan.startChild({\n name: description,\n op,\n data: allData,\n startTimestamp: convertOtelTimeToSeconds(span.startTime),\n spanId,\n origin,\n }) as SentrySpan;\n sentrySpan.setStatus(mapStatus(span));\n\n node.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, sentrySpan, remaining);\n });\n\n sentrySpan.end(convertOtelTimeToSeconds(span.endTime));\n}\n\nfunction getSpanData(span: ReadableSpan): {\n data: Record<string, unknown>;\n op?: string;\n description: string;\n source?: TransactionSource;\n origin?: SpanOrigin;\n} {\n const { op: definedOp, source: definedSource, origin } = parseSpan(span);\n const { op: inferredOp, description, source: inferredSource, data: inferredData } = parseSpanDescription(span);\n\n const op = definedOp || inferredOp;\n const source = definedSource || inferredSource;\n\n const data = { ...inferredData, ...getData(span) };\n\n return {\n op,\n description,\n source,\n origin,\n data,\n };\n}\n\n/**\n * Remove custom `sentry.` attribtues we do not need to send.\n * These are more carrier attributes we use inside of the SDK, we do not need to send them to the API.\n */\nfunction removeSentryAttributes(data: Record<string, unknown>): Record<string, unknown> {\n const cleanedData = { ...data };\n\n /* eslint-disable @typescript-eslint/no-dynamic-delete */\n delete cleanedData[InternalSentrySemanticAttributes.PARENT_SAMPLED];\n delete cleanedData[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];\n /* eslint-enable @typescript-eslint/no-dynamic-delete */\n\n return cleanedData;\n}\n\nfunction getData(span: ReadableSpan): Record<string, unknown> {\n const attributes = span.attributes;\n const data: Record<string, unknown> = {\n 'otel.kind': SpanKind[span.kind],\n };\n\n if (attributes[SemanticAttributes.HTTP_STATUS_CODE]) {\n const statusCode = attributes[SemanticAttributes.HTTP_STATUS_CODE] as string;\n data['http.response.status_code'] = statusCode;\n }\n\n const requestData = getRequestSpanData(span);\n\n if (requestData.url) {\n data.url = requestData.url;\n }\n\n if (requestData['http.query']) {\n data['http.query'] = requestData['http.query'].slice(1);\n }\n if (requestData['http.fragment']) {\n data['http.fragment'] = requestData['http.fragment'].slice(1);\n }\n\n return data;\n}\n\nconst SCOPE_ON_START_SPAN_FIELD = '_sentryScope';\nconst ISOLATION_SCOPE_ON_START_SPAN_FIELD = '_sentryIsolationScope';\n\n/** Sets the scope and isolation scope to be used for when the transaction is finished. */\nfunction setCapturedScopesOnTransaction(span: Transaction, scope: Scope, isolationScope: Scope): void {\n if (span) {\n addNonEnumerableProperty(span, ISOLATION_SCOPE_ON_START_SPAN_FIELD, isolationScope);\n addNonEnumerableProperty(span, SCOPE_ON_START_SPAN_FIELD, scope);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA8BA;AACA;AACA;AACO,MAAM,oBAA2C;;AAIxD,GAAS,WAAW,GAAG;AACvB,IAAI,IAAI,CAAC,QAAS,GAAE,KAAK,CAAA;AACzB,IAAI,IAAI,CAAC,cAAe,GAAE,EAAE,CAAA;AAC5B,GAAE;AACF;AACA;AACA,GAAS,MAAM,CAAC,KAAK,EAAkB,cAAc,EAAwC;AAC7F,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE;AACvB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,GAAG,CAAA;AAC9B,GAAE;AACF;AACA,EAAE,IAAI,WAAW,CAAC,YAAY,CAAC,EAAE;AACjC,IAAI,IAAI,CAAC,YAAY,CAAA,GAAI,WAAW,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAC3D,GAAE;AACF,EAAE,IAAI,WAAW,CAAC,eAAe,CAAC,EAAE;AACpC,IAAI,IAAI,CAAC,eAAe,CAAA,GAAI,WAAW,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AACjE,GAAE;AACF;AACA,EAAE,OAAO,IAAI,CAAA;AACb,CAAA;AACA;AACA,MAAM,yBAAA,GAA4B,cAAc,CAAA;AAChD,MAAM,mCAAA,GAAsC,uBAAuB,CAAA;AACnE;AACA;AACA,SAAS,8BAA8B,CAAC,IAAI,EAAe,KAAK,EAAS,cAAc,EAAe;AACtG,EAAE,IAAI,IAAI,EAAE;AACZ,IAAI,wBAAwB,CAAC,IAAI,EAAE,mCAAmC,EAAE,cAAc,CAAC,CAAA;AACvF,IAAI,wBAAwB,CAAC,IAAI,EAAE,yBAAyB,EAAE,KAAK,CAAC,CAAA;AACpE,GAAE;AACF;;;;"}
@@ -1,15 +1,14 @@
1
1
  import { trace, ROOT_CONTEXT } from '@opentelemetry/api';
2
2
  import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
3
+ import { getCurrentHub } from '@sentry/core';
3
4
  import { logger } from '@sentry/utils';
4
- import { getCurrentHub } from './custom/hub.js';
5
- import { OpenTelemetryScope } from './custom/scope.js';
6
5
  import { DEBUG_BUILD } from './debug-build.js';
7
6
  import { SentrySpanExporter } from './spanExporter.js';
8
7
  import { maybeCaptureExceptionForTimedEvent } from './utils/captureExceptionForTimedEvent.js';
9
8
  import { getHubFromContext } from './utils/contextData.js';
10
- import { setSpanParent, setSpanScope, setSpanHub, setSpanFinishScope, getSpanHub } from './utils/spanData.js';
9
+ import { setSpanParent, setSpanHub, setSpanScopes, getSpanHub } from './utils/spanData.js';
11
10
 
12
- function onSpanStart(span, parentContext, _ScopeClass) {
11
+ function onSpanStart(span, parentContext) {
13
12
  // This is a reliable way to get the parent span - because this is exactly how the parent is identified in the OTEL SDK
14
13
  const parentSpan = trace.getSpan(parentContext);
15
14
  const hub = getHubFromContext(parentContext);
@@ -23,6 +22,7 @@ function onSpanStart(span, parentContext, _ScopeClass) {
23
22
  // We do this instead of just falling back to `getCurrentHub` to avoid attaching the wrong hub
24
23
  let actualHub = hub;
25
24
  if (parentContext === ROOT_CONTEXT) {
25
+ // eslint-disable-next-line deprecation/deprecation
26
26
  actualHub = getCurrentHub();
27
27
  }
28
28
 
@@ -30,18 +30,16 @@ function onSpanStart(span, parentContext, _ScopeClass) {
30
30
  if (actualHub) {
31
31
  // eslint-disable-next-line deprecation/deprecation
32
32
  const scope = actualHub.getScope();
33
- setSpanScope(span, scope);
33
+ // eslint-disable-next-line deprecation/deprecation
34
+ const isolationScope = actualHub.getIsolationScope();
34
35
  setSpanHub(span, actualHub);
35
-
36
- // Use this scope for finishing the span
37
- const finishScope = (scope ).clone();
38
- finishScope.activeSpan = span;
39
- setSpanFinishScope(span, finishScope);
36
+ setSpanScopes(span, { scope, isolationScope });
40
37
  }
41
38
  }
42
39
 
43
40
  function onSpanEnd(span) {
44
41
  // Capture exceptions as events
42
+ // eslint-disable-next-line deprecation/deprecation
45
43
  const hub = getSpanHub(span) || getCurrentHub();
46
44
  span.events.forEach(event => {
47
45
  maybeCaptureExceptionForTimedEvent(hub, event, span);
@@ -53,18 +51,15 @@ function onSpanEnd(span) {
53
51
  * the Sentry SDK.
54
52
  */
55
53
  class SentrySpanProcessor extends BatchSpanProcessor {
56
-
57
- constructor(options = {}) {
54
+ constructor() {
58
55
  super(new SentrySpanExporter());
59
-
60
- this._scopeClass = options.scopeClass || OpenTelemetryScope;
61
56
  }
62
57
 
63
58
  /**
64
59
  * @inheritDoc
65
60
  */
66
61
  onStart(span, parentContext) {
67
- onSpanStart(span, parentContext, this._scopeClass);
62
+ onSpanStart(span, parentContext);
68
63
 
69
64
  DEBUG_BUILD && logger.log(`[Tracing] Starting span "${span.name}" (${span.spanContext().spanId})`);
70
65
 
@@ -1 +1 @@
1
- {"version":3,"file":"spanProcessor.js","sources":["../../src/spanProcessor.ts"],"sourcesContent":["import type { Context } from '@opentelemetry/api';\nimport { ROOT_CONTEXT, trace } from '@opentelemetry/api';\nimport type { Span, SpanProcessor as SpanProcessorInterface } from '@opentelemetry/sdk-trace-base';\nimport { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';\nimport { logger } from '@sentry/utils';\n\nimport { getCurrentHub } from './custom/hub';\nimport { OpenTelemetryScope } from './custom/scope';\nimport { DEBUG_BUILD } from './debug-build';\nimport { SentrySpanExporter } from './spanExporter';\nimport { maybeCaptureExceptionForTimedEvent } from './utils/captureExceptionForTimedEvent';\nimport { getHubFromContext } from './utils/contextData';\nimport { getSpanHub, setSpanFinishScope, setSpanHub, setSpanParent, setSpanScope } from './utils/spanData';\n\nfunction onSpanStart(span: Span, parentContext: Context, _ScopeClass: typeof OpenTelemetryScope): void {\n // This is a reliable way to get the parent span - because this is exactly how the parent is identified in the OTEL SDK\n const parentSpan = trace.getSpan(parentContext);\n const hub = getHubFromContext(parentContext);\n\n // We need access to the parent span in order to be able to move up the span tree for breadcrumbs\n if (parentSpan) {\n setSpanParent(span, parentSpan);\n }\n\n // The root context does not have a hub stored, so we check for this specifically\n // We do this instead of just falling back to `getCurrentHub` to avoid attaching the wrong hub\n let actualHub = hub;\n if (parentContext === ROOT_CONTEXT) {\n actualHub = getCurrentHub();\n }\n\n // We need the scope at time of span creation in order to apply it to the event when the span is finished\n if (actualHub) {\n // eslint-disable-next-line deprecation/deprecation\n const scope = actualHub.getScope();\n setSpanScope(span, scope);\n setSpanHub(span, actualHub);\n\n // Use this scope for finishing the span\n const finishScope = (scope as OpenTelemetryScope).clone();\n finishScope.activeSpan = span;\n setSpanFinishScope(span, finishScope);\n }\n}\n\nfunction onSpanEnd(span: Span): void {\n // Capture exceptions as events\n const hub = getSpanHub(span) || getCurrentHub();\n span.events.forEach(event => {\n maybeCaptureExceptionForTimedEvent(hub, event, span);\n });\n}\n\n/**\n * Converts OpenTelemetry Spans to Sentry Spans and sends them to Sentry via\n * the Sentry SDK.\n */\nexport class SentrySpanProcessor extends BatchSpanProcessor implements SpanProcessorInterface {\n private _scopeClass: typeof OpenTelemetryScope;\n\n public constructor(options: { scopeClass?: typeof OpenTelemetryScope } = {}) {\n super(new SentrySpanExporter());\n\n this._scopeClass = options.scopeClass || OpenTelemetryScope;\n }\n\n /**\n * @inheritDoc\n */\n public onStart(span: Span, parentContext: Context): void {\n onSpanStart(span, parentContext, this._scopeClass);\n\n DEBUG_BUILD && logger.log(`[Tracing] Starting span \"${span.name}\" (${span.spanContext().spanId})`);\n\n return super.onStart(span, parentContext);\n }\n\n /** @inheritDoc */\n public onEnd(span: Span): void {\n DEBUG_BUILD && logger.log(`[Tracing] Finishing span \"${span.name}\" (${span.spanContext().spanId})`);\n\n if (!this._shouldSendSpanToSentry(span)) {\n // Prevent this being called to super.onEnd(), which would pass this to the span exporter\n return;\n }\n\n onSpanEnd(span);\n\n return super.onEnd(span);\n }\n\n /**\n * You can overwrite this in a sub class to implement custom behavior for dropping spans.\n * If you return `false` here, the span will not be passed to the exporter and thus not be sent.\n */\n protected _shouldSendSpanToSentry(_span: Span): boolean {\n return true;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAcA,SAAS,WAAW,CAAC,IAAI,EAAQ,aAAa,EAAW,WAAW,EAAmC;AACvG;AACA,EAAE,MAAM,aAAa,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;AACjD,EAAE,MAAM,GAAI,GAAE,iBAAiB,CAAC,aAAa,CAAC,CAAA;AAC9C;AACA;AACA,EAAE,IAAI,UAAU,EAAE;AAClB,IAAI,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;AACnC,GAAE;AACF;AACA;AACA;AAC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AC,CAAA;AACtD;AACA,IAAI,WAAA,IAAe,MAAM,CAAC,GAAG,CAAC,CAAC,yBAAyB,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AACtG;AACA,IAAI,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;AAC7C,GAAE;AACF;AACA;AACA,GAAS,KAAK,CAAC,IAAI,EAAc;AACjC,IAAI,WAAA,IAAe,MAAM,CAAC,GAAG,CAAC,CAAC,0BAA0B,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AACvG;AACA,IAAI,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAAE;AAC7C;AACA,MAAM,OAAM;AACZ,KAAI;AACJ;AACA,IAAI,SAAS,CAAC,IAAI,CAAC,CAAA;AACnB;AACA,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AAC5B,GAAE;AACF;AACA;AACA;AACA;AACA;AACA,GAAY,uBAAuB,CAAC,KAAK,EAAiB;AAC1D,IAAI,OAAO,IAAI,CAAA;AACf,GAAE;AACF;;;;"}
1
+ {"version":3,"file":"spanProcessor.js","sources":["../../src/spanProcessor.ts"],"sourcesContent":["import type { Context } from '@opentelemetry/api';\nimport { ROOT_CONTEXT, trace } from '@opentelemetry/api';\nimport type { Span, SpanProcessor as SpanProcessorInterface } from '@opentelemetry/sdk-trace-base';\nimport { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';\nimport { getCurrentHub } from '@sentry/core';\nimport { logger } from '@sentry/utils';\n\nimport { DEBUG_BUILD } from './debug-build';\nimport { SentrySpanExporter } from './spanExporter';\nimport { maybeCaptureExceptionForTimedEvent } from './utils/captureExceptionForTimedEvent';\nimport { getHubFromContext } from './utils/contextData';\nimport { getSpanHub, setSpanHub, setSpanParent, setSpanScopes } from './utils/spanData';\n\nfunction onSpanStart(span: Span, parentContext: Context): void {\n // This is a reliable way to get the parent span - because this is exactly how the parent is identified in the OTEL SDK\n const parentSpan = trace.getSpan(parentContext);\n const hub = getHubFromContext(parentContext);\n\n // We need access to the parent span in order to be able to move up the span tree for breadcrumbs\n if (parentSpan) {\n setSpanParent(span, parentSpan);\n }\n\n // The root context does not have a hub stored, so we check for this specifically\n // We do this instead of just falling back to `getCurrentHub` to avoid attaching the wrong hub\n let actualHub = hub;\n if (parentContext === ROOT_CONTEXT) {\n // eslint-disable-next-line deprecation/deprecation\n actualHub = getCurrentHub();\n }\n\n // We need the scope at time of span creation in order to apply it to the event when the span is finished\n if (actualHub) {\n // eslint-disable-next-line deprecation/deprecation\n const scope = actualHub.getScope();\n // eslint-disable-next-line deprecation/deprecation\n const isolationScope = actualHub.getIsolationScope();\n setSpanHub(span, actualHub);\n setSpanScopes(span, { scope, isolationScope });\n }\n}\n\nfunction onSpanEnd(span: Span): void {\n // Capture exceptions as events\n // eslint-disable-next-line deprecation/deprecation\n const hub = getSpanHub(span) || getCurrentHub();\n span.events.forEach(event => {\n maybeCaptureExceptionForTimedEvent(hub, event, span);\n });\n}\n\n/**\n * Converts OpenTelemetry Spans to Sentry Spans and sends them to Sentry via\n * the Sentry SDK.\n */\nexport class SentrySpanProcessor extends BatchSpanProcessor implements SpanProcessorInterface {\n public constructor() {\n super(new SentrySpanExporter());\n }\n\n /**\n * @inheritDoc\n */\n public onStart(span: Span, parentContext: Context): void {\n onSpanStart(span, parentContext);\n\n DEBUG_BUILD && logger.log(`[Tracing] Starting span \"${span.name}\" (${span.spanContext().spanId})`);\n\n return super.onStart(span, parentContext);\n }\n\n /** @inheritDoc */\n public onEnd(span: Span): void {\n DEBUG_BUILD && logger.log(`[Tracing] Finishing span \"${span.name}\" (${span.spanContext().spanId})`);\n\n if (!this._shouldSendSpanToSentry(span)) {\n // Prevent this being called to super.onEnd(), which would pass this to the span exporter\n return;\n }\n\n onSpanEnd(span);\n\n return super.onEnd(span);\n }\n\n /**\n * You can overwrite this in a sub class to implement custom behavior for dropping spans.\n * If you return `false` here, the span will not be passed to the exporter and thus not be sent.\n */\n protected _shouldSendSpanToSentry(_span: Span): boolean {\n return true;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAaA,SAAS,WAAW,CAAC,IAAI,EAAQ,aAAa,EAAiB;AAC/D;AACA,EAAE,MAAM,aAAa,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;AACjD,EAAE,MAAM,GAAI,GAAE,iBAAiB,CAAC,aAAa,CAAC,CAAA;AAC9C;AACA;AACA,EAAE,IAAI,UAAU,EAAE;AAClB,IAAI,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;AACnC,GAAE;AACF;AACA;AACA;AACA,EAAE,IAAI,SAAU,GAAE,GAAG,CAAA;AACrB,EAAE,IAAI,aAAc,KAAI,YAAY,EAAE;AACtC;AACA,IAAI,SAAU,GAAE,aAAa,EAAE,CAAA;AAC/B,GAAE;AACF;AACA;AACA,EAAE,IAAI,SAAS,EAAE;AACjB;AACA,IAAI,MAAM,KAAM,GAAE,SAAS,CAAC,QAAQ,EAAE,CAAA;AACtC;AACA,IAAI,MAAM,cAAe,GAAE,SAAS,CAAC,iBAAiB,EAAE,CAAA;AACxD,IAAI,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;AAC/B,IAAI,aAAa,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,cAAe,EAAC,CAAC,CAAA;AAClD,GAAE;AACF,CAAA;AACA;AACA,SAAS,SAAS,CAAC,IAAI,EAAc;AACrC;AACA;AACA,EAAE,MAAM,GAAI,GAAE,UAAU,CAAC,IAAI,CAAE,IAAG,aAAa,EAAE,CAAA;AACjD,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS;AAC/B,IAAI,kCAAkC,CAAC,GAAG,EA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