Skip to content

Commit

Permalink
[core] Stop sending service information (#738)
Browse files Browse the repository at this point in the history
* [core] Remove calls to /services endpoints

* remove more service pieces

* Fix tests for removing /services call

* fix rubocop offense

* 🔥 set_service_info 🔥

* fix sidekiq and redis tests

* Fix default active_record service name

* ensure we use a clean @done_once

* remove rails service test cases

* don't assert rails sidekiq services
  • Loading branch information
brettlangdon committed Apr 17, 2019
1 parent 0d08e84 commit 9a6d0e6
Show file tree
Hide file tree
Showing 43 changed files with 102 additions and 466 deletions.
7 changes: 0 additions & 7 deletions lib/ddtrace/contrib/active_model_serializers/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ def patch
begin
# Subscribe to ActiveModelSerializers events
Events.subscribe!

# Set service info
get_option(:tracer).set_service_info(
get_option(:service_name),
Ext::APP,
Datadog::Ext::AppTypes::WEB
)
rescue StandardError => e
Datadog::Tracer.log.error("Unable to apply ActiveModelSerializers integration: #{e}")
end
Expand Down
8 changes: 3 additions & 5 deletions lib/ddtrace/contrib/active_record/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ class Settings < Contrib::Configuration::Settings
lazy: true

option :orm_service_name
option :service_name, depends_on: [:tracer] do |value|
(value || Utils.adapter_name).tap do |service_name|
tracer.set_service_info(service_name, Ext::APP, Datadog::Ext::AppTypes::DB)
end
end
option :service_name,
default: -> { Utils.adapter_name },
lazy: true

option :tracer, default: Datadog.tracer do |value|
value.tap do
Expand Down
7 changes: 0 additions & 7 deletions lib/ddtrace/contrib/dalli/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ def patch
begin
add_pin!
::Dalli::Server.send(:include, Instrumentation)

# TODO: When Dalli pin is removed, set service info.
# get_option(:tracer).set_service_info(
# get_option(:service_name),
# Ext::APP,
# Datadog::Ext::AppTypes::CACHE
# )
rescue StandardError => e
Datadog::Tracer.log.error("Unable to apply Dalli integration: #{e}")
end
Expand Down
2 changes: 0 additions & 2 deletions lib/ddtrace/contrib/faraday/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def analytics_sample_rate

def setup_service!
return if options[:service_name] == datadog_configuration[:service_name]

Patcher.register_service(options[:service_name])
end
end
end
Expand Down
11 changes: 0 additions & 11 deletions lib/ddtrace/contrib/faraday/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ def patch

add_pin!
add_middleware!

# TODO: When Faraday pin is removed, set service info.
# register_service(get_option(:service_name))
rescue StandardError => e
Datadog::Tracer.log.error("Unable to apply Faraday integration: #{e}")
end
Expand All @@ -45,14 +42,6 @@ def add_middleware!
::Faraday::Middleware.register_middleware(ddtrace: Middleware)
end

def register_service(name)
get_option(:tracer).set_service_info(
name,
Ext::APP,
Datadog::Ext::AppTypes::WEB
)
end

def get_option(option)
Datadog.configuration[:faraday].get_option(option)
end
Expand Down
7 changes: 0 additions & 7 deletions lib/ddtrace/contrib/grape/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ def patch

add_pin!

# TODO: When Grape pin is removed, set service info.
# get_option(:tracer).set_service_info(
# get_option(:service_name),
# Ext::APP,
# Datadog::Ext::AppTypes::WEB
# )

# Subscribe to ActiveSupport events
Datadog::Contrib::Grape::Endpoint.subscribe
rescue StandardError => e
Expand Down
5 changes: 1 addition & 4 deletions lib/ddtrace/contrib/graphql/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ class Settings < Contrib::Configuration::Settings
lazy: true

option :schemas
option :service_name, default: Ext::SERVICE_NAME, depends_on: [:tracer] do |value|
get_option(:tracer).set_service_info(value, Ext::APP, Datadog::Ext::AppTypes::WEB)
value
end
option :service_name, default: Ext::SERVICE_NAME
end
end
end
Expand Down
7 changes: 0 additions & 7 deletions lib/ddtrace/contrib/grpc/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ def patch

add_pin!

# TODO: When GRPC pin is removed, set service info.
# get_option(:tracer).set_service_info(
# get_option(:service_name),
# Ext::APP,
# Datadog::Ext::AppTypes::WEB
# )

prepend_interceptor
rescue StandardError => e
Datadog::Tracer.log.error("Unable to apply gRPC integration: #{e}")
Expand Down
8 changes: 0 additions & 8 deletions lib/ddtrace/contrib/racecar/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ def patch
begin
# Subscribe to Racecar events
Events.subscribe!

# Set service info
configuration = Datadog.configuration[:racecar]
configuration[:tracer].set_service_info(
configuration[:service_name],
Ext::APP,
Datadog::Ext::AppTypes::WORKER
)
rescue StandardError => e
Datadog::Tracer.log.error("Unable to apply Racecar integration: #{e}")
end
Expand Down
12 changes: 2 additions & 10 deletions lib/ddtrace/contrib/rack/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,9 @@ class Settings < Contrib::Configuration::Settings
option :quantize, default: {}
option :request_queuing, default: false

option :service_name, default: Ext::SERVICE_NAME, depends_on: [:tracer] do |value|
get_option(:tracer).set_service_info(value, Ext::APP, Datadog::Ext::AppTypes::WEB)
value
end
option :service_name, default: Ext::SERVICE_NAME

option :web_service_name, default: Ext::WEBSERVER_SERVICE_NAME, depends_on: [:tracer, :request_queuing] do |value|
if get_option(:request_queuing)
get_option(:tracer).set_service_info(value, Ext::WEBSERVER_APP, Datadog::Ext::AppTypes::WEB)
end
value
end
option :web_service_name, default: Ext::WEBSERVER_SERVICE_NAME
end
end
end
Expand Down
7 changes: 0 additions & 7 deletions lib/ddtrace/contrib/rails/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def self.setup

activate_rack!(config)
activate_active_record!(config)
set_service_info!(config)

# By default, default service would be guessed from the script
# being executed, but here we know better, get it from Rails config.
Expand Down Expand Up @@ -64,12 +63,6 @@ def self.activate_active_record!(config)
tracer: config[:tracer]
)
end

