Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get kafka auto instrumentation to work #271

Open
lexctk opened this issue Apr 17, 2024 · 0 comments
Open

Unable to get kafka auto instrumentation to work #271

lexctk opened this issue Apr 17, 2024 · 0 comments

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

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

No branches or pull requests

1 participant