Skip to content

Commit

Permalink
squash: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
arielvalentin committed Oct 9, 2023
1 parent 0e1cfa0 commit 2134016
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -39,7 +45,7 @@ def self.install
end
end

def self.uninstall
def uninstall
@subscriptions&.each { |subscriber| ActiveSupport::Notifications.unsubscribe(subscriber) }
@subscriptions = nil
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# frozen_string_literal: true

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

module OpenTelemetry
module Instrumentation
module ActiveJob
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# frozen_string_literal: true

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

module OpenTelemetry
module Instrumentation
module ActiveJob
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# frozen_string_literal: true

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

module OpenTelemetry
module Instrumentation
module ActiveJob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# frozen_string_literal: true

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

module OpenTelemetry
module Instrumentation
module ActiveJob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit 2134016

Please sign in to comment.