* Creates a new `Span` while setting the current `Span.id` as `parentSpanId`. * This inherits the sampling decision from the parent span.
( parentSpan: Span, scope: Scope, spanArguments: SentrySpanArguments, isolationScope: Scope, )
| 546 | * This inherits the sampling decision from the parent span. |
| 547 | */ |
| 548 | function _startChildSpan( |
| 549 | parentSpan: Span, |
| 550 | scope: Scope, |
| 551 | spanArguments: SentrySpanArguments, |
| 552 | isolationScope: Scope, |
| 553 | ): Span { |
| 554 | const { spanId, traceId } = parentSpan.spanContext(); |
| 555 | const _isTracingSuppressed = isTracingSuppressed(scope); |
| 556 | const sampled = _isTracingSuppressed ? false : spanIsSampled(parentSpan); |
| 557 | |
| 558 | const childSpan = sampled |
| 559 | ? new SentrySpan({ |
| 560 | ...spanArguments, |
| 561 | parentSpanId: spanId, |
| 562 | traceId, |
| 563 | sampled, |
| 564 | }) |
| 565 | : new SentryNonRecordingSpan({ traceId }); |
| 566 | |
| 567 | addChildSpanToSpan(parentSpan, childSpan); |
| 568 | |
| 569 | setCapturedScopesOnSpan(childSpan, scope, isolationScope); |
| 570 | |
| 571 | const client = getClient(); |
| 572 | |
| 573 | if (!client) { |
| 574 | return childSpan; |
| 575 | } |
| 576 | |
| 577 | if (hasSpanStreamingEnabled(client) && spanIsNonRecordingSpan(childSpan)) { |
| 578 | if (spanIsNonRecordingSpan(parentSpan) && parentSpan.dropReason) { |
| 579 | // We land here if the parent span was a segment span that was ignored (`ignoreSpans`). |
| 580 | // In this case, the child was also ignored (see `sampled` above) but we need to |
| 581 | // record a client outcome for the child. |
| 582 | childSpan.dropReason = parentSpan.dropReason; |
| 583 | client.recordDroppedEvent(parentSpan.dropReason, 'span'); |
| 584 | } else if (!_isTracingSuppressed) { |
| 585 | // Otherwise, the child is not sampled due to sampling of the parent span, |
| 586 | // hence we record a sample_rate client outcome for the child. |
| 587 | childSpan.dropReason = 'sample_rate'; |
| 588 | client.recordDroppedEvent('sample_rate', 'span'); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | client.emit('spanStart', childSpan); |
| 593 | // If it has an endTimestamp, it's already ended |
| 594 | if (spanArguments.endTimestamp) { |
| 595 | client.emit('spanEnd', childSpan); |
| 596 | client.emit('afterSpanEnd', childSpan); |
| 597 | } |
| 598 | |
| 599 | return childSpan; |
| 600 | } |
| 601 | |
| 602 | function getParentSpan(scope: Scope, customParentSpan: Span | null | undefined): SentrySpan | undefined { |
| 603 | // always use the passed in span directly |
no test coverage detected