Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Unable to get kafka auto instrumentation to work #271

Open
lexctk opened this issue Apr 17, 2024 · 1 comment
Open

Unable to get kafka auto instrumentation to work #271

lexctk opened this issue Apr 17, 2024 · 1 comment

Comments

@lexctk
Copy link

lexctk commented Apr 17, 2024

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 [email protected]
@opentelemetry/instrumentation-http Applying patch for [email protected]

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
Copy link

son-la commented Jun 13, 2024

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants