Skip to content

Commit 48da3f8

Browse files
HazATkamilogorek
authored andcommitted
feat: Some cleanup and changes
1 parent dd7bb41 commit 48da3f8

File tree

6 files changed

+32
-65
lines changed

6 files changed

+32
-65
lines changed

packages/hub/src/hub.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Integration,
99
IntegrationClass,
1010
Severity,
11-
SpanDetails,
11+
SpanProps,
1212
User,
1313
} from '@sentry/types';
1414
import { consoleSandbox, dynamicRequire, getGlobalObject, isNodeEnv, logger, uuid4 } from '@sentry/utils';
@@ -389,17 +389,17 @@ export class Hub implements HubInterface {
389389
/**
390390
* @inheritDoc
391391
*/
392-
public startSpan(spanDetails?: SpanDetails): Span {
392+
public startSpan(spanProps?: SpanProps): Span {
393393
const scope = this.getScope();
394394

395395
if (scope) {
396396
const span = scope.getSpan();
397397
if (span) {
398-
return span.newSpan(spanDetails);
398+
return span.newSpan(spanProps);
399399
}
400400
}
401401

402-
return new Span(spanDetails);
402+
return new Span(spanProps);
403403
}
404404

405405
/**

packages/hub/src/span.ts

+24-31
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Span as SpanInterface, SpanDetails } from '@sentry/types';
1+
import { Span as SpanInterface, SpanProps } from '@sentry/types';
22
import { uuid4 } from '@sentry/utils';
33

44
export const TRACEPARENT_REGEXP = /^[ \t]*([0-9a-f]{32})?-?([0-9a-f]{16})?-?([01])?[ \t]*$/;
55

66
/**
7-
* Span containg all data about a span
7+
* Span contains all data about a span
88
*/
9-
export class Span implements SpanInterface {
9+
export class Span implements SpanInterface, SpanProps {
1010
/**
1111
* Trace ID
1212
*/
@@ -57,38 +57,38 @@ export class Span implements SpanInterface {
5757
*/
5858
public finishedSpans: Span[] = [];
5959

60-
public constructor(spanDetails?: SpanDetails) {
61-
if (!spanDetails) {
60+
public constructor(spanProps?: SpanProps) {
61+
if (!spanProps) {
6262
return this;
6363
}
6464

65-
if (spanDetails.traceId) {
66-
this._traceId = spanDetails.traceId;
65+
if (spanProps.traceId) {
66+
this._traceId = spanProps.traceId;
6767
}
68-
if (spanDetails.spanId) {
69-
this._spanId = spanDetails.spanId;
68+
if (spanProps.spanId) {
69+
this._spanId = spanProps.spanId;
7070
}
71-
if (spanDetails.parentSpanId) {
72-
this._parentSpanId = spanDetails.parentSpanId;
71+
if (spanProps.parentSpanId) {
72+
this._parentSpanId = spanProps.parentSpanId;
7373
}
74-
if (spanDetails.sampled) {
75-
this.sampled = spanDetails.sampled;
74+
if (spanProps.sampled) {
75+
this.sampled = spanProps.sampled;
7676
}
77-
if (spanDetails.transaction) {
78-
this.transaction = spanDetails.transaction;
77+
if (spanProps.transaction) {
78+
this.transaction = spanProps.transaction;
7979
}
80-
if (spanDetails.op) {
81-
this.op = spanDetails.op;
80+
if (spanProps.op) {
81+
this.op = spanProps.op;
8282
}
83-
if (spanDetails.description) {
84-
this.description = spanDetails.description;
83+
if (spanProps.description) {
84+
this.description = spanProps.description;
8585
}
8686
}
8787

8888
/** JSDoc */
89-
public newSpan(spanDetails?: Pick<SpanDetails, Exclude<keyof SpanDetails, 'spanId'>>): Span {
89+
public newSpan(spanProps?: Pick<SpanProps, Exclude<keyof SpanProps, 'spanId'>>): Span {
9090
const span = new Span({
91-
...spanDetails,
91+
...spanProps,
9292
parentSpanId: this._parentSpanId,
9393
sampled: this.sampled,
9494
traceId: this._traceId,
@@ -99,27 +99,19 @@ export class Span implements SpanInterface {
9999
return span;
100100
}
101101

102-
/**
103-
* Setter for transaction.
104-
*/
105-
public setTransaction(transaction: string | undefined): this {
106-
this.transaction = transaction;
107-
return this;
108-
}
109-
110102
/**
111103
* Continues a trace
112104
* @param traceparent Traceparent string
113105
*/
114106
public static fromTraceparent(
115107
traceparent: string,
116-
spanDetails?: Pick<SpanDetails, Exclude<keyof SpanDetails, 'spanId' | 'sampled' | 'traceid'>>,
108+
spanProps?: Pick<SpanProps, Exclude<keyof SpanProps, 'spanId' | 'sampled' | 'traceid'>>,
117109
): Span | undefined {
118110
const matches = traceparent.match(TRACEPARENT_REGEXP);
119111
if (matches) {
120112
const [traceId, spanId, sampled] = matches;
121113
return new Span({
122-
...spanDetails,
114+
...spanProps,
123115
sampled,
124116
spanId,
125117
traceId,
@@ -142,6 +134,7 @@ export class Span implements SpanInterface {
142134
public toTraceparent(): string {
143135
return `${this._traceId}-${this._spanId}${this.sampled ? '-1' : '0'}`;
144136
}
137+
145138
/**
146139
* @inheritDoc
147140
*/

packages/integrations/src/tracing.ts

-26
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ interface TracingOptions {
66
tracingOrigins?: Array<string | RegExp>;
77
traceFetch?: boolean;
88
traceXHR?: boolean;
9-
autoStartOnDomReady?: boolean;
109
}
1110

1211
/**
@@ -56,31 +55,6 @@ export class Tracing implements Integration {
5655
if (this._options.traceFetch !== false) {
5756
this._traceFetch(getCurrentHub);
5857
}
59-
if (this._options.autoStartOnDomReady !== false) {
60-
getGlobalObject<Window>().addEventListener('DOMContentLoaded', () => {
61-
Tracing.startTrace(getCurrentHub(), getGlobalObject<Window>().location.href);
62-
});
63-
getGlobalObject<Window>().document.onreadystatechange = () => {
64-
if (document.readyState === 'complete') {
65-
Tracing.startTrace(getCurrentHub(), getGlobalObject<Window>().location.href);
66-
}
67-
};
68-
}
69-
}
70-
71-
/**
72-
* Starts a new trace
73-
* @param hub The hub to start the trace on
74-
* @param transaction Optional transaction
75-
*/
76-
public static startTrace(hub: Hub, transaction?: string): void {
77-
const span = hub.startSpan({
78-
transaction,
79-
});
80-
81-
hub.configureScope(scope => {
82-
scope.setSpan(span);
83-
});
8458
}
8559

8660
/**

packages/types/src/hub.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Event, EventHint } from './event';
44
import { Integration, IntegrationClass } from './integration';
55
import { Scope } from './scope';
66
import { Severity } from './severity';
7-
import { Span, SpanDetails } from './span';
7+
import { Span, SpanProps } from './span';
88
import { User } from './user';
99

1010
/**
@@ -173,7 +173,7 @@ export interface Hub {
173173
traceHeaders(): { [key: string]: string };
174174

175175
/** JSDoc */
176-
startSpan(spanDetails?: SpanDetails): Span;
176+
startSpan(spanProps?: SpanProps): Span;
177177

178178
/** JSDoc */
179179
finishSpan(span: Span): string | undefined;

packages/types/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export { Response } from './response';
1616
export { Scope } from './scope';
1717
export { SdkInfo } from './sdkinfo';
1818
export { Severity } from './severity';
19-
export { Span, SpanDetails } from './span';
19+
export { Span, SpanProps } from './span';
2020
export { StackFrame } from './stackframe';
2121
export { Stacktrace } from './stacktrace';
2222
export { Status } from './status';

packages/types/src/span.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface Span {
99
}
1010

1111
/** JSDoc */
12-
export interface SpanDetails {
12+
export interface SpanProps {
1313
description?: string;
1414
op?: string;
1515
parentSpanId?: string;

0 commit comments

Comments
 (0)