Skip to content

Commit 0ad436e

Browse files
committed
ref: Remove makeRoot
1 parent a2351ab commit 0ad436e

File tree

5 files changed

+21
-34
lines changed

5 files changed

+21
-34
lines changed

packages/apm/src/hubextensions.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
import { getMainCarrier, Hub } from '@sentry/hub';
22
import { SpanContext } from '@sentry/types';
3-
import { isInstanceOf } from '@sentry/utils';
43

54
import { 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. */
167
function 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
}

packages/apm/src/integrations/tracing.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,10 @@ export class Tracing implements Integration {
371371
return undefined;
372372
}
373373

374-
Tracing._activeTransaction = hub.startSpan(
375-
{
376-
...spanContext,
377-
transaction: name,
378-
},
379-
true,
380-
);
374+
Tracing._activeTransaction = hub.startSpan({
375+
...spanContext,
376+
transaction: name,
377+
});
381378

382379
// We set the transaction on the scope so if there are any other spans started outside of this integration
383380
// we also add them to this transaction.

packages/apm/src/span.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ export class Span implements SpanInterface, SpanContext {
195195
/**
196196
* @inheritDoc
197197
*/
198-
public isChildSpan(): boolean {
199-
return this._parentSpanId !== undefined;
198+
public isRootSpan(): boolean {
199+
return this._parentSpanId === undefined;
200200
}
201201

202202
/**
@@ -283,6 +283,11 @@ export class Span implements SpanInterface, SpanContext {
283283

284284
this.timestamp = timestampWithMs();
285285

286+
// We will not send any child spans
287+
if (!this.isRootSpan()) {
288+
return undefined;
289+
}
290+
286291
// This happens if a span was initiated outside of `hub.startSpan`
287292
// Also if the span was sampled (sampled = false) in `hub.startSpan` already
288293
if (this.spanRecorder === undefined) {
@@ -306,11 +311,6 @@ export class Span implements SpanInterface, SpanContext {
306311
}).timestamp;
307312
}
308313

309-
// We will not send any child spans
310-
if (this.isChildSpan()) {
311-
return undefined;
312-
}
313-
314314
return this._hub.captureEvent({
315315
contexts: {
316316
trace: this.getTraceContext(),

packages/apm/test/hub.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('Hub', () => {
3535
expect(child.sampled).toBeFalsy();
3636
});
3737
});
38+
3839
describe('start', () => {
3940
test('simple', () => {
4041
const hub = new Hub(new BrowserClient());

packages/types/src/span.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ export interface Span {
7070
isSuccess(): boolean;
7171

7272
/**
73-
* Determines if the span is a child of another span
73+
* Determines if the span is transaction (root)
7474
*/
75-
isChildSpan(): boolean;
75+
isRootSpan(): boolean;
7676
}
7777

7878
/** Interface holder all properties that can be set on a Span on creation. */

0 commit comments

Comments
 (0)