Skip to content

Commit

Permalink
test(tracing): test that spans are named correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mentos1386 committed Mar 22, 2022
1 parent 34c61f4 commit 2d50187
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/tracing/decorators/span.spec.ts
@@ -0,0 +1,48 @@
import { context, trace } from '@opentelemetry/api';
import { Span } from './span';
import { NodeSDK, tracing } from '@opentelemetry/sdk-node';

class TestSpan {
@Span()
singleSpan() {
return trace.getSpan(context.active());
}

@Span()
doubleSpan() {
return this.singleSpan();
}
}

describe('Span', () => {
let instance: TestSpan;
let otelSdk: NodeSDK;

beforeEach(async () => {
instance = new TestSpan();

otelSdk = new NodeSDK({
traceExporter: new tracing.ConsoleSpanExporter(),
// Noop Span Processor disables any spans from being outputted
// by ConsoleSpanExporter.
// Remove it if you want to debug spans exported.
spanProcessor: new tracing.NoopSpanProcessor(),
});

await otelSdk.start();
});

afterEach(async () => {
await otelSdk.shutdown();
});

it('should set correct span', async () => {
const response = instance.singleSpan();
expect((response as any).name).toEqual('TestSpan.singleSpan');
});

it('should set correct span even when calling other method with Span decorator', async () => {
const response = instance.doubleSpan();
expect((response as any).name).toEqual('TestSpan.singleSpan');
});
});

0 comments on commit 2d50187

Please sign in to comment.