Closed
Description
Version
27.5.1
Steps to reproduce
- Set up a Node.js project with Jest, OpenTelemetry SDK, and BullMQInstrumentation.
- Configure the NodeTracerProvider with an InMemorySpanExporter and a SimpleSpanProcessor.
- Write a Jest test to add a job to a BullMQ queue.
- Run the Jest test and check the captured spans.
Expected behavior
The InMemorySpanExporter should have captured exactly one span corresponding to the job addition operation.
Actual behavior
No spans are captured in the Jest environment, despite the operation completing successfully.
When running tests using Jest and the OpenTelemetry Node.js SDK with the BullMQInstrumentation plugin, spans expected from the operation of adding a job to a BullMQ queue are not being captured. The same setup appears to function correctly when run outside of Jest (e.g., directly in Node.js scripts or with other test runners like Mocha).
Additional context
The setup and test configurations are as follows:
import { createTestNode } from "@test-utils";
import { context } from "@opentelemetry/api";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { AsyncHooksContextManager } from "@opentelemetry/context-async-hooks";
import { InMemorySpanExporter, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
import { BullMQInstrumentation } from "@jenniferplusplus/opentelemetry-instrumentation-bullmq"
import { v4 } from "uuid";
import type * as bullmq from 'bullmq';
let Queue: typeof bullmq.Queue;
describe("tracing with BullMQInstrumentation", () => {
const provider = new NodeTracerProvider();
const memoryExporter = new InMemorySpanExporter();
provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
const instrumentation = new BullMQInstrumentation();
const contextManager = new AsyncHooksContextManager();
beforeAll(async () => {
await node.up();
contextManager.enable();
context.setGlobalContextManager(contextManager);
instrumentation.setTracerProvider(provider);
instrumentation.enable();
});
afterAll(async () => {
await node.down();
contextManager.disable();
instrumentation.disable();
});
it("should create a span for add", async () => {
const q = new Queue('queue', {connection});
await q.addBulk([{name: 'testJob', data: {test: 'yes'}}])
const spans = memoryExporter.getFinishedSpans();
expect(spans).toHaveLength(1);
});
});
Environment
System:
OS: Windows 11 10.0.22631
CPU: (12) x64 13th Gen Intel(R) Core(TM) i7-1355U
Binaries:
Node: 14.21.3 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.21 - ~\AppData\Roaming\npm\yarn.CMD
npm: 6.14.18 - C:\Program Files\nodejs\npm.CMD
pnpm: 8.15.5 - ~\AppData\Local\pnpm\pnpm.EXE