diff --git a/packages/core/src/tracing/span.ts b/packages/core/src/tracing/span.ts index 3ce158c8addf..27cd287a017e 100644 --- a/packages/core/src/tracing/span.ts +++ b/packages/core/src/tracing/span.ts @@ -161,6 +161,15 @@ export class Span implements SpanInterface { } } + /** An alias for `description` of the Span. */ + public get name(): string { + return this.description || ''; + } + /** Update the name of the span. */ + public set name(name: string) { + this.setName(name); + } + /** * @inheritDoc */ diff --git a/packages/core/test/lib/tracing/span.test.ts b/packages/core/test/lib/tracing/span.test.ts new file mode 100644 index 000000000000..c54085704022 --- /dev/null +++ b/packages/core/test/lib/tracing/span.test.ts @@ -0,0 +1,32 @@ +import { Span } from '../../../src'; + +describe('span', () => { + it('works with name', () => { + const span = new Span({ name: 'span name' }); + expect(span.name).toEqual('span name'); + expect(span.description).toEqual('span name'); + }); + + it('works with description', () => { + const span = new Span({ description: 'span name' }); + expect(span.name).toEqual('span name'); + expect(span.description).toEqual('span name'); + }); + + it('works without name', () => { + const span = new Span({}); + expect(span.name).toEqual(''); + expect(span.description).toEqual(undefined); + }); + + it('allows to update the name', () => { + const span = new Span({ name: 'span name' }); + expect(span.name).toEqual('span name'); + expect(span.description).toEqual('span name'); + + span.name = 'new name'; + + expect(span.name).toEqual('new name'); + expect(span.description).toEqual('new name'); + }); +}); diff --git a/packages/core/test/lib/tracing/transaction.test.ts b/packages/core/test/lib/tracing/transaction.test.ts new file mode 100644 index 000000000000..b9218eae77cb --- /dev/null +++ b/packages/core/test/lib/tracing/transaction.test.ts @@ -0,0 +1,17 @@ +import { Transaction } from '../../../src'; + +describe('transaction', () => { + it('works with name', () => { + const transaction = new Transaction({ name: 'span name' }); + expect(transaction.name).toEqual('span name'); + }); + + it('allows to update the name', () => { + const transaction = new Transaction({ name: 'span name' }); + expect(transaction.name).toEqual('span name'); + + transaction.name = 'new name'; + + expect(transaction.name).toEqual('new name'); + }); +}); diff --git a/packages/types/src/span.ts b/packages/types/src/span.ts index 7485bbf88d72..c931b7e457c2 100644 --- a/packages/types/src/span.ts +++ b/packages/types/src/span.ts @@ -88,6 +88,11 @@ export interface SpanContext { /** Span holding trace_id, span_id */ export interface Span extends SpanContext { + /** + * Human-readable identifier for the span. Identical to span.description. + */ + name: string; + /** * @inheritDoc */