@sentry/opentelemetry 7.105.0 → 8.0.0-alpha.2

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 (147) 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 +16 -4
  5. package/cjs/constants.js.map +1 -1
  6. package/cjs/contextManager.js +42 -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 +9 -9
  17. package/cjs/index.js.map +1 -1
  18. package/cjs/propagator.js +125 -40
  19. package/cjs/propagator.js.map +1 -1
  20. package/cjs/sampler.js +7 -6
  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 +62 -58
  27. package/cjs/spanExporter.js.map +1 -1
  28. package/cjs/spanProcessor.js +16 -18
  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 +35 -15
  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/mapStatus.js +5 -4
  39. package/cjs/utils/mapStatus.js.map +1 -1
  40. package/cjs/utils/setupCheck.js +17 -0
  41. package/cjs/utils/setupCheck.js.map +1 -0
  42. package/cjs/utils/spanData.js +23 -23
  43. package/cjs/utils/spanData.js.map +1 -1
  44. package/esm/asyncContextStrategy.js +89 -18
  45. package/esm/asyncContextStrategy.js.map +1 -1
  46. package/esm/constants.js +11 -4
  47. package/esm/constants.js.map +1 -1
  48. package/esm/contextManager.js +41 -17
  49. package/esm/contextManager.js.map +1 -1
  50. package/esm/custom/client.js +0 -28
  51. package/esm/custom/client.js.map +1 -1
  52. package/esm/custom/getCurrentHub.js +101 -0
  53. package/esm/custom/getCurrentHub.js.map +1 -0
  54. package/esm/custom/hub.js +4 -133
  55. package/esm/custom/hub.js.map +1 -1
  56. package/esm/custom/transaction.js +4 -32
  57. package/esm/custom/transaction.js.map +1 -1
  58. package/esm/index.js +7 -5
  59. package/esm/index.js.map +1 -1
  60. package/esm/propagator.js +128 -45
  61. package/esm/propagator.js.map +1 -1
  62. package/esm/sampler.js +7 -6
  63. package/esm/sampler.js.map +1 -1
  64. package/esm/semanticAttributes.js +0 -9
  65. package/esm/semanticAttributes.js.map +1 -1
  66. package/esm/setupEventContextTrace.js +14 -9
  67. package/esm/setupEventContextTrace.js.map +1 -1
  68. package/esm/spanExporter.js +63 -59
  69. package/esm/spanExporter.js.map +1 -1
  70. package/esm/spanProcessor.js +12 -14
  71. package/esm/spanProcessor.js.map +1 -1
  72. package/esm/trace.js +122 -26
  73. package/esm/trace.js.map +1 -1
  74. package/esm/utils/addOriginToSpan.js +2 -2
  75. package/esm/utils/addOriginToSpan.js.map +1 -1
  76. package/esm/utils/contextData.js +33 -15
  77. package/esm/utils/contextData.js.map +1 -1
  78. package/esm/utils/dynamicSamplingContext.js +59 -0
  79. package/esm/utils/dynamicSamplingContext.js.map +1 -0
  80. package/esm/utils/mapStatus.js +5 -4
  81. package/esm/utils/mapStatus.js.map +1 -1
  82. package/esm/utils/setupCheck.js +14 -0
  83. package/esm/utils/setupCheck.js.map +1 -0
  84. package/esm/utils/spanData.js +22 -20
  85. package/esm/utils/spanData.js.map +1 -1
  86. package/package.json +5 -5
  87. package/types/asyncContextStrategy.d.ts.map +1 -1
  88. package/types/constants.d.ts +6 -2
  89. package/types/constants.d.ts.map +1 -1
  90. package/types/contextManager.d.ts +1 -1
  91. package/types/contextManager.d.ts.map +1 -1
  92. package/types/custom/client.d.ts.map +1 -1
  93. package/types/custom/getCurrentHub.d.ts +7 -0
  94. package/types/custom/getCurrentHub.d.ts.map +1 -0
  95. package/types/custom/hub.d.ts +2 -33
  96. package/types/custom/hub.d.ts.map +1 -1
  97. package/types/custom/transaction.d.ts +1 -10
  98. package/types/custom/transaction.d.ts.map +1 -1
  99. package/types/index.d.ts +7 -5
  100. package/types/index.d.ts.map +1 -1
  101. package/types/propagator.d.ts +11 -2
  102. package/types/propagator.d.ts.map +1 -1
  103. package/types/sampler.d.ts.map +1 -1
  104. package/types/semanticAttributes.d.ts +0 -9
  105. package/types/semanticAttributes.d.ts.map +1 -1
  106. package/types/setupEventContextTrace.d.ts.map +1 -1
  107. package/types/spanExporter.d.ts.map +1 -1
  108. package/types/spanProcessor.d.ts +1 -5
  109. package/types/spanProcessor.d.ts.map +1 -1
  110. package/types/trace.d.ts +14 -3
  111. package/types/trace.d.ts.map +1 -1
  112. package/types/types.d.ts +7 -12
  113. package/types/types.d.ts.map +1 -1
  114. package/types/utils/addOriginToSpan.d.ts.map +1 -1
  115. package/types/utils/contextData.d.ts +21 -10
  116. package/types/utils/contextData.d.ts.map +1 -1
  117. package/types/utils/dynamicSamplingContext.d.ts +11 -0
  118. package/types/utils/dynamicSamplingContext.d.ts.map +1 -0
  119. package/types/utils/mapStatus.d.ts +2 -2
  120. package/types/utils/mapStatus.d.ts.map +1 -1
  121. package/types/utils/setupCheck.d.ts +9 -0
  122. package/types/utils/setupCheck.d.ts.map +1 -0
  123. package/types/utils/spanData.d.ts +14 -8
  124. package/types/utils/spanData.d.ts.map +1 -1
  125. package/types-ts3.8/constants.d.ts +6 -2
  126. package/types-ts3.8/contextManager.d.ts +1 -1
  127. package/types-ts3.8/custom/getCurrentHub.d.ts +7 -0
  128. package/types-ts3.8/custom/hub.d.ts +2 -33
  129. package/types-ts3.8/custom/transaction.d.ts +1 -10
  130. package/types-ts3.8/index.d.ts +7 -5
  131. package/types-ts3.8/propagator.d.ts +11 -2
  132. package/types-ts3.8/semanticAttributes.d.ts +0 -9
  133. package/types-ts3.8/spanProcessor.d.ts +1 -5
  134. package/types-ts3.8/trace.d.ts +14 -3
  135. package/types-ts3.8/types.d.ts +7 -12
  136. package/types-ts3.8/utils/contextData.d.ts +21 -10
  137. package/types-ts3.8/utils/dynamicSamplingContext.d.ts +11 -0
  138. package/types-ts3.8/utils/mapStatus.d.ts +2 -2
  139. package/types-ts3.8/utils/setupCheck.d.ts +9 -0
  140. package/types-ts3.8/utils/spanData.d.ts +14 -8
  141. package/cjs/custom/scope.js +0 -202
  142. package/cjs/custom/scope.js.map +0 -1
  143. package/esm/custom/scope.js +0 -200
  144. package/esm/custom/scope.js.map +0 -1
  145. package/types/custom/scope.d.ts +0 -42
  146. package/types/custom/scope.d.ts.map +0 -1
  147. package/types-ts3.8/custom/scope.d.ts +0 -42
