DataDog / dd-trace-js

JavaScript APM Tracer
https://docs.datadoghq.com/tracing/
Other
640 stars 303 forks source link

Feature Request: BullMQ Support #1704

Open dtinth opened 2 years ago

dtinth commented 2 years ago

Bull is a Node.js task queue package with over 300k weekly downloads and over 11k stargazers.

Workaround

We at @opn-ooo are currently integrating with Bull queue manually by monkey-patching the Bull queue.process function after creating like this:

  const queue = new Queue(/* … */)

  // Integrate with Datadog
  const original = queue.process
  queue.process = function (fn) {
    return original.call(
      this,
      tracer.wrap('bull.process', { resource: name }, async job => {
        const span = tracer.scope().active()
        if (span) {
          span.addTags({ job_id: job.id })
        }

        return await fn(job)
      })
    )
  }

Note that this workaround requires the processing function to be written using async function or a function that returns a promise. The done callback pattern is not supported.

weijialiu-hiretual commented 2 years ago

How is the development progress now? I also encountered this problem. In the projects using bull, some logs have traceid and some do not.

GeoffreyPlitt commented 1 year ago

+1

arvinshippit commented 1 year ago

+1

vivianintech commented 1 year ago

+1

dejavoodooo commented 1 year ago

+1

tprei commented 1 year ago

+1

Hi is there anyone going through with this? I would like to contribute if possible

KingofHamyang commented 1 year ago

+1

notetook commented 1 year ago

+1

tlhunter commented 9 months ago

See https://github.com/DataDog/dd-trace-js/issues/3577 for potential workarounds

sitoftonic commented 6 months ago

+1

jonfreeland commented 3 months ago

This post was very helpful. Here's how I ended up doing it in my worker base class:

new Worker(
  queueName,
  async (job) => {
    // Wrap job processing for tracing
    return await tracer.wrap(
      "bullmq.process",
      { resource: job.name },
      async () => {
        const span = tracer.scope().active();
        if (span) {
          span.addTags({
            jobId: job.id,
            jobName: job.name,
            queueName: queueName,
          });
        }
        // Run the job
        return await this.handleJob(
          job.name,
          job.data,
          job.id || "anonymous",
        );
      },
    )();
  },
  /* other stuff */
);