Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(tracing): test that spans are named correctly
- Loading branch information
1 parent
34c61f4
commit 2d50187
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); |