@sentry/opentelemetry 10.61.0 → 10.63.0

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 (37) hide show
  1. package/build/cjs/{resource-PpJQa_6P.js → asyncContextStrategy-CvLbRw2N.js} +98 -104
  2. package/build/cjs/asyncContextStrategy-CvLbRw2N.js.map +1 -0
  3. package/build/cjs/index.browser.js +31 -35
  4. package/build/cjs/index.browser.js.map +1 -1
  5. package/build/cjs/index.js +64 -38
  6. package/build/cjs/index.js.map +1 -1
  7. package/build/esm/{resource-CB9ITx8O.js → asyncContextStrategy-DfM95hx5.js} +102 -108
  8. package/build/esm/asyncContextStrategy-DfM95hx5.js.map +1 -0
  9. package/build/esm/index.browser.js +1 -5
  10. package/build/esm/index.browser.js.map +1 -1
  11. package/build/esm/index.js +35 -7
  12. package/build/esm/index.js.map +1 -1
  13. package/build/esm/package.json +1 -1
  14. package/build/types/asyncContextStrategy.d.ts +4 -1
  15. package/build/types/asyncContextStrategy.d.ts.map +1 -1
  16. package/build/types/asyncLocalStorageContextManager.d.ts.map +1 -1
  17. package/build/types/exports.d.ts +0 -1
  18. package/build/types/exports.d.ts.map +1 -1
  19. package/build/types/index.browser.d.ts +1 -0
  20. package/build/types/index.browser.d.ts.map +1 -1
  21. package/build/types/index.d.ts +1 -0
  22. package/build/types/index.d.ts.map +1 -1
  23. package/build/types/nodeAsyncContextStrategy.d.ts +4 -0
  24. package/build/types/nodeAsyncContextStrategy.d.ts.map +1 -0
  25. package/build/types/spanProcessor.d.ts.map +1 -1
  26. package/build/types/utils/parseSpanDescription.d.ts.map +1 -1
  27. package/build/types/utils/suppressTracing.d.ts +2 -0
  28. package/build/types/utils/suppressTracing.d.ts.map +1 -1
  29. package/build/types-ts3.8/asyncContextStrategy.d.ts +4 -1
  30. package/build/types-ts3.8/exports.d.ts +0 -1
  31. package/build/types-ts3.8/index.browser.d.ts +1 -0
  32. package/build/types-ts3.8/index.d.ts +1 -0
  33. package/build/types-ts3.8/nodeAsyncContextStrategy.d.ts +4 -0
  34. package/build/types-ts3.8/utils/suppressTracing.d.ts +2 -0
  35. package/package.json +2 -2
  36. package/build/cjs/resource-PpJQa_6P.js.map +0 -1
  37. package/build/esm/resource-CB9ITx8O.js.map +0 -1
@@ -1,8 +1,8 @@
1
1
  const api = require('@opentelemetry/api');
2
2
  const core = require('@sentry/core');
3
3
  const attributes = require('@sentry/conventions/attributes');
4
- const core$1 = require('@opentelemetry/core');
5
4
  const sdkTraceBase = require('@opentelemetry/sdk-trace-base');
5
+ const core$1 = require('@opentelemetry/core');
6
6
 
7
7
  const SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE = "sentry.parentIsRemote";
8
8
  const SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION = "sentry.graphql.operation";
@@ -247,10 +247,10 @@ function descriptionForHttpMethod({ name, kind, attributes }, httpMethod) {
247
247
  data.url = url;
248
248
  }
249
249
  if (query) {
250
- data["http.query"] = query;
250
+ data["http.query"] = query.slice(1);
251
251
  }
252
252
  if (fragment) {
253
- data["http.fragment"] = fragment;
253
+ data["http.fragment"] = fragment.slice(1);
254
254
  }
255
255
  const isClientOrServerKind = kind === api.SpanKind.CLIENT || kind === api.SpanKind.SERVER;
256
256
  const origin = attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] || "manual";
@@ -745,6 +745,10 @@ function suppressTracing(callback) {
745
745
  const ctx = core$1.suppressTracing(api.context.active());
746
746
  return api.context.with(ctx, callback);
747
747
  }
748
+ function isTracingSuppressed(scope) {
749
+ const ctx = scope ? getContextFromScope(scope) : api.context.active();
750
+ return ctx ? core$1.isTracingSuppressed(ctx) : false;
751
+ }
748
752
 
