MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / _startRootSpan

Function _startRootSpan

packages/core/src/tracing/trace.ts:482–542  ·  view source on GitHub ↗
(
  spanArguments: SentrySpanArguments,
  scope: Scope,
  isolationScope: Scope,
  parentSampled?: boolean,
)

Source from the content-addressed store, hash-verified

480}
481
482function _startRootSpan(
483 spanArguments: SentrySpanArguments,
484 scope: Scope,
485 isolationScope: Scope,
486 parentSampled?: boolean,
487): SentrySpan {
488 const client = getClient();
489 const options: Partial<ClientOptions> = client?.getOptions() || {};
490
491 const { name = '' } = spanArguments;
492
493 const mutableSpanSamplingData = { spanAttributes: { ...spanArguments.attributes }, spanName: name, parentSampled };
494
495 // we don't care about the decision for the moment; this is just a placeholder
496 client?.emit('beforeSampling', mutableSpanSamplingData, { decision: false });
497
498 // If hook consumers override the parentSampled flag, we will use that value instead of the actual one
499 const finalParentSampled = mutableSpanSamplingData.parentSampled ?? parentSampled;
500 const finalAttributes = mutableSpanSamplingData.spanAttributes;
501
502 const currentPropagationContext = scope.getPropagationContext();
503 const _isTracingSuppressed = isTracingSuppressed(scope);
504
505 const [sampled, sampleRate, localSampleRateWasApplied] = _isTracingSuppressed
506 ? [false]
507 : sampleSpan(
508 options,
509 {
510 name,
511 parentSampled: finalParentSampled,
512 attributes: finalAttributes,
513 normalizedRequest: isolationScope.getScopeData().sdkProcessingMetadata.normalizedRequest,
514 parentSampleRate: parseSampleRate(currentPropagationContext.dsc?.sample_rate),
515 },
516 currentPropagationContext.sampleRand,
517 );
518
519 const rootSpan = new SentrySpan({
520 ...spanArguments,
521 attributes: {
522 [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',
523 [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]:
524 sampleRate !== undefined && localSampleRateWasApplied ? sampleRate : undefined,
525 ...finalAttributes,
526 },
527 sampled,
528 });
529
530 if (!sampled && client && !_isTracingSuppressed) {
531 DEBUG_BUILD && debug.log('[Tracing] Discarding root span because its trace was not chosen to be sampled.');
532 client.recordDroppedEvent('sample_rate', hasSpanStreamingEnabled(client) ? 'span' : 'transaction');
533 }
534
535 setCapturedScopesOnSpan(rootSpan, scope, isolationScope);
536
537 if (client) {
538 client.emit('spanStart', rootSpan);
539 }

Callers 1

createChildOrRootSpanFunction · 0.85

Calls 11

getClientFunction · 0.90
sampleSpanFunction · 0.90
parseSampleRateFunction · 0.90
hasSpanStreamingEnabledFunction · 0.90
setCapturedScopesOnSpanFunction · 0.90
getPropagationContextMethod · 0.80
getScopeDataMethod · 0.80
isTracingSuppressedFunction · 0.70
getOptionsMethod · 0.65
emitMethod · 0.65
logMethod · 0.65

Tested by

no test coverage detected