Skip to content

Commit

Permalink
RF-29783 Add configuration for Datadog service name
Browse files Browse the repository at this point in the history
If a Datadog service name is configured, use that when tracing.
If it is not, continue to use the default qc.job.
  • Loading branch information
Collin Chan committed Jul 28, 2023
1 parent 2bd0155 commit 3d65438
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion lib/queue_classic_plus/datadog.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 14 additions & 0 deletions spec/datadog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3d65438

Please sign in to comment.