Skip to content

Commit ae37b6f

Browse files
committed
feat(tracing): Add setName method on spans
1 parent 695a671 commit ae37b6f

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

packages/core/src/tracing/span.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ export class Span implements SpanInterface {
152152
if (spanContext.description) {
153153
this.description = spanContext.description;
154154
}
155+
if (spanContext.name) {
156+
this.description = spanContext.name;
157+
}
155158
if (spanContext.data) {
156159
this.data = spanContext.data;
157160
}
@@ -243,6 +246,13 @@ export class Span implements SpanInterface {
243246
return this;
244247
}
245248

249+
/**
250+
* @inheritDoc
251+
*/
252+
public setName(name: string): void {
253+
this.description = name;
254+
}
255+
246256
/**
247257
* @inheritDoc
248258
*/

packages/core/src/tracing/transaction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
4444
*/
4545
public constructor(transactionContext: TransactionContext, hub?: Hub) {
4646
super(transactionContext);
47+
delete this.description;
4748

4849
this._measurements = {};
4950
this._contexts = {};

packages/tracing/test/span.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ describe('Span', () => {
8282
span.setData('foo', true);
8383
expect(span.data.foo).toBe(true);
8484
});
85+
86+
test('setName', () => {
87+
const span = new Span({});
88+
expect(span.description).toBeUndefined();
89+
span.setName('foo');
90+
expect(span.description).toBe('foo');
91+
});
8592
});
8693

8794
describe('status', () => {

packages/types/src/span.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export interface SpanContext {
99
*/
1010
description?: string;
1111

12+
/**
13+
* Human-readable identifier for the span. Alias for span.description.
14+
*/
15+
name?: string;
16+
1217
/**
1318
* Operation of the Span.
1419
*/
@@ -139,6 +144,11 @@ export interface Span extends SpanContext {
139144
*/
140145
setHttpStatus(httpStatus: number): this;
141146

147+
/**
148+
* Set the name of the span.
149+
*/
150+
setName(name: string): void;
151+
142152
/**
143153
* Creates a new `Span` while setting the current `Span.id` as `parentSpanId`.
144154
* Also the `sampled` decision will be inherited.

packages/types/src/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export type TraceparentData = Pick<TransactionContext, 'traceId' | 'parentSpanId
4242
/**
4343
* Transaction "Class", inherits Span only has `setName`
4444
*/
45-
export interface Transaction extends TransactionContext, Span {
45+
export interface Transaction extends TransactionContext, Omit<Span, 'setName' | 'name'> {
4646
/**
4747
* @inheritDoc
4848
*/

0 commit comments

Comments
 (0)