def self.set_service_info!(config)
tracer = config[:tracer]
tracer.set_service_info(config[:controller_service], Ext::APP, Datadog::Ext::AppTypes::WEB)
tracer.set_service_info(config[:cache_service], Ext::APP, Datadog::Ext::AppTypes::CACHE)
end
end
end
end
Expand Down
7 changes: 0 additions & 7 deletions lib/ddtrace/contrib/rake/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ def patch
begin
# Add instrumentation patch to Rake task
::Rake::Task.send(:include, Instrumentation)

# Set service info
get_option(:tracer).set_service_info(
get_option(:service_name),
Ext::APP,
Datadog::Ext::AppTypes::WORKER
)
rescue StandardError => e
Datadog::Tracer.log.error("Unable to apply Rake integration: #{e}")
end
Expand Down
5 changes: 1 addition & 4 deletions lib/ddtrace/contrib/rest_client/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ class Settings < Contrib::Configuration::Settings
lazy: true

option :distributed_tracing, default: true
option :service_name, default: Ext::SERVICE_NAME, depends_on: [:tracer] do |value|
get_option(:tracer).set_service_info(value, Ext::APP, Datadog::Ext::AppTypes::WEB)
value
end
option :service_name, default: Ext::SERVICE_NAME
end
end
end
Expand Down
10 changes: 0 additions & 10 deletions lib/ddtrace/contrib/shoryuken/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class Tracer
def initialize(options = {})
@tracer = options[:tracer] || configuration[:tracer]
@shoryuken_service = options[:service_name] || configuration[:service_name]
set_service_info(@shoryuken_service)
end

def call(worker_instance, queue, sqs_msg, body)
Expand Down Expand Up @@ -40,15 +39,6 @@ def resource(worker_instance, body)
def configuration
Datadog.configuration[:shoryuken]
end

def set_service_info(service)
return if @tracer.nil? || @tracer.services[service]
@tracer.set_service_info(
service,
Ext::APP,
Datadog::Ext::AppTypes::WORKER
)
end
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/ddtrace/contrib/sidekiq/client_tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ClientTracer
def initialize(options = {})
super
@sidekiq_service = options[:client_service_name] || configuration[:client_service_name]
set_service_info(@sidekiq_service)
end

# Client middleware arguments are documented here:
Expand Down
1 change: 0 additions & 1 deletion lib/ddtrace/contrib/sidekiq/server_tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def call(worker, job, queue)
resource = job_resource(job)

service = service_from_worker_config(resource) || @sidekiq_service
set_service_info(service)

@tracer.trace(Ext::SPAN_JOB, service: service, span_type: Datadog::Ext::AppTypes::WORKER) do |span|
span.resource = resource
Expand Down
10 changes: 0 additions & 10 deletions lib/ddtrace/contrib/sidekiq/tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ def job_resource(job)
job['class']
end
end

