@@ -13,7 +13,7 @@ import type {
1313import { dropUndefinedKeys , logger , timestampInSeconds , uuid4 } from '@sentry/utils' ;
1414
1515import { DEBUG_BUILD } from '../debug-build' ;
16- import { spanToTraceContext , spanToTraceHeader } from '../utils/spanUtils' ;
16+ import { spanGetAttributes , spanToTraceContext , spanToTraceHeader } from '../utils/spanUtils' ;
1717import { ensureTimestampInSeconds } from './utils' ;
1818
1919/**
@@ -97,21 +97,18 @@ export class Span implements SpanInterface {
9797 public description ?: string ;
9898
9999 /**
100- * @inheritDoc
100+ * Tags for the span.
101+ * @deprecated Use `getSpanAttributes(span)` instead.
101102 */
102103 public tags : { [ key : string ] : Primitive } ;
103104
104105 /**
105- * @inheritDoc
106+ * Data for the span.
107+ * @deprecated Use `getSpanAttributes(span)` instead.
106108 */
107109 // eslint-disable-next-line @typescript-eslint/no-explicit-any
108110 public data : { [ key : string ] : any } ;
109111
110- /**
111- * @inheritDoc
112- */
113- public attributes : SpanAttributes ;
114-
115112 /**
116113 * List of spans that were finalized
117114 */
@@ -132,6 +129,8 @@ export class Span implements SpanInterface {
132129 */
133130 public origin ?: SpanOrigin ;
134131
132+ protected _attributes : SpanAttributes ;
133+
135134 /**
136135 * You should never call the constructor manually, always use `Sentry.startTransaction()`
137136 * or call `startChild()` on an existing span.
@@ -143,9 +142,11 @@ export class Span implements SpanInterface {
143142 this . traceId = spanContext . traceId || uuid4 ( ) ;
144143 this . spanId = spanContext . spanId || uuid4 ( ) . substring ( 16 ) ;
145144 this . startTimestamp = spanContext . startTimestamp || timestampInSeconds ( ) ;
145+ // eslint-disable-next-line deprecation/deprecation
146146 this . tags = spanContext . tags || { } ;
147+ // eslint-disable-next-line deprecation/deprecation
147148 this . data = spanContext . data || { } ;
148- this . attributes = spanContext . attributes || { } ;
149+ this . _attributes = spanContext . attributes || { } ;
149150 this . instrumenter = spanContext . instrumenter || 'sentry' ;
150151 this . origin = spanContext . origin || 'manual' ;
151152
@@ -173,6 +174,25 @@ export class Span implements SpanInterface {
173174 }
174175 }
175176
177+ // This rule conflicts with another eslint rule :(
178+ /* eslint-disable @typescript-eslint/member-ordering */
179+
180+ /**
181+ * Attributes for the span.
182+ * @deprecated Use `getSpanAttributes(span)` instead.
183+ */
184+ public get attributes ( ) : SpanAttributes {
185+ return this . _attributes ;
186+ }
187+
188+ /**
189+ * Attributes for the span.
190+ * @deprecated Use `setAttributes()` instead.
191+ */
192+ public set attributes ( attributes : SpanAttributes ) {
193+ this . _attributes = attributes ;
194+ }
195+
176196 /** An alias for `description` of the Span. */
177197 public get name ( ) : string {
178198 return this . description || '' ;
@@ -184,6 +204,8 @@ export class Span implements SpanInterface {
184204 this . updateName ( name ) ;
185205 }
186206
207+ /* eslint-enable @typescript-eslint/member-ordering */
208+
187209 /**
188210 * @inheritDoc
189211 */
@@ -218,18 +240,29 @@ export class Span implements SpanInterface {
218240 }
219241
220242 /**
221- * @inheritDoc
243+ * Sets the tag attribute on the current span.
244+ *
245+ * Can also be used to unset a tag, by passing `undefined`.
246+ *
247+ * @param key Tag key
248+ * @param value Tag value
249+ * @deprecated Use `setAttribute()` instead.
222250 */
223251 public setTag ( key : string , value : Primitive ) : this {
252+ // eslint-disable-next-line deprecation/deprecation
224253 this . tags = { ...this . tags , [ key ] : value } ;
225254 return this ;
226255 }
227256
228257 /**
229- * @inheritDoc
258+ * Sets the data attribute on the current span
259+ * @param key Data key
260+ * @param value Data value
261+ * @deprecated Use `setAttribute()` instead.
230262 */
231263 // eslint-disable-next-line @typescript-eslint/no-explicit-any
232264 public setData ( key : string , value : any ) : this {
265+ // eslint-disable-next-line deprecation/deprecation
233266 this . data = { ...this . data , [ key ] : value } ;
234267 return this ;
235268 }
@@ -238,9 +271,9 @@ export class Span implements SpanInterface {
238271 public setAttribute ( key : string , value : SpanAttributeValue | undefined ) : void {
239272 if ( value === undefined ) {
240273 // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
241- delete this . attributes [ key ] ;
274+ delete this . _attributes [ key ] ;
242275 } else {
243- this . attributes [ key ] = value ;
276+ this . _attributes [ key ] = value ;
244277 }
245278 }
246279
@@ -261,7 +294,9 @@ export class Span implements SpanInterface {
261294 * @inheritDoc
262295 */
263296 public setHttpStatus ( httpStatus : number ) : this {
297+ // eslint-disable-next-line deprecation/deprecation
264298 this . setTag ( 'http.status_code' , String ( httpStatus ) ) ;
299+ // eslint-disable-next-line deprecation/deprecation
265300 this . setData ( 'http.response.status_code' , httpStatus ) ;
266301 const spanStatus = spanStatusfromHttpCode ( httpStatus ) ;
267302 if ( spanStatus !== 'unknown_error' ) {
@@ -329,7 +364,7 @@ export class Span implements SpanInterface {
329364 */
330365 public toContext ( ) : SpanContext {
331366 return dropUndefinedKeys ( {
332- data : this . _getData ( ) ,
367+ data : spanGetAttributes ( this ) ,
333368 description : this . description ,
334369 endTimestamp : this . endTimestamp ,
335370 op : this . op ,
@@ -338,6 +373,7 @@ export class Span implements SpanInterface {
338373 spanId : this . spanId ,
339374 startTimestamp : this . startTimestamp ,
340375 status : this . status ,
376+ // eslint-disable-next-line deprecation/deprecation
341377 tags : this . tags ,
342378 traceId : this . traceId ,
343379 } ) ;
@@ -347,6 +383,7 @@ export class Span implements SpanInterface {
347383 * @inheritDoc
348384 */
349385 public updateWithContext ( spanContext : SpanContext ) : this {
386+ // eslint-disable-next-line deprecation/deprecation
350387 this . data = spanContext . data || { } ;
351388 this . description = spanContext . description ;
352389 this . endTimestamp = spanContext . endTimestamp ;
@@ -356,6 +393,7 @@ export class Span implements SpanInterface {
356393 this . spanId = spanContext . spanId || this . spanId ;
357394 this . startTimestamp = spanContext . startTimestamp || this . startTimestamp ;
358395 this . status = spanContext . status ;
396+ // eslint-disable-next-line deprecation/deprecation
359397 this . tags = spanContext . tags || { } ;
360398 this . traceId = spanContext . traceId || this . traceId ;
361399
@@ -387,49 +425,20 @@ export class Span implements SpanInterface {
387425 origin ?: SpanOrigin ;
388426 } {
389427 return dropUndefinedKeys ( {
390- data : this . _getData ( ) ,
428+ data : spanGetAttributes ( this ) ,
391429 description : this . description ,
392430 op : this . op ,
393431 parent_span_id : this . parentSpanId ,
394432 span_id : this . spanId ,
395433 start_timestamp : this . startTimestamp ,
396434 status : this . status ,
435+ // eslint-disable-next-line deprecation/deprecation
397436 tags : Object . keys ( this . tags ) . length > 0 ? this . tags : undefined ,
398437 timestamp : this . endTimestamp ,
399438 trace_id : this . traceId ,
400439 origin : this . origin ,
401440 } ) ;
402441 }
403-
404- /**
405- * Get the merged data for this span.
406- * For now, this combines `data` and `attributes` together,
407- * until eventually we can ingest `attributes` directly.
408- */
409- private _getData ( ) :
410- | {
411- // eslint-disable-next-line @typescript-eslint/no-explicit-any
412- [ key : string ] : any ;
413- }
414- | undefined {
415- const { data, attributes } = this ;
416-
417- const hasData = Object . keys ( data ) . length > 0 ;
418- const hasAttributes = Object . keys ( attributes ) . length > 0 ;
419-
420- if ( ! hasData && ! hasAttributes ) {
421- return undefined ;
422- }
423-
424- if ( hasData && hasAttributes ) {
425- return {
426- ...data ,
427- ...attributes ,
428- } ;
429- }
430-
431- return hasData ? data : attributes ;
432- }
433442}
434443
435444export type SpanStatusType =
0 commit comments