Skip to content

Commit 15e3745

Browse files
committed
ref: Make span types more robust
With more strict TS settings, these could lead to problems: 1. `startChild()` should return a span interface, to match the interface implementation. 2. no need to overwrite `updateName` for transaction, this messes with the inherited type `this` as the this is now a transaction, not a span... we can skip this. Fixes #10654
1 parent c00bbac commit 15e3745

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

packages/core/src/tracing/span.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,16 @@ export class Span implements SpanInterface {
105105

106106
protected _traceId: string;
107107
protected _spanId: string;
108-
protected _parentSpanId?: string;
108+
protected _parentSpanId?: string | undefined;
109109
protected _sampled: boolean | undefined;
110-
protected _name?: string;
110+
protected _name?: string | undefined;
111111
protected _attributes: SpanAttributes;
112112
/** Epoch timestamp in seconds when the span started. */
113113
protected _startTime: number;
114114
/** Epoch timestamp in seconds when the span ended. */
115-
protected _endTime?: number;
115+
protected _endTime?: number | undefined;
116116
/** Internal keeper of the status */
117-
protected _status?: SpanStatusType | string;
117+
protected _status?: SpanStatusType | string | undefined;
118118

119119
private _logMessage?: string;
120120

@@ -385,7 +385,7 @@ export class Span implements SpanInterface {
385385
*/
386386
public startChild(
387387
spanContext?: Pick<SpanContext, Exclude<keyof SpanContext, 'sampled' | 'traceId' | 'parentSpanId'>>,
388-
): Span {
388+
): SpanInterface {
389389
const childSpan = new Span({
390390
...spanContext,
391391
parentSpanId: this._spanId,

packages/core/src/tracing/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
3535

3636
private _contexts: Contexts;
3737

38-
private _trimEnd?: boolean;
38+
private _trimEnd?: boolean | undefined;
3939

4040
// DO NOT yet remove this property, it is used in a hack for v7 backwards compatibility.
4141
private _frozenDynamicSamplingContext: Readonly<Partial<DynamicSamplingContext>> | undefined;

packages/types/src/span.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,43 +104,43 @@ export interface SpanContext {
104104
*
105105
* @deprecated Use `name` instead.
106106
*/
107-
description?: string;
107+
description?: string | undefined;
108108

109109
/**
110110
* Human-readable identifier for the span. Alias for span.description.
111111
*/
112-
name?: string;
112+
name?: string | undefined;
113113

114114
/**
115115
* Operation of the Span.
116116
*/
117-
op?: string;
117+
op?: string | undefined;
118118

119119
/**
120120
* Completion status of the Span.
121121
* See: {@sentry/tracing SpanStatus} for possible values
122122
*/
123-
status?: string;
123+
status?: string | undefined;
124124

125125
/**
126126
* Parent Span ID
127127
*/
128-
parentSpanId?: string;
128+
parentSpanId?: string | undefined;
129129

130130
/**
131131
* Was this span chosen to be sent as part of the sample?
132132
*/
133-
sampled?: boolean;
133+
sampled?: boolean | undefined;
134134

135135
/**
136136
* Span ID
137137
*/
138-
spanId?: string;
138+
spanId?: string | undefined;
139139

140140
/**
141141
* Trace ID
142142
*/
143-
traceId?: string;
143+
traceId?: string | undefined;
144144

145145
/**
146146
* Tags of the Span.
@@ -162,22 +162,22 @@ export interface SpanContext {
162162
/**
163163
* Timestamp in seconds (epoch time) indicating when the span started.
164164
*/
165-
startTimestamp?: number;
165+
startTimestamp?: number | undefined;
166166

167167
/**
168168
* Timestamp in seconds (epoch time) indicating when the span ended.
169169
*/
170-
endTimestamp?: number;
170+
endTimestamp?: number | undefined;
171171

172172
/**
173173
* The instrumenter that created this span.
174174
*/
175-
instrumenter?: Instrumenter;
175+
instrumenter?: Instrumenter | undefined;
176176

177177
/**
178178
* The origin of the span, giving context about what created the span.
179179
*/
180-
origin?: SpanOrigin;
180+
origin?: SpanOrigin | undefined;
181181
}
182182

183183
/** Span holding trace_id, span_id */
@@ -194,7 +194,7 @@ export interface Span extends Omit<SpanContext, 'op' | 'status' | 'origin'> {
194194
* @deprecated Use `startSpan()` functions to set, `span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'op')
195195
* to update and `spanToJSON().op` to read the op instead
196196
*/
197-
op?: string;
197+
op?: string | undefined;
198198

199199
/**
200200
* The ID of the span.
@@ -207,7 +207,7 @@ export interface Span extends Omit<SpanContext, 'op' | 'status' | 'origin'> {
207207
*
208208
* @deprecated Use `spanToJSON(span).parent_span_id` instead.
209209
*/
210-
parentSpanId?: string;
210+
parentSpanId?: string | undefined;
211211

212212
/**
213213
* The ID of the trace.
@@ -219,7 +219,7 @@ export interface Span extends Omit<SpanContext, 'op' | 'status' | 'origin'> {
219219
* Was this span chosen to be sent as part of the sample?
220220
* @deprecated Use `isRecording()` instead.
221221
*/
222-
sampled?: boolean;
222+
sampled?: boolean | undefined;
223223

224224
/**
225225
* Timestamp in seconds (epoch time) indicating when the span started.
@@ -231,7 +231,7 @@ export interface Span extends Omit<SpanContext, 'op' | 'status' | 'origin'> {
231231
* Timestamp in seconds (epoch time) indicating when the span ended.
232232
* @deprecated Use `spanToJSON()` instead.
233233
*/
234-
endTimestamp?: number;
234+
endTimestamp?: number | undefined;
235235

236236
/**
237237
* Tags for the span.
@@ -271,14 +271,14 @@ export interface Span extends Omit<SpanContext, 'op' | 'status' | 'origin'> {
271271
*
272272
* @deprecated Use `.setStatus` to set or update and `spanToJSON()` to read the status.
273273
*/
274-
status?: string;
274+
status?: string | undefined;
275275

276276
/**
277277
* The origin of the span, giving context about what created the span.
278278
*
279279
* @deprecated Use `startSpan` function to set and `spanToJSON(span).origin` to read the origin instead.
280280
*/
281-
origin?: SpanOrigin;
281+
origin?: SpanOrigin | undefined;
282282

283283
/**
284284
* Get context data for this span.

packages/types/src/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ export interface TransactionContext extends SpanContext {
2121
* accounted for in child spans, like what happens in the idle transaction Tracing integration, where we finish the
2222
* transaction after a given "idle time" and we don't want this "idle time" to be part of the transaction.
2323
*/
24-
trimEnd?: boolean;
24+
trimEnd?: boolean | undefined;
2525

2626
/**
2727
* If this transaction has a parent, the parent's sampling decision
2828
*/
29-
parentSampled?: boolean;
29+
parentSampled?: boolean | undefined;
3030

3131
/**
3232
* Metadata associated with the transaction, for internal SDK use.

0 commit comments

Comments
 (0)