Skip to content

Commit 7f2681b

Browse files
committed
feat(core): Deprecate Span.origin in favor of sentry.origin attribute
1 parent 33d1cb0 commit 7f2681b

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

packages/core/src/semanticAttributes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ export const SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE = 'sentry.sample_rate';
1414
* Use this attribute to represent the operation of a span.
1515
*/
1616
export const SEMANTIC_ATTRIBUTE_SENTRY_OP = 'sentry.op';
17+
18+
/**
19+
* Use this attribute to represent the origin of a span.
20+
*/
21+
export const SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'sentry.origin';

packages/core/src/tracing/span.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616
import { dropUndefinedKeys, logger, timestampInSeconds, uuid4 } from '@sentry/utils';
1717

1818
import { DEBUG_BUILD } from '../debug-build';
19-
import { SEMANTIC_ATTRIBUTE_SENTRY_OP } from '../semanticAttributes';
19+
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes';
2020
import { getRootSpan } from '../utils/getRootSpan';
2121
import {
2222
TRACE_FLAG_NONE,
@@ -105,11 +105,6 @@ export class Span implements SpanInterface {
105105
*/
106106
public instrumenter: Instrumenter;
107107

108-
/**
109-
* The origin of the span, giving context about what created the span.
110-
*/
111-
public origin?: SpanOrigin;
112-
113108
protected _traceId: string;
114109
protected _spanId: string;
115110
protected _sampled: boolean | undefined;
@@ -142,7 +137,9 @@ export class Span implements SpanInterface {
142137
this._attributes = spanContext.attributes ? { ...spanContext.attributes } : {};
143138
// eslint-disable-next-line deprecation/deprecation
144139
this.instrumenter = spanContext.instrumenter || 'sentry';
145-
this.origin = spanContext.origin || 'manual';
140+
141+
this.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanContext.origin || 'manual');
142+
146143
// eslint-disable-next-line deprecation/deprecation
147144
this._name = spanContext.name || spanContext.description;
148145

@@ -332,6 +329,24 @@ export class Span implements SpanInterface {
332329
this.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, op);
333330
}
334331

332+
/**
333+
* The origin of the span, giving context about what created the span.
334+
*
335+
* @deprecated Use `spanToJSON().origin` to read the origin instead.
336+
*/
337+
public get origin(): SpanOrigin | undefined {
338+
return this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined;
339+
}
340+
341+
/**
342+
* The origin of the span, giving context about what created the span.
343+
*
344+
* @deprecated Use `startSpan()` functions to set the origin instead.
345+
*/
346+
public set origin(origin: SpanOrigin | undefined) {
347+
this.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);
348+
}
349+
335350
/* eslint-enable @typescript-eslint/member-ordering */
336351

337352
/** @inheritdoc */
@@ -597,7 +612,7 @@ export class Span implements SpanInterface {
597612
tags: Object.keys(this.tags).length > 0 ? this.tags : undefined,
598613
timestamp: this._endTime,
599614
trace_id: this._traceId,
600-
origin: this.origin,
615+
origin: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined,
601616
});
602617
}
603618

packages/types/src/span.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ export interface Span extends Omit<SpanContext, 'op' | 'status'> {
251251
*/
252252
status?: string;
253253

254+
/**
255+
* The origin of the span, giving context about what created the span.
256+
*
257+
* @deprecated Use `startSpan` function to set and `spanToJSON(span).origin` to read the origin instead.
258+
*/
259+
origin?: SpanOrigin;
260+
254261
/**
255262
* Get context data for this span.
256263
* This includes the spanId & the traceId.

0 commit comments

Comments
 (0)