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(bunny): headers property needs to exist #661

Merged
merged 2 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def self.destination_name(exchange, routing_key)
def self.extract_context(properties)
# use the receive span as parent context
parent_context = OpenTelemetry.propagation.extract(properties[:tracer_receive_headers])
return [parent_context, nil] if properties[:headers].nil?

# link to the producer context
producer_context = OpenTelemetry.propagation.extract(properties[:headers])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

require_relative '../../../../lib/opentelemetry/instrumentation/bunny/patch_helpers'

describe OpenTelemetry::Instrumentation::Bunny::PatchHelpers do
let(:properties) do
{
headers: {
'traceparent' => '00-eab67ae26433f603121bd5674149d9e1-2007f3325d3cb6d6-01'
},
tracer_receive_headers: {
'traceparent' => '00-cd52775b3cb38931adf5fa880f890c25-cddb52a470027489-01'
}
}
end

describe '.extract_context' do
it 'returns the parent context with links when headers from producer exists' do
parent_context, links = OpenTelemetry::Instrumentation::Bunny::PatchHelpers.extract_context(properties)
_(parent_context).must_be_instance_of(OpenTelemetry::Context)
_(links).must_be_instance_of(Array)
_(links.first).must_be_instance_of(OpenTelemetry::Trace::Link)
end

it 'returns the parent context with no links when headers from producer not present' do
properties.delete(:headers)
parent_context, links = OpenTelemetry::Instrumentation::Bunny::PatchHelpers.extract_context(properties)
_(parent_context).must_be_instance_of(OpenTelemetry::Context)
_(links).must_be_nil
end
end
end
1 change: 1 addition & 0 deletions instrumentation/bunny/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
c.error_handler = ->(exception:, message:) { raise(exception || message) }
c.logger = Logger.new($stderr, level: ENV.fetch('OTEL_LOG_LEVEL', 'fatal').to_sym)
c.add_span_processor SPAN_PROCESSOR
c.propagators = [OpenTelemetry::Trace::Propagation::TraceContext.text_map_propagator]
maciekm marked this conversation as resolved.
Show resolved Hide resolved
end