diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/subscriber.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers.rb similarity index 91% rename from instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/subscriber.rb rename to instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers.rb index c00f095a7e..31b54678e8 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/subscriber.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + require_relative 'mappers/attribute' require_relative 'handlers/default' require_relative 'handlers/enqueue' @@ -9,8 +13,10 @@ module OpenTelemetry module Instrumentation module ActiveJob # Custom subscriber that handles ActiveJob notifications - class Subscriber - def self.install + module Handlers + module_function + + def install return unless Array(@subscriptions).empty? tracer = Instrumentation.instance.tracer @@ -39,7 +45,7 @@ def self.install end end - def self.uninstall + def uninstall @subscriptions&.each { |subscriber| ActiveSupport::Notifications.unsubscribe(subscriber) } @subscriptions = nil end diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/default.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/default.rb index c6842280ab..ad1c7bb8c6 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/default.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/default.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + module OpenTelemetry module Instrumentation module ActiveJob diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/enqueue.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/enqueue.rb index fab4203e21..a4831adc94 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/enqueue.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/enqueue.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + module OpenTelemetry module Instrumentation module ActiveJob diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/perform.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/perform.rb index 5bcad5c226..4da52fc41b 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/perform.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/perform.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + module OpenTelemetry module Instrumentation module ActiveJob diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/instrumentation.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/instrumentation.rb index 8b721ec01f..683824b97a 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/instrumentation.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/instrumentation.rb @@ -64,13 +64,13 @@ def gem_version def require_dependencies require_relative 'patches/base' - require_relative 'subscriber' + require_relative 'handlers' end def patch_activejob ::ActiveJob::Base.prepend(Patches::Base) unless ::ActiveJob::Base.ancestors.include?(Patches::Base) - Subscriber.install + Handlers.install end end end diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/mappers/attribute.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/mappers/attribute.rb index cb39384aec..fad8b79342 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/mappers/attribute.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/mappers/attribute.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + module OpenTelemetry module Instrumentation module ActiveJob diff --git a/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/subscriber_test.rb b/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/handlers_test.rb similarity index 99% rename from instrumentation/active_job/test/opentelemetry/instrumentation/active_job/subscriber_test.rb rename to instrumentation/active_job/test/opentelemetry/instrumentation/active_job/handlers_test.rb index fc1bf4ea32..8a11e70e7a 100644 --- a/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/subscriber_test.rb +++ b/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/handlers_test.rb @@ -8,7 +8,7 @@ require_relative '../../../../lib/opentelemetry/instrumentation/active_job' -describe OpenTelemetry::Instrumentation::ActiveJob::Subscriber do +describe OpenTelemetry::Instrumentation::ActiveJob::Handlers do let(:instrumentation) { OpenTelemetry::Instrumentation::ActiveJob::Instrumentation.instance } # Technically these are the defaults. But ActiveJob seems to act oddly if you re-install # the instrumentation over and over again - so we manipulate instance variables to @@ -22,7 +22,7 @@ let(:retry_span) { spans.find { |s| s.name == 'retry_stopped.active_job' } } before do - OpenTelemetry::Instrumentation::ActiveJob::Subscriber.uninstall + OpenTelemetry::Instrumentation::ActiveJob::Handlers.uninstall instrumentation.instance_variable_set(:@config, config) instrumentation.instance_variable_set(:@installed, false)