From 3d65438a1891286e260bad2110375fffa770bd14 Mon Sep 17 00:00:00 2001 From: Collin Chan Date: Fri, 28 Jul 2023 12:24:59 +0000 Subject: [PATCH] RF-29783 Add configuration for Datadog service name If a Datadog service name is configured, use that when tracing. If it is not, continue to use the default qc.job. --- Gemfile | 1 + lib/queue_classic_plus/datadog.rb | 10 +++++++++- spec/datadog_spec.rb | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) 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