-
Notifications
You must be signed in to change notification settings - Fork 40
Context propagation between producer and consumer doesn't work. #88
Comments
Hi @IvanovOleg , Can you share more of your setup? |
@blumamir kafkajs
returns empty array (I've modified the instrumentation code for debugging) producer app: const opentelemetry = require('@opentelemetry/api');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
const { KafkaJsInstrumentation } = require('opentelemetry-instrumentation-kafkajs');
const collectorOptions = {
serviceName: 'producer-service'
};
// Create and configure NodeTracerProvider
const traceProvider = new NodeTracerProvider({
// be sure to disable old plugin
plugins: {
kafkajs: { enabled: false, path: 'opentelemetry-plugin-kafkajs' }
}
});
const exporter = new CollectorTraceExporter(collectorOptions);
traceProvider.addSpanProcessor(new SimpleSpanProcessor(exporter));
traceProvider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
traceProvider.register()
registerInstrumentations({
traceProvider,
instrumentations: [
new KafkaJsInstrumentation({
// see under for available configuration
})
]
});
const tracer = opentelemetry.trace.getTracer('producer-service');
const { Kafka, logLevel } = require('kafkajs');
const kafka = new Kafka({
clientId: 'producer',
brokers: ['kafka:9092'],
logLevel: logLevel.DEBUG
});
const producer = kafka.producer();
const run = async () => {
await producer.connect()
await producer.send({
topic: 'staff',
messages: [
{ value: 'Hello Oleg' }
]
})
await producer.disconnect()
}
run().catch(console.error) consumer app: const opentelemetry = require('@opentelemetry/api');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
const { KafkaJsInstrumentation } = require('opentelemetry-instrumentation-kafkajs');
const collectorOptions = {
serviceName: 'consumer-service'
};
// Create and configure NodeTracerProvider
const traceProvider = new NodeTracerProvider({
// be sure to disable old plugin
plugins: {
kafkajs: { enabled: false, path: 'opentelemetry-plugin-kafkajs' }
}
});
const exporter = new CollectorTraceExporter(collectorOptions);
traceProvider.addSpanProcessor(new SimpleSpanProcessor(exporter));
traceProvider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
traceProvider.register()
registerInstrumentations({
traceProvider,
instrumentations: [
new KafkaJsInstrumentation({
// see under for available configuration
})
]
});
const tracer = opentelemetry.trace.getTracer('consumer-service');
const { Kafka, logLevel } = require('kafkajs')
const kafka = new Kafka({
clientId: 'consumer',
brokers: ['kafka:9092'],
logLevel: logLevel.DEBUG
})
const consumer = kafka.consumer({ groupId: 'test-group' })
const run = async () => {
// Consuming
await consumer.connect()
await consumer.subscribe({ topic: 'staff', fromBeginning: true })
await consumer.run({
eachMessage: async ({ topic, partition, message }) => {
console.log({
message,
partition,
offset: message.offset,
value: message.value.toString(),
})
},
})
}
run().catch(console.error) |
Can you please paste here your package.json dependencies? specifically
|
producer: {
"name": "producer",
"version": "0.1.0",
"description": "A simple kafka producer.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/IvanovOleg/nodejs-otel-sample.git"
},
"keywords": [
"opentelemetry"
],
"author": "Oleg Ivanov",
"license": "ISC",
"bugs": {
"url": "https://github.com/IvanovOleg/nodejs-otel-sample/issues"
},
"homepage": "https://github.com/IvanovOleg/nodejs-otel-sample#readme",
"dependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/exporter-collector": "^0.18.0",
"@opentelemetry/instrumentation": "^0.18.0",
"@opentelemetry/node": "^0.18.0",
"@opentelemetry/tracing": "^0.18.0",
"kafkajs": "^1.15.0",
"log4js": "^6.3.0",
"opentelemetry-instrumentation-kafkajs": "^0.2.3"
}
} consumer: {
"name": "consumer",
"version": "0.1.0",
"description": "A simple kafka consumer app.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/IvanovOleg/nodejs-otel-sample.git"
},
"keywords": [
"opentelemetry"
],
"author": "Oleg Ivanov",
"license": "ISC",
"bugs": {
"url": "https://github.com/IvanovOleg/nodejs-otel-sample/issues"
},
"homepage": "https://github.com/IvanovOleg/nodejs-otel-sample#readme",
"dependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/exporter-collector": "^0.18.0",
"@opentelemetry/instrumentation": "^0.18.0",
"@opentelemetry/node": "^0.18.0",
"@opentelemetry/tracing": "^0.18.0",
"kafkajs": "^1.15.0",
"log4js": "^6.3.0",
"opentelemetry-instrumentation-kafkajs": "^0.3.0"
}
}
|
I'm not sure about this case, but there have been cases of incompatibility with the The instrumentation library depends on |
@blumamir Will try. Thanks |
@blumamir I tried "@opentelemetry/api": "^0.18.0" and it doesn't work either. |
Cool thanks for letting us know. Please share if you find other issues with the plugin functionality/documentation |
@IvanovOleg , I took a second look on your setup. your producer is using Until opentelemetry apis stabilize, we need to publish a separate version of instrumentations which are compatible with each breaking change in the core packages. |
@blumamir Yes, 0.3.0 fixes the issue |
Hello,
I've created two simple apps: producer and consumer and enabled autoinstrumentation. I am getting spans from those apps in Jaeger, but they are not connected. I added the debug logging to console and see that on the producer side opentelemetry-instrumentation doesn't add any headers. Is there any specific step required to enable context propagation?
Thanks
The text was updated successfully, but these errors were encountered: