Skip to content

Commit

Permalink
refactor: move methods around
Browse files Browse the repository at this point in the history
  • Loading branch information
arielvalentin authored Sep 24, 2023
1 parent e7344ae commit 63b902f
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,17 @@ def on_start(name, _id, payload, subscriber)
end

class Subscriber < ::ActiveSupport::Subscriber
EVENT_HANDLERS = {
'enqueue.active_job' => EnqueueSubscriber.new(OpenTelemetry.tracer_provider.tracer('otel-active_job', '0.0.1')),
'perform.active_job' => PerformSubscriber.new(OpenTelemetry.tracer_provider.tracer('otel-active_job', '0.0.1')),
}
attr_reader :tracer

def initialize(...)
super
@tracer = OpenTelemetry.tracer_provider.tracer('otel-active_job', '0.0.1')
@handlers_by_pattern = {
'enqueue.active_job' => EnqueueSubscriber.new(OpenTelemetry.tracer_provider.tracer('otel-active_job', '0.0.1')),
'perform.active_job' => PerformSubscriber.new(OpenTelemetry.tracer_provider.tracer('otel-active_job', '0.0.1')),
'enqueue.active_job' => EnqueueSubscriber.new(@tracer),
'perform.active_job' => PerformSubscriber.new(@tracer),
}
end

attach_to :active_job

# The methods below are the events the Subscriber is interested in.
def enqueue(...); end
def perform(...);end
Expand Down Expand Up @@ -177,9 +173,7 @@ def as_otel_semconv_attrs(job)
otel_attributes
end

def tracer
OpenTelemetry.tracer_provider.tracer('otel-active_job', '0.0.1')
end
attach_to :active_job
end
end
end
Expand Down

0 comments on commit 63b902f

Please sign in to comment.