jenniferplusplus/opentelemetry-instrumentation-bullmq

No Spans are send

Closed this issue · 3 comments

Hi,

i dont get it to work with my nestjs application.

Might need anything?

Tracer code:

  SimpleSpanProcessor,
} from '@opentelemetry/sdk-trace-base';
import { tracing, NodeSDK } from '@opentelemetry/sdk-node';
import * as process from 'process';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { KafkaJsInstrumentation } from 'opentelemetry-instrumentation-kafkajs';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { BullMQInstrumentation } from '@jenniferplusplus/opentelemetry-instrumentation-bullmq';

const exporter = new OTLPTraceExporter({
  url: 'http://locahost:4318/v1/traces',
});

export const otelSDK = new NodeSDK({
  resource: new Resource({
    [SemanticResourceAttributes.SERVICE_NAME]:
      "campaign-publishing-control",
    [SemanticResourceAttributes.SERVICE_NAMESPACE]: process.env.CUSTOMER_ID
  }),
  spanProcessor: new SimpleSpanProcessor(exporter),
  traceExporter: new tracing.ConsoleSpanExporter(),
  instrumentations: [
    new HttpInstrumentation(),
    new ExpressInstrumentation({
      enabled: true
    }),
    new NestInstrumentation({
      enabled: true
    }),
    new KafkaJsInstrumentation(),
    new BullMQInstrumentation({
      enabled: true
    })
  ],
});

// gracefully shut down the SDK on process exit
process.on('SIGTERM', () => {
  otelSDK
    .shutdown()
    .then(
      () => console.log('SDK shut down successfully'),
      (err) => console.log('Error shutting down SDK', err),
    )
    .finally(() => process.exit(0));
});

Node: 16

"@opentelemetry/exporter-metrics-otlp-http": "^0.46.0",
    "@opentelemetry/instrumentation-express": "^0.34.0",
    "@opentelemetry/instrumentation-http": "^0.46.0",
    "@opentelemetry/instrumentation-nestjs-core": "^0.33.3",
    "@opentelemetry/resources": "^1.19.0",
    "@opentelemetry/sdk-node": "^0.46.0",
    "@opentelemetry/sdk-trace-base": "^1.19.0",
    "@opentelemetry/semantic-conventions": "^1.19.0",
    ```

Ok found it the tracer has to be the very first import in main.ts, probably because otel is wrapping the modules and if its not wrapped before an import there is no tracing.

@fabianboerner I haven't worked in nodejs for a little while, but when I did the recommended way to configure OTel instrumentation was to load it as an extra required module at app start up.

So, if you have your application's main entrypoint in main.js and your instrumentations at trace.js, you would start the app like this.

node -r trace.js main.js

-r tells node to do a require on the trace.js file before running the script in main.js. That way you can be sure that everything is instrumented no matter how your application is organized.

thanks for the hint, i will try that.

For now it was just enough to put the import of the file at the first position in main.ts