|
1 | 1 | import type { Hub, Scope, Span, SpanTimeInput, StartSpanOptions, TransactionContext } from '@sentry/types'; |
2 | 2 |
|
3 | | -import { addNonEnumerableProperty, dropUndefinedKeys, logger, tracingContextFromHeaders } from '@sentry/utils'; |
4 | | -import { getDynamicSamplingContextFromSpan } from '.'; |
| 3 | +import { dropUndefinedKeys, logger, tracingContextFromHeaders } from '@sentry/utils'; |
| 4 | + |
5 | 5 | import { getCurrentScope, getIsolationScope, withScope } from '../currentScopes'; |
6 | 6 |
|
7 | 7 | import { DEBUG_BUILD } from '../debug-build'; |
8 | 8 | import { getCurrentHub } from '../hub'; |
9 | 9 | import { handleCallbackErrors } from '../utils/handleCallbackErrors'; |
10 | 10 | import { hasTracingEnabled } from '../utils/hasTracingEnabled'; |
11 | 11 | import { spanIsSampled, spanTimeInputToSeconds, spanToJSON } from '../utils/spanUtils'; |
| 12 | +import { getDynamicSamplingContextFromSpan } from './dynamicSamplingContext'; |
| 13 | +import { addChildSpanToSpan, getActiveSpan, setCapturedScopesOnSpan } from './utils'; |
12 | 14 |
|
13 | 15 | /** |
14 | 16 | * Wraps a function with a transaction/span and finishes the span after the function is done. |
@@ -152,14 +154,6 @@ export function startInactiveSpan(context: StartSpanOptions): Span | undefined { |
152 | 154 | }); |
153 | 155 | } |
154 | 156 |
|
155 | | -/** |
156 | | - * Returns the currently active span. |
157 | | - */ |
158 | | -export function getActiveSpan(): Span | undefined { |
159 | | - // eslint-disable-next-line deprecation/deprecation |
160 | | - return getCurrentScope().getSpan(); |
161 | | -} |
162 | | - |
163 | 157 | interface ContinueTrace { |
164 | 158 | /** |
165 | 159 | * Continue a trace from `sentry-trace` and `baggage` values. |
@@ -353,70 +347,3 @@ function normalizeContext(context: StartSpanOptions): TransactionContext { |
353 | 347 |
|
354 | 348 | return context; |
355 | 349 | } |
356 | | - |
357 | | -const CHILD_SPANS_FIELD = '_sentryChildSpans'; |
358 | | - |
359 | | -type SpanWithPotentialChildren = Span & { |
360 | | - [CHILD_SPANS_FIELD]?: Set<Span>; |
361 | | -}; |
362 | | - |
363 | | -/** |
364 | | - * Adds an opaque child span reference to a span. |
365 | | - */ |
366 | | -export function addChildSpanToSpan(span: SpanWithPotentialChildren, childSpan: Span): void { |
367 | | - if (span[CHILD_SPANS_FIELD] && span[CHILD_SPANS_FIELD].size < 1000) { |
368 | | - span[CHILD_SPANS_FIELD].add(childSpan); |
369 | | - } else { |
370 | | - span[CHILD_SPANS_FIELD] = new Set([childSpan]); |
371 | | - } |
372 | | -} |
373 | | - |
374 | | -/** |
375 | | - * Obtains the entire span tree, meaning a span + all of its descendants for a particular span. |
376 | | - */ |
377 | | -export function getSpanTree(span: SpanWithPotentialChildren): Span[] { |
378 | | - const resultSet = new Set<Span>(); |
379 | | - |
380 | | - function addSpanChildren(span: SpanWithPotentialChildren): void { |
381 | | - // This exit condition is required to not infinitely loop in case of a circular dependency. |
382 | | - if (resultSet.has(span)) { |
383 | | - return; |
384 | | - } else { |
385 | | - resultSet.add(span); |
386 | | - const childSpans = span[CHILD_SPANS_FIELD] ? Array.from(span[CHILD_SPANS_FIELD]) : []; |
387 | | - for (const childSpan of childSpans) { |
388 | | - addSpanChildren(childSpan); |
389 | | - } |
390 | | - } |
391 | | - } |
392 | | - |
393 | | - addSpanChildren(span); |
394 | | - |
395 | | - return Array.from(resultSet); |
396 | | -} |
397 | | - |
398 | | -const SCOPE_ON_START_SPAN_FIELD = '_sentryScope'; |
399 | | -const ISOLATION_SCOPE_ON_START_SPAN_FIELD = '_sentryIsolationScope'; |
400 | | - |
401 | | -type SpanWithScopes = Span & { |
402 | | - [SCOPE_ON_START_SPAN_FIELD]?: Scope; |
403 | | - [ISOLATION_SCOPE_ON_START_SPAN_FIELD]?: Scope; |
404 | | -}; |
405 | | - |
406 | | -/** Store the scope & isolation scope for a span, which can the be used when it is finished. */ |
407 | | -function setCapturedScopesOnSpan(span: Span | undefined, scope: Scope, isolationScope: Scope): void { |
408 | | - if (span) { |
409 | | - addNonEnumerableProperty(span, ISOLATION_SCOPE_ON_START_SPAN_FIELD, isolationScope); |
410 | | - addNonEnumerableProperty(span, SCOPE_ON_START_SPAN_FIELD, scope); |
411 | | - } |
412 | | -} |
413 | | - |
414 | | -/** |
415 | | - * Grabs the scope and isolation scope off a span that were active when the span was started. |
416 | | - */ |
417 | | -export function getCapturedScopesOnSpan(span: Span): { scope?: Scope; isolationScope?: Scope } { |
418 | | - return { |
419 | | - scope: (span as SpanWithScopes)[SCOPE_ON_START_SPAN_FIELD], |
420 | | - isolationScope: (span as SpanWithScopes)[ISOLATION_SCOPE_ON_START_SPAN_FIELD], |
421 | | - }; |
422 | | -} |
0 commit comments