diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/subscriber.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/subscriber.rb index 36ea81e04a..fb5cf48248 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/subscriber.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/subscriber.rb @@ -62,11 +62,18 @@ def finish(_name, _id, payload) rescue StandardError => e OpenTelemetry.handle_error(exception: e) ensure + finish_span(span, tokens) + end + + def finish_span(span, tokens) + # closes the span after all attributes have been finalized begin span&.finish rescue StandardError => e OpenTelemetry.handle_error(exception: e) end + + # pops the context stack tokens&.reverse&.each do |token| OpenTelemetry::Context.detach(token) rescue StandardError => e diff --git a/instrumentation/active_job/test/instrumentation/active_job/instrumentation_test.rb b/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/instrumentation_test.rb similarity index 93% rename from instrumentation/active_job/test/instrumentation/active_job/instrumentation_test.rb rename to instrumentation/active_job/test/opentelemetry/instrumentation/active_job/instrumentation_test.rb index c1c2381ea7..e41b7eb5cc 100644 --- a/instrumentation/active_job/test/instrumentation/active_job/instrumentation_test.rb +++ b/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/instrumentation_test.rb @@ -6,7 +6,7 @@ require 'test_helper' -require_relative '../../../lib/opentelemetry/instrumentation/active_job' +require_relative '../../../../lib/opentelemetry/instrumentation/active_job' describe OpenTelemetry::Instrumentation::ActiveJob do let(:instrumentation) { OpenTelemetry::Instrumentation::ActiveJob::Instrumentation.instance } diff --git a/instrumentation/active_job/test/instrumentation/active_job/patches/base_test.rb b/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/patches/base_test.rb similarity index 91% rename from instrumentation/active_job/test/instrumentation/active_job/patches/base_test.rb rename to instrumentation/active_job/test/opentelemetry/instrumentation/active_job/patches/base_test.rb index 95a41d3cb3..d8c5cc22eb 100644 --- a/instrumentation/active_job/test/instrumentation/active_job/patches/base_test.rb +++ b/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/patches/base_test.rb @@ -6,7 +6,7 @@ require 'test_helper' -require_relative '../../../../lib/opentelemetry/instrumentation/active_job' +require_relative '../../../../../lib/opentelemetry/instrumentation/active_job' describe OpenTelemetry::Instrumentation::ActiveJob::Patches::Base do describe 'serialization / deserialization' do diff --git a/instrumentation/active_job/test/instrumentation/active_job/subscriber_test.rb b/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/subscriber_test.rb similarity index 99% rename from instrumentation/active_job/test/instrumentation/active_job/subscriber_test.rb rename to instrumentation/active_job/test/opentelemetry/instrumentation/active_job/subscriber_test.rb index 2c4eb74843..5ef2023f9f 100644 --- a/instrumentation/active_job/test/instrumentation/active_job/subscriber_test.rb +++ b/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/subscriber_test.rb @@ -6,7 +6,7 @@ require 'test_helper' -require_relative '../../../lib/opentelemetry/instrumentation/active_job' +require_relative '../../../../lib/opentelemetry/instrumentation/active_job' describe OpenTelemetry::Instrumentation::ActiveJob::Subscriber do let(:instrumentation) { OpenTelemetry::Instrumentation::ActiveJob::Instrumentation.instance }