diff --git a/Gemfile b/Gemfile index 22fa825..f76421c 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gemspec gem "queue_classic_matchers", github: 'rainforestapp/queue_classic_matchers' gem 'pry' +gem 'dry-configurable' group :development do gem "guard-rspec", require: false diff --git a/lib/queue_classic_plus/datadog.rb b/lib/queue_classic_plus/datadog.rb index 2f767a3..5ca88d3 100644 --- a/lib/queue_classic_plus/datadog.rb +++ b/lib/queue_classic_plus/datadog.rb @@ -1,9 +1,17 @@ # frozen_string_literal: true +require 'dry-configurable' + module QueueClassicDatadog + extend Dry::Configurable + + setting :dd_service + def _perform(*args) + service_name = QueueClassicDatadog.config.dd_service || 'qc.job' + if Gem.loaded_specs['ddtrace'].version >= Gem::Version.new('1') - Datadog::Tracing.trace('qc.job', service: 'qc.job', resource: "#{name}#perform") do |_| + Datadog::Tracing.trace('qc.job', service: service_name, resource: "#{name}#perform") do |_| super end else diff --git a/spec/datadog_spec.rb b/spec/datadog_spec.rb index dc05abb..8d65470 100644 --- a/spec/datadog_spec.rb +++ b/spec/datadog_spec.rb @@ -15,4 +15,18 @@ def self.perform ) subject end + + context "when service name is configured" do + let(:configured_service_name) { "configured_service_name" } + + it "traces using the service name" do + require 'queue_classic_plus/datadog' + QueueClassicDatadog.config.dd_service = configured_service_name + + expect(Datadog::Tracing).to receive(:trace).with( + 'qc.job', service: configured_service_name, resource: 'FunkyName#perform' + ) + subject + end + end end