( spanArguments: SentrySpanArguments, scope: Scope, isolationScope: Scope, parentSampled?: boolean, )
| 480 | } |
| 481 | |
| 482 | function _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 | } |
no test coverage detected