Skip to content

feat(core): Add name to Span #8949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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