question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Integrating with Kafka-Node and similar Kafka clients

See original GitHub issue

Part 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:closed
  • Created 4 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
watsoncommented, Apr 11, 2019

I’ve created a PR to update the types: #1001

1reaction
watsoncommented, Apr 11, 2019

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

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found