11import { getMainCarrier , Hub } from '@sentry/hub' ;
22import { SpanContext } from '@sentry/types' ;
3- import { isInstanceOf } from '@sentry/utils' ;
43
54import { Span } from './span' ;
65
7- /**
8- * Checks whether given value is instance of Span
9- * @param span value to check
10- */
11- function isSpanInstance ( span : unknown ) : span is Span {
12- return isInstanceOf ( span , Span ) ;
13- }
14-
156/** Returns all trace headers that are currently on the top scope. */
167function traceHeaders ( ) : { [ key : string ] : string } {
178 // @ts -ignore
@@ -33,11 +24,9 @@ function traceHeaders(): { [key: string]: string } {
3324 * and attach a `SpanRecorder`. If it's of type `SpanContext` and there is already a `Span` on the Scope,
3425 * the created Span will have a reference to it and become it's child. Otherwise it'll crete a new `Span`.
3526 *
36- * @param spanOrSpanContext Already constructed span or properties with which the span should be created
37- * @param makeRoot This will just create the span as it is and will not attach it to the span on the scope (if there is one).
38- * Under some circumstances, in internal integrations, for example, this is used to make sure they are not interfering with each other.
27+ * @param spanContext Already constructed span or properties with which the span should be created
3928 */
40- function startSpan ( spanOrSpanContext ?: Span | SpanContext , makeRoot : boolean = false ) : Span {
29+ function startSpan ( spanContext ?: SpanContext ) : Span {
4130 // @ts -ignore
4231 const hub = this as Hub ;
4332 const scope = hub . getScope ( ) ;
@@ -48,20 +37,20 @@ function startSpan(spanOrSpanContext?: Span | SpanContext, makeRoot: boolean = f
4837 // If we do not have this, we will add it later on twice to the span recorder and therefore have too many spans
4938 let addedAsChild = false ;
5039
51- if ( ! isSpanInstance ( spanOrSpanContext ) && ! makeRoot && scope ) {
40+ if ( scope ) {
5241 const parentSpan = scope . getSpan ( ) as Span ;
5342 if ( parentSpan ) {
54- span = parentSpan . child ( spanOrSpanContext ) ;
43+ span = parentSpan . child ( spanContext ) ;
5544 addedAsChild = true ;
5645 }
5746 }
5847
59- if ( ! isSpanInstance ( span ) ) {
60- span = new Span ( spanOrSpanContext , hub ) ;
48+ if ( ! span ) {
49+ span = new Span ( spanContext , hub ) ;
6150 }
6251
6352 // We only roll the dice on sampling for "root" spans (transactions) because the childs inherit this state
64- if ( span . sampled === undefined && ! span . isChildSpan ( ) ) {
53+ if ( span . sampled === undefined && span . isRootSpan ( ) ) {
6554 const sampleRate = ( client && client . getOptions ( ) . tracesSampleRate ) || 0 ;
6655 span . sampled = Math . random ( ) < sampleRate ;
6756 }
0 commit comments