def set_service_info(service)
# Ensure the tracer knows about this service.
return if @tracer.services[service]
@tracer.set_service_info(
service,
Ext::APP,
Datadog::Ext::AppTypes::WORKER
)
end
end
end
end
Expand Down
5 changes: 1 addition & 4 deletions lib/ddtrace/contrib/sinatra/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ class Settings < Contrib::Configuration::Settings
option :headers, default: DEFAULT_HEADERS
option :resource_script_names, default: false

option :service_name, default: Ext::SERVICE_NAME, depends_on: [:tracer] do |value|
get_option(:tracer).set_service_info(value, Ext::APP, Datadog::Ext::AppTypes::WEB)
value
end
option :service_name, default: Ext::SERVICE_NAME
end
end
end
Expand Down
5 changes: 0 additions & 5 deletions lib/ddtrace/encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ def encode_traces(traces)
encode(to_send)
end

# Encodes services hash
def encode_services(services)
encode(services)
end

# Defines the underlying format used during traces or services encoding.
# This method must be implemented and should only be used by the internal functions.
def encode(_)
Expand Down
2 changes: 0 additions & 2 deletions lib/ddtrace/pin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ def datadog_pin
end

def service_name=(name)
tracer.set_service_info(name, app, app_type) if name && app && app_type

@service_name = name
end

Expand Down
16 changes: 10 additions & 6 deletions lib/ddtrace/sync_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ def initialize(options = {})
end
end

def write(trace, services)
def write(trace, services = nil)
unless services.nil?
Datadog::Patcher.do_once('SyncWriter#write') do
Datadog::Tracer.log.warn(%(
write: Writing services has been deprecated and no longer need to be provided.
write(traces, services) can be updted to write(traces)
))
end
end

perform_concurrently(
proc { flush_services(services) },
proc { flush_trace(trace) }
)
rescue => e
Expand All @@ -25,10 +33,6 @@ def perform_concurrently(*tasks)
tasks.map { |task| Thread.new(&task) }.each(&:join)
end

def flush_services(services)
transport.send(:services, services)
end

def flush_trace(trace)
processed_traces = Pipeline.process!([trace])
transport.send(:traces, processed_traces)
Expand Down
31 changes: 20 additions & 11 deletions lib/ddtrace/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Datadog
# of these function calls and sub-requests would be encapsulated within a single trace.
# rubocop:disable Metrics/ClassLength
class Tracer
attr_reader :sampler, :services, :tags, :provider
attr_reader :sampler, :tags, :provider
attr_accessor :enabled, :writer
attr_writer :default_service

Expand Down Expand Up @@ -67,6 +67,15 @@ def self.debug_logging
log.level == Logger::DEBUG
end

def services
# Only log each deprecation warning once (safeguard against log spam)
Datadog::Patcher.do_once('Tracer#set_service_info') do
Datadog::Tracer.log.warn('services: Usage of Tracer.services has been deprecated')
end

{}
end

# Shorthand that calls the `shutdown!` method of a registered worker.
# It's useful to ensure that the Trace Buffer is properly flushed before
# shutting down the application.
Expand Down Expand Up @@ -110,7 +119,6 @@ def initialize(options = {})
@context_flush = options[:partial_flush] ? Datadog::ContextFlush.new(options) : nil

@mutex = Mutex.new
@services = {}
@tags = {}
end

Expand Down Expand Up @@ -162,14 +170,16 @@ def configure(options = {})
# Set the information about the given service. A valid example is:
#
# tracer.set_service_info('web-application', 'rails', 'web')
#
# set_service_info is deprecated, no service information needs to be tracked
def set_service_info(service, app, app_type)
@services[service] = {
'app' => app,
'app_type' => app_type
}

return unless Datadog::Tracer.debug_logging
Datadog::Tracer.log.debug("set_service_info: service: #{service} app: #{app} type: #{app_type}")
# Only log each deprecation warning once (safeguard against log spam)
Datadog::Patcher.do_once('Tracer#set_service_info') do
Datadog::Tracer.log.warn(%(
set_service_info: Usage of set_service_info has been deprecated,
service information no longer needs to be reported to the trace agent.
))
end
end

# A default value for service. One should really override this one
Expand Down Expand Up @@ -380,8 +390,7 @@ def write(trace)
Datadog::Tracer.log.debug(str)
end

@writer.write(trace, @services)
@services = {}
@writer.write(trace)
end

private :write, :guess_context_and_parent
Expand Down
Loading

0 comments on commit 9a6d0e6

Please sign in to comment.