749
753
  function setupEventContextTrace(client) {
750
754
  client.on("preprocessEvent", (event) => {
@@ -765,103 +769,6 @@ function setupEventContextTrace(client) {
765
769
  });
766
770
  }
767
771
 
768
- function getTraceData({
769
- span,
770
- scope,
771
- client,
772
- propagateTraceparent
773
- } = {}) {
774
- let ctx = (scope && getContextFromScope(scope)) ?? api.context.active();
775
- if (span) {
776
- const { scope: scope2 } = core.getCapturedScopesOnSpan(span);
777
- ctx = scope2 && getContextFromScope(scope2) || api.trace.setSpan(api.context.active(), span);
778
- }
779
- const { traceId, spanId, sampled, dynamicSamplingContext } = getInjectionData(ctx, { scope, client });
780
- const traceData = {
781
- "sentry-trace": core.generateSentryTraceHeader(traceId, spanId, sampled),
782
- baggage: core.dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext)
783
- };
784
- if (propagateTraceparent) {
785
- traceData.traceparent = core.generateTraceparentHeader(traceId, spanId, sampled);
786
- }
787
- return traceData;
788
- }
789
-
790
- function setOpenTelemetryContextAsyncContextStrategy() {
791
- function getScopes() {
792
- const ctx = api.context.active();
793
- const scopes = getScopesFromContext(ctx);
794
- if (scopes) {
795
- return scopes;
796
- }
797
- return {
798
- scope: core.getDefaultCurrentScope(),
799
- isolationScope: core.getDefaultIsolationScope()
800
- };
801
- }
802
- function withScope(callback) {
803
- const ctx = api.context.active();
804
- return api.context.with(ctx, () => {
805
- return callback(getCurrentScope());
806
- });
807
- }
808
- function withSetScope(scope, callback) {
809
- const ctx = getContextFromScope(scope) || api.context.active();
810
- return api.context.with(ctx.setValue(SENTRY_FORK_SET_SCOPE_CONTEXT_KEY, scope), () => {
811
- return callback(scope);
812
- });
813
- }
814
- function withIsolationScope(callback) {
815
- const ctx = api.context.active();
816
- return api.context.with(ctx.setValue(SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY, true), () => {
817
- return callback(getIsolationScope());
818
- });
819
- }
820
- function withSetIsolationScope(isolationScope, callback) {
821
- const ctx = api.context.active();
822
- return api.context.with(ctx.setValue(SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY, isolationScope), () => {
823
- return callback(getIsolationScope());
824
- });
825
- }
826
- function getCurrentScope() {
827
- return getScopes().scope;
828
- }
829
- function getIsolationScope() {
830
- return getScopes().isolationScope;
831
- }
832
- core.setAsyncContextStrategy({
833
- withScope,
834
- withSetScope,
835
- withSetIsolationScope,
836
- withIsolationScope,
837
- getCurrentScope,
838
- getIsolationScope,
839
- startSpan,
840
- startSpanManual,
841
- startInactiveSpan,
842
- getActiveSpan,
843
- suppressTracing,
844
- getTraceData,
845
- continueTrace,
846
- startNewTrace,
847
- // The types here don't fully align, because our own `Span` type is narrower
848
- // than the OTEL one - but this is OK for here, as we now we'll only have OTEL spans passed around
849
- withActiveSpan,
850
- getTracingChannelBinding: () => {
851
- try {
852
- const contextManager = api.context._getContextManager();
853
- const lookup = contextManager.getAsyncLocalStorageLookup();
854
- return {
855
- asyncLocalStorage: lookup.asyncLocalStorage,
856
- getStoreWithActiveSpan: (span) => api.trace.setSpan(api.context.active(), span)
857
- };
858
- } catch {
859
- return void 0;
860
- }
861
- }
862
- });
863
- }
864
-
865
772
  function buildContextWithSentryScopes(context, activeContext) {
866
773
  const span = api.trace.getSpan(context);
867
774
  let effectiveContext;
@@ -1377,7 +1284,7 @@ function backfillStreamedSpanDataFromOtel(spanJSON, hint) {
1377
1284
  if (!attributes) {
1378
1285
  return;
1379
1286
  }
1380
- const kind = hint?.spanKind ?? api.SpanKind.INTERNAL;
1287
+ const kind = hint?.spanKind ?? core.SPAN_KIND.INTERNAL;
1381
1288
  const { op, description, source, data } = inferSpanData(spanJSON.name, attributes, kind);
1382
1289
  spanJSON.name = description;
1383
1290
  core.safeSetSpanJSONAttributes(spanJSON, {
@@ -1385,9 +1292,9 @@ function backfillStreamedSpanDataFromOtel(spanJSON, hint) {
1385
1292
  [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
1386
1293
  ...data
1387
1294
  });
1388
- if (kind !== api.SpanKind.INTERNAL) {
1295
+ if (kind !== core.SPAN_KIND.INTERNAL) {
1389
1296
  core.safeSetSpanJSONAttributes(spanJSON, {
1390
- "otel.kind": api.SpanKind[kind]
1297
+ "otel.kind": core.spanKindToName(kind)
1391
1298
  });
1392
1299
  }
1393
1300
  }
@@ -1666,6 +1573,93 @@ function getSentryResource(serviceNameFallback) {
1666
1573
  });
1667
1574
  }
1668
1575
 
1576
+ function getTraceData({
1577
+ span,
1578
+ scope,
1579
+ client,
1580
+ propagateTraceparent
1581
+ } = {}) {
1582
+ let ctx = (scope && getContextFromScope(scope)) ?? api.context.active();
1583
+ if (span) {
1584
+ const { scope: scope2 } = core.getCapturedScopesOnSpan(span);
1585
+ ctx = scope2 && getContextFromScope(scope2) || api.trace.setSpan(api.context.active(), span);
1586
+ }
1587
+ const { traceId, spanId, sampled, dynamicSamplingContext } = getInjectionData(ctx, { scope, client });
1588
+ const traceData = {
1589
+ "sentry-trace": core.generateSentryTraceHeader(traceId, spanId, sampled),
1590
+ baggage: core.dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext)
1591
+ };
1592
+ if (propagateTraceparent) {
1593
+ traceData.traceparent = core.generateTraceparentHeader(traceId, spanId, sampled);
1594
+ }
1595
+ return traceData;
1596
+ }
1597
+
1598
+ function setOpenTelemetryContextAsyncContextStrategy(options) {
1599
+ function getScopes() {
1600
+ const ctx = api.context.active();
1601
+ const scopes = getScopesFromContext(ctx);
1602
+ if (scopes) {
1603
+ return scopes;
1604
+ }
1605
+ return {
1606
+ scope: core.getDefaultCurrentScope(),
1607
+ isolationScope: core.getDefaultIsolationScope()
1608
+ };
1609
+ }
1610
+ function withScope(callback) {
1611
+ const ctx = api.context.active();
1612
+ return api.context.with(ctx, () => {
1613
+ return callback(getCurrentScope());
1614
+ });
1615
+ }
1616
+ function withSetScope(scope, callback) {
1617
+ const ctx = getContextFromScope(scope) || api.context.active();
1618
+ return api.context.with(ctx.setValue(SENTRY_FORK_SET_SCOPE_CONTEXT_KEY, scope), () => {
1619
+ return callback(scope);
1620
+ });
1621
+ }
1622
+ function withIsolationScope(callback) {
1623
+ const ctx = api.context.active();
1624
+ return api.context.with(ctx.setValue(SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY, true), () => {
1625
+ return callback(getIsolationScope());
1626
+ });
1627
+ }
1628
+ function withSetIsolationScope(isolationScope, callback) {
1629
+ const ctx = api.context.active();
1630
+ return api.context.with(ctx.setValue(SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY, isolationScope), () => {
1631
+ return callback(getIsolationScope());
1632
+ });
1633
+ }
1634
+ function getCurrentScope() {
1635
+ return getScopes().scope;
1636
+ }
1637
+ function getIsolationScope() {
1638
+ return getScopes().isolationScope;
1639
+ }
1640
+ core.setAsyncContextStrategy({
1641
+ withScope,
1642
+ withSetScope,
1643
+ withSetIsolationScope,
1644
+ withIsolationScope,
1645
+ getCurrentScope,
1646
+ getIsolationScope,
1647
+ startSpan,
1648
+ startSpanManual,
1649
+ startInactiveSpan,
1650
+ getActiveSpan,
1651
+ suppressTracing,
1652
+ isTracingSuppressed,
1653
+ getTraceData,
1654
+ continueTrace,
1655
+ startNewTrace,
1656
+ // The types here don't fully align, because our own `Span` type is narrower
1657
+ // than the OTEL one - but this is OK for here, as we now we'll only have OTEL spans passed around
1658
+ withActiveSpan,
1659
+ getTracingChannelBinding: options?.getTracingChannelBinding
1660
+ });
1661
+ }
1662
+
1669
1663
  exports.SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION = SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION;
1670
1664
  exports.SENTRY_SCOPES_CONTEXT_KEY = SENTRY_SCOPES_CONTEXT_KEY;
1671
1665
  exports.SentryPropagator = SentryPropagator;
@@ -1699,4 +1693,4 @@ exports.withActiveSpan = withActiveSpan;
1699
1693
  exports.wrapClientClass = wrapClientClass;
1700
1694
  exports.wrapContextManagerClass = wrapContextManagerClass;
1701
1695
  exports.wrapSamplingDecision = wrapSamplingDecision;
1702
- //# sourceMappingURL=resource-PpJQa_6P.js.map
1696
+ //# sourceMappingURL=asyncContextStrategy-CvLbRw2N.js.map