Skip to content

Commit 6643671

Browse files
authored
feat(core): Add name to Span (#8949)
In order to align `Span` & `Transaction` for usage in new performance APIs, this add `name` to the `Span` that also always returns a string.
1 parent 0d49557 commit 6643671

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

packages/core/src/tracing/span.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ export class Span implements SpanInterface {
161161
}
162162
}
163163

164+
/** An alias for `description` of the Span. */
165+
public get name(): string {
166+
return this.description || '';
167+
}
168+
/** Update the name of the span. */
169+
public set name(name: string) {
170+
this.setName(name);
171+
}
172+
164173
/**
165174
* @inheritDoc
166175
*/
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Span } from '../../../src';
2+
3+
describe('span', () => {
4+
it('works with name', () => {
5+
const span = new Span({ name: 'span name' });
6+
expect(span.name).toEqual('span name');
7+
expect(span.description).toEqual('span name');
8+
});
9+
10+
it('works with description', () => {
11+
const span = new Span({ description: 'span name' });
12+
expect(span.name).toEqual('span name');
13+
expect(span.description).toEqual('span name');
14+
});
15+
16+
it('works without name', () => {
17+
const span = new Span({});
18+
expect(span.name).toEqual('');
19+
expect(span.description).toEqual(undefined);
20+
});
21+
22+
it('allows to update the name', () => {
23+
const span = new Span({ name: 'span name' });
24+
expect(span.name).toEqual('span name');
25+
expect(span.description).toEqual('span name');
26+
27+
span.name = 'new name';
28+
29+
expect(span.name).toEqual('new name');
30+
expect(span.description).toEqual('new name');
31+
});
32+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Transaction } from '../../../src';
2+
3+
describe('transaction', () => {
4+
it('works with name', () => {
5+
const transaction = new Transaction({ name: 'span name' });
6+
expect(transaction.name).toEqual('span name');
7+
});
8+
9+
it('allows to update the name', () => {
10+
const transaction = new Transaction({ name: 'span name' });
11+
expect(transaction.name).toEqual('span name');
12+
13+
transaction.name = 'new name';
14+
15+
expect(transaction.name).toEqual('new name');
16+
});
17+
});

packages/types/src/span.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ export interface SpanContext {
8888

8989
/** Span holding trace_id, span_id */
9090
export interface Span extends SpanContext {
91+
/**
92+
* Human-readable identifier for the span. Identical to span.description.
93+
*/
94+
name: string;
95+
9196
/**
9297
* @inheritDoc
9398
*/

0 commit comments

Comments
 (0)