Skip to content

Commit

Permalink
feat(core): Add name to Span (#8949)
Browse files Browse the repository at this point in the history
In order to align `Span` & `Transaction` for usage in new performance
APIs, this add `name` to the `Span` that also always returns a string.
  • Loading branch information
mydea authored Sep 6, 2023
1 parent 0d49557 commit 6643671
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/core/src/tracing/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
32 changes: 32 additions & 0 deletions packages/core/test/lib/tracing/span.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
17 changes: 17 additions & 0 deletions packages/core/test/lib/tracing/transaction.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
5 changes: 5 additions & 0 deletions packages/types/src/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 6643671

Please sign in to comment.