From 63b902f0197f36bdd54aca802b4f6ca3b17d85f0 Mon Sep 17 00:00:00 2001 From: Ariel Valentin Date: Sun, 24 Sep 2023 13:53:26 +0000 Subject: [PATCH] refactor: move methods around --- .../instrumentation/active_job/subscriber.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) 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 0fe7d233c..bb516152d 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/subscriber.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/subscriber.rb @@ -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 @@ -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