@sentry/opentelemetry 8.0.0-alpha.5 → 8.0.0-alpha.7
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 +152 -80
- package/cjs/index.js.map +1 -1
- package/esm/index.js +156 -84
- package/esm/index.js.map +1 -1
- package/package.json +4 -4
- package/types/propagator.d.ts +4 -0
- package/types/propagator.d.ts.map +1 -1
- package/types/spanExporter.d.ts +16 -10
- package/types/spanExporter.d.ts.map +1 -1
- package/types/spanProcessor.d.ts +12 -9
- package/types/spanProcessor.d.ts.map +1 -1
- package/types/trace.d.ts +9 -8
- package/types/trace.d.ts.map +1 -1
- package/types/utils/groupSpansWithParents.d.ts +4 -0
- package/types/utils/groupSpansWithParents.d.ts.map +1 -1
- package/types-ts3.8/propagator.d.ts +4 -0
- package/types-ts3.8/spanExporter.d.ts +16 -10
- package/types-ts3.8/spanProcessor.d.ts +12 -9
- package/types-ts3.8/trace.d.ts +9 -8
- package/types-ts3.8/utils/groupSpansWithParents.d.ts +4 -0
package/esm/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { _optionalChain } from '@sentry/utils';
|
|
2
2
|
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
|
|
3
|
-
import { parseUrl, getSanitizedUrlString, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, propagationContextFromHeaders, baggageHeaderToDynamicSamplingContext, dynamicSamplingContextToSentryBaggageHeader, dropUndefinedKeys, stripUrlQueryAndFragment,
|
|
3
|
+
import { parseUrl, getSanitizedUrlString, LRUMap, logger, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, propagationContextFromHeaders, stringMatchesSomePattern, baggageHeaderToDynamicSamplingContext, dynamicSamplingContextToSentryBaggageHeader, dropUndefinedKeys, stripUrlQueryAndFragment, isNaN } from '@sentry/utils';
|
|
4
4
|
import * as api from '@opentelemetry/api';
|
|
5
5
|
import { trace, SpanKind, createContextKey, propagation, TraceFlags, context, SpanStatusCode, ROOT_CONTEXT, isSpanContextValid } from '@opentelemetry/api';
|
|
6
|
-
import { SDK_VERSION, getCurrentScope, getIsolationScope, getClient, getDynamicSamplingContextFromClient, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, isSentryRequestUrl, handleCallbackErrors, SEMANTIC_ATTRIBUTE_SENTRY_OP, getRootSpan, continueTrace as continueTrace$1, withScope, captureEvent, addBreadcrumb, setUser, setTags, setTag, setExtra, setExtras, setContext, startSession, endSession, setAsyncContextStrategy, getDefaultCurrentScope, getDefaultIsolationScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getStatusMessage, getMetricSummaryJsonForSpan, addChildSpanToSpan, hasTracingEnabled } from '@sentry/core';
|
|
6
|
+
import { SDK_VERSION, getCurrentScope, getIsolationScope, getClient, getDynamicSamplingContextFromClient, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, isSentryRequestUrl, handleCallbackErrors, SEMANTIC_ATTRIBUTE_SENTRY_OP, getRootSpan, continueTrace as continueTrace$1, withScope, captureEvent, addBreadcrumb, setUser, setTags, setTag, setExtra, setExtras, setContext, startSession, endSession, setAsyncContextStrategy, getDefaultCurrentScope, getDefaultIsolationScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getStatusMessage, getMetricSummaryJsonForSpan, addChildSpanToSpan, hasTracingEnabled } from '@sentry/core';
|
|
7
7
|
export { getClient } from '@sentry/core';
|
|
8
|
-
import { W3CBaggagePropagator, isTracingSuppressed, TraceState, suppressTracing
|
|
9
|
-
import {
|
|
8
|
+
import { W3CBaggagePropagator, isTracingSuppressed, TraceState, suppressTracing } from '@opentelemetry/core';
|
|
9
|
+
import { SamplingDecision } from '@opentelemetry/sdk-trace-base';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Check if a given span has attributes.
|
|
@@ -262,6 +262,13 @@ function getContextFromScope(scope) {
|
|
|
262
262
|
return SCOPE_CONTEXT_MAP.get(scope);
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
+
/**
|
|
266
|
+
* This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
|
|
267
|
+
*
|
|
268
|
+
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
|
|
269
|
+
*/
|
|
270
|
+
const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
|
|
271
|
+
|
|
265
272
|
const setupElements = new Set();
|
|
266
273
|
|
|
267
274
|
/** Get all the OpenTelemetry elements that have been set up. */
|
|
@@ -299,9 +306,14 @@ function getPropagationContextFromSpanContext(spanContext) {
|
|
|
299
306
|
* Injects and extracts `sentry-trace` and `baggage` headers from carriers.
|
|
300
307
|
*/
|
|
301
308
|
class SentryPropagator extends W3CBaggagePropagator {
|
|
309
|
+
/** A map of URLs that have already been checked for if they match tracePropagationTargets. */
|
|
310
|
+
|
|
302
311
|
constructor() {
|
|
303
312
|
super();
|
|
304
313
|
setIsSetup('SentryPropagator');
|
|
314
|
+
|
|
315
|
+
// We're caching results so we don't have to recompute regexp every time we create a request.
|
|
316
|
+
this._urlMatchesTargetsMap = new LRUMap(100);
|
|
305
317
|
}
|
|
306
318
|
|
|
307
319
|
/**
|
|
@@ -309,6 +321,20 @@ class SentryPropagator extends W3CBaggagePropagator {
|
|
|
309
321
|
*/
|
|
310
322
|
inject(context, carrier, setter) {
|
|
311
323
|
if (isTracingSuppressed(context)) {
|
|
324
|
+
DEBUG_BUILD && logger.log('[Tracing] Not injecting trace data for url because tracing is suppressed.');
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const activeSpan = trace.getSpan(context);
|
|
329
|
+
const url = activeSpan && _optionalChain$7([spanToJSON, 'call', _ => _(activeSpan), 'access', _2 => _2.data, 'optionalAccess', _3 => _3[SemanticAttributes.HTTP_URL]]);
|
|
330
|
+
const tracePropagationTargets = _optionalChain$7([getClient, 'call', _4 => _4(), 'optionalAccess', _5 => _5.getOptions, 'call', _6 => _6(), 'optionalAccess', _7 => _7.tracePropagationTargets]);
|
|
331
|
+
if (
|
|
332
|
+
typeof url === 'string' &&
|
|
333
|
+
tracePropagationTargets &&
|
|
334
|
+
!this._shouldInjectTraceData(tracePropagationTargets, url)
|
|
335
|
+
) {
|
|
336
|
+
DEBUG_BUILD &&
|
|
337
|
+
logger.log('[Tracing] Not injecting trace data for url because it does not matchTracePropagationTargets:', url);
|
|
312
338
|
return;
|
|
313
339
|
}
|
|
314
340
|
|
|
@@ -365,6 +391,22 @@ class SentryPropagator extends W3CBaggagePropagator {
|
|
|
365
391
|
fields() {
|
|
366
392
|
return [SENTRY_TRACE_HEADER, SENTRY_BAGGAGE_HEADER];
|
|
367
393
|
}
|
|
394
|
+
|
|
395
|
+
/** If we want to inject trace data for a given URL. */
|
|
396
|
+
_shouldInjectTraceData(tracePropagationTargets, url) {
|
|
397
|
+
if (tracePropagationTargets === undefined) {
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const cachedDecision = this._urlMatchesTargetsMap.get(url);
|
|
402
|
+
if (cachedDecision !== undefined) {
|
|
403
|
+
return cachedDecision;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const decision = stringMatchesSomePattern(url, tracePropagationTargets);
|
|
407
|
+
this._urlMatchesTargetsMap.set(url, decision);
|
|
408
|
+
return decision;
|
|
409
|
+
}
|
|
368
410
|
}
|
|
369
411
|
|
|
370
412
|
/** Exported for tests. */
|
|
@@ -397,7 +439,7 @@ function getInjectionData(context)
|
|
|
397
439
|
|
|
398
440
|
{
|
|
399
441
|
const span = trace.getSpan(context);
|
|
400
|
-
const spanIsRemote = _optionalChain$7([span, 'optionalAccess',
|
|
442
|
+
const spanIsRemote = _optionalChain$7([span, 'optionalAccess', _8 => _8.spanContext, 'call', _9 => _9(), 'access', _10 => _10.isRemote]);
|
|
401
443
|
|
|
402
444
|
// If we have a local span, we can just pick everything from it
|
|
403
445
|
if (span && !spanIsRemote) {
|
|
@@ -413,7 +455,7 @@ function getInjectionData(context)
|
|
|
413
455
|
}
|
|
414
456
|
|
|
415
457
|
// Else we try to use the propagation context from the scope
|
|
416
|
-
const scope = _optionalChain$7([getScopesFromContext, 'call',
|
|
458
|
+
const scope = _optionalChain$7([getScopesFromContext, 'call', _11 => _11(context), 'optionalAccess', _12 => _12.scope]);
|
|
417
459
|
if (scope) {
|
|
418
460
|
const propagationContext = scope.getPropagationContext();
|
|
419
461
|
const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, propagationContext.traceId);
|
|
@@ -455,7 +497,7 @@ function getDynamicSamplingContext(
|
|
|
455
497
|
traceId,
|
|
456
498
|
) {
|
|
457
499
|
// If we have a DSC on the propagation context, we just use it
|
|
458
|
-
if (_optionalChain$7([propagationContext, 'optionalAccess',
|
|
500
|
+
if (_optionalChain$7([propagationContext, 'optionalAccess', _13 => _13.dsc])) {
|
|
459
501
|
return propagationContext.dsc;
|
|
460
502
|
}
|
|
461
503
|
|
|
@@ -535,10 +577,10 @@ function getSamplingDecision(spanContext) {
|
|
|
535
577
|
const dscString = traceState ? traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
|
|
536
578
|
const dsc = dscString ? baggageHeaderToDynamicSamplingContext(dscString) : undefined;
|
|
537
579
|
|
|
538
|
-
if (_optionalChain$7([dsc, 'optionalAccess',
|
|
580
|
+
if (_optionalChain$7([dsc, 'optionalAccess', _14 => _14.sampled]) === 'true') {
|
|
539
581
|
return true;
|
|
540
582
|
}
|
|
541
|
-
if (_optionalChain$7([dsc, 'optionalAccess',
|
|
583
|
+
if (_optionalChain$7([dsc, 'optionalAccess', _15 => _15.sampled]) === 'false') {
|
|
542
584
|
return false;
|
|
543
585
|
}
|
|
544
586
|
|
|
@@ -629,11 +671,12 @@ function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[
|
|
|
629
671
|
/**
|
|
630
672
|
* Wraps a function with a transaction/span and finishes the span after the function is done.
|
|
631
673
|
* The created span is the active span and will be used as parent by other spans created inside the function
|
|
632
|
-
* and can be accessed via `Sentry.
|
|
674
|
+
* and can be accessed via `Sentry.getActiveSpan()`, as long as the function is executed while the scope is active.
|
|
633
675
|
*
|
|
634
676
|
* If you want to create a span that is not set as active, use {@link startInactiveSpan}.
|
|
635
677
|
*
|
|
636
|
-
*
|
|
678
|
+
* You'll always get a span passed to the callback,
|
|
679
|
+
* it may just be a non-recording span if the span is not sampled or if tracing is disabled.
|
|
637
680
|
*/
|
|
638
681
|
function startSpan(options, callback) {
|
|
639
682
|
const tracer = getTracer();
|
|
@@ -652,7 +695,10 @@ function startSpan(options, callback) {
|
|
|
652
695
|
return handleCallbackErrors(
|
|
653
696
|
() => callback(span),
|
|
654
697
|
() => {
|
|
655
|
-
span
|
|
698
|
+
// Only set the span status to ERROR when there wasn't any status set before, in order to avoid stomping useful span statuses
|
|
699
|
+
if (spanToJSON(span).status === undefined) {
|
|
700
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
701
|
+
}
|
|
656
702
|
},
|
|
657
703
|
() => span.end(),
|
|
658
704
|
);
|
|
@@ -666,7 +712,8 @@ function startSpan(options, callback) {
|
|
|
666
712
|
* The created span is the active span and will be used as parent by other spans created inside the function
|
|
667
713
|
* and can be accessed via `Sentry.getActiveSpan()`, as long as the function is executed while the scope is active.
|
|
668
714
|
*
|
|
669
|
-
*
|
|
715
|
+
* You'll always get a span passed to the callback,
|
|
716
|
+
* it may just be a non-recording span if the span is not sampled or if tracing is disabled.
|
|
670
717
|
*/
|
|
671
718
|
function startSpanManual(
|
|
672
719
|
options,
|
|
@@ -688,7 +735,10 @@ function startSpanManual(
|
|
|
688
735
|
return handleCallbackErrors(
|
|
689
736
|
() => callback(span, () => span.end()),
|
|
690
737
|
() => {
|
|
691
|
-
span
|
|
738
|
+
// Only set the span status to ERROR when there wasn't any status set before, in order to avoid stomping useful span statuses
|
|
739
|
+
if (spanToJSON(span).status === undefined) {
|
|
740
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
741
|
+
}
|
|
692
742
|
},
|
|
693
743
|
);
|
|
694
744
|
});
|
|
@@ -696,13 +746,12 @@ function startSpanManual(
|
|
|
696
746
|
|
|
697
747
|
/**
|
|
698
748
|
* Creates a span. This span is not set as active, so will not get automatic instrumentation spans
|
|
699
|
-
* as children or be able to be accessed via `Sentry.
|
|
749
|
+
* as children or be able to be accessed via `Sentry.getActiveSpan()`.
|
|
700
750
|
*
|
|
701
751
|
* If you want to create a span that is set as active, use {@link startSpan}.
|
|
702
752
|
*
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
* and the `span` returned from the callback will be undefined.
|
|
753
|
+
* This function will always return a span,
|
|
754
|
+
* it may just be a non-recording span if the span is not sampled or if tracing is disabled.
|
|
706
755
|
*/
|
|
707
756
|
function startInactiveSpan(options) {
|
|
708
757
|
const tracer = getTracer();
|
|
@@ -727,7 +776,7 @@ function startInactiveSpan(options) {
|
|
|
727
776
|
* passed `null` to start an entirely new span tree.
|
|
728
777
|
*
|
|
729
778
|
* @param span Spans started in the context of the provided callback will be children of this span. If `null` is passed,
|
|
730
|
-
* spans started within the callback will
|
|
779
|
+
* spans started within the callback will be root spans.
|
|
731
780
|
* @param callback Execution context in which the provided span will be active. Is passed the newly forked scope.
|
|
732
781
|
* @returns the value returned from the provided callback function.
|
|
733
782
|
*/
|
|
@@ -1174,13 +1223,6 @@ function wrapContextManagerClass(
|
|
|
1174
1223
|
return SentryContextManager ;
|
|
1175
1224
|
}
|
|
1176
1225
|
|
|
1177
|
-
/**
|
|
1178
|
-
* This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
|
|
1179
|
-
*
|
|
1180
|
-
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
|
|
1181
|
-
*/
|
|
1182
|
-
const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
|
|
1183
|
-
|
|
1184
1226
|
/** If this attribute is true, it means that the parent is a remote span. */
|
|
1185
1227
|
const SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE = 'sentry.parentIsRemote';
|
|
1186
1228
|
|
|
@@ -1205,14 +1247,19 @@ function groupSpansWithParents(spans) {
|
|
|
1205
1247
|
});
|
|
1206
1248
|
}
|
|
1207
1249
|
|
|
1208
|
-
|
|
1250
|
+
/**
|
|
1251
|
+
* This returns the _local_ parent ID - `parentId` on the span may point to a remote span.
|
|
1252
|
+
*/
|
|
1253
|
+
function getLocalParentId(span) {
|
|
1209
1254
|
const parentIsRemote = span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE] === true;
|
|
1210
|
-
|
|
1211
|
-
const id = span.spanContext().spanId;
|
|
1212
|
-
|
|
1213
1255
|
// If the parentId is the trace parent ID, we pretend it's undefined
|
|
1214
1256
|
// As this means the parent exists somewhere else
|
|
1215
|
-
|
|
1257
|
+
return !parentIsRemote ? span.parentSpanId : undefined;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
function createOrUpdateSpanNodeAndRefs(nodeMap, span) {
|
|
1261
|
+
const id = span.spanContext().spanId;
|
|
1262
|
+
const parentId = getLocalParentId(span);
|
|
1216
1263
|
|
|
1217
1264
|
if (!parentId) {
|
|
1218
1265
|
createOrUpdateNode(nodeMap, { id, span, children: [] });
|
|
@@ -1472,36 +1519,70 @@ function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[
|
|
|
1472
1519
|
/**
|
|
1473
1520
|
* A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.
|
|
1474
1521
|
*/
|
|
1475
|
-
class SentrySpanExporter
|
|
1522
|
+
class SentrySpanExporter {
|
|
1476
1523
|
|
|
1477
1524
|
constructor() {
|
|
1478
|
-
this._stopped = false;
|
|
1479
1525
|
this._finishedSpans = [];
|
|
1480
1526
|
}
|
|
1481
1527
|
|
|
1482
|
-
/**
|
|
1483
|
-
export(
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1528
|
+
/** Export a single span. */
|
|
1529
|
+
export(span) {
|
|
1530
|
+
this._finishedSpans.push(span);
|
|
1531
|
+
|
|
1532
|
+
// If the span has a local parent ID, we don't need to export anything just yet
|
|
1533
|
+
if (getLocalParentId(span)) {
|
|
1534
|
+
const openSpanCount = this._finishedSpans.length;
|
|
1535
|
+
DEBUG_BUILD && logger.log(`SpanExporter has ${openSpanCount} unsent spans remaining`);
|
|
1536
|
+
this._cleanupOldSpans();
|
|
1537
|
+
return;
|
|
1489
1538
|
}
|
|
1490
1539
|
|
|
1491
|
-
|
|
1492
|
-
|
|
1540
|
+
this._clearTimeout();
|
|
1541
|
+
|
|
1542
|
+
// If we got a parent span, we try to send the span tree
|
|
1543
|
+
// Wait a tick for this, to ensure we avoid race conditions
|
|
1544
|
+
this._flushTimeout = setTimeout(() => {
|
|
1545
|
+
this.flush();
|
|
1546
|
+
}, 1);
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
/** Try to flush any pending spans immediately. */
|
|
1550
|
+
flush() {
|
|
1551
|
+
this._clearTimeout();
|
|
1493
1552
|
|
|
1494
|
-
this._finishedSpans.
|
|
1553
|
+
const openSpanCount = this._finishedSpans.length;
|
|
1495
1554
|
|
|
1496
1555
|
const remainingSpans = maybeSend(this._finishedSpans);
|
|
1497
1556
|
|
|
1498
1557
|
const remainingOpenSpanCount = remainingSpans.length;
|
|
1499
|
-
const sentSpanCount = openSpanCount
|
|
1558
|
+
const sentSpanCount = openSpanCount - remainingOpenSpanCount;
|
|
1500
1559
|
|
|
1501
1560
|
DEBUG_BUILD &&
|
|
1502
1561
|
logger.log(`SpanExporter exported ${sentSpanCount} spans, ${remainingOpenSpanCount} unsent spans remaining`);
|
|
1503
1562
|
|
|
1504
|
-
this.
|
|
1563
|
+
this._cleanupOldSpans(remainingSpans);
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
/** Clear the exporter. */
|
|
1567
|
+
clear() {
|
|
1568
|
+
this._finishedSpans = [];
|
|
1569
|
+
this._clearTimeout();
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
/** Clear the flush timeout. */
|
|
1573
|
+
_clearTimeout() {
|
|
1574
|
+
if (this._flushTimeout) {
|
|
1575
|
+
clearTimeout(this._flushTimeout);
|
|
1576
|
+
this._flushTimeout = undefined;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
/**
|
|
1581
|
+
* Remove any span that is older than 5min.
|
|
1582
|
+
* We do this to avoid leaking memory.
|
|
1583
|
+
*/
|
|
1584
|
+
_cleanupOldSpans(spans = this._finishedSpans) {
|
|
1585
|
+
this._finishedSpans = spans.filter(span => {
|
|
1505
1586
|
const shouldDrop = shouldCleanupSpan(span, 5 * 60);
|
|
1506
1587
|
DEBUG_BUILD &&
|
|
1507
1588
|
shouldDrop &&
|
|
@@ -1512,23 +1593,6 @@ class SentrySpanExporter {
|
|
|
1512
1593
|
);
|
|
1513
1594
|
return !shouldDrop;
|
|
1514
1595
|
});
|
|
1515
|
-
|
|
1516
|
-
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
/** @inheritDoc */
|
|
1520
|
-
shutdown() {
|
|
1521
|
-
const forceFlush = this.forceFlush();
|
|
1522
|
-
this._stopped = true;
|
|
1523
|
-
this._finishedSpans = [];
|
|
1524
|
-
return forceFlush;
|
|
1525
|
-
}
|
|
1526
|
-
|
|
1527
|
-
/** @inheritDoc */
|
|
1528
|
-
forceFlush() {
|
|
1529
|
-
return new Promise(resolve => {
|
|
1530
|
-
this.export(this._finishedSpans, () => resolve());
|
|
1531
|
-
});
|
|
1532
1596
|
}
|
|
1533
1597
|
}
|
|
1534
1598
|
|
|
@@ -1571,8 +1635,12 @@ function maybeSend(spans) {
|
|
|
1571
1635
|
.filter((span) => !!span);
|
|
1572
1636
|
}
|
|
1573
1637
|
|
|
1638
|
+
function nodeIsCompletedRootNode(node) {
|
|
1639
|
+
return !!node.span && !node.parentNode;
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1574
1642
|
function getCompletedRootNodes(nodes) {
|
|
1575
|
-
return nodes.filter(
|
|
1643
|
+
return nodes.filter(nodeIsCompletedRootNode);
|
|
1576
1644
|
}
|
|
1577
1645
|
|
|
1578
1646
|
function shouldCleanupSpan(span, maxStartTimeOffsetSeconds) {
|
|
@@ -1617,7 +1685,7 @@ function createTransactionForOtelSpan(span) {
|
|
|
1617
1685
|
data: attributes,
|
|
1618
1686
|
origin,
|
|
1619
1687
|
op,
|
|
1620
|
-
status: getStatusMessage(status),
|
|
1688
|
+
status: getStatusMessage(status), // As per protocol, span status is allowed to be undefined
|
|
1621
1689
|
});
|
|
1622
1690
|
|
|
1623
1691
|
const transactionEvent = {
|
|
@@ -1691,7 +1759,7 @@ function createAndFinishSpanForOtelSpan(node, spans, remaining) {
|
|
|
1691
1759
|
start_timestamp: convertOtelTimeToSeconds(startTime),
|
|
1692
1760
|
// This is [0,0] by default in OTEL, in which case we want to interpret this as no end time
|
|
1693
1761
|
timestamp: convertOtelTimeToSeconds(endTime) || undefined,
|
|
1694
|
-
status: getStatusMessage(status),
|
|
1762
|
+
status: getStatusMessage(status), // As per protocol, span status is allowed to be undefined
|
|
1695
1763
|
op,
|
|
1696
1764
|
origin,
|
|
1697
1765
|
_metrics_summary: getMetricSummaryJsonForSpan(span ),
|
|
@@ -1804,18 +1872,32 @@ function onSpanStart(span, parentContext) {
|
|
|
1804
1872
|
|
|
1805
1873
|
function onSpanEnd(span) {
|
|
1806
1874
|
const client = getClient();
|
|
1807
|
-
_optionalChain$1([client, 'optionalAccess', _3 => _3.emit, 'call', _4 => _4('spanEnd', span)]);
|
|
1875
|
+
_optionalChain$1([client, 'optionalAccess', _3 => _3.emit, 'call', _4 => _4('spanEnd', span )]);
|
|
1808
1876
|
}
|
|
1809
1877
|
|
|
1810
1878
|
/**
|
|
1811
1879
|
* Converts OpenTelemetry Spans to Sentry Spans and sends them to Sentry via
|
|
1812
1880
|
* the Sentry SDK.
|
|
1813
1881
|
*/
|
|
1814
|
-
class SentrySpanProcessor
|
|
1815
|
-
constructor() {
|
|
1816
|
-
super(new SentrySpanExporter());
|
|
1882
|
+
class SentrySpanProcessor {
|
|
1817
1883
|
|
|
1884
|
+
constructor() {
|
|
1818
1885
|
setIsSetup('SentrySpanProcessor');
|
|
1886
|
+
this._exporter = new SentrySpanExporter();
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
/**
|
|
1890
|
+
* @inheritDoc
|
|
1891
|
+
*/
|
|
1892
|
+
async forceFlush() {
|
|
1893
|
+
this._exporter.flush();
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
/**
|
|
1897
|
+
* @inheritDoc
|
|
1898
|
+
*/
|
|
1899
|
+
async shutdown() {
|
|
1900
|
+
this._exporter.clear();
|
|
1819
1901
|
}
|
|
1820
1902
|
|
|
1821
1903
|
/**
|
|
@@ -1828,30 +1910,20 @@ class SentrySpanProcessor extends BatchSpanProcessor {
|
|
|
1828
1910
|
// once we decoupled opentelemetry from SentrySpan
|
|
1829
1911
|
|
|
1830
1912
|
DEBUG_BUILD && logger.log(`[Tracing] Starting span "${span.name}" (${span.spanContext().spanId})`);
|
|
1831
|
-
|
|
1832
|
-
return super.onStart(span, parentContext);
|
|
1833
1913
|
}
|
|
1834
1914
|
|
|
1835
1915
|
/** @inheritDoc */
|
|
1836
1916
|
onEnd(span) {
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
if (!this._shouldSendSpanToSentry(span)) {
|
|
1840
|
-
// Prevent this being called to super.onEnd(), which would pass this to the span exporter
|
|
1917
|
+
if (span.spanContext().traceFlags !== TraceFlags.SAMPLED) {
|
|
1918
|
+
DEBUG_BUILD && logger.log(`[Tracing] Finishing unsampled span "${span.name}" (${span.spanContext().spanId})`);
|
|
1841
1919
|
return;
|
|
1842
1920
|
}
|
|
1843
1921
|
|
|
1844
|
-
|
|
1922
|
+
DEBUG_BUILD && logger.log(`[Tracing] Finishing span "${span.name}" (${span.spanContext().spanId})`);
|
|
1845
1923
|
|
|
1846
|
-
|
|
1847
|
-
}
|
|
1924
|
+
onSpanEnd(span);
|
|
1848
1925
|
|
|
1849
|
-
|
|
1850
|
-
* You can overwrite this in a sub class to implement custom behavior for dropping spans.
|
|
1851
|
-
* If you return `false` here, the span will not be passed to the exporter and thus not be sent.
|
|
1852
|
-
*/
|
|
1853
|
-
_shouldSendSpanToSentry(_span) {
|
|
1854
|
-
return true;
|
|
1926
|
+
this._exporter.export(span);
|
|
1855
1927
|
}
|
|
1856
1928
|
}
|
|
1857
1929
|
|