Skip to content

Commit

Permalink
test: assert active spans are indeed active with help of TestStackCon…
Browse files Browse the repository at this point in the history
…textManager

Signed-off-by: naseemkullah <[email protected]>
  • Loading branch information
naseemkullah committed May 28, 2021
1 parent 0335473 commit 1944b4e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/opentelemetry-tracing/test/Tracer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
trace,
TraceFlags
} from '@opentelemetry/api';
import { getSpan } from '@opentelemetry/api/build/src/trace/context-utils';
import {
AlwaysOffSampler,
AlwaysOnSampler,
Expand All @@ -32,6 +33,7 @@ import {
} from '@opentelemetry/core';
import * as assert from 'assert';
import { BasicTracerProvider, Span, Tracer } from '../src';
import { TestStackContextManager } from './export/TestStackContextManager';

describe('Tracer', () => {
const tracerProvider = new BasicTracerProvider();
Expand All @@ -50,7 +52,13 @@ describe('Tracer', () => {
}
}

beforeEach(() => {
const contextManager = new TestStackContextManager().enable();
context.setGlobalContextManager(contextManager);
});

afterEach(() => {
context.disable();
delete envSource.OTEL_TRACES_SAMPLER;
delete envSource.OTEL_TRACES_SAMPLER_ARG;
});
Expand Down Expand Up @@ -231,7 +239,7 @@ describe('Tracer', () => {

assert.strictEqual(tracer.startActiveSpan('my-span', span => {
try {
// todo: assert.strictEqual(getSpan(context.active()), span)
assert.strictEqual(getSpan(context.active()), span)
return 1
} finally {
span.end();
Expand All @@ -248,7 +256,7 @@ describe('Tracer', () => {

assert.strictEqual(tracer.startActiveSpan('my-span', {}, span => {
try {
// todo: assert.strictEqual(getSpan(context.active()), span)
assert.strictEqual(getSpan(context.active()), span)
return 1
} finally {
span.end();
Expand All @@ -269,7 +277,7 @@ describe('Tracer', () => {

assert.strictEqual(tracer.startActiveSpan('my-span', {}, ctx, span => {
try {
// todo: assert.strictEqual(getSpan(context.active()), span)
assert.strictEqual(getSpan(context.active()), span)
assert.strictEqual(ctx.getValue(ctxKey), 'bar')
return 1
} finally {
Expand Down

0 comments on commit 1944b4e

Please sign in to comment.