Unable to get kafka auto instrumentation to work
lexctk opened this issue · 1 comments
lexctk commented
instrumentation.ts
import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
import { Resource } from "@opentelemetry/resources";
import { AlwaysOnSampler, ConsoleSpanExporter, NodeTracerProvider, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-node";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http";
import { KafkaJsInstrumentation } from "opentelemetry-instrumentation-kafkajs";
const provider = new NodeTracerProvider({
resource: new Resource({
"service.name": "my app",
"service.version": "1.0.0",
}),
sampler: new AlwaysOnSampler(),
});
registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new HttpInstrumentation(),
new KafkaJsInstrumentation()
],
});
const exporter = new ConsoleSpanExporter();
const processor = new SimpleSpanProcessor(exporter);
provider.addSpanProcessor(processor);
provider.register();
index.ts
import "instrumentation";
// import other stuff
// run app
package-json
{
"main": "index.js",
"scripts": {
"start": "node --env-file=./config/local.env dist/index.js",
"build": "npx ncc build ./src/index.ts -o dist",
},
"engines": {
"node": ">=20.9.0",
"npm": ">=10.1.0"
},
"dependencies": {
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.50.0",
"@opentelemetry/instrumentation": "^0.50.0",
"@opentelemetry/instrumentation-http": "^0.50.0",
"@opentelemetry/otlp-exporter-base": "^0.50.0",
"@opentelemetry/resources": "^1.23.0",
"@opentelemetry/sdk-trace-node": "^1.23.0",
"@opentelemetry/winston-transport": "^0.2.0",
"kafkajs": "^2.2.4",
"opentelemetry-instrumentation-kafkajs": "^0.40.0",
}
...
}
Here's the debug log
> node --env-file=./config/local.env dist/index.js
@opentelemetry/api: Registered a global for diag v1.8.0.
@opentelemetry/api: Registered a global for trace v1.8.0.
@opentelemetry/api: Registered a global for context v1.8.0.
@opentelemetry/api: Registered a global for propagation v1.8.0.
@opentelemetry/instrumentation-http Applying patch for http@21.6.2
@opentelemetry/instrumentation-http Applying patch for https@21.6.2
http auto instrumentation working correctly, the issue is only with opentelemetry-instrumentation-kafkajs
The documentation here: https://github.com/aspecto-io/opentelemetry-ext-js/tree/master/packages/instrumentation-kafkajs
seems out of date. "plugins" does not exist in NodeTracerProvider config:
Object literal may only specify known properties, and plugins does not exist in type TracerConfig
son-la commented
Took me couple of hours and eventually I found out that we need to use opentelemetry/instrumentation-kafkajs
. The one in your package.json
is deprecated