Module: OpenTelemetry::Instrumentation::RubyKafka::Utils

Defined in:
lib/opentelemetry/instrumentation/ruby_kafka/utils.rb

Overview

Utilities to help with instrumenting kafka

Class Method Summary collapse

Class Method Details

.extract_message_key(key) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/opentelemetry/instrumentation/ruby_kafka/utils.rb', line 14

def extract_message_key(key)
  # skip encode if already valid utf8
  return key if key.nil? || (key.encoding == Encoding::UTF_8 && key.valid_encoding?)

  key.encode(Encoding::UTF_8)
rescue Encoding::UndefinedConversionError
  nil
end