Skip to content

Commit e2f2a54

Browse files
committed
Refactor Pin to automatically set service info
1 parent 690b189 commit e2f2a54

File tree

16 files changed

+61
-48
lines changed

16 files changed

+61
-48
lines changed

lib/ddtrace/configuration/pin_setup.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def call
2222

2323
attr_reader :pin, :opts
2424

25-
ATTRS = [:service_name, :app, :tags, :app_type, :name, :tracer].freeze
25+
ATTRS = [:app, :tags, :app_type, :name, :tracer, :service_name].freeze
2626

2727
private_constant :ATTRS
2828
end

lib/ddtrace/contrib/aws/patcher.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def patch
2323

2424
add_pin
2525
add_plugin(Seahorse::Client::Base, *loaded_constants)
26-
Datadog.tracer.set_service_info(get_option(:service_name), 'aws', Ext::AppTypes::WEB)
2726

2827
@patched = true
2928
rescue => e
@@ -38,9 +37,9 @@ def patched?
3837
private
3938

4039
def add_pin
41-
Pin.new(get_option(:service_name), app_type: Ext::AppTypes::WEB).tap do |pin|
42-
pin.onto(::Aws)
43-
end
40+
Pin
41+
.new(get_option(:service_name), app: 'aws', app_type: Ext::AppTypes::WEB)
42+
.onto(::Aws)
4443
end
4544

4645
def add_plugin(*targets)

lib/ddtrace/contrib/dalli/patcher.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def patch
2222

2323
add_pin!
2424
Instrumentation.patch!
25-
Datadog.tracer.set_service_info(get_option(:service_name), 'dalli', Ext::AppTypes::CACHE)
2625

2726
@patched = true
2827
rescue => e
@@ -43,9 +42,9 @@ def compatible?
4342
end
4443

4544
def add_pin!
46-
Pin.new(get_option(:service_name), app_type: Ext::AppTypes::CACHE).tap do |pin|
47-
pin.onto(::Dalli)
48-
end
45+
Pin
46+
.new(get_option(:service_name), app: 'dalli', app_type: Ext::AppTypes::CACHE)
47+
.onto(::Dalli)
4948
end
5049
end
5150
end

lib/ddtrace/contrib/elasticsearch/patcher.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def patch
3434
require 'ddtrace/contrib/elasticsearch/quantize'
3535

3636
patch_elasticsearch_transport_client()
37-
Datadog.tracer.set_service_info(get_option(:service_name), 'elasticsearch', Ext::AppTypes::DB)
3837

3938
@patched = true
4039
rescue StandardError => e

lib/ddtrace/contrib/faraday/patcher.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def patch
3131

3232
add_pin
3333
add_middleware
34-
register_service(get_option(:service_name))
3534

3635
@patched = true
3736
rescue => e
@@ -56,10 +55,12 @@ def compatible?
5655
end
5756

5857
def add_pin
59-
Pin.new(get_option(:service_name), app_type: Ext::AppTypes::WEB).tap do |pin|
60-
pin.onto(::Faraday)
61-
pin.tracer = get_option(:tracer)
62-
end
58+
Pin.new(
59+
get_option(:service_name),
60+
app: 'faraday',
61+
app_type: Ext::AppTypes::WEB,
62+
tracer: get_option(:tracer)
63+
).onto(::Faraday)
6364
end
6465

6566
def add_middleware

lib/ddtrace/contrib/grape/patcher.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ def patch
3535
service = get_option(:service_name)
3636
pin = Datadog::Pin.new(service, app: 'grape', app_type: Datadog::Ext::AppTypes::WEB)
3737
pin.onto(::Grape)
38-
if pin.tracer && pin.service
39-
pin.tracer.set_service_info(pin.service, 'grape', pin.app_type)
40-
end
4138

4239
# subscribe to ActiveSupport events
4340
Datadog::Contrib::Grape::Endpoint.subscribe()

lib/ddtrace/contrib/mongodb/patcher.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ def initialize(*args, &blk)
6767
service = Datadog.configuration[:mongo][:service_name]
6868
pin = Datadog::Pin.new(service, app: APP, app_type: Datadog::Ext::AppTypes::DB)
6969
pin.onto(self)
70-
if pin.tracer && pin.service
71-
pin.tracer.set_service_info(pin.service, 'mongodb', pin.app_type)
72-
end
7370
end
7471

7572
def datadog_pin

lib/ddtrace/contrib/redis/patcher.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def datadog_pin
5454
end
5555

5656
# rubocop:disable Metrics/MethodLength
57-
# rubocop:disable Metrics/BlockLength
5857
def patch_redis_client
5958
::Redis::Client.class_eval do
6059
alias_method :initialize_without_datadog, :initialize
@@ -66,9 +65,6 @@ def initialize(*args)
6665
service = Datadog.configuration[:redis][:service_name]
6766
pin = Datadog::Pin.new(service, app: 'redis', app_type: Datadog::Ext::AppTypes::DB)
6867
pin.onto(self)
69-
if pin.tracer && pin.service
70-
pin.tracer.set_service_info(pin.service, pin.app, pin.app_type)
71-
end
7268
initialize_without_datadog(*args)
7369
end
7470

lib/ddtrace/contrib/resque/patcher.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ def patched?
4040
private
4141

4242
def add_pin
43-
Pin.new(get_option(:service_name), app_type: Ext::AppTypes::WORKER).tap do |pin|
44-
pin.onto(::Resque)
45-
end
43+
Pin
44+
.new(get_option(:service_name), app: 'resque', app_type: Ext::AppTypes::WORKER)
45+
.onto(::Resque)
4646
end
4747
end
4848
end

lib/ddtrace/contrib/resque/resque_job.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def around_perform(*args)
2525
Resque.before_first_fork do
2626
pin = Datadog::Pin.get_from(Resque)
2727
next unless pin && pin.tracer
28-
pin.tracer.set_service_info(pin.service, 'resque', Datadog::Ext::AppTypes::WORKER)
2928

3029
# Create SyncWriter instance before forking
3130
sync_writer = Datadog::SyncWriter.new(transport: pin.tracer.writer.transport)

0 commit comments

Comments
 (0)