All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bybutter.sisyphus.middleware.kafka.metrics.MicrometerKafkaLogger.kt Maven / Gradle / Ivy

There is a newer version: 2.1.22
Show newest version
package com.bybutter.sisyphus.middleware.kafka.metrics

import com.bybutter.sisyphus.middleware.kafka.KafkaListener
import com.bybutter.sisyphus.middleware.kafka.KafkaLogger
import io.micrometer.core.instrument.MeterRegistry
import org.apache.kafka.clients.consumer.ConsumerRecord
import org.apache.kafka.clients.consumer.KafkaConsumer
import java.time.Duration

class MicrometerKafkaLogger(private val registry: MeterRegistry) : KafkaLogger {
    override val id: String = MicrometerKafkaLogger::class.java.canonicalName

    override fun log(
        listener: KafkaListener<*, *>,
        consumer: KafkaConsumer<*, *>,
        message: ConsumerRecord<*, *>,
        costNanoTime: Long,
        exception: Exception?
    ) {
        registry.timer(
            "sisyphus_kafka_consumer",
            "topic", message.topic(),
            "partition", message.partition().toString(),
            "groupId", consumer.groupMetadata().groupId(),
            "memberId", consumer.groupMetadata().memberId(),
            "listener", listener.javaClass.canonicalName,
            "exception", exception?.javaClass?.canonicalName ?: "None"
        ).record(Duration.ofNanos(costNanoTime))
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy