jenniferplusplus/opentelemetry-instrumentation-bullmq

Propagate trace context to workers

Closed this issue ยท 4 comments

Hello @jenniferplusplus ๐Ÿ‘‹

I was starting to wonder how I could pass the trace coming from an API to the consumers, and I noticed this package to instrument with Otel our BullMQ.

Would it make sense to instrument this package in a way it detects the trace ID on the add() method, and set the trace context in the worker doing the process? (is it even possible?)

What I had in mind was to use propagation to detect the current trace (https://opentelemetry.io/docs/languages/js/propagation/) and pass it in the data object with a custom property (_otel: { traceparent: <traceparent>}). Then when the worker picks up a job, we could remove the field _otel and instruct the new context to use the traceparent. What do you think?

I would be curious to give it a try!

@Lp-Francois I don't actually work on projects that depend on BullMQ anymore, so tbh it's been a couple of years since I really gave this project much thought.

IIRC, trace context does propagate from Add down to the worker. I certainly meant for it to, and I'm pretty sure it used to. If that's not working, I would consider it a bug and want to fix it.

Also, I had built the propagation field into the job headers, rather than the data. It seemed less likely to disrupt workers

Hello! So I double checked, and I did something wrong with my example, I started fresh with a simple setup on NestJS and I can get the same traceID through the job :)

Sorry for the issue, will close :)

No worries, glad it's working for you