@sentry/opentelemetry 8.0.0-alpha.2 → 8.0.0-alpha.4

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 (176) hide show
  1. package/README.md +2 -1
  2. package/cjs/index.js +2120 -55
  3. package/cjs/index.js.map +1 -1
  4. package/esm/index.js +2091 -23
  5. package/esm/index.js.map +1 -1
  6. package/esm/package.json +1 -0
  7. package/package.json +18 -5
  8. package/types/asyncContextStrategy.d.ts.map +1 -1
  9. package/types/constants.d.ts +2 -3
  10. package/types/constants.d.ts.map +1 -1
  11. package/types/contextManager.d.ts.map +1 -1
  12. package/types/custom/getCurrentHub.d.ts.map +1 -1
  13. package/types/index.d.ts +4 -6
  14. package/types/index.d.ts.map +1 -1
  15. package/types/propagator.d.ts +16 -1
  16. package/types/propagator.d.ts.map +1 -1
  17. package/types/sampler.d.ts.map +1 -1
  18. package/types/semanticAttributes.d.ts +2 -7
  19. package/types/semanticAttributes.d.ts.map +1 -1
  20. package/types/setupEventContextTrace.d.ts.map +1 -1
  21. package/types/spanExporter.d.ts.map +1 -1
  22. package/types/spanProcessor.d.ts.map +1 -1
  23. package/types/trace.d.ts +14 -1
  24. package/types/trace.d.ts.map +1 -1
  25. package/types/types.d.ts +3 -4
  26. package/types/types.d.ts.map +1 -1
  27. package/types/utils/captureExceptionForTimedEvent.d.ts +1 -2
  28. package/types/utils/captureExceptionForTimedEvent.d.ts.map +1 -1
  29. package/types/utils/contextData.d.ts +1 -11
  30. package/types/utils/contextData.d.ts.map +1 -1
  31. package/types/utils/dynamicSamplingContext.d.ts.map +1 -1
  32. package/types/utils/getActiveSpan.d.ts +0 -5
  33. package/types/utils/getActiveSpan.d.ts.map +1 -1
  34. package/types/utils/groupSpansWithParents.d.ts.map +1 -1
  35. package/types/utils/spanData.d.ts +1 -14
  36. package/types/utils/spanData.d.ts.map +1 -1
  37. package/types-ts3.8/constants.d.ts +2 -3
  38. package/types-ts3.8/index.d.ts +4 -6
  39. package/types-ts3.8/propagator.d.ts +16 -1
  40. package/types-ts3.8/semanticAttributes.d.ts +2 -7
  41. package/types-ts3.8/trace.d.ts +14 -1
  42. package/types-ts3.8/types.d.ts +3 -4
  43. package/types-ts3.8/utils/captureExceptionForTimedEvent.d.ts +1 -2
  44. package/types-ts3.8/utils/contextData.d.ts +1 -11
  45. package/types-ts3.8/utils/getActiveSpan.d.ts +0 -5
  46. package/types-ts3.8/utils/spanData.d.ts +1 -14
  47. package/cjs/asyncContextStrategy.js +0 -114
  48. package/cjs/asyncContextStrategy.js.map +0 -1
  49. package/cjs/constants.js +0 -30
  50. package/cjs/constants.js.map +0 -1
  51. package/cjs/contextManager.js +0 -87
  52. package/cjs/contextManager.js.map +0 -1
  53. package/cjs/custom/client.js +0 -64
  54. package/cjs/custom/client.js.map +0 -1
  55. package/cjs/custom/getCurrentHub.js +0 -106
  56. package/cjs/custom/getCurrentHub.js.map +0 -1
  57. package/cjs/custom/hub.js +0 -13
  58. package/cjs/custom/hub.js.map +0 -1
  59. package/cjs/custom/hubextensions.js +0 -37
  60. package/cjs/custom/hubextensions.js.map +0 -1
  61. package/cjs/custom/transaction.js +0 -26
  62. package/cjs/custom/transaction.js.map +0 -1
  63. package/cjs/debug-build.js +0 -11
  64. package/cjs/debug-build.js.map +0 -1
  65. package/cjs/propagator.js +0 -217
  66. package/cjs/propagator.js.map +0 -1
  67. package/cjs/sampler.js +0 -188
  68. package/cjs/sampler.js.map +0 -1
  69. package/cjs/semanticAttributes.js +0 -12
  70. package/cjs/semanticAttributes.js.map +0 -1
  71. package/cjs/setupEventContextTrace.js +0 -40
  72. package/cjs/setupEventContextTrace.js.map +0 -1
  73. package/cjs/spanExporter.js +0 -307
  74. package/cjs/spanExporter.js.map +0 -1
  75. package/cjs/spanProcessor.js +0 -98
  76. package/cjs/spanProcessor.js.map +0 -1
  77. package/cjs/trace.js +0 -222
  78. package/cjs/trace.js.map +0 -1
  79. package/cjs/utils/addOriginToSpan.js +0 -11
  80. package/cjs/utils/addOriginToSpan.js.map +0 -1
  81. package/cjs/utils/captureExceptionForTimedEvent.js +0 -59
  82. package/cjs/utils/captureExceptionForTimedEvent.js.map +0 -1
  83. package/cjs/utils/contextData.js +0 -61
  84. package/cjs/utils/contextData.js.map +0 -1
  85. package/cjs/utils/convertOtelTimeToSeconds.js +0 -9
  86. package/cjs/utils/convertOtelTimeToSeconds.js.map +0 -1
  87. package/cjs/utils/dynamicSamplingContext.js +0 -64
  88. package/cjs/utils/dynamicSamplingContext.js.map +0 -1
  89. package/cjs/utils/getActiveSpan.js +0 -29
  90. package/cjs/utils/getActiveSpan.js.map +0 -1
  91. package/cjs/utils/getRequestSpanData.js +0 -48
  92. package/cjs/utils/getRequestSpanData.js.map +0 -1
  93. package/cjs/utils/getSpanKind.js +0 -21
  94. package/cjs/utils/getSpanKind.js.map +0 -1
  95. package/cjs/utils/groupSpansWithParents.js +0 -74
  96. package/cjs/utils/groupSpansWithParents.js.map +0 -1
  97. package/cjs/utils/isSentryRequest.js +0 -29
  98. package/cjs/utils/isSentryRequest.js.map +0 -1
  99. package/cjs/utils/mapStatus.js +0 -77
  100. package/cjs/utils/mapStatus.js.map +0 -1
  101. package/cjs/utils/parseSpanDescription.js +0 -158
  102. package/cjs/utils/parseSpanDescription.js.map +0 -1
  103. package/cjs/utils/setupCheck.js +0 -17
  104. package/cjs/utils/setupCheck.js.map +0 -1
  105. package/cjs/utils/spanData.js +0 -72
  106. package/cjs/utils/spanData.js.map +0 -1
  107. package/cjs/utils/spanTypes.js +0 -77
  108. package/cjs/utils/spanTypes.js.map +0 -1
  109. package/esm/asyncContextStrategy.js +0 -112
  110. package/esm/asyncContextStrategy.js.map +0 -1
  111. package/esm/constants.js +0 -20
  112. package/esm/constants.js.map +0 -1
  113. package/esm/contextManager.js +0 -82
  114. package/esm/contextManager.js.map +0 -1
  115. package/esm/custom/client.js +0 -59
  116. package/esm/custom/client.js.map +0 -1
  117. package/esm/custom/getCurrentHub.js +0 -101
  118. package/esm/custom/getCurrentHub.js.map +0 -1
  119. package/esm/custom/hub.js +0 -11
  120. package/esm/custom/hub.js.map +0 -1
  121. package/esm/custom/hubextensions.js +0 -35
  122. package/esm/custom/hubextensions.js.map +0 -1
  123. package/esm/custom/transaction.js +0 -24
  124. package/esm/custom/transaction.js.map +0 -1
  125. package/esm/debug-build.js +0 -9
  126. package/esm/debug-build.js.map +0 -1
  127. package/esm/propagator.js +0 -210
  128. package/esm/propagator.js.map +0 -1
  129. package/esm/sampler.js +0 -186
  130. package/esm/sampler.js.map +0 -1
  131. package/esm/semanticAttributes.js +0 -10
  132. package/esm/semanticAttributes.js.map +0 -1
  133. package/esm/setupEventContextTrace.js +0 -38
  134. package/esm/setupEventContextTrace.js.map +0 -1
  135. package/esm/spanExporter.js +0 -305
  136. package/esm/spanExporter.js.map +0 -1
  137. package/esm/spanProcessor.js +0 -96
  138. package/esm/spanProcessor.js.map +0 -1
  139. package/esm/trace.js +0 -217
  140. package/esm/trace.js.map +0 -1
  141. package/esm/utils/addOriginToSpan.js +0 -9
  142. package/esm/utils/addOriginToSpan.js.map +0 -1
  143. package/esm/utils/captureExceptionForTimedEvent.js +0 -57
  144. package/esm/utils/captureExceptionForTimedEvent.js.map +0 -1
  145. package/esm/utils/contextData.js +0 -54
  146. package/esm/utils/contextData.js.map +0 -1
  147. package/esm/utils/convertOtelTimeToSeconds.js +0 -7
  148. package/esm/utils/convertOtelTimeToSeconds.js.map +0 -1
  149. package/esm/utils/dynamicSamplingContext.js +0 -59
  150. package/esm/utils/dynamicSamplingContext.js.map +0 -1
  151. package/esm/utils/getActiveSpan.js +0 -26
  152. package/esm/utils/getActiveSpan.js.map +0 -1
  153. package/esm/utils/getRequestSpanData.js +0 -46
  154. package/esm/utils/getRequestSpanData.js.map +0 -1
  155. package/esm/utils/getSpanKind.js +0 -19
  156. package/esm/utils/getSpanKind.js.map +0 -1
  157. package/esm/utils/groupSpansWithParents.js +0 -72
  158. package/esm/utils/groupSpansWithParents.js.map +0 -1
  159. package/esm/utils/isSentryRequest.js +0 -27
  160. package/esm/utils/isSentryRequest.js.map +0 -1
  161. package/esm/utils/mapStatus.js +0 -75
  162. package/esm/utils/mapStatus.js.map +0 -1
  163. package/esm/utils/parseSpanDescription.js +0 -154
  164. package/esm/utils/parseSpanDescription.js.map +0 -1
  165. package/esm/utils/setupCheck.js +0 -14
  166. package/esm/utils/setupCheck.js.map +0 -1
  167. package/esm/utils/spanData.js +0 -63
  168. package/esm/utils/spanData.js.map +0 -1
  169. package/esm/utils/spanTypes.js +0 -70
  170. package/esm/utils/spanTypes.js.map +0 -1
  171. package/types/custom/hubextensions.d.ts +0 -5
  172. package/types/custom/hubextensions.d.ts.map +0 -1
  173. package/types/custom/transaction.d.ts +0 -8
  174. package/types/custom/transaction.d.ts.map +0 -1
  175. package/types-ts3.8/custom/hubextensions.d.ts +0 -5
  176. package/types-ts3.8/custom/transaction.d.ts +0 -8
