diff --git a/packages/core/src/tracing/span.ts b/packages/core/src/tracing/span.ts index 1340ea3db55c..4301391ff1da 100644 --- a/packages/core/src/tracing/span.ts +++ b/packages/core/src/tracing/span.ts @@ -152,6 +152,9 @@ export class Span implements SpanInterface { if (spanContext.description) { this.description = spanContext.description; } + if (spanContext.name) { + this.description = spanContext.name; + } if (spanContext.data) { this.data = spanContext.data; } @@ -243,6 +246,13 @@ export class Span implements SpanInterface { return this; } + /** + * @inheritDoc + */ + public setName(name: string): void { + this.description = name; + } + /** * @inheritDoc */ diff --git a/packages/core/src/tracing/transaction.ts b/packages/core/src/tracing/transaction.ts index 9a901df3d316..ee0a5724b9bf 100644 --- a/packages/core/src/tracing/transaction.ts +++ b/packages/core/src/tracing/transaction.ts @@ -44,6 +44,9 @@ export class Transaction extends SpanClass implements TransactionInterface { */ public constructor(transactionContext: TransactionContext, hub?: Hub) { super(transactionContext); + // We need to delete description since it's set by the Span class constructor + // but not needed for transactions. + delete this.description; this._measurements = {}; this._contexts = {}; diff --git a/packages/sveltekit/test/server/handle.test.ts b/packages/sveltekit/test/server/handle.test.ts index ffe1db0e9e75..eb0276b7f95d 100644 --- a/packages/sveltekit/test/server/handle.test.ts +++ b/packages/sveltekit/test/server/handle.test.ts @@ -201,7 +201,7 @@ describe('handleSentry', () => { expect(ref.spanRecorder.spans).toHaveLength(2); expect(ref.spanRecorder.spans).toEqual( expect.arrayContaining([ - expect.objectContaining({ op: 'http.server', description: 'GET /users/[id]' }), + expect.objectContaining({ op: 'http.server', name: 'GET /users/[id]' }), expect.objectContaining({ op: 'http.server', description: 'GET api/users/details/[id]' }), ]), ); diff --git a/packages/tracing/test/span.test.ts b/packages/tracing/test/span.test.ts index 1720dd4e6ec4..e6e35e105508 100644 --- a/packages/tracing/test/span.test.ts +++ b/packages/tracing/test/span.test.ts @@ -82,6 +82,13 @@ describe('Span', () => { span.setData('foo', true); expect(span.data.foo).toBe(true); }); + + test('setName', () => { + const span = new Span({}); + expect(span.description).toBeUndefined(); + span.setName('foo'); + expect(span.description).toBe('foo'); + }); }); describe('status', () => { diff --git a/packages/types/src/span.ts b/packages/types/src/span.ts index 756a6808910c..a689590c499e 100644 --- a/packages/types/src/span.ts +++ b/packages/types/src/span.ts @@ -9,6 +9,11 @@ export interface SpanContext { */ description?: string; + /** + * Human-readable identifier for the span. Alias for span.description. + */ + name?: string; + /** * Operation of the Span. */ @@ -139,6 +144,11 @@ export interface Span extends SpanContext { */ setHttpStatus(httpStatus: number): this; + /** + * Set the name of the span. + */ + setName(name: string): void; + /** * Creates a new `Span` while setting the current `Span.id` as `parentSpanId`. * Also the `sampled` decision will be inherited. diff --git a/packages/types/src/transaction.ts b/packages/types/src/transaction.ts index 42d266abbda7..3e1ad24d4669 100644 --- a/packages/types/src/transaction.ts +++ b/packages/types/src/transaction.ts @@ -42,7 +42,7 @@ export type TraceparentData = Pick { /** * @inheritDoc */