@sentry/opentelemetry 10.62.0 → 10.64.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.
- package/README.md +29 -0
- package/build/cjs/{resource-DuZKnQnC.js → asyncContextStrategy-xEzxBKVX.js} +308 -128
- package/build/cjs/asyncContextStrategy-xEzxBKVX.js.map +1 -0
- package/build/cjs/index.browser.js +35 -35
- package/build/cjs/index.browser.js.map +1 -1
- package/build/cjs/index.js +68 -38
- package/build/cjs/index.js.map +1 -1
- package/build/esm/{resource-DazDAxCp.js → asyncContextStrategy-CIqtsDXI.js} +310 -133
- package/build/esm/asyncContextStrategy-CIqtsDXI.js.map +1 -0
- package/build/esm/index.browser.js +1 -5
- package/build/esm/index.browser.js.map +1 -1
- package/build/esm/index.js +35 -7
- package/build/esm/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/types/applyOtelSpanData.d.ts +18 -0
- package/build/types/applyOtelSpanData.d.ts.map +1 -0
- package/build/types/asyncContextStrategy.d.ts +4 -1
- package/build/types/asyncContextStrategy.d.ts.map +1 -1
- package/build/types/asyncLocalStorageContextManager.d.ts.map +1 -1
- package/build/types/custom/client.d.ts.map +1 -1
- package/build/types/exports.d.ts +5 -2
- package/build/types/exports.d.ts.map +1 -1
- package/build/types/index.browser.d.ts +1 -0
- package/build/types/index.browser.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/nodeAsyncContextStrategy.d.ts +4 -0
- package/build/types/nodeAsyncContextStrategy.d.ts.map +1 -0
- package/build/types/spanProcessor.d.ts.map +1 -1
- package/build/types/tracer.d.ts +13 -0
- package/build/types/tracer.d.ts.map +1 -0
- package/build/types/tracerProvider.d.ts +23 -0
- package/build/types/tracerProvider.d.ts.map +1 -0
- package/build/types/types.d.ts +6 -2
- package/build/types/types.d.ts.map +1 -1
- package/build/types/utils/backfillStreamedSpanData.d.ts +16 -0
- package/build/types/utils/backfillStreamedSpanData.d.ts.map +1 -0
- package/build/types/utils/enhanceDscWithOpenTelemetryRootSpanName.d.ts.map +1 -1
- package/build/types/utils/getSamplingDecision.d.ts +17 -0
- package/build/types/utils/getSamplingDecision.d.ts.map +1 -1
- package/build/types/utils/mapStatus.d.ts +3 -1
- package/build/types/utils/mapStatus.d.ts.map +1 -1
- package/build/types/utils/parseSpanDescription.d.ts.map +1 -1
- package/build/types/utils/setupCheck.d.ts +1 -1
- package/build/types/utils/setupCheck.d.ts.map +1 -1
- package/build/types/utils/suppressTracing.d.ts +2 -0
- package/build/types/utils/suppressTracing.d.ts.map +1 -1
- package/build/types-ts3.8/applyOtelSpanData.d.ts +18 -0
- package/build/types-ts3.8/asyncContextStrategy.d.ts +4 -1
- package/build/types-ts3.8/exports.d.ts +5 -2
- package/build/types-ts3.8/index.browser.d.ts +1 -0
- package/build/types-ts3.8/index.d.ts +1 -0
- package/build/types-ts3.8/nodeAsyncContextStrategy.d.ts +4 -0
- package/build/types-ts3.8/tracer.d.ts +13 -0
- package/build/types-ts3.8/tracerProvider.d.ts +23 -0
- package/build/types-ts3.8/types.d.ts +6 -2
- package/build/types-ts3.8/utils/backfillStreamedSpanData.d.ts +16 -0
- package/build/types-ts3.8/utils/getSamplingDecision.d.ts +17 -0
- package/build/types-ts3.8/utils/mapStatus.d.ts +3 -1
- package/build/types-ts3.8/utils/setupCheck.d.ts +1 -1
- package/build/types-ts3.8/utils/suppressTracing.d.ts +2 -0
- package/package.json +5 -5
- package/build/cjs/resource-DuZKnQnC.js.map +0 -1
- package/build/esm/resource-DazDAxCp.js.map +0 -1
package/README.md
CHANGED
|
@@ -85,6 +85,35 @@ function setupSentry() {
|
|
|
85
85
|
A full setup example can be found in
|
|
86
86
|
[node-experimental](https://github.com/getsentry/sentry-javascript/blob/develop/packages/node-experimental).
|
|
87
87
|
|
|
88
|
+
## Sentry Tracer Provider
|
|
89
|
+
|
|
90
|
+
`SentryTracerProvider` is a minimal OpenTelemetry tracer provider which creates native Sentry spans directly.
|
|
91
|
+
It is useful when code uses the global OpenTelemetry API and you do not need the full OpenTelemetry SDK span processor
|
|
92
|
+
and exporter pipeline.
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
import { trace } from '@opentelemetry/api';
|
|
96
|
+
import { SentryTracerProvider } from '@sentry/opentelemetry';
|
|
97
|
+
|
|
98
|
+
trace.setGlobalTracerProvider(new SentryTracerProvider());
|
|
99
|
+
|
|
100
|
+
const span = trace.getTracer('example').startSpan('work');
|
|
101
|
+
span.end();
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
In `@sentry/node`, this is the default tracer provider. To use the full OpenTelemetry SDK `BasicTracerProvider`
|
|
105
|
+
instead, opt out with:
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
Sentry.init({
|
|
109
|
+
dsn: 'xxx',
|
|
110
|
+
openTelemetryBasicTracerProvider: true,
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Providing `openTelemetrySpanProcessors` also falls back to the full OpenTelemetry SDK provider, since custom span
|
|
115
|
+
processors require the SDK span pipeline. The `SentryTracerProvider` does not handle OpenTelemetry logs and metrics.
|
|
116
|
+
|
|
88
117
|
## Links
|
|
89
118
|
|
|
90
119
|
- [Official SDK Docs](https://docs.sentry.io/quickstart/)
|
|
@@ -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";
|
|
@@ -164,6 +164,17 @@ function getSamplingDecision(spanContext) {
|
|
|
164
164
|
}
|
|
165
165
|
return void 0;
|
|
166
166
|
}
|
|
167
|
+
function getSampledForPropagation(span, client) {
|
|
168
|
+
const spanContext = span.spanContext();
|
|
169
|
+
const samplingDecision = getSamplingDecision(spanContext);
|
|
170
|
+
if (samplingDecision !== void 0) {
|
|
171
|
+
return samplingDecision;
|
|
172
|
+
}
|
|
173
|
+
if (!core.hasSpansEnabled(client?.getOptions()) || spanContext.isRemote || !core.spanIsSentrySpan(core.getRootSpan(span))) {
|
|
174
|
+
return void 0;
|
|
175
|
+
}
|
|
176
|
+
return core.spanIsSampled(span);
|
|
177
|
+
}
|
|
167
178
|
|
|
168
179
|
function inferSpanData(spanName, attributes$1, kind) {
|
|
169
180
|
const httpMethod = attributes$1[attributes.HTTP_REQUEST_METHOD] || attributes$1[attributes.HTTP_METHOD];
|
|
@@ -200,8 +211,16 @@ function inferSpanData(spanName, attributes$1, kind) {
|
|
|
200
211
|
return { op: void 0, description: spanName, source: "custom" };
|
|
201
212
|
}
|
|
202
213
|
function parseSpanDescription(span) {
|
|
203
|
-
|
|
204
|
-
|
|
214
|
+
let attributes;
|
|
215
|
+
let name;
|
|
216
|
+
if (spanHasAttributes(span)) {
|
|
217
|
+
attributes = span.attributes;
|
|
218
|
+
name = spanHasName(span) ? span.name : "<unknown>";
|
|
219
|
+
} else {
|
|
220
|
+
const json = typeof span.spanContext === "function" ? core.spanToJSON(span) : void 0;
|
|
221
|
+
attributes = json?.data || {};
|
|
222
|
+
name = spanHasName(span) ? span.name : json?.description || "<unknown>";
|
|
223
|
+
}
|
|
205
224
|
const kind = getSpanKind(span);
|
|
206
225
|
return inferSpanData(name, attributes, kind);
|
|
207
226
|
}
|
|
@@ -247,10 +266,10 @@ function descriptionForHttpMethod({ name, kind, attributes }, httpMethod) {
|
|
|
247
266
|
data.url = url;
|
|
248
267
|
}
|
|
249
268
|
if (query) {
|
|
250
|
-
data["http.query"] = query;
|
|
269
|
+
data["http.query"] = query.slice(1);
|
|
251
270
|
}
|
|
252
271
|
if (fragment) {
|
|
253
|
-
data["http.fragment"] = fragment;
|
|
272
|
+
data["http.fragment"] = fragment.slice(1);
|
|
254
273
|
}
|
|
255
274
|
const isClientOrServerKind = kind === api.SpanKind.CLIENT || kind === api.SpanKind.SERVER;
|
|
256
275
|
const origin = attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] || "manual";
|
|
@@ -319,12 +338,16 @@ function enhanceDscWithOpenTelemetryRootSpanName(client) {
|
|
|
319
338
|
const jsonSpan = core.spanToJSON(rootSpan);
|
|
320
339
|
const attributes = jsonSpan.data;
|
|
321
340
|
const source = attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
|
|
322
|
-
const
|
|
323
|
-
if (
|
|
324
|
-
dsc.transaction
|
|
341
|
+
const sampled = getSampledForPropagation(rootSpan, client);
|
|
342
|
+
if (sampled === false) {
|
|
343
|
+
delete dsc.transaction;
|
|
344
|
+
} else if (jsonSpan.description) {
|
|
345
|
+
const { description } = parseSpanDescription(rootSpan);
|
|
346
|
+
if (source !== "url" && description) {
|
|
347
|
+
dsc.transaction = description;
|
|
348
|
+
}
|
|
325
349
|
}
|
|
326
350
|
if (core.hasSpansEnabled()) {
|
|
327
|
-
const sampled = getSamplingDecision(rootSpan.spanContext());
|
|
328
351
|
dsc.sampled = sampled == void 0 ? void 0 : String(sampled);
|
|
329
352
|
}
|
|
330
353
|
});
|
|
@@ -476,8 +499,7 @@ function getInjectionData(context2, options = {}) {
|
|
|
476
499
|
dynamicSamplingContext: dynamicSamplingContext2,
|
|
477
500
|
traceId: spanContext.traceId,
|
|
478
501
|
spanId: spanContext.spanId,
|
|
479
|
-
sampled:
|
|
480
|
-
// TODO: Do we need to change something here?
|
|
502
|
+
sampled: getSampledForPropagation(span, options.client)
|
|
481
503
|
};
|
|
482
504
|
}
|
|
483
505
|
const scope = options.scope || getScopesFromContext(context2)?.scope || core.getCurrentScope();
|
|
@@ -745,6 +767,10 @@ function suppressTracing(callback) {
|
|
|
745
767
|
const ctx = core$1.suppressTracing(api.context.active());
|
|
746
768
|
return api.context.with(ctx, callback);
|
|
747
769
|
}
|
|
770
|
+
function isTracingSuppressed(scope) {
|
|
771
|
+
const ctx = scope ? getContextFromScope(scope) : api.context.active();
|
|
772
|
+
return ctx ? core$1.isTracingSuppressed(ctx) : false;
|
|
773
|
+
}
|
|
748
774
|
|
|
749
775
|
function setupEventContextTrace(client) {
|
|
750
776
|
client.on("preprocessEvent", (event) => {
|
|
@@ -765,103 +791,6 @@ function setupEventContextTrace(client) {
|
|
|
765
791
|
});
|
|
766
792
|
}
|
|
767
793
|
|
|
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
794
|
function buildContextWithSentryScopes(context, activeContext) {
|
|
866
795
|
const span = api.trace.getSpan(context);
|
|
867
796
|
let effectiveContext;
|
|
@@ -1314,6 +1243,23 @@ function getData(span) {
|
|
|
1314
1243
|
return data;
|
|
1315
1244
|
}
|
|
1316
1245
|
|
|
1246
|
+
function backfillStreamedSpanDataFromOtel(spanJSON, hint) {
|
|
1247
|
+
const attributes = spanJSON.attributes ?? {};
|
|
1248
|
+
const kind = hint?.spanKind ?? core.SPAN_KIND.INTERNAL;
|
|
1249
|
+
const { op, description, source, data } = inferSpanData(spanJSON.name, attributes, kind);
|
|
1250
|
+
spanJSON.name = description;
|
|
1251
|
+
core.safeSetSpanJSONAttributes(spanJSON, {
|
|
1252
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
|
|
1253
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
|
|
1254
|
+
...data
|
|
1255
|
+
});
|
|
1256
|
+
if (kind !== core.SPAN_KIND.INTERNAL) {
|
|
1257
|
+
core.safeSetSpanJSONAttributes(spanJSON, {
|
|
1258
|
+
"otel.kind": core.spanKindToName(kind)
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1317
1263
|
class SentrySpanProcessor {
|
|
1318
1264
|
constructor(options) {
|
|
1319
1265
|
this._unsubscribePreprocessSpan = void 0;
|
|
@@ -1372,25 +1318,6 @@ class SentrySpanProcessor {
|
|
|
1372
1318
|
}
|
|
1373
1319
|
}
|
|
1374
1320
|
}
|
|
1375
|
-
function backfillStreamedSpanDataFromOtel(spanJSON, hint) {
|
|
1376
|
-
const attributes = spanJSON.attributes;
|
|
1377
|
-
if (!attributes) {
|
|
1378
|
-
return;
|
|
1379
|
-
}
|
|
1380
|
-
const kind = hint?.spanKind ?? core.SPAN_KIND.INTERNAL;
|
|
1381
|
-
const { op, description, source, data } = inferSpanData(spanJSON.name, attributes, kind);
|
|
1382
|
-
spanJSON.name = description;
|
|
1383
|
-
core.safeSetSpanJSONAttributes(spanJSON, {
|
|
1384
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
|
|
1385
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
|
|
1386
|
-
...data
|
|
1387
|
-
});
|
|
1388
|
-
if (kind !== core.SPAN_KIND.INTERNAL) {
|
|
1389
|
-
core.safeSetSpanJSONAttributes(spanJSON, {
|
|
1390
|
-
"otel.kind": core.spanKindToName(kind)
|
|
1391
|
-
});
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
1321
|
|
|
1395
1322
|
class SentrySampler {
|
|
1396
1323
|
constructor(client) {
|
|
@@ -1602,6 +1529,169 @@ function getValidSpan(context) {
|
|
|
1602
1529
|
return span && api.isSpanContextValid(span.spanContext()) ? span : void 0;
|
|
1603
1530
|
}
|
|
1604
1531
|
|
|
1532
|
+
function applyOtelSpanData(span, options = {}) {
|
|
1533
|
+
const spanJSON = core.spanToJSON(span);
|
|
1534
|
+
const attributes = spanJSON.data;
|
|
1535
|
+
const kind = span.kind ?? api.SpanKind.INTERNAL;
|
|
1536
|
+
const mayInferSource = core.spanShouldInferOtelSource(span);
|
|
1537
|
+
const hasCustomSpanName = attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME] !== void 0;
|
|
1538
|
+
const canInferSource = mayInferSource && !hasCustomSpanName && !core.spanSourceWasExplicitlySet(span);
|
|
1539
|
+
const attributesForInference = canInferSource && attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === "custom" ? { ...attributes, [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: void 0 } : attributes;
|
|
1540
|
+
const inferred = inferSpanData(spanJSON.description || "<unknown>", attributesForInference, kind);
|
|
1541
|
+
if (kind !== api.SpanKind.INTERNAL && attributes["otel.kind"] === void 0) {
|
|
1542
|
+
span.setAttribute("otel.kind", api.SpanKind[kind]);
|
|
1543
|
+
}
|
|
1544
|
+
if (inferred.op && attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_OP] === void 0) {
|
|
1545
|
+
span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, inferred.op);
|
|
1546
|
+
}
|
|
1547
|
+
const shouldApplyInferredSource = inferred.source !== void 0 && inferred.source !== "custom" && (options.finalizeStatus || inferred.source !== "url") && (spanJSON.parent_span_id === void 0 || kind === api.SpanKind.SERVER);
|
|
1548
|
+
if (shouldApplyInferredSource && (attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === void 0 || canInferSource)) {
|
|
1549
|
+
span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, inferred.source);
|
|
1550
|
+
}
|
|
1551
|
+
if (inferred.data) {
|
|
1552
|
+
Object.entries(inferred.data).forEach(([key, value]) => {
|
|
1553
|
+
if (value !== void 0 && attributes[key] === void 0) {
|
|
1554
|
+
span.setAttribute(key, value);
|
|
1555
|
+
}
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1558
|
+
if (options.finalizeStatus) {
|
|
1559
|
+
applyOtelCompatibilityAttributes(span, attributes);
|
|
1560
|
+
const client = core.getClient();
|
|
1561
|
+
applyOtelSpanStatus(span, attributes, spanJSON.status, !!client && core.hasSpanStreamingEnabled(client));
|
|
1562
|
+
}
|
|
1563
|
+
if (mayInferSource && inferred.description !== spanJSON.description && (attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] !== "custom" || canInferSource)) {
|
|
1564
|
+
span.updateName(inferred.description);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
function applyOtelSpanKind(span, kind) {
|
|
1568
|
+
core.addNonEnumerableProperty(span, "kind", kind ?? api.SpanKind.INTERNAL);
|
|
1569
|
+
}
|
|
1570
|
+
function applyOtelSpanStatus(span, attributes, status, spanStreamingEnabled) {
|
|
1571
|
+
if (status === void 0) {
|
|
1572
|
+
span.setStatus(inferStatusFromAttributes(attributes) || { code: core.SPAN_STATUS_OK });
|
|
1573
|
+
return;
|
|
1574
|
+
}
|
|
1575
|
+
if (!spanStreamingEnabled && status !== "ok" && !isStatusErrorMessageValid(status)) {
|
|
1576
|
+
span.setStatus({ code: core.SPAN_STATUS_ERROR, message: "internal_error" });
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
function applyOtelCompatibilityAttributes(span, attributes$1) {
|
|
1580
|
+
const legacyHttpStatusCode = attributes$1[attributes.HTTP_STATUS_CODE];
|
|
1581
|
+
if (attributes$1[attributes.HTTP_RESPONSE_STATUS_CODE] === void 0 && legacyHttpStatusCode !== void 0) {
|
|
1582
|
+
span.setAttribute(attributes.HTTP_RESPONSE_STATUS_CODE, legacyHttpStatusCode);
|
|
1583
|
+
attributes$1[attributes.HTTP_RESPONSE_STATUS_CODE] = legacyHttpStatusCode;
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
class SentryTracer {
|
|
1588
|
+
/** @inheritdoc */
|
|
1589
|
+
startSpan(name, options = {}, ctx) {
|
|
1590
|
+
const parentContext = ctx || api.context.active();
|
|
1591
|
+
const parentSpan = options.root ? void 0 : api.trace.getSpan(parentContext);
|
|
1592
|
+
if (core$1.isTracingSuppressed(parentContext)) {
|
|
1593
|
+
return this._createNonRecordingSpan(parentSpan);
|
|
1594
|
+
}
|
|
1595
|
+
const span = this._startSentrySpan(name, options, parentSpan, ctx !== void 0);
|
|
1596
|
+
core.markSpanAsTracerProviderSpan(span);
|
|
1597
|
+
applyOtelSpanKind(span, options.kind);
|
|
1598
|
+
if (options.attributes?.[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === void 0) {
|
|
1599
|
+
core.markSpanForOtelSourceInference(span);
|
|
1600
|
+
}
|
|
1601
|
+
applyOtelSpanData(span);
|
|
1602
|
+
return span;
|
|
1603
|
+
}
|
|
1604
|
+
startActiveSpan(name, optionsOrFn, contextOrFn, fn) {
|
|
1605
|
+
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
1606
|
+
const ctx = typeof contextOrFn === "function" || contextOrFn === void 0 ? api.context.active() : contextOrFn;
|
|
1607
|
+
const callback = typeof optionsOrFn === "function" ? optionsOrFn : typeof contextOrFn === "function" ? contextOrFn : fn;
|
|
1608
|
+
const span = this.startSpan(name, options, ctx);
|
|
1609
|
+
const capturedIsolationScope = core.getCapturedScopesOnSpan(span).isolationScope;
|
|
1610
|
+
const withCapturedIsolationScope = (contextToFork) => capturedIsolationScope ? contextToFork.setValue(SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY, capturedIsolationScope) : contextToFork;
|
|
1611
|
+
if (core.spanIsIgnored(span) && api.trace.getSpan(ctx)) {
|
|
1612
|
+
return api.context.with(withCapturedIsolationScope(ctx), () => callback(span));
|
|
1613
|
+
}
|
|
1614
|
+
return api.context.with(withCapturedIsolationScope(api.trace.setSpan(ctx, span)), () => {
|
|
1615
|
+
core._INTERNAL_setSpanForScope(core.getCurrentScope(), span);
|
|
1616
|
+
return callback(span);
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
_startSentrySpan(name, options, parentSpan, hasExplicitContext) {
|
|
1620
|
+
const sentryOptions = {
|
|
1621
|
+
name,
|
|
1622
|
+
attributes: options.attributes,
|
|
1623
|
+
links: options.links,
|
|
1624
|
+
startTime: options.startTime
|
|
1625
|
+
};
|
|
1626
|
+
if (options.root) {
|
|
1627
|
+
return core.startNewTrace(() => core._INTERNAL_startInactiveSpan({ ...sentryOptions, parentSpan: null }));
|
|
1628
|
+
}
|
|
1629
|
+
if (parentSpan?.spanContext().isRemote) {
|
|
1630
|
+
return this._startRootSpanWithRemoteParent(sentryOptions, parentSpan);
|
|
1631
|
+
}
|
|
1632
|
+
if (parentSpan) {
|
|
1633
|
+
return core._INTERNAL_startInactiveSpan({ ...sentryOptions, parentSpan });
|
|
1634
|
+
}
|
|
1635
|
+
return core.startNewTrace(
|
|
1636
|
+
() => core._INTERNAL_startInactiveSpan({
|
|
1637
|
+
...sentryOptions,
|
|
1638
|
+
parentSpan: hasExplicitContext ? null : void 0
|
|
1639
|
+
})
|
|
1640
|
+
);
|
|
1641
|
+
}
|
|
1642
|
+
_startRootSpanWithRemoteParent(options, parentSpan) {
|
|
1643
|
+
const { spanId, traceId, traceState } = parentSpan.spanContext();
|
|
1644
|
+
const dsc = core.getDynamicSamplingContextFromSpan(parentSpan);
|
|
1645
|
+
const sampleRand = typeof dsc.sample_rand === "string" ? Number(dsc.sample_rand) : void 0;
|
|
1646
|
+
const hasIncomingDsc = !!traceState?.get(SENTRY_TRACE_STATE_DSC);
|
|
1647
|
+
return core.withScope((scope) => {
|
|
1648
|
+
scope.setPropagationContext({
|
|
1649
|
+
traceId,
|
|
1650
|
+
parentSpanId: spanId,
|
|
1651
|
+
sampled: getSamplingDecision(parentSpan.spanContext()),
|
|
1652
|
+
dsc: hasIncomingDsc ? dsc : void 0,
|
|
1653
|
+
sampleRand: typeof sampleRand === "number" && !Number.isNaN(sampleRand) ? sampleRand : core._INTERNAL_safeMathRandom()
|
|
1654
|
+
});
|
|
1655
|
+
core._INTERNAL_setSpanForScope(scope, void 0);
|
|
1656
|
+
return core._INTERNAL_startInactiveSpan({ ...options, parentSpan: null });
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
_createNonRecordingSpan(parentSpan) {
|
|
1660
|
+
const span = new core.SentryNonRecordingSpan({ traceId: parentSpan?.spanContext().traceId });
|
|
1661
|
+
if (parentSpan) {
|
|
1662
|
+
core.addChildSpanToSpan(parentSpan, span);
|
|
1663
|
+
}
|
|
1664
|
+
core.setCapturedScopesOnSpan(span, core.getCurrentScope(), core.getIsolationScope());
|
|
1665
|
+
return span;
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
class SentryTracerProvider {
|
|
1670
|
+
constructor(options = {}) {
|
|
1671
|
+
this._tracers = /* @__PURE__ */ new Map();
|
|
1672
|
+
this.resource = options.resource;
|
|
1673
|
+
}
|
|
1674
|
+
/** @inheritdoc */
|
|
1675
|
+
getTracer(name, version, options) {
|
|
1676
|
+
const key = JSON.stringify([name, version, options]);
|
|
1677
|
+
const cachedTracer = this._tracers.get(key);
|
|
1678
|
+
if (cachedTracer) {
|
|
1679
|
+
return cachedTracer;
|
|
1680
|
+
}
|
|
1681
|
+
const tracer = new SentryTracer();
|
|
1682
|
+
this._tracers.set(key, tracer);
|
|
1683
|
+
return tracer;
|
|
1684
|
+
}
|
|
1685
|
+
/** Compatibility with SDK tracer providers. */
|
|
1686
|
+
forceFlush() {
|
|
1687
|
+
return Promise.resolve();
|
|
1688
|
+
}
|
|
1689
|
+
/** Compatibility with SDK tracer providers. */
|
|
1690
|
+
shutdown() {
|
|
1691
|
+
return Promise.resolve();
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1605
1695
|
const ATTR_TELEMETRY_SDK_LANGUAGE = "telemetry.sdk.language";
|
|
1606
1696
|
const ATTR_TELEMETRY_SDK_NAME = "telemetry.sdk.name";
|
|
1607
1697
|
const ATTR_TELEMETRY_SDK_VERSION = "telemetry.sdk.version";
|
|
@@ -1666,11 +1756,101 @@ function getSentryResource(serviceNameFallback) {
|
|
|
1666
1756
|
});
|
|
1667
1757
|
}
|
|
1668
1758
|
|
|
1759
|
+
function getTraceData({
|
|
1760
|
+
span,
|
|
1761
|
+
scope,
|
|
1762
|
+
client,
|
|
1763
|
+
propagateTraceparent
|
|
1764
|
+
} = {}) {
|
|
1765
|
+
let ctx = (scope && getContextFromScope(scope)) ?? api.context.active();
|
|
1766
|
+
if (span) {
|
|
1767
|
+
const { scope: scope2 } = core.getCapturedScopesOnSpan(span);
|
|
1768
|
+
ctx = scope2 && getContextFromScope(scope2) || api.trace.setSpan(api.context.active(), span);
|
|
1769
|
+
}
|
|
1770
|
+
const { traceId, spanId, sampled, dynamicSamplingContext } = getInjectionData(ctx, { scope, client });
|
|
1771
|
+
const traceData = {
|
|
1772
|
+
"sentry-trace": core.generateSentryTraceHeader(traceId, spanId, sampled),
|
|
1773
|
+
baggage: core.dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext)
|
|
1774
|
+
};
|
|
1775
|
+
if (propagateTraceparent) {
|
|
1776
|
+
traceData.traceparent = core.generateTraceparentHeader(traceId, spanId, sampled);
|
|
1777
|
+
}
|
|
1778
|
+
return traceData;
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
function setOpenTelemetryContextAsyncContextStrategy(options) {
|
|
1782
|
+
function getScopes() {
|
|
1783
|
+
const ctx = api.context.active();
|
|
1784
|
+
const scopes = getScopesFromContext(ctx);
|
|
1785
|
+
if (scopes) {
|
|
1786
|
+
return scopes;
|
|
1787
|
+
}
|
|
1788
|
+
return {
|
|
1789
|
+
scope: core.getDefaultCurrentScope(),
|
|
1790
|
+
isolationScope: core.getDefaultIsolationScope()
|
|
1791
|
+
};
|
|
1792
|
+
}
|
|
1793
|
+
function withScope(callback) {
|
|
1794
|
+
const ctx = api.context.active();
|
|
1795
|
+
return api.context.with(ctx, () => {
|
|
1796
|
+
return callback(getCurrentScope());
|
|
1797
|
+
});
|
|
1798
|
+
}
|
|
1799
|
+
function withSetScope(scope, callback) {
|
|
1800
|
+
const ctx = getContextFromScope(scope) || api.context.active();
|
|
1801
|
+
return api.context.with(ctx.setValue(SENTRY_FORK_SET_SCOPE_CONTEXT_KEY, scope), () => {
|
|
1802
|
+
return callback(scope);
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1805
|
+
function withIsolationScope(callback) {
|
|
1806
|
+
const ctx = api.context.active();
|
|
1807
|
+
return api.context.with(ctx.setValue(SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY, true), () => {
|
|
1808
|
+
return callback(getIsolationScope());
|
|
1809
|
+
});
|
|
1810
|
+
}
|
|
1811
|
+
function withSetIsolationScope(isolationScope, callback) {
|
|
1812
|
+
const ctx = api.context.active();
|
|
1813
|
+
return api.context.with(ctx.setValue(SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY, isolationScope), () => {
|
|
1814
|
+
return callback(getIsolationScope());
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
function getCurrentScope() {
|
|
1818
|
+
return getScopes().scope;
|
|
1819
|
+
}
|
|
1820
|
+
function getIsolationScope() {
|
|
1821
|
+
return getScopes().isolationScope;
|
|
1822
|
+
}
|
|
1823
|
+
core.setAsyncContextStrategy({
|
|
1824
|
+
withScope,
|
|
1825
|
+
withSetScope,
|
|
1826
|
+
withSetIsolationScope,
|
|
1827
|
+
withIsolationScope,
|
|
1828
|
+
getCurrentScope,
|
|
1829
|
+
getIsolationScope,
|
|
1830
|
+
startSpan,
|
|
1831
|
+
startSpanManual,
|
|
1832
|
+
startInactiveSpan,
|
|
1833
|
+
getActiveSpan,
|
|
1834
|
+
suppressTracing,
|
|
1835
|
+
isTracingSuppressed,
|
|
1836
|
+
getTraceData,
|
|
1837
|
+
continueTrace,
|
|
1838
|
+
startNewTrace,
|
|
1839
|
+
// The types here don't fully align, because our own `Span` type is narrower
|
|
1840
|
+
// than the OTEL one - but this is OK for here, as we now we'll only have OTEL spans passed around
|
|
1841
|
+
withActiveSpan,
|
|
1842
|
+
getTracingChannelBinding: options?.getTracingChannelBinding
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1669
1846
|
exports.SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION = SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION;
|
|
1670
1847
|
exports.SENTRY_SCOPES_CONTEXT_KEY = SENTRY_SCOPES_CONTEXT_KEY;
|
|
1671
1848
|
exports.SentryPropagator = SentryPropagator;
|
|
1672
1849
|
exports.SentrySampler = SentrySampler;
|
|
1673
1850
|
exports.SentrySpanProcessor = SentrySpanProcessor;
|
|
1851
|
+
exports.SentryTracerProvider = SentryTracerProvider;
|
|
1852
|
+
exports.applyOtelSpanData = applyOtelSpanData;
|
|
1853
|
+
exports.backfillStreamedSpanDataFromOtel = backfillStreamedSpanDataFromOtel;
|
|
1674
1854
|
exports.buildContextWithSentryScopes = buildContextWithSentryScopes;
|
|
1675
1855
|
exports.continueTrace = continueTrace;
|
|
1676
1856
|
exports.enhanceDscWithOpenTelemetryRootSpanName = enhanceDscWithOpenTelemetryRootSpanName;
|
|
@@ -1699,4 +1879,4 @@ exports.withActiveSpan = withActiveSpan;
|
|
|
1699
1879
|
exports.wrapClientClass = wrapClientClass;
|
|
1700
1880
|
exports.wrapContextManagerClass = wrapContextManagerClass;
|
|
1701
1881
|
exports.wrapSamplingDecision = wrapSamplingDecision;
|
|
1702
|
-
//# sourceMappingURL=
|
|
1882
|
+
//# sourceMappingURL=asyncContextStrategy-xEzxBKVX.js.map
|