Skip to content

Commit

Permalink
Merge pull request #52 from rainforestapp/RF-29783-allow-configuratio…
Browse files Browse the repository at this point in the history
…n-of-datadog-service-name

[RF-29783] Add configuration for Datadog service name
CChanHY authored Jul 31, 2023
2 parents 2bd0155 + 3d65438 commit d30fb5e
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
@@ -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
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
14 changes: 14 additions & 0 deletions spec/datadog_spec.rb
Original file line number Diff line number Diff line change
@@ -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 d30fb5e

Please sign in to comment.