Skip to content
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 @@ -43,7 +43,7 @@ def wrap_lambda(event:, context:, handler:, flush_timeout: DEFAULT_FLUSH_TIMEOUT
begin
response = yield

unless span.attributes.key?(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE)
if span.recording? && !span.attributes.key?(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE)
status_code = response['statusCode'] || response[:statusCode] if response.is_a?(Hash)
span.set_attribute(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE, status_code) if status_code
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,25 @@
end
end
end

describe 'no raise error when the span is not recording' do
it 'no raise error' do
otel_wrapper = OpenTelemetry::Instrumentation::AwsLambda::Handler.new
tracer = OpenTelemetry.tracer_provider.tracer

OpenTelemetry::Trace.stub(:with_span, lambda { |_span, &block|
block.call(OpenTelemetry::Trace::Span::INVALID, OpenTelemetry::Context.current)
}) do
tracer.stub(:in_span, lambda { |_name, **_kwargs, &block|
block.call(OpenTelemetry::Trace::Span::INVALID, OpenTelemetry::Context.current)
}) do
otel_wrapper.stub(:call_original_handler, {}) do
assert otel_wrapper.call_wrapped(event: sqs_record, context: context)
end
end
end
end
end
end

describe 'validate_if_span_is_registered' do
Expand Down