From 587634be686ba650ae29cda58a2c672443c9e10e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=B0=D1=80=D0=B0=D1=81=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=94=D0=B5=D0=BD=D0=B8=D1=81=20=D0=90=D0=BD=D0=B0=D1=82=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=B5=D0=B2=D0=B8=D1=87?= Date: Mon, 8 Jul 2024 13:36:05 +0000 Subject: [PATCH] [DEX-2307] fix: trace_id --- CHANGELOG.md | 6 ++++++ lib/sbmt/kafka_consumer/base_consumer.rb | 12 ++++-------- lib/sbmt/kafka_consumer/version.rb | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d494f22..ab9561a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +## [2.6.1] - 2024-07-05 + +### Fixed + +- Use the current `trace_id` instead of creating a new one + ## [2.6.0] - 2024-07-01 ### Added diff --git a/lib/sbmt/kafka_consumer/base_consumer.rb b/lib/sbmt/kafka_consumer/base_consumer.rb index 95beef3..a87baf8 100644 --- a/lib/sbmt/kafka_consumer/base_consumer.rb +++ b/lib/sbmt/kafka_consumer/base_consumer.rb @@ -3,8 +3,6 @@ module Sbmt module KafkaConsumer class BaseConsumer < Karafka::BaseConsumer - attr_reader :trace_id - def self.consumer_klass(skip_on_error: false, middlewares: []) Class.new(self) do const_set(:SKIP_ON_ERROR, skip_on_error) @@ -41,8 +39,6 @@ def process_batch? private def with_instrumentation(message) - @trace_id = SecureRandom.base58 - logger.tagged( trace_id: trace_id, topic: message.metadata.topic, partition: message.metadata.partition, @@ -69,8 +65,6 @@ def with_instrumentation(message) end def with_batch_instrumentation(messages) - @trace_id = SecureRandom.base58 - logger.tagged( trace_id: trace_id, first_offset: messages.first.metadata.offset, @@ -88,8 +82,6 @@ def with_batch_instrumentation(messages) end def with_common_instrumentation(name, message) - @trace_id = SecureRandom.base58 - logger.tagged( trace_id: trace_id ) do @@ -173,6 +165,10 @@ def call_middlewares(message, middlewares) end traverse_chain.call end + + def trace_id + @trace_id ||= SecureRandom.base58 + end end end end diff --git a/lib/sbmt/kafka_consumer/version.rb b/lib/sbmt/kafka_consumer/version.rb index bb86d65..8ce33b6 100644 --- a/lib/sbmt/kafka_consumer/version.rb +++ b/lib/sbmt/kafka_consumer/version.rb @@ -2,6 +2,6 @@ module Sbmt module KafkaConsumer - VERSION = "2.6.0" + VERSION = "2.6.1" end end