lib/opentelemetry/instrumentation/sidekiq/instrumentation.rb in opentelemetry-instrumentation-sidekiq-0.12.0 vs lib/opentelemetry/instrumentation/sidekiq/instrumentation.rb in opentelemetry-instrumentation-sidekiq-0.13.0

- old
+ new

@@ -8,24 +8,49 @@ module Instrumentation module Sidekiq # The Instrumentation class contains logic to detect and install the Sidekiq # instrumentation class Instrumentation < OpenTelemetry::Instrumentation::Base + MINIMUM_VERSION = Gem::Version.new('4.2.10') + install do |_config| require_dependencies add_client_middleware add_server_middleware + patch_on_startup end present do defined?(::Sidekiq) end + compatible do + gem_version >= MINIMUM_VERSION + end + private + def gem_version + Gem.loaded_specs['sidekiq'].version + end + def require_dependencies require_relative 'middlewares/client/tracer_middleware' require_relative 'middlewares/server/tracer_middleware' + + require_relative 'patches/processor' + require_relative 'patches/launcher' + require_relative 'patches/poller' + end + + def patch_on_startup + ::Sidekiq.configure_server do |config| + config.on(:startup) do + ::Sidekiq::Processor.prepend(Patches::Processor) + ::Sidekiq::Launcher.prepend(Patches::Launcher) + ::Sidekiq::Scheduled::Poller.prepend(Patches::Poller) + end + end end def add_client_middleware ::Sidekiq.configure_client do |config| config.client_middleware do |chain|