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 @@ -23,7 +23,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 +47,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 All @@ -74,6 +74,14 @@ def extract_message_key(key)
rescue Encoding::UndefinedConversionError
nil
end

def getter
@getter ||= if Gem::Version.new(::Rdkafka::VERSION) >= Gem::Version.new('0.13.0')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very sorry for the delayed review.

Is this something that can be checked at installation time as opposed to when the worker processes the first message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about this? 21e4a43

Context::Propagation.text_map_getter
else
OpenTelemetry::Common::Propagation.symbol_key_getter
end
end
end
end
end
Expand Down