Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: suppress deprecation warning in Rdkafka Instrumentation #884

Merged
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
Loading