@sentry/opentelemetry 7.104.0 → 8.0.0-alpha.1

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