@@ -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,32 @@ 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
+ setCapturedScopesOnTransaction(transaction, capturedSpanScopes.scope, capturedSpanScopes.isolationScope);
188
+ }
177
189
 
178
190
  return transaction;
179
191
  }
@@ -195,21 +207,19 @@ function createAndFinishSpanForOtelSpan(node, sentryParentSpan, remaining) {
195
207
  const spanId = span.spanContext().spanId;
196
208
  const { attributes } = span;
197
209
 
198
- const { op, description, tags, data, origin } = getSpanData(span);
210
+ const { op, description, data, origin } = getSpanData(span);
199
211
  const allData = { ...removeSentryAttributes(attributes), ...data };
200
212
 
201
213
  // eslint-disable-next-line deprecation/deprecation
202
214
  const sentrySpan = sentryParentSpan.startChild({
203
- description,
215
+ name: description,
204
216
  op,
205
217
  data: allData,
206
- status: mapStatus(span),
207
- instrumenter: 'otel',
208
218
  startTimestamp: convertOtelTimeToSeconds(span.startTime),
209
219
  spanId,
210
220
  origin,
211
- tags,
212
- });
221
+ }) ;
222
+ sentrySpan.setStatus(mapStatus(span));
213
223
 
214
224
  node.children.forEach(child => {
215
225
  createAndFinishSpanForOtelSpan(child, sentrySpan, remaining);
@@ -227,7 +237,6 @@ function getSpanData(span)
227
237
  const op = definedOp || inferredOp;
228
238
  const source = definedSource || inferredSource;
229
239
 
230
- const tags = getTags(span);
231
240
  const data = { ...inferredData, ...getData(span) };
232
241
 
233
242
  return {
@@ -235,7 +244,6 @@ function getSpanData(span)
235
244
  description,
236
245
  source,
237
246
  origin,
238
- tags,
239
247
  data,
240
248
  };
241
249
  }
@@ -249,27 +257,12 @@ function removeSentryAttributes(data) {
249
257
 
250
258
  /* eslint-disable @typescript-eslint/no-dynamic-delete */
251
259
  delete cleanedData[InternalSentrySemanticAttributes.PARENT_SAMPLED];
252
- delete cleanedData[InternalSentrySemanticAttributes.ORIGIN];
253
- delete cleanedData[InternalSentrySemanticAttributes.OP];
254
- delete cleanedData[InternalSentrySemanticAttributes.SOURCE];
255
260
  delete cleanedData[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];
256
261
  /* eslint-enable @typescript-eslint/no-dynamic-delete */
257
262
 
258
263
  return cleanedData;
259
264
  }
260
265
 
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
266
  function getData(span) {
274
267
  const attributes = span.attributes;
275
268
  const data = {
@@ -297,5 +290,16 @@ function getData(span) {
297
290
  return data;
298
291
  }
299
292
 
293
+ const SCOPE_ON_START_SPAN_FIELD = '_sentryScope';
294
+ const ISOLATION_SCOPE_ON_START_SPAN_FIELD = '_sentryIsolationScope';
295
+
296
+ /** Sets the scope and isolation scope to be used for when the transaction is finished. */
297
+ function setCapturedScopesOnTransaction(span, scope, isolationScope) {
298
+ if (span) {
299
+ addNonEnumerableProperty(span, ISOLATION_SCOPE_ON_START_SPAN_FIELD, isolationScope);
300
+ addNonEnumerableProperty(span, SCOPE_ON_START_SPAN_FIELD, scope);
301
+ }
302
+ }
303
+
300
304
  export { SentrySpanExporter };
301
305
  //# 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']) {\n data['http.fragment'] = requestData['http.fragment'].slice(1);\n }\n\n return data;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;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A,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 setCapturedScopesOnTransaction(transaction, capturedSpanScopes.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,MAAM,OAAO,cAAc,CAAC;AAC5B,QAAQ,IAAI,EAAE,gBAAgB,CAAC,MAAM;AACrC,QAAQ,KAAK,EAAE,IAAI,KAAK,CAAC,2BAA2B,CAAC;AACrD,OAAO,CAAC,CAAA;AACR,KAAI;AACJ;AACA,IAAI,MA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AChD,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,15 @@
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 { setIsSetup } from './utils/setupCheck.js';
10
+ import { setSpanParent, setSpanHub, setSpanScopes, getSpanHub } from './utils/spanData.js';
11
11
 
12
- function onSpanStart(span, parentContext, _ScopeClass) {
12
+ function onSpanStart(span, parentContext) {
13
13
  // This is a reliable way to get the parent span - because this is exactly how the parent is identified in the OTEL SDK
14
14
  const parentSpan = trace.getSpan(parentContext);
15
15
  const hub = getHubFromContext(parentContext);
@@ -23,6 +23,7 @@ function onSpanStart(span, parentContext, _ScopeClass) {
23
23
  // We do this instead of just falling back to `getCurrentHub` to avoid attaching the wrong hub
24
24
  let actualHub = hub;
25
25
  if (parentContext === ROOT_CONTEXT) {
26
+ // eslint-disable-next-line deprecation/deprecation
26
27
  actualHub = getCurrentHub();
27
28
  }
28
29
 
@@ -30,18 +31,16 @@ function onSpanStart(span, parentContext, _ScopeClass) {
30
31
  if (actualHub) {
31
32
  // eslint-disable-next-line deprecation/deprecation
32
33
  const scope = actualHub.getScope();
33
- setSpanScope(span, scope);
34
+ // eslint-disable-next-line deprecation/deprecation
35
+ const isolationScope = actualHub.getIsolationScope();
34
36
  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);
37
+ setSpanScopes(span, { scope, isolationScope });
40
38
  }
41
39
  }
42
40
 
43
41
  function onSpanEnd(span) {
44
42
  // Capture exceptions as events
43
+ // eslint-disable-next-line deprecation/deprecation
45
44
  const hub = getSpanHub(span) || getCurrentHub();
46
45
  span.events.forEach(event => {
47
46
  maybeCaptureExceptionForTimedEvent(hub, event, span);
@@ -53,18 +52,17 @@ function onSpanEnd(span) {
53
52
  * the Sentry SDK.
54
53
  */
55
54
  class SentrySpanProcessor extends BatchSpanProcessor {
56
-
57
- constructor(options = {}) {
55
+ constructor() {
58
56
  super(new SentrySpanExporter());
59
57
 
60
- this._scopeClass = options.scopeClass || OpenTelemetryScope;
58
+ setIsSetup('SentrySpanProcessor');
61
59
  }
62
60
 
63
61
  /**
64
62
  * @inheritDoc
65
63
  */
66
64
  onStart(span, parentContext) {
67
- onSpanStart(span, parentContext, this._scopeClass);
65
+ onSpanStart(span, parentContext);
68
66
 
69
67
  DEBUG_BUILD && logger.log(`[Tracing] Starting span "${span.name}" (${span.spanContext().spanId})`);
70
68
 
@@ -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;AACA,EAAE,IAAI,SAAU,GAAE,GAAG,CAAA;AACrB,EAAE,IAAI,aAAc,KAAI,YAAY,EAAE;AACtC,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,IAAI,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AAC7B,IAAI,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;AAC/B;AACA;AACA,IAAI,MAAM,c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B,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 { setIsSetup } from './utils/setupCheck';\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 setIsSetup('SentrySpanProcessor');\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":";;;;;;;;;;;AAcA,SAAS,WAAW,CAAC,IAAI,EAAQ,aAAa,EAAiB;AAC/D;AACA,EAAE,MAAM,aAAa,KAAK,CA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EAAQ,aAAa,EAAiB;AAC3D,IAAI,WAAW,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;AACpC;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;;;;"}
package/esm/trace.js CHANGED
@@ -1,8 +1,11 @@
1
- import { context, trace, SpanStatusCode } from '@opentelemetry/api';
2
- import { suppressTracing } from '@opentelemetry/core';
3
- import { handleCallbackErrors, SDK_VERSION } from '@sentry/core';
4
- import { getClient } from './custom/hub.js';
5
- import { InternalSentrySemanticAttributes } from './semanticAttributes.js';
1
+ import { trace, SpanStatusCode, context, TraceFlags } from '@opentelemetry/api';
2
+ import { suppressTracing, TraceState } from '@opentelemetry/core';
3
+ import { handleCallbackErrors, getCurrentScope, getClient, SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
4
+ import { dynamicSamplingContextToSentryBaggageHeader } from '@sentry/utils';
5
+ import { SENTRY_TRACE_STATE_DSC } from './constants.js';
6
+ import { getContextFromScope } from './utils/contextData.js';
7
+ import { getDynamicSamplingContextFromSpan } from './utils/dynamicSamplingContext.js';
8
+ import { getRootSpan } from './utils/getActiveSpan.js';
6
9
  import { setSpanMetadata } from './utils/spanData.js';
7
10
 
8
11
  /**
@@ -14,17 +17,19 @@ import { setSpanMetadata } from './utils/spanData.js';
14
17
  *
15
18
  * Note that you'll always get a span passed to the callback, it may just be a NonRecordingSpan if the span is not sampled.
16
19
  */
17
- function startSpan(spanContext, callback) {
20
+ function startSpan(options, callback) {
18
21
  const tracer = getTracer();
19
22
 
20
- const { name } = spanContext;
23
+ const { name } = options;
21
24
 
22
- const activeCtx = context.active();
23
- const shouldSkipSpan = spanContext.onlyIfParent && !trace.getSpan(activeCtx);
25
+ const activeCtx = getContext(options.scope, options.forceTransaction);
26
+ const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);
24
27
  const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;
25
28
 
29
+ const spanContext = getSpanContext(options);
30
+
26
31
  return tracer.startActiveSpan(name, spanContext, ctx, span => {
27
- _applySentryAttributesToSpan(span, spanContext);
32
+ _applySentryAttributesToSpan(span, options);
28
33
 
29
34
  return handleCallbackErrors(
30
35
  () => callback(span),
@@ -45,17 +50,19 @@ function startSpan(spanContext, callback) {
45
50
  *
46
51
  * Note that you'll always get a span passed to the callback, it may just be a NonRecordingSpan if the span is not sampled.
47
52
  */
48
- function startSpanManual(spanContext, callback) {
53
+ function startSpanManual(options, callback) {
49
54
  const tracer = getTracer();
50
55
 
51
- const { name } = spanContext;
56
+ const { name } = options;
52
57
 
53
- const activeCtx = context.active();
54
- const shouldSkipSpan = spanContext.onlyIfParent && !trace.getSpan(activeCtx);
58
+ const activeCtx = getContext(options.scope, options.forceTransaction);
59
+ const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);
55
60
  const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;
56
61
 
62
+ const spanContext = getSpanContext(options);
63
+
57
64
  return tracer.startActiveSpan(name, spanContext, ctx, span => {
58
- _applySentryAttributesToSpan(span, spanContext);
65
+ _applySentryAttributesToSpan(span, options);
59
66
 
60
67
  return handleCallbackErrors(
61
68
  () => callback(span),
@@ -76,40 +83,57 @@ function startSpanManual(spanContext, callback) {
76
83
  * or you didn't set `tracesSampleRate` or `tracesSampler`, this function will not generate spans
77
84
  * and the `span` returned from the callback will be undefined.
78
85
  */
79
- function startInactiveSpan(spanContext) {
86
+ function startInactiveSpan(options) {
80
87
  const tracer = getTracer();
81
88
 
82
- const { name } = spanContext;
89
+ const { name } = options;
83
90
 
84
- const activeCtx = context.active();
85
- const shouldSkipSpan = spanContext.onlyIfParent && !trace.getSpan(activeCtx);
91
+ const activeCtx = getContext(options.scope, options.forceTransaction);
92
+ const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);
86
93
  const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;
87
94
 
95
+ const spanContext = getSpanContext(options);
96
+
88
97
  const span = tracer.startSpan(name, spanContext, ctx);
89
98
 
90
- _applySentryAttributesToSpan(span, spanContext);
99
+ _applySentryAttributesToSpan(span, options);
91
100
 
92
101
  return span;
93
102
  }
94
103
 
104
+ /**
105
+ * Forks the current scope and sets the provided span as active span in the context of the provided callback. Can be
106
+ * passed `null` to start an entirely new span tree.
107
+ *
108
+ * @param span Spans started in the context of the provided callback will be children of this span. If `null` is passed,
109
+ * spans started within the callback will not be attached to a parent span.
110
+ * @param callback Execution context in which the provided span will be active. Is passed the newly forked scope.
111
+ * @returns the value returned from the provided callback function.
112
+ */
113
+ function withActiveSpan(span, callback) {
114
+ const newContextWithActiveSpan = span ? trace.setSpan(context.active(), span) : trace.deleteSpan(context.active());
115
+ return context.with(newContextWithActiveSpan, () => callback(getCurrentScope()));
116
+ }
117
+
95
118
  function getTracer() {
96
119
  const client = getClient();
97
120
  return (client && client.tracer) || trace.getTracer('@sentry/opentelemetry', SDK_VERSION);
98
121
  }
99
122
 
100
- function _applySentryAttributesToSpan(span, spanContext) {
101
- const { origin, op, source, metadata } = spanContext;
123
+ function _applySentryAttributesToSpan(span, options) {
124
+ // eslint-disable-next-line deprecation/deprecation
125
+ const { origin, op, source, metadata } = options;
102
126
 
103
127
  if (origin) {
104
- span.setAttribute(InternalSentrySemanticAttributes.ORIGIN, origin);
128
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);
105
129
  }
106
130
 
107
131
  if (op) {
108
- span.setAttribute(InternalSentrySemanticAttributes.OP, op);
132
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, op);
109
133
  }
110
134
 
111
135
  if (source) {
112
- span.setAttribute(InternalSentrySemanticAttributes.SOURCE, source);
136
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
113
137
  }
114
138
 
115
139
  if (metadata) {
@@ -117,5 +141,77 @@ function _applySentryAttributesToSpan(span, spanContext) {
117
141
  }
118
142
  }
119
143
 
120
- export { startInactiveSpan, startSpan, startSpanManual };
144
+ function getSpanContext(options) {
145
+ const { startTime, attributes, kind } = options;
146
+
147
+ // OTEL expects timestamps in ms, not seconds
148
+ const fixedStartTime = typeof startTime === 'number' ? ensureTimestampInMilliseconds(startTime) : startTime;
149
+
150
+ return {
151
+ attributes,
152
+ kind,
153
+ startTime: fixedStartTime,
154
+ };
155
+ }
156
+
157
+ function ensureTimestampInMilliseconds(timestamp) {
158
+ const isMs = timestamp < 9999999999;
159
+ return isMs ? timestamp * 1000 : timestamp;
160
+ }
161
+
162
+ function getContext(scope, forceTransaction) {
163
+ const ctx = getContextForScope(scope);
164
+
165
+ if (!forceTransaction) {
166
+ return ctx;
167
+ }
168
+
169
+ // Else we need to "fix" the context to have no parent span
170
+ const parentSpan = trace.getSpan(ctx);
171
+
172
+ // If there is no parent span, all good, nothing to do!
173
+ if (!parentSpan) {
174
+ return ctx;
175
+ }
176
+
177
+ // Else, we need to do two things:
178
+ // 1. Unset the parent span from the context, so we'll create a new root span
179
+ // 2. Ensure the propagation context is correct, so we'll continue from the parent span
180
+ const ctxWithoutSpan = trace.deleteSpan(ctx);
181
+
182
+ const { spanId, traceId, traceFlags } = parentSpan.spanContext();
183
+ // eslint-disable-next-line no-bitwise
184
+ const sampled = Boolean(traceFlags & TraceFlags.SAMPLED);
185
+
186
+ const rootSpan = getRootSpan(parentSpan);
187
+ const dsc = getDynamicSamplingContextFromSpan(rootSpan);
188
+ const dscString = dynamicSamplingContextToSentryBaggageHeader(dsc);
189
+
190
+ const traceState = dscString ? new TraceState().set(SENTRY_TRACE_STATE_DSC, dscString) : undefined;
191
+
192
+ const spanContext = {
193
+ traceId,
194
+ spanId,
195
+ isRemote: true,
196
+ traceFlags: sampled ? TraceFlags.SAMPLED : TraceFlags.NONE,
197
+ traceState,
198
+ };
199
+
200
+ const ctxWithSpanContext = trace.setSpanContext(ctxWithoutSpan, spanContext);
201
+
202
+ return ctxWithSpanContext;
203
+ }
204
+
205
+ function getContextForScope(scope) {
206
+ if (scope) {
207
+ const ctx = getContextFromScope(scope);
208
+ if (ctx) {
209
+ return ctx;
210
+ }
211
+ }
212
+
213
+ return context.active();
214
+ }
215
+
216
+ export { startInactiveSpan, startSpan, startSpanManual, withActiveSpan };
121
217
  //# sourceMappingURL=trace.js.map