Skip to content

Commit

Permalink
fix: suppress deprecation warning in Rdkafka Instrumentation (#884)
Browse files Browse the repository at this point in the history
* fix: suppress deprecation warning in Rdkafka Instrumentation

* memoize getter

* Use constant

* rubocop fix

---------

Co-authored-by: Ariel Valentin <[email protected]>
  • Loading branch information
yoheyk and arielvalentin authored Apr 5, 2024
1 parent 6fb6eb3 commit 8cbc6b6
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ module Rdkafka
module Patches
# The Consumer module contains the instrumentation patch for the Consumer class
module Consumer
GETTER = if Gem::Version.new(::Rdkafka::VERSION) >= Gem::Version.new('0.13.0')
Context::Propagation.text_map_getter
else
OpenTelemetry::Common::Propagation.symbol_key_getter
end
private_constant :GETTER

def each
super do |message|
attributes = {
Expand All @@ -23,7 +30,7 @@ def each
message_key = extract_message_key(message.key)
attributes['messaging.kafka.message_key'] = message_key if message_key

parent_context = OpenTelemetry.propagation.extract(message.headers, getter: OpenTelemetry::Common::Propagation.symbol_key_getter)
parent_context = OpenTelemetry.propagation.extract(message.headers, getter: GETTER)
span_context = OpenTelemetry::Trace.current_span(parent_context).context
links = [OpenTelemetry::Trace::Link.new(span_context)] if span_context.valid?

Expand All @@ -47,7 +54,7 @@ def each_batch(max_items: 100, bytes_threshold: Float::INFINITY, timeout_ms: 250
}

links = messages.map do |message|
trace_context = OpenTelemetry.propagation.extract(message.headers, getter: OpenTelemetry::Common::Propagation.symbol_key_getter)
trace_context = OpenTelemetry.propagation.extract(message.headers, getter: GETTER)
span_context = OpenTelemetry::Trace.current_span(trace_context).context
OpenTelemetry::Trace::Link.new(span_context) if span_context.valid?
end
Expand Down

0 comments on commit 8cbc6b6

Please sign in to comment.