@sentry/opentelemetry 8.0.0-alpha.9 → 8.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js CHANGED
@@ -89,8 +89,8 @@ function getRequestSpanData(span) {
89
89
  }
90
90
 
91
91
  const data = {
92
- url: span.attributes[semanticConventions.SemanticAttributes.HTTP_URL] ,
93
- 'http.method': span.attributes[semanticConventions.SemanticAttributes.HTTP_METHOD] ,
92
+ url: span.attributes[semanticConventions.SEMATTRS_HTTP_URL] ,
93
+ 'http.method': span.attributes[semanticConventions.SEMATTRS_HTTP_METHOD] ,
94
94
  };
95
95
 
96
96
  // Default to GET if URL is set but method is not
@@ -99,7 +99,7 @@ function getRequestSpanData(span) {
99
99
  }
100
100
 
101
101
  try {
102
- const urlStr = span.attributes[semanticConventions.SemanticAttributes.HTTP_URL];
102
+ const urlStr = span.attributes[semanticConventions.SEMATTRS_HTTP_URL];
103
103
  if (typeof urlStr === 'string') {
104
104
  const url = utils.parseUrl(urlStr);
105
105
 
@@ -119,7 +119,7 @@ function getRequestSpanData(span) {
119
119
  return data;
120
120
  }
121
121
 
122
- function _optionalChain$9(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
122
+ function _optionalChain$7(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
123
123
 
124
124
  // Typescript complains if we do not use `...args: any[]` for the mixin, with:
125
125
  // A mixin class must have a constructor with a single rest parameter of type 'any[]'.ts(2545)
@@ -160,7 +160,7 @@ function wrapClientClass
160
160
  */
161
161
  async flush(timeout) {
162
162
  const provider = this.traceProvider;
163
- const spanProcessor = _optionalChain$9([provider, 'optionalAccess', _ => _.activeSpanProcessor]);
163
+ const spanProcessor = _optionalChain$7([provider, 'optionalAccess', _ => _.activeSpanProcessor]);
164
164
 
165
165
  if (spanProcessor) {
166
166
  await spanProcessor.forceFlush();
@@ -188,40 +188,13 @@ function getSpanKind(span) {
188
188
  return api.SpanKind.INTERNAL;
189
189
  }
190
190
 
191
- // We store the parent span, scopes & metadata in separate weakmaps, so we can access them for a given span
192
- // This way we can enhance the data that an OTEL Span natively gives us
193
- // and since we are using weakmaps, we do not need to clean up after ourselves
194
- const SpanScopes = new WeakMap
195
-
196
- ();
197
-
198
- /**
199
- * Set the Sentry scope to be used for finishing a given OTEL span.
200
- * This is different from `setCapturedScopesOnSpan`, as that works on _sentry_ spans,
201
- * while here we are basically "caching" this on the otel spans.
202
- */
203
- function setSpanScopes(
204
- span,
205
- scopes
206
-
207
- ,
208
- ) {
209
- SpanScopes.set(span, scopes);
210
- }
211
-
212
- /** Get the Sentry scopes to use for finishing an OTEL span. */
213
- function getSpanScopes(span)
214
-
215
- {
216
- return SpanScopes.get(span);
217
- }
218
-
219
191
  const SENTRY_TRACE_HEADER = 'sentry-trace';
220
192
  const SENTRY_BAGGAGE_HEADER = 'baggage';
221
193
 
222
194
  const SENTRY_TRACE_STATE_DSC = 'sentry.dsc';
223
195
  const SENTRY_TRACE_STATE_PARENT_SPAN_ID = 'sentry.parent_span_id';
224
196
  const SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING = 'sentry.sampled_not_recording';
197
+ const SENTRY_TRACE_STATE_URL = 'sentry.url';
225
198
 
226
199
  const SENTRY_SCOPES_CONTEXT_KEY = api.createContextKey('sentry_scopes');
227
200
 
@@ -231,7 +204,7 @@ const SENTRY_FORK_SET_SCOPE_CONTEXT_KEY = api.createContextKey('sentry_fork_set_
231
204
 
232
205
  const SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY = api.createContextKey('sentry_fork_set_isolation_scope');
233
206
 
234
- const SCOPE_CONTEXT_MAP = new WeakMap();
207
+ const SCOPE_CONTEXT_FIELD = '_scopeContext';
235
208
 
236
209
  /**
237
210
  * Try to get the current scopes from the given OTEL context.
@@ -254,7 +227,7 @@ function setScopesOnContext(context, scopes) {
254
227
  * We need this to get the context from the scope in the `trace` functions.
255
228
  */
256
229
  function setContextOnScope(scope, context) {
257
- SCOPE_CONTEXT_MAP.set(scope, context);
230
+ utils.addNonEnumerableProperty(scope, SCOPE_CONTEXT_FIELD, context);
258
231
  }
259
232
 
260
233
  /**
@@ -262,10 +235,10 @@ function setContextOnScope(scope, context) {
262
235
  * TODO v8: Use this for the `trace` functions.
263
236
  * */
264
237
  function getContextFromScope(scope) {
265
- return SCOPE_CONTEXT_MAP.get(scope);
238
+ return (scope )[SCOPE_CONTEXT_FIELD];
266
239
  }
267
240
 
268
- function _optionalChain$8(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
241
+ function _optionalChain$6(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
269
242
 
270
243
  /**
271
244
  * OpenTelemetry only knows about SAMPLED or NONE decision,
@@ -295,10 +268,10 @@ function getSamplingDecision(spanContext) {
295
268
  const dscString = traceState ? traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
296
269
  const dsc = dscString ? utils.baggageHeaderToDynamicSamplingContext(dscString) : undefined;
297
270
 
298
- if (_optionalChain$8([dsc, 'optionalAccess', _ => _.sampled]) === 'true') {
271
+ if (_optionalChain$6([dsc, 'optionalAccess', _ => _.sampled]) === 'true') {
299
272
  return true;
300
273
  }
301
- if (_optionalChain$8([dsc, 'optionalAccess', _2 => _2.sampled]) === 'false') {
274
+ if (_optionalChain$6([dsc, 'optionalAccess', _2 => _2.sampled]) === 'false') {
302
275
  return false;
303
276
  }
304
277
 
@@ -315,19 +288,19 @@ function parseSpanDescription(span) {
315
288
  const name = spanHasName(span) ? span.name : '<unknown>';
316
289
 
317
290
  // if http.method exists, this is an http request span
318
- const httpMethod = attributes[semanticConventions.SemanticAttributes.HTTP_METHOD];
291
+ const httpMethod = attributes[semanticConventions.SEMATTRS_HTTP_METHOD];
319
292
  if (httpMethod) {
320
293
  return descriptionForHttpMethod({ attributes, name, kind: getSpanKind(span) }, httpMethod);
321
294
  }
322
295
 
323
296
  // If db.type exists then this is a database call span.
324
- const dbSystem = attributes[semanticConventions.SemanticAttributes.DB_SYSTEM];
297
+ const dbSystem = attributes[semanticConventions.SEMATTRS_DB_SYSTEM];
325
298
  if (dbSystem) {
326
299
  return descriptionForDbSystem({ attributes, name });
327
300
  }
328
301
 
329
302
  // If rpc.service exists then this is a rpc call span.
330
- const rpcService = attributes[semanticConventions.SemanticAttributes.RPC_SERVICE];
303
+ const rpcService = attributes[semanticConventions.SEMATTRS_RPC_SERVICE];
331
304
  if (rpcService) {
332
305
  return {
333
306
  op: 'rpc',
@@ -337,7 +310,7 @@ function parseSpanDescription(span) {
337
310
  }
338
311
 
339
312
  // If messaging.system exists then this is a messaging system span.
340
- const messagingSystem = attributes[semanticConventions.SemanticAttributes.MESSAGING_SYSTEM];
313
+ const messagingSystem = attributes[semanticConventions.SEMATTRS_MESSAGING_SYSTEM];
341
314
  if (messagingSystem) {
342
315
  return {
343
316
  op: 'message',
@@ -347,7 +320,7 @@ function parseSpanDescription(span) {
347
320
  }
348
321
 
349
322
  // If faas.trigger exists then this is a function as a service span.
350
- const faasTrigger = attributes[semanticConventions.SemanticAttributes.FAAS_TRIGGER];
323
+ const faasTrigger = attributes[semanticConventions.SEMATTRS_FAAS_TRIGGER];
351
324
  if (faasTrigger) {
352
325
  return { op: faasTrigger.toString(), description: name, source: 'route' };
353
326
  }
@@ -357,7 +330,7 @@ function parseSpanDescription(span) {
357
330
 
358
331
  function descriptionForDbSystem({ attributes, name }) {
359
332
  // Use DB statement (Ex "SELECT * FROM table") if possible as description.
360
- const statement = attributes[semanticConventions.SemanticAttributes.DB_STATEMENT];
333
+ const statement = attributes[semanticConventions.SEMATTRS_DB_STATEMENT];
361
334
 
362
335
  const description = statement ? statement.toString() : name;
363
336
 
@@ -420,11 +393,11 @@ function getSanitizedUrl(
420
393
 
421
394
  {
422
395
  // This is the relative path of the URL, e.g. /sub
423
- const httpTarget = attributes[semanticConventions.SemanticAttributes.HTTP_TARGET];
396
+ const httpTarget = attributes[semanticConventions.SEMATTRS_HTTP_TARGET];
424
397
  // This is the full URL, including host & query params etc., e.g. https://example.com/sub?foo=bar
425
- const httpUrl = attributes[semanticConventions.SemanticAttributes.HTTP_URL];
398
+ const httpUrl = attributes[semanticConventions.SEMATTRS_HTTP_URL];
426
399
  // This is the normalized route name - may not always be available!
427
- const httpRoute = attributes[semanticConventions.SemanticAttributes.HTTP_ROUTE];
400
+ const httpRoute = attributes[semanticConventions.SEMATTRS_HTTP_ROUTE];
428
401
 
429
402
  const parsedUrl = typeof httpUrl === 'string' ? utils.parseUrl(httpUrl) : undefined;
430
403
  const url = parsedUrl ? utils.getSanitizedUrlString(parsedUrl) : undefined;
@@ -451,7 +424,7 @@ function getSanitizedUrl(
451
424
  return { urlPath: undefined, url, query, fragment, hasRoute: false };
452
425
  }
453
426
 
454
- function _optionalChain$7(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
427
+ function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
455
428
  /**
456
429
  * Creates a dynamic sampling context from a span (and client and scope)
457
430
  *
@@ -466,7 +439,7 @@ function getDynamicSamplingContextFromSpan(span) {
466
439
  }
467
440
 
468
441
  const traceState = span.spanContext().traceState;
469
- const traceStateDsc = _optionalChain$7([traceState, 'optionalAccess', _ => _.get, 'call', _2 => _2(SENTRY_TRACE_STATE_DSC)]);
442
+ const traceStateDsc = _optionalChain$5([traceState, 'optionalAccess', _ => _.get, 'call', _2 => _2(SENTRY_TRACE_STATE_DSC)]);
470
443
 
471
444
  // If the span has a DSC, we want it to take precedence
472
445
  const dscOnSpan = traceStateDsc ? utils.baggageHeaderToDynamicSamplingContext(traceStateDsc) : undefined;
@@ -516,7 +489,7 @@ function isSentryRequestSpan(span) {
516
489
 
517
490
  const { attributes } = span;
518
491
 
519
- const httpUrl = attributes[semanticConventions.SemanticAttributes.HTTP_URL];
492
+ const httpUrl = attributes[semanticConventions.SEMATTRS_HTTP_URL];
520
493
 
521
494
  if (!httpUrl) {
522
495
  return false;
@@ -551,7 +524,7 @@ function setIsSetup(element) {
551
524
  setupElements.add(element);
552
525
  }
553
526
 
554
- function _optionalChain$6(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
527
+ function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
555
528
 
556
529
  /** Get the Sentry propagation context from a span context. */
557
530
  function getPropagationContextFromSpan(span) {
@@ -603,15 +576,19 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
603
576
  }
604
577
 
605
578
  const activeSpan = api.trace.getSpan(context);
606
- const url = activeSpan && _optionalChain$6([core.spanToJSON, 'call', _ => _(activeSpan), 'access', _2 => _2.data, 'optionalAccess', _3 => _3[semanticConventions.SemanticAttributes.HTTP_URL]]);
607
- const tracePropagationTargets = _optionalChain$6([core.getClient, 'call', _4 => _4(), 'optionalAccess', _5 => _5.getOptions, 'call', _6 => _6(), 'optionalAccess', _7 => _7.tracePropagationTargets]);
579
+ const url = activeSpan && getCurrentURL(activeSpan);
580
+
581
+ const tracePropagationTargets = _optionalChain$4([core.getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getOptions, 'call', _3 => _3(), 'optionalAccess', _4 => _4.tracePropagationTargets]);
608
582
  if (
609
583
  typeof url === 'string' &&
610
584
  tracePropagationTargets &&
611
585
  !this._shouldInjectTraceData(tracePropagationTargets, url)
612
586
  ) {
613
587
  DEBUG_BUILD &&
614
- utils.logger.log('[Tracing] Not injecting trace data for url because it does not matchTracePropagationTargets:', url);
588
+ utils.logger.log(
589
+ '[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:',
590
+ url,
591
+ );
615
592
  return;
616
593
  }
617
594
 
@@ -639,7 +616,10 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
639
616
  }, baggage);
640
617
  }
641
618
 
642
- setter.set(carrier, SENTRY_TRACE_HEADER, utils.generateSentryTraceHeader(traceId, spanId, sampled));
619
+ // We also want to avoid setting the default OTEL trace ID, if we get that for whatever reason
620
+ if (traceId && traceId !== '00000000000000000000000000000000') {
621
+ setter.set(carrier, SENTRY_TRACE_HEADER, utils.generateSentryTraceHeader(traceId, spanId, sampled));
622
+ }
643
623
 
644
624
  super.inject(api.propagation.setBaggage(context, baggage), carrier, setter);
645
625
  }
@@ -726,8 +706,8 @@ function makeTraceState({
726
706
  function getInjectionData(context)
727
707
 
728
708
  {
729
- const span = api.trace.getSpan(context);
730
- const spanIsRemote = _optionalChain$6([span, 'optionalAccess', _8 => _8.spanContext, 'call', _9 => _9(), 'access', _10 => _10.isRemote]);
709
+ const span = core.hasTracingEnabled() ? api.trace.getSpan(context) : undefined;
710
+ const spanIsRemote = _optionalChain$4([span, 'optionalAccess', _5 => _5.spanContext, 'call', _6 => _6(), 'access', _7 => _7.isRemote]);
731
711
 
732
712
  // If we have a local span, we can just pick everything from it
733
713
  if (span && !spanIsRemote) {
@@ -744,39 +724,15 @@ function getInjectionData(context)
744
724
  }
745
725
 
746
726
  // Else we try to use the propagation context from the scope
747
- const scope = _optionalChain$6([getScopesFromContext, 'call', _11 => _11(context), 'optionalAccess', _12 => _12.scope]);
748
- if (scope) {
749
- const propagationContext = scope.getPropagationContext();
750
- const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, propagationContext.traceId);
751
- return {
752
- dynamicSamplingContext,
753
- traceId: propagationContext.traceId,
754
- spanId: propagationContext.spanId,
755
- sampled: propagationContext.sampled,
756
- };
757
- }
758
-
759
- // Else, we look at the remote span context
760
- if (span) {
761
- const spanContext = span.spanContext();
762
- const propagationContext = getPropagationContextFromSpan(span);
763
- const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, spanContext.traceId);
764
-
765
- return {
766
- dynamicSamplingContext,
767
- traceId: spanContext.traceId,
768
- spanId: spanContext.spanId,
769
- sampled: getSamplingDecision(spanContext),
770
- };
771
- }
727
+ const scope = _optionalChain$4([getScopesFromContext, 'call', _8 => _8(context), 'optionalAccess', _9 => _9.scope]) || core.getCurrentScope();
772
728
 
773
- // If we have neither, there is nothing much we can do, but that should not happen usually
774
- // Unless there is a detached OTEL context being passed around
729
+ const propagationContext = scope.getPropagationContext();
730
+ const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, propagationContext.traceId);
775
731
  return {
776
- dynamicSamplingContext: undefined,
777
- traceId: undefined,
778
- spanId: undefined,
779
- sampled: undefined,
732
+ dynamicSamplingContext,
733
+ traceId: propagationContext.traceId,
734
+ spanId: propagationContext.spanId,
735
+ sampled: propagationContext.sampled,
780
736
  };
781
737
  }
782
738
 
@@ -786,7 +742,7 @@ function getDynamicSamplingContext(
786
742
  traceId,
787
743
  ) {
788
744
  // If we have a DSC on the propagation context, we just use it
789
- if (_optionalChain$6([propagationContext, 'optionalAccess', _13 => _13.dsc])) {
745
+ if (_optionalChain$4([propagationContext, 'optionalAccess', _10 => _10.dsc])) {
790
746
  return propagationContext.dsc;
791
747
  }
792
748
 
@@ -848,7 +804,31 @@ function getExistingBaggage(carrier) {
848
804
  }
849
805
  }
850
806
 
851
- function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
807
+ /**
808
+ * It is pretty tricky to get access to the outgoing request URL of a request in the propagator.
809
+ * As we only have access to the context of the span to be sent and the carrier (=headers),
810
+ * but the span may be unsampled and thus have no attributes.
811
+ *
812
+ * So we use the following logic:
813
+ * 1. If we have an active span, we check if it has a URL attribute.
814
+ * 2. Else, if the active span has no URL attribute (e.g. it is unsampled), we check a special trace state (which we set in our sampler).
815
+ */
816
+ function getCurrentURL(span) {
817
+ const urlAttribute = _optionalChain$4([core.spanToJSON, 'call', _11 => _11(span), 'access', _12 => _12.data, 'optionalAccess', _13 => _13[semanticConventions.SEMATTRS_HTTP_URL]]);
818
+ if (urlAttribute) {
819
+ return urlAttribute;
820
+ }
821
+
822
+ // Also look at the traceState, which we may set in the sampler even for unsampled spans
823
+ const urlTraceState = _optionalChain$4([span, 'access', _14 => _14.spanContext, 'call', _15 => _15(), 'access', _16 => _16.traceState, 'optionalAccess', _17 => _17.get, 'call', _18 => _18(SENTRY_TRACE_STATE_URL)]);
824
+ if (urlTraceState) {
825
+ return urlTraceState;
826
+ }
827
+
828
+ return undefined;
829
+ }
830
+
831
+ function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
852
832
 
853
833
  /**
854
834
  * Wraps a function with a transaction/span and finishes the span after the function is done.
@@ -1000,7 +980,7 @@ function ensureTimestampInMilliseconds(timestamp) {
1000
980
 
1001
981
  function getContext(scope, forceTransaction) {
1002
982
  const ctx = getContextForScope(scope);
1003
- const actualScope = _optionalChain$5([getScopesFromContext, 'call', _ => _(ctx), 'optionalAccess', _2 => _2.scope]);
983
+ const actualScope = _optionalChain$3([getScopesFromContext, 'call', _ => _(ctx), 'optionalAccess', _2 => _2.scope]);
1004
984
 
1005
985
  const parentSpan = api.trace.getSpan(ctx);
1006
986
 
@@ -1102,6 +1082,12 @@ function continueTrace(options, callback) {
1102
1082
  });
1103
1083
  }
1104
1084
 
1085
+ /** Suppress tracing in the given callback, ensuring no spans are generated inside of it. */
1086
+ function suppressTracing(callback) {
1087
+ const ctx = core$1.suppressTracing(api.context.active());
1088
+ return api.context.with(ctx, callback);
1089
+ }
1090
+
1105
1091
  /**
1106
1092
  * Ensure the global hub is setup.
1107
1093
  *
@@ -1111,80 +1097,14 @@ function setupGlobalHub() {
1111
1097
  // noop
1112
1098
  }
1113
1099
 
1114
- function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1115
-
1116
- /**
1117
- * This is for legacy reasons, and returns a proxy object instead of a hub to be used.
1118
- * @deprecated Use the methods directly.
1119
- */
1120
- function getCurrentHub() {
1121
- return {
1122
- bindClient(client) {
1123
- const scope = core.getCurrentScope();
1124
- scope.setClient(client);
1125
- },
1126
-
1127
- withScope: core.withScope,
1128
- getClient: () => core.getClient() ,
1129
- getScope: core.getCurrentScope,
1130
- getIsolationScope: core.getIsolationScope,
1131
- captureException: (exception, hint) => {
1132
- return core.getCurrentScope().captureException(exception, hint);
1133
- },
1134
- captureMessage: (message, level, hint) => {
1135
- return core.getCurrentScope().captureMessage(message, level, hint);
1136
- },
1137
- captureEvent: core.captureEvent,
1138
- addBreadcrumb: core.addBreadcrumb,
1139
- setUser: core.setUser,
1140
- setTags: core.setTags,
1141
- setTag: core.setTag,
1142
- setExtra: core.setExtra,
1143
- setExtras: core.setExtras,
1144
- setContext: core.setContext,
1145
-
1146
- getIntegration(integration) {
1147
- return _optionalChain$4([core.getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getIntegrationByName, 'call', _3 => _3(integration.id)]) || null;
1148
- },
1149
-
1150
- startSession: core.startSession,
1151
-
1152
- endSession: core.endSession,
1153
-
1154
- captureSession(endSession) {
1155
- // both send the update and pull the session from the scope
1156
- if (endSession) {
1157
- // eslint-disable-next-line deprecation/deprecation
1158
- return this.endSession();
1159
- }
1160
-
1161
- // only send the update
1162
- _sendSessionUpdate();
1163
- },
1164
- };
1165
- }
1166
-
1167
- /**
1168
- * Sends the current Session on the scope
1169
- */
1170
- function _sendSessionUpdate() {
1171
- const scope = core.getCurrentScope();
1172
- const client = core.getClient();
1173
-
1174
- const session = scope.getSession();
1175
- if (client && session) {
1176
- client.captureSession(session);
1177
- }
1178
- }
1179
-
1180
1100
  /** Ensure the `trace` context is set on all events. */
1181
1101
  function setupEventContextTrace(client) {
1182
- client.addEventProcessor(event => {
1102
+ client.on('preprocessEvent', event => {
1183
1103
  const span = getActiveSpan();
1184
1104
  // For transaction events, this is handled separately
1185
1105
  // Because the active span may not be the span that is actually the transaction event
1186
1106
  if (!span || event.type === 'transaction') {
1187
- return event;
1107
+ return;
1188
1108
  }
1189
1109
 
1190
1110
  const spanContext = span.spanContext();
@@ -1199,13 +1119,16 @@ function setupEventContextTrace(client) {
1199
1119
  ...event.contexts,
1200
1120
  };
1201
1121
 
1122
+ event.sdkProcessingMetadata = {
1123
+ dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
1124
+ ...event.sdkProcessingMetadata,
1125
+ };
1126
+
1202
1127
  const rootSpan = core.getRootSpan(span);
1203
1128
  const transactionName = spanHasName(rootSpan) ? rootSpan.name : undefined;
1204
1129
  if (transactionName && !event.transaction) {
1205
1130
  event.transaction = transactionName;
1206
1131
  }
1207
-
1208
- return event;
1209
1132
  });
1210
1133
  }
1211
1134
 
@@ -1230,22 +1153,6 @@ function setOpenTelemetryContextAsyncContextStrategy() {
1230
1153
  };
1231
1154
  }
1232
1155
 
1233
- function getCurrentHub$1() {
1234
- // eslint-disable-next-line deprecation/deprecation
1235
- const hub = getCurrentHub();
1236
- return {
1237
- ...hub,
1238
- getScope: () => {
1239
- const scopes = getScopes();
1240
- return scopes.scope;
1241
- },
1242
- getIsolationScope: () => {
1243
- const scopes = getScopes();
1244
- return scopes.isolationScope;
1245
- },
1246
- };
1247
- }
1248
-
1249
1156
  function withScope(callback) {
1250
1157
  const ctx = api.context.active();
1251
1158
 
@@ -1303,7 +1210,6 @@ function setOpenTelemetryContextAsyncContextStrategy() {
1303
1210
  }
1304
1211
 
1305
1212
  core.setAsyncContextStrategy({
1306
- getCurrentHub: getCurrentHub$1,
1307
1213
  withScope,
1308
1214
  withSetScope,
1309
1215
  withSetIsolationScope,
@@ -1317,10 +1223,11 @@ function setOpenTelemetryContextAsyncContextStrategy() {
1317
1223
  // The types here don't fully align, because our own `Span` type is narrower
1318
1224
  // than the OTEL one - but this is OK for here, as we now we'll only have OTEL spans passed around
1319
1225
  withActiveSpan: withActiveSpan ,
1226
+ suppressTracing: suppressTracing,
1320
1227
  });
1321
1228
  }
1322
1229
 
1323
- function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1230
+ function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1324
1231
 
1325
1232
  /**
1326
1233
  * Wrap an OpenTelemetry ContextManager in a way that ensures the context is kept in sync with the Sentry Hub.
@@ -1358,8 +1265,8 @@ function wrapContextManagerClass(
1358
1265
  ...args
1359
1266
  ) {
1360
1267
  const currentScopes = getScopesFromContext(context);
1361
- const currentScope = _optionalChain$3([currentScopes, 'optionalAccess', _ => _.scope]) || core.getCurrentScope();
1362
- const currentIsolationScope = _optionalChain$3([currentScopes, 'optionalAccess', _2 => _2.isolationScope]) || core.getIsolationScope();
1268
+ const currentScope = _optionalChain$2([currentScopes, 'optionalAccess', _ => _.scope]) || core.getCurrentScope();
1269
+ const currentIsolationScope = _optionalChain$2([currentScopes, 'optionalAccess', _2 => _2.isolationScope]) || core.getIsolationScope();
1363
1270
 
1364
1271
  const shouldForkIsolationScope = context.getValue(SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY) === true;
1365
1272
  const scope = context.getValue(SENTRY_FORK_SET_SCOPE_CONTEXT_KEY) ;
@@ -1487,6 +1394,10 @@ const canonicalGrpcErrorCodesMap = {
1487
1394
  '16': 'unauthenticated',
1488
1395
  } ;
1489
1396
 
1397
+ const isStatusErrorMessageValid = (message) => {
1398
+ return Object.values(canonicalGrpcErrorCodesMap).includes(message );
1399
+ };
1400
+
1490
1401
  /**
1491
1402
  * Get a Sentry span status from an otel span.
1492
1403
  */
@@ -1500,14 +1411,18 @@ function mapStatus(span) {
1500
1411
  return { code: core.SPAN_STATUS_OK };
1501
1412
  // If the span is already marked as erroneous we return that exact status
1502
1413
  } else if (status.code === api.SpanStatusCode.ERROR) {
1503
- return { code: core.SPAN_STATUS_ERROR, message: status.message };
1414
+ if (typeof status.message === 'undefined' || isStatusErrorMessageValid(status.message)) {
1415
+ return { code: core.SPAN_STATUS_ERROR, message: status.message };
1416
+ } else {
1417
+ return { code: core.SPAN_STATUS_ERROR, message: 'unknown_error' };
1418
+ }
1504
1419
  }
1505
1420
  }
1506
1421
 
1507
1422
  // If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
1508
1423
 
1509
- const httpCodeAttribute = attributes[semanticConventions.SemanticAttributes.HTTP_STATUS_CODE];
1510
- const grpcCodeAttribute = attributes[semanticConventions.SemanticAttributes.RPC_GRPC_STATUS_CODE];
1424
+ const httpCodeAttribute = attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE];
1425
+ const grpcCodeAttribute = attributes[semanticConventions.SEMATTRS_RPC_GRPC_STATUS_CODE];
1511
1426
 
1512
1427
  const numberHttpCode =
1513
1428
  typeof httpCodeAttribute === 'number'
@@ -1532,8 +1447,6 @@ function mapStatus(span) {
1532
1447
  }
1533
1448
  }
1534
1449
 
1535
- function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1536
-
1537
1450
  /**
1538
1451
  * A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.
1539
1452
  */
@@ -1681,7 +1594,7 @@ function parseSpan(span) {
1681
1594
 
1682
1595
  function createTransactionForOtelSpan(span) {
1683
1596
  const { op, description, data, origin = 'manual', source } = getSpanData(span);
1684
- const capturedSpanScopes = getSpanScopes(span);
1597
+ const capturedSpanScopes = core.getCapturedScopesOnSpan(span );
1685
1598
 
1686
1599
  const sampleRate = span.attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] ;
1687
1600
 
@@ -1713,8 +1626,6 @@ function createTransactionForOtelSpan(span) {
1713
1626
  contexts: {
1714
1627
  trace: traceContext,
1715
1628
  otel: {
1716
- // TODO: remove the attributes here?
1717
- attributes: removeSentryAttributes(span.attributes),
1718
1629
  resource: span.resource.attributes,
1719
1630
  },
1720
1631
  },
@@ -1725,8 +1636,8 @@ function createTransactionForOtelSpan(span) {
1725
1636
  type: 'transaction',
1726
1637
  sdkProcessingMetadata: {
1727
1638
  ...utils.dropUndefinedKeys({
1728
- capturedSpanScope: _optionalChain$2([capturedSpanScopes, 'optionalAccess', _ => _.scope]),
1729
- capturedSpanIsolationScope: _optionalChain$2([capturedSpanScopes, 'optionalAccess', _2 => _2.isolationScope]),
1639
+ capturedSpanScope: capturedSpanScopes.scope,
1640
+ capturedSpanIsolationScope: capturedSpanScopes.isolationScope,
1730
1641
  sampleRate,
1731
1642
  dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
1732
1643
  }),
@@ -1834,8 +1745,8 @@ function getData(span) {
1834
1745
  'otel.kind': api.SpanKind[span.kind],
1835
1746
  };
1836
1747
 
1837
- if (attributes[semanticConventions.SemanticAttributes.HTTP_STATUS_CODE]) {
1838
- const statusCode = attributes[semanticConventions.SemanticAttributes.HTTP_STATUS_CODE] ;
1748
+ if (attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE]) {
1749
+ const statusCode = attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE] ;
1839
1750
  data['http.response.status_code'] = statusCode;
1840
1751
  }
1841
1752
 
@@ -1884,7 +1795,7 @@ function onSpanStart(span, parentContext) {
1884
1795
 
1885
1796
  // We need the scope at time of span creation in order to apply it to the event when the span is finished
1886
1797
  if (scopes) {
1887
- setSpanScopes(span, scopes);
1798
+ core.setCapturedScopesOnSpan(span, scopes.scope, scopes.isolationScope);
1888
1799
  }
1889
1800
 
1890
1801
  core.logSpanStart(span);
@@ -1955,33 +1866,45 @@ class SentrySampler {
1955
1866
  context,
1956
1867
  traceId,
1957
1868
  spanName,
1958
- _spanKind,
1869
+ spanKind,
1959
1870
  spanAttributes,
1960
1871
  _links,
1961
1872
  ) {
1962
1873
  const options = this._client.getOptions();
1963
1874
 
1875
+ const parentSpan = api.trace.getSpan(context);
1876
+ const parentContext = _optionalChain([parentSpan, 'optionalAccess', _ => _.spanContext, 'call', _2 => _2()]);
1877
+
1878
+ let traceState = _optionalChain([parentContext, 'optionalAccess', _3 => _3.traceState]) || new core$1.TraceState();
1879
+
1880
+ // We always keep the URL on the trace state, so we can access it in the propagator
1881
+ const url = spanAttributes[semanticConventions.SEMATTRS_HTTP_URL];
1882
+ if (url && typeof url === 'string') {
1883
+ traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
1884
+ }
1885
+
1964
1886
  if (!core.hasTracingEnabled(options)) {
1965
- return { decision: sdkTraceBase.SamplingDecision.NOT_RECORD };
1887
+ return { decision: sdkTraceBase.SamplingDecision.NOT_RECORD, traceState };
1966
1888
  }
1967
1889
 
1968
- const parentSpan = api.trace.getSpan(context);
1969
- const parentContext = _optionalChain([parentSpan, 'optionalAccess', _ => _.spanContext, 'call', _2 => _2()]);
1970
- const traceState = _optionalChain([parentContext, 'optionalAccess', _3 => _3.traceState]) || new core$1.TraceState();
1890
+ // If we have a http.client span that has no local parent, we never want to sample it
1891
+ // but we want to leave downstream sampling decisions up to the server
1892
+ if (
1893
+ spanKind === api.SpanKind.CLIENT &&
1894
+ spanAttributes[semanticConventions.SEMATTRS_HTTP_METHOD] &&
1895
+ (!parentSpan || _optionalChain([parentContext, 'optionalAccess', _4 => _4.isRemote]))
1896
+ ) {
1897
+ return { decision: sdkTraceBase.SamplingDecision.NOT_RECORD, traceState };
1898
+ }
1971
1899
 
1972
- let parentSampled = undefined;
1900
+ const parentSampled = parentSpan ? getParentSampled(parentSpan, traceId, spanName) : undefined;
1973
1901
 
1974
- // Only inherit sample rate if `traceId` is the same
1975
- // Note for testing: `isSpanContextValid()` checks the format of the traceId/spanId, so we need to pass valid ones
1976
- if (parentSpan && parentContext && api.isSpanContextValid(parentContext) && parentContext.traceId === traceId) {
1977
- if (parentContext.isRemote) {
1978
- parentSampled = getParentRemoteSampled(parentSpan);
1979
- DEBUG_BUILD &&
1980
- utils.logger.log(`[Tracing] Inheriting remote parent's sampled decision for ${spanName}: ${parentSampled}`);
1981
- } else {
1982
- parentSampled = getSamplingDecision(parentContext);
1983
- DEBUG_BUILD && utils.logger.log(`[Tracing] Inheriting parent's sampled decision for ${spanName}: ${parentSampled}`);
1984
- }
1902
+ // If we encounter a span emitted by Next.js, we do not want to sample it
1903
+ // The reason for this is that the data quality of the spans varies, it is different per version of Next,
1904
+ // and we need to keep our manual instrumentation around for the edge runtime anyhow.
1905
+ // BUT we only do this if we don't have a parent span with a sampling decision yet
1906
+ if (spanAttributes['next.span_type'] && typeof parentSampled !== 'boolean') {
1907
+ return { decision: sdkTraceBase.SamplingDecision.NOT_RECORD, traceState: traceState };
1985
1908
  }
1986
1909
 
1987
1910
  const [sampled, sampleRate] = core.sampleSpan(options, {
@@ -1998,7 +1921,7 @@ class SentrySampler {
1998
1921
  [core.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,
1999
1922
  };
2000
1923
 
2001
- const method = `${spanAttributes[semanticConventions.SemanticAttributes.HTTP_METHOD]}`.toUpperCase();
1924
+ const method = `${spanAttributes[semanticConventions.SEMATTRS_HTTP_METHOD]}`.toUpperCase();
2002
1925
  if (method === 'OPTIONS' || method === 'HEAD') {
2003
1926
  DEBUG_BUILD && utils.logger.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
2004
1927
  return {
@@ -2019,6 +1942,7 @@ class SentrySampler {
2019
1942
  return {
2020
1943
  decision: sdkTraceBase.SamplingDecision.RECORD_AND_SAMPLED,
2021
1944
  attributes,
1945
+ traceState,
2022
1946
  };
2023
1947
  }
2024
1948
 
@@ -2036,26 +1960,38 @@ function getParentRemoteSampled(parentSpan) {
2036
1960
  return traceparentData && traceId === traceparentData.traceId ? traceparentData.sampled : undefined;
2037
1961
  }
2038
1962
 
2039
- /**
2040
- * The following internal utils are not considered public API and are subject to change.
2041
- * @hidden
2042
- */
2043
- const _INTERNAL = {
2044
- getRequestSpanData,
2045
- } ;
1963
+ function getParentSampled(parentSpan, traceId, spanName) {
1964
+ const parentContext = parentSpan.spanContext();
1965
+
1966
+ // Only inherit sample rate if `traceId` is the same
1967
+ // Note for testing: `isSpanContextValid()` checks the format of the traceId/spanId, so we need to pass valid ones
1968
+ if (api.isSpanContextValid(parentContext) && parentContext.traceId === traceId) {
1969
+ if (parentContext.isRemote) {
1970
+ const parentSampled = getParentRemoteSampled(parentSpan);
1971
+ DEBUG_BUILD &&
1972
+ utils.logger.log(`[Tracing] Inheriting remote parent's sampled decision for ${spanName}: ${parentSampled}`);
1973
+ return parentSampled;
1974
+ }
1975
+
1976
+ const parentSampled = getSamplingDecision(parentContext);
1977
+ DEBUG_BUILD && utils.logger.log(`[Tracing] Inheriting parent's sampled decision for ${spanName}: ${parentSampled}`);
1978
+ return parentSampled;
1979
+ }
1980
+
1981
+ return undefined;
1982
+ }
2046
1983
 
2047
1984
  exports.getClient = core.getClient;
1985
+ exports.getCurrentHubShim = core.getCurrentHubShim;
2048
1986
  exports.SentryPropagator = SentryPropagator;
2049
1987
  exports.SentrySampler = SentrySampler;
2050
1988
  exports.SentrySpanProcessor = SentrySpanProcessor;
2051
- exports._INTERNAL = _INTERNAL;
2052
1989
  exports.continueTrace = continueTrace;
2053
1990
  exports.getActiveSpan = getActiveSpan;
2054
- exports.getCurrentHub = getCurrentHub;
2055
1991
  exports.getDynamicSamplingContextFromSpan = getDynamicSamplingContextFromSpan;
1992
+ exports.getRequestSpanData = getRequestSpanData;
2056
1993
  exports.getScopesFromContext = getScopesFromContext;
2057
1994
  exports.getSpanKind = getSpanKind;
2058
- exports.getSpanScopes = getSpanScopes;
2059
1995
  exports.isSentryRequestSpan = isSentryRequestSpan;
2060
1996
  exports.openTelemetrySetupCheck = openTelemetrySetupCheck;
2061
1997
  exports.setOpenTelemetryContextAsyncContextStrategy = setOpenTelemetryContextAsyncContextStrategy;
@@ -2070,6 +2006,7 @@ exports.spanHasStatus = spanHasStatus;
2070
2006
  exports.startInactiveSpan = startInactiveSpan;
2071
2007
  exports.startSpan = startSpan;
2072
2008
  exports.startSpanManual = startSpanManual;
2009
+ exports.suppressTracing = suppressTracing;
2073
2010
  exports.withActiveSpan = withActiveSpan;
2074
2011
  exports.wrapClientClass = wrapClientClass;
2075
2012
  exports.wrapContextManagerClass = wrapContextManagerClass;