@@ -1,307 +0,0 @@
1
- Object.defineProperty(exports, '__esModule', { value: true });
2
-
3
- const api = require('@opentelemetry/api');
4
- const core = require('@opentelemetry/core');
5
- const semanticConventions = require('@opentelemetry/semantic-conventions');
6
- const core$1 = require('@sentry/core');
7
- const utils = require('@sentry/utils');
8
- const transaction = require('./custom/transaction.js');
9
- const debugBuild = require('./debug-build.js');
10
- const semanticAttributes = require('./semanticAttributes.js');
11
- const convertOtelTimeToSeconds = require('./utils/convertOtelTimeToSeconds.js');
12
- const dynamicSamplingContext = require('./utils/dynamicSamplingContext.js');
13
- const getRequestSpanData = require('./utils/getRequestSpanData.js');
14
- const groupSpansWithParents = require('./utils/groupSpansWithParents.js');
15
- const mapStatus = require('./utils/mapStatus.js');
16
- const parseSpanDescription = require('./utils/parseSpanDescription.js');
17
- const spanData = require('./utils/spanData.js');
18
-
19
- /**
20
- * A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.
21
- */
22
- class SentrySpanExporter {
23
-
24
- constructor() {
25
- this._stopped = false;
26
- this._finishedSpans = [];
27
- }
28
-
29
- /** @inheritDoc */
30
- export(spans, resultCallback) {
31
- if (this._stopped) {
32
- return resultCallback({
33
- code: core.ExportResultCode.FAILED,
34
- error: new Error('Exporter has been stopped'),
35
- });
36
- }
37
-
38
- const openSpanCount = this._finishedSpans.length;
39
- const newSpanCount = spans.length;
40
-
41
- this._finishedSpans.push(...spans);
42
-
43
- const remainingSpans = maybeSend(this._finishedSpans);
44
-
45
- const remainingOpenSpanCount = remainingSpans.length;
46
- const sentSpanCount = openSpanCount + newSpanCount - remainingOpenSpanCount;
47
-
48
- debugBuild.DEBUG_BUILD &&
49
- utils.logger.log(`SpanExporter exported ${sentSpanCount} spans, ${remainingOpenSpanCount} unsent spans remaining`);
50
-
51
- this._finishedSpans = remainingSpans.filter(span => {
52
- const shouldDrop = shouldCleanupSpan(span, 5 * 60);
53
- debugBuild.DEBUG_BUILD &&
54
- shouldDrop &&
55
- utils.logger.log(
56
- `SpanExporter dropping span ${span.name} (${
57
- span.spanContext().spanId
58
- }) because it is pending for more than 5 minutes.`,
59
- );
60
- return !shouldDrop;
61
- });
62
-
63
- resultCallback({ code: core.ExportResultCode.SUCCESS });
64
- }
65
-
66
- /** @inheritDoc */
67
- shutdown() {
68
- const forceFlush = this.forceFlush();
69
- this._stopped = true;
70
- this._finishedSpans = [];
71
- return forceFlush;
72
- }
73
-
74
- /** @inheritDoc */
75
- forceFlush() {
76
- return new Promise(resolve => {
77
- this.export(this._finishedSpans, () => resolve());
78
- });
79
- }
80
- }
81
-
82
- /**
83
- * Send the given spans, but only if they are part of a finished transaction.
84
- *
85
- * Returns the unsent spans.
86
- * Spans remain unsent when their parent span is not yet finished.
87
- * This will happen regularly, as child spans are generally finished before their parents.
88
- * But it _could_ also happen because, for whatever reason, a parent span was lost.
89
- * In this case, we'll eventually need to clean this up.
90
- */
91
- function maybeSend(spans) {
92
- const grouped = groupSpansWithParents.groupSpansWithParents(spans);
93
- const remaining = new Set(grouped);
94
-
95
- const rootNodes = getCompletedRootNodes(grouped);
96
-
97
- rootNodes.forEach(root => {
98
- remaining.delete(root);
99
- const span = root.span;
100
- const transaction = createTransactionForOtelSpan(span);
101
-
102
- root.children.forEach(child => {
103
- createAndFinishSpanForOtelSpan(child, transaction, remaining);
104
- });
105
-
106
- transaction.end(span.endTime);
107
- });
108
-
109
- return Array.from(remaining)
110
- .map(node => node.span)
111
- .filter((span) => !!span);
112
- }
113
-
114
- function getCompletedRootNodes(nodes) {
115
- return nodes.filter((node) => !!node.span && !node.parentNode);
116
- }
117
-
118
- function shouldCleanupSpan(span, maxStartTimeOffsetSeconds) {
119
- const cutoff = Date.now() / 1000 - maxStartTimeOffsetSeconds;
120
- return convertOtelTimeToSeconds.convertOtelTimeToSeconds(span.startTime) < cutoff;
121
- }
122
-
123
- function parseSpan(span) {
124
- const attributes = span.attributes;
125
-
126
- const origin = attributes[core$1.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] ;
127
- const op = attributes[core$1.SEMANTIC_ATTRIBUTE_SENTRY_OP] ;
128
- const source = attributes[core$1.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] ;
129
-
130
- return { origin, op, source };
131
- }
132
-
133
- function createTransactionForOtelSpan(span) {
134
- // eslint-disable-next-line deprecation/deprecation
135
- const hub = spanData.getSpanHub(span) || core$1.getCurrentHub();
136
- const spanContext = span.spanContext();
137
- const spanId = spanContext.spanId;
138
- const traceId = spanContext.traceId;
139
- const parentSpanId = span.parentSpanId;
140
-
141
- const parentSampled = span.attributes[semanticAttributes.InternalSentrySemanticAttributes.PARENT_SAMPLED] ;
142
-
143
- const { op, description, data, origin, source } = getSpanData(span);
144
- const metadata = spanData.getSpanMetadata(span);
145
- const capturedSpanScopes = spanData.getSpanScopes(span);
146
-
147
- const sampleRate = span.attributes[core$1.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] ;
148
-
149
- const attributes = {
150
- [core$1.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
151
- [core$1.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,
152
- ...data,
153
- ...removeSentryAttributes(span.attributes),
154
- };
155
-
156
- const dynamicSamplingContext$1 = dynamicSamplingContext.getDynamicSamplingContextFromSpan(span);
157
-
158
- const transaction$1 = transaction.startTransaction(hub, {
159
- spanId,
160
- traceId,
161
- parentSpanId,
162
- parentSampled,
163
- name: description,
164
- op,
165
- startTimestamp: convertOtelTimeToSeconds.convertOtelTimeToSeconds(span.startTime),
166
- metadata: {
167
- ...utils.dropUndefinedKeys({
168
- dynamicSamplingContext: dynamicSamplingContext$1,
169
- sampleRate,
170
- }),
171
- ...metadata,
172
- },
173
- attributes,
174
- origin,
175
- sampled: true,
176
- });
177
-
178
- transaction$1.setStatus(mapStatus.mapStatus(span));
179
-
180
- // We currently don't want to write this to the scope because it would mutate it.
181
- // In the future we will likely have some sort of transaction payload factory where we can pass this context in directly
182
- // eslint-disable-next-line deprecation/deprecation
183
- transaction$1.setContext('otel', {
184
- attributes: removeSentryAttributes(span.attributes),
185
- resource: span.resource.attributes,
186
- });
187
-
188
- if (capturedSpanScopes) {
189
- setCapturedScopesOnTransaction(transaction$1, capturedSpanScopes.scope, capturedSpanScopes.isolationScope);
190
- }
191
-
192
- return transaction$1;
193
- }
194
-
195
- function createAndFinishSpanForOtelSpan(node, sentryParentSpan, remaining) {
196
- remaining.delete(node);
197
- const span = node.span;
198
-
199
- const shouldDrop = !span;
200
-
201
- // If this span should be dropped, we still want to create spans for the children of this
202
- if (shouldDrop) {
203
- node.children.forEach(child => {
204
- createAndFinishSpanForOtelSpan(child, sentryParentSpan, remaining);
205
- });
206
- return;
207
- }
208
-
209
- const spanId = span.spanContext().spanId;
210
- const { attributes } = span;
211
-
212
- const { op, description, data, origin } = getSpanData(span);
213
- const allData = { ...removeSentryAttributes(attributes), ...data };
214
-
215
- // eslint-disable-next-line deprecation/deprecation
216
- const sentrySpan = sentryParentSpan.startChild({
217
- name: description,
218
- op,
219
- data: allData,
220
- startTimestamp: convertOtelTimeToSeconds.convertOtelTimeToSeconds(span.startTime),
221
- spanId,
222
- origin,
223
- }) ;
224
- sentrySpan.setStatus(mapStatus.mapStatus(span));
225
-
226
- node.children.forEach(child => {
227
- createAndFinishSpanForOtelSpan(child, sentrySpan, remaining);
228
- });
229
-
230
- sentrySpan.end(convertOtelTimeToSeconds.convertOtelTimeToSeconds(span.endTime));
231
- }
232
-
233
- function getSpanData(span)
234
-
235
- {
236
- const { op: definedOp, source: definedSource, origin } = parseSpan(span);
237
- const { op: inferredOp, description, source: inferredSource, data: inferredData } = parseSpanDescription.parseSpanDescription(span);
238
-
239
- const op = definedOp || inferredOp;
240
- const source = definedSource || inferredSource;
241
-
242
- const data = { ...inferredData, ...getData(span) };
243
-
244
- return {
245
- op,
246
- description,
247
- source,
248
- origin,
249
- data,
250
- };
251
- }
252
-
253
- /**
254
- * Remove custom `sentry.` attribtues we do not need to send.
255
- * These are more carrier attributes we use inside of the SDK, we do not need to send them to the API.
256
- */
257
- function removeSentryAttributes(data) {
258
- const cleanedData = { ...data };
259
-
260
- /* eslint-disable @typescript-eslint/no-dynamic-delete */
261
- delete cleanedData[semanticAttributes.InternalSentrySemanticAttributes.PARENT_SAMPLED];
262
- delete cleanedData[core$1.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];
263
- /* eslint-enable @typescript-eslint/no-dynamic-delete */
264
-
265
- return cleanedData;
266
- }
267
-
268
- function getData(span) {
269
- const attributes = span.attributes;
270
- const data = {
271
- 'otel.kind': api.SpanKind[span.kind],
272
- };
273
-
274
- if (attributes[semanticConventions.SemanticAttributes.HTTP_STATUS_CODE]) {
275
- const statusCode = attributes[semanticConventions.SemanticAttributes.HTTP_STATUS_CODE] ;
276
- data['http.response.status_code'] = statusCode;
277
- }
278
-
279
- const requestData = getRequestSpanData.getRequestSpanData(span);
280
-
281
- if (requestData.url) {
282
- data.url = requestData.url;
283
- }
284
-
285
- if (requestData['http.query']) {
286
- data['http.query'] = requestData['http.query'].slice(1);
287
- }
288
- if (requestData['http.fragment']) {
289
- data['http.fragment'] = requestData['http.fragment'].slice(1);
290
- }
291
-
292
- return data;
293
- }
294
-
295
- const SCOPE_ON_START_SPAN_FIELD = '_sentryScope';
296
- const ISOLATION_SCOPE_ON_START_SPAN_FIELD = '_sentryIsolationScope';
297
-
298
- /** Sets the scope and isolation scope to be used for when the transaction is finished. */
299
- function setCapturedScopesOnTransaction(span, scope, isolationScope) {
300
- if (span) {
301
- utils.addNonEnumerableProperty(span, ISOLATION_SCOPE_ON_START_SPAN_FIELD, isolationScope);
302
- utils.addNonEnumerableProperty(span, SCOPE_ON_START_SPAN_FIELD, scope);
303
- }
304
- }
305
-
306
- exports.SentrySpanExporter = SentrySpanExporter;
307
- //# sourceMappingURL=spanExporter.js.map
@@ -1 +0,0 @@
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":["ExportResultCode","DEBUG_BUILD","logger","groupSpansWithParents","convertOtelTimeToSeconds","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","getSpanHub","getCurrentHub","InternalSentrySemanticAttributes","getSpanMetadata","getSpanScopes","SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE","dynamicSamplingContext","getDynamicSamplingContextFromSpan","transaction","startTransaction","dropUndefinedKeys","mapStatus","parseSpanDescription","SpanKind","SemanticAttributes","getRequestSpanData","addNonEnumerableProperty"],"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,EAAEA,qBAAgB,CAAC,MAAM;AACrC,QAAQ,KAAK,EAAE,IAAI,KAAK,CAAC,2BAA2B,CAAC;AACrD,OAAO,CAAC,CAAA;AACR,KAAI;AACJ;AACA,IAAI,MAAM,aAAc,GAAE,IAAI,CAAC,cAAc,CA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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,IAAIC,8BAAwB,CAAC,IAAI,EAAE,mCAAmC,EAAE,cAAc,CAAC,CAAA;AACvF,IAAIA,8BAAwB,CAAC,IAAI,EAAE,yBAAyB,EAAE,KAAK,CAAC,CAAA;AACpE,GAAE;AACF;;;;"}
@@ -1,98 +0,0 @@
1
- Object.defineProperty(exports, '__esModule', { value: true });
2
-
3
- const api = require('@opentelemetry/api');
4
- const sdkTraceBase = require('@opentelemetry/sdk-trace-base');
5
- const core = require('@sentry/core');
6
- const utils = require('@sentry/utils');
7
- const debugBuild = require('./debug-build.js');
8
- const spanExporter = require('./spanExporter.js');
9
- const captureExceptionForTimedEvent = require('./utils/captureExceptionForTimedEvent.js');
10
- const contextData = require('./utils/contextData.js');
11
- const setupCheck = require('./utils/setupCheck.js');
12
- const spanData = require('./utils/spanData.js');
13
-
14
- function onSpanStart(span, parentContext) {
15
- // This is a reliable way to get the parent span - because this is exactly how the parent is identified in the OTEL SDK
16
- const parentSpan = api.trace.getSpan(parentContext);
17
- const hub = contextData.getHubFromContext(parentContext);
18
-
19
- // We need access to the parent span in order to be able to move up the span tree for breadcrumbs
20
- if (parentSpan) {
21
- spanData.setSpanParent(span, parentSpan);
22
- }
23
-
24
- // The root context does not have a hub stored, so we check for this specifically
25
- // We do this instead of just falling back to `getCurrentHub` to avoid attaching the wrong hub
26
- let actualHub = hub;
27
- if (parentContext === api.ROOT_CONTEXT) {
28
- // eslint-disable-next-line deprecation/deprecation
29
- actualHub = core.getCurrentHub();
30
- }
31
-
32
- // We need the scope at time of span creation in order to apply it to the event when the span is finished
33
- if (actualHub) {
34
- // eslint-disable-next-line deprecation/deprecation
35
- const scope = actualHub.getScope();
36
- // eslint-disable-next-line deprecation/deprecation
37
- const isolationScope = actualHub.getIsolationScope();
38
- spanData.setSpanHub(span, actualHub);
39
- spanData.setSpanScopes(span, { scope, isolationScope });
40
- }
41
- }
42
-
43
- function onSpanEnd(span) {
44
- // Capture exceptions as events
45
- // eslint-disable-next-line deprecation/deprecation
46
- const hub = spanData.getSpanHub(span) || core.getCurrentHub();
47
- span.events.forEach(event => {
48
- captureExceptionForTimedEvent.maybeCaptureExceptionForTimedEvent(hub, event, span);
49
- });
50
- }
51
-
52
- /**
53
- * Converts OpenTelemetry Spans to Sentry Spans and sends them to Sentry via
54
- * the Sentry SDK.
55
- */
56
- class SentrySpanProcessor extends sdkTraceBase.BatchSpanProcessor {
57
- constructor() {
58
- super(new spanExporter.SentrySpanExporter());
59
-
60
- setupCheck.setIsSetup('SentrySpanProcessor');
61
- }
62
-
63
- /**
64
- * @inheritDoc
65
- */
66
- onStart(span, parentContext) {
67
- onSpanStart(span, parentContext);
68
-
69
- debugBuild.DEBUG_BUILD && utils.logger.log(`[Tracing] Starting span "${span.name}" (${span.spanContext().spanId})`);
70
-
71
- return super.onStart(span, parentContext);
72
- }
73
-
74
- /** @inheritDoc */
75
- onEnd(span) {
76
- debugBuild.DEBUG_BUILD && utils.logger.log(`[Tracing] Finishing span "${span.name}" (${span.spanContext().spanId})`);
77
-
78
- if (!this._shouldSendSpanToSentry(span)) {
79
- // Prevent this being called to super.onEnd(), which would pass this to the span exporter
80
- return;
81
- }
82
-
83
- onSpanEnd(span);
84
-
85
- return super.onEnd(span);
86
- }
87
-
88
- /**
89
- * You can overwrite this in a sub class to implement custom behavior for dropping spans.
90
- * If you return `false` here, the span will not be passed to the exporter and thus not be sent.
91
- */
92
- _shouldSendSpanToSentry(_span) {
93
- return true;
94
- }
95
- }
96
-
97
- exports.SentrySpanProcessor = SentrySpanProcessor;
98
- //# sourceMappingURL=spanProcessor.js.map
@@ -1 +0,0 @@
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":["trace","getHubFromContext","setSpanParent","ROOT_CONTEXT","getCurrentHub","setSpanHub","setSpanScopes","getSpanHub","maybeCaptureExceptionForTimedEvent","BatchSpanProcessor","SentrySpanExporter","setIsSetup","DEBUG_BUILD","logger"],"mappings":";;;;;;;;;;;;;AAcA,SAAS,WAAW,CAAC,IAAI,EAAQ,aAAa,EAAiB;AAC/D;AACA,EAAE,MAAM,aAAaA,SAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;AACjD,EAAE,MAAM,GAAI,GAAEC,6BAAiB,CAAC,aAAa,CAAC,CAAA;AAC9C;AACA;AACA,EAAE,IAAI,UAAU,EAAE;AAClB,IAAIC,sBAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;AACnC,GAAE;AACF;AACA;AACA;AACA,EAAE,IAAI,SAAU,GAAE,GAAG,CAAA;AACrB,EAAE,IAAI,aAAc,KAAIC,gBAAY,EAAE;AACtC;AACA,IAAI,SAAU,GAAEC,kBAAa,EAAE,CAAA;AAC/B,GAAE;AACF;AACA;AACA,EAAE,IAAI,SAAS,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AAI,EAAc;AACjC,IAAID,sBAAA,IAAeC,YAAM,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/cjs/trace.js DELETED
@@ -1,222 +0,0 @@
1
- Object.defineProperty(exports, '__esModule', { value: true });
2
-
3
- const api = require('@opentelemetry/api');
4
- const core = require('@opentelemetry/core');
5
- const core$1 = require('@sentry/core');
6
- const utils = require('@sentry/utils');
7
- const constants = require('./constants.js');
8
- const contextData = require('./utils/contextData.js');
9
- const dynamicSamplingContext = require('./utils/dynamicSamplingContext.js');
10
- const getActiveSpan = require('./utils/getActiveSpan.js');
11
- const spanData = require('./utils/spanData.js');
12
-
13
- /**
14
- * Wraps a function with a transaction/span and finishes the span after the function is done.
15
- * The created span is the active span and will be used as parent by other spans created inside the function
16
- * and can be accessed via `Sentry.getSpan()`, as long as the function is executed while the scope is active.
17
- *
18
- * If you want to create a span that is not set as active, use {@link startInactiveSpan}.
19
- *
20
- * Note that you'll always get a span passed to the callback, it may just be a NonRecordingSpan if the span is not sampled.
21
- */
22
- function startSpan(options, callback) {
23
- const tracer = getTracer();
24
-
25
- const { name } = options;
26
-
27
- const activeCtx = getContext(options.scope, options.forceTransaction);
28
- const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
29
- const ctx = shouldSkipSpan ? core.suppressTracing(activeCtx) : activeCtx;
30
-
31
- const spanContext = getSpanContext(options);
32
-
33
- return tracer.startActiveSpan(name, spanContext, ctx, span => {
34
- _applySentryAttributesToSpan(span, options);
35
-
36
- return core$1.handleCallbackErrors(
37
- () => callback(span),
38
- () => {
39
- span.setStatus({ code: api.SpanStatusCode.ERROR });
40
- },
41
- () => span.end(),
42
- );
43
- });
44
- }
45
-
46
- /**
47
- * Similar to `Sentry.startSpan`. Wraps a function with a span, but does not finish the span
48
- * after the function is done automatically. You'll have to call `span.end()` manually.
49
- *
50
- * The created span is the active span and will be used as parent by other spans created inside the function
51
- * and can be accessed via `Sentry.getActiveSpan()`, as long as the function is executed while the scope is active.
52
- *
53
- * Note that you'll always get a span passed to the callback, it may just be a NonRecordingSpan if the span is not sampled.
54
- */
55
- function startSpanManual(options, callback) {
56
- const tracer = getTracer();
57
-
58
- const { name } = options;
59
-
60
- const activeCtx = getContext(options.scope, options.forceTransaction);
61
- const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
62
- const ctx = shouldSkipSpan ? core.suppressTracing(activeCtx) : activeCtx;
63
-
64
- const spanContext = getSpanContext(options);
65
-
66
- return tracer.startActiveSpan(name, spanContext, ctx, span => {
67
- _applySentryAttributesToSpan(span, options);
68
-
69
- return core$1.handleCallbackErrors(
70
- () => callback(span),
71
- () => {
72
- span.setStatus({ code: api.SpanStatusCode.ERROR });
73
- },
74
- );
75
- });
76
- }
77
-
78
- /**
79
- * Creates a span. This span is not set as active, so will not get automatic instrumentation spans
80
- * as children or be able to be accessed via `Sentry.getSpan()`.
81
- *
82
- * If you want to create a span that is set as active, use {@link startSpan}.
83
- *
84
- * Note that if you have not enabled tracing extensions via `addTracingExtensions`
85
- * or you didn't set `tracesSampleRate` or `tracesSampler`, this function will not generate spans
86
- * and the `span` returned from the callback will be undefined.
87
- */
88
- function startInactiveSpan(options) {
89
- const tracer = getTracer();
90
-
91
- const { name } = options;
92
-
93
- const activeCtx = getContext(options.scope, options.forceTransaction);
94
- const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
95
- const ctx = shouldSkipSpan ? core.suppressTracing(activeCtx) : activeCtx;
96
-
97
- const spanContext = getSpanContext(options);
98
-
99
- const span = tracer.startSpan(name, spanContext, ctx);
100
-
101
- _applySentryAttributesToSpan(span, options);
102
-
103
- return span;
104
- }
105
-
106
- /**
107
- * Forks the current scope and sets the provided span as active span in the context of the provided callback. Can be
108
- * passed `null` to start an entirely new span tree.
109
- *
110
- * @param span Spans started in the context of the provided callback will be children of this span. If `null` is passed,
111
- * spans started within the callback will not be attached to a parent span.
112
- * @param callback Execution context in which the provided span will be active. Is passed the newly forked scope.
113
- * @returns the value returned from the provided callback function.
114
- */
115
- function withActiveSpan(span, callback) {
116
- const newContextWithActiveSpan = span ? api.trace.setSpan(api.context.active(), span) : api.trace.deleteSpan(api.context.active());
117
- return api.context.with(newContextWithActiveSpan, () => callback(core$1.getCurrentScope()));
118
- }
119
-
120
- function getTracer() {
121
- const client = core$1.getClient();
122
- return (client && client.tracer) || api.trace.getTracer('@sentry/opentelemetry', core$1.SDK_VERSION);
123
- }
124
-
125
- function _applySentryAttributesToSpan(span, options) {
126
- // eslint-disable-next-line deprecation/deprecation
127
- const { origin, op, source, metadata } = options;
128
-
129
- if (origin) {
130
- span.setAttribute(core$1.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);
131
- }
132
-
133
- if (op) {
134
- span.setAttribute(core$1.SEMANTIC_ATTRIBUTE_SENTRY_OP, op);
135
- }
136
-
137
- if (source) {
138
- span.setAttribute(core$1.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
139
- }
140
-
141
- if (metadata) {
142
- spanData.setSpanMetadata(span, metadata);
143
- }
144
- }
145
-
146
- function getSpanContext(options) {
147
- const { startTime, attributes, kind } = options;
148
-
149
- // OTEL expects timestamps in ms, not seconds
150
- const fixedStartTime = typeof startTime === 'number' ? ensureTimestampInMilliseconds(startTime) : startTime;
151
-
152
- return {
153
- attributes,
154
- kind,
155
- startTime: fixedStartTime,
156
- };
157
- }
158
-
159
- function ensureTimestampInMilliseconds(timestamp) {
160
- const isMs = timestamp < 9999999999;
161
- return isMs ? timestamp * 1000 : timestamp;
162
- }
163
-
164
- function getContext(scope, forceTransaction) {
165
- const ctx = getContextForScope(scope);
166
-
167
- if (!forceTransaction) {
168
- return ctx;
169
- }
170
-
171
- // Else we need to "fix" the context to have no parent span
172
- const parentSpan = api.trace.getSpan(ctx);
173
-
174
- // If there is no parent span, all good, nothing to do!
175
- if (!parentSpan) {
176
- return ctx;
177
- }
178
-
179
- // Else, we need to do two things:
180
- // 1. Unset the parent span from the context, so we'll create a new root span
181
- // 2. Ensure the propagation context is correct, so we'll continue from the parent span
182
- const ctxWithoutSpan = api.trace.deleteSpan(ctx);
183
-
184
- const { spanId, traceId, traceFlags } = parentSpan.spanContext();
185
- // eslint-disable-next-line no-bitwise
186
- const sampled = Boolean(traceFlags & api.TraceFlags.SAMPLED);
187
-
188
- const rootSpan = getActiveSpan.getRootSpan(parentSpan);
189
- const dsc = dynamicSamplingContext.getDynamicSamplingContextFromSpan(rootSpan);
190
- const dscString = utils.dynamicSamplingContextToSentryBaggageHeader(dsc);
191
-
192
- const traceState = dscString ? new core.TraceState().set(constants.SENTRY_TRACE_STATE_DSC, dscString) : undefined;
193
-
194
- const spanContext = {
195
- traceId,
196
- spanId,
197
- isRemote: true,
198
- traceFlags: sampled ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE,
199
- traceState,
200
- };
201
-
202
- const ctxWithSpanContext = api.trace.setSpanContext(ctxWithoutSpan, spanContext);
203
-
204
- return ctxWithSpanContext;
205
- }
206
-
207
- function getContextForScope(scope) {
208
- if (scope) {
209
- const ctx = contextData.getContextFromScope(scope);
210
- if (ctx) {
211
- return ctx;
212
- }
213
- }
214
-
215
- return api.context.active();
216
- }
217
-
218
- exports.startInactiveSpan = startInactiveSpan;
219
- exports.startSpan = startSpan;
220
- exports.startSpanManual = startSpanManual;
221
- exports.withActiveSpan = withActiveSpan;
222
- //# sourceMappingURL=trace.js.map