Integrating with Kafka-Node and similar Kafka clients
See original GitHub issuePart of our system relies on Kafka for message queues. I would like to be able to continue tracing transactions as they pass through Kafka via various producers and consumers, creating spans along the way. We are setting up kafka-node, which is a fairly common package, like this:
const kafka = require('kafka-node'),
HighLevelProducer = kafka.HighLevelProducer,
ConsumerGroup = kafka.ConsumerGroup,
client = new kafka.KafkaClient({kafkaHost: kafkaConfig.kafkaHost}),
producer = new HighLevelProducer(client),
consumer = new ConsumerGroup(
{
kafkaHost: kafkaConfig.kafkaHost,
groupId: kafkaConfig.groupId,
fromOffset: 'earliest',
},
'os-events-raw'
),
appEventsConsumer = new ConsumerGroup(
{
kafkaHost: kafkaConfig.kafkaHost,
groupId: kafkaConfig.groupId,
fromOffset: 'earliest',
},
'app-events'
),
osEventsConsumer = new ConsumerGroup(
{
kafkaHost: kafkaConfig.kafkaHost,
groupId: kafkaConfig.groupId,
fromOffset: 'earliest',
},
'os-events'
),
smcEventsConsumer = new ConsumerGroup(
{
kafkaHost: kafkaConfig.kafkaHost,
groupId: kafkaConfig.groupId,
fromOffset: 'earliest',
},
'smc-events'
);
events get handled like this:
consumer.on('message', (kafkaMessage) => {
let message =null;
try {
message = JSON.parse(kafkaMessage.value);
} catch (e) {
logger.error('failure parsing kafka message',{e,message})
return;
}
if (!message) {
logger.error('message is empty',{kafkaMessage})
return;
}
let eventTransform = rawOsEventTransform(message);
if (!eventTransform) {
logger.error('XML parse error',{message})
return;
}
producer.send([{
topic: 'os-events',
messages: [eventTransform]
}], (err, data) => {
if (err) {
logger.error('kafka error', {err});
}
});
});
So, as you can see, a typical case is a consumer taking messages from a topic, transforming them and producing them to another topic.
If there is an example of how we can log this using the APM agent, then great. If not, I’d like to be able to do so.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Intro to KafkaJS - a Modern Kafka Client for Node.js - Confluent
The first step to getting started with KafkaJS is to configure how it will connect to Kafka. KafkaJS is made up of a...
Read more >Kafka Node | 6 Best Steps of Integrating Kafka with NodeJS
Integrating Kafka with NodeJS · 1. Starting Zookeeper · 2. Start Kafka Server · 3. Topic Creation · 4. Integrating Kafka with NodeJS...
Read more >Kakajs the simplest way to use Kafka with Node JS - Medium
I am writing this based on my experience of using Kafka confluent with Node JS, let's first check on Kafka Apache Kafka is...
Read more >Implementing a Kafka Producer and Consumer In Node.js ...
This post will show you how to create a Kafka producer and consumer in Node.js. It will also show you the various configuration...
Read more >Experimenting with Apache Kafka and NodeJS
Apache Kafka is an open-source distributed event streaming platform that is used to connect systems together. Kafka lets applications ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve created a PR to update the types: #1001
Oh, that’s probably because we didn’t update the TypeScript
.d.ts
file. That’s a mistake. I’ll make sure to fix it ASAP. Thanks for letting us know