Skip to content

Commit

Permalink
Merge pull request #1922 from DataDog/refactor/tracer_integration_set…
Browse files Browse the repository at this point in the history
…tings

Move integration settings into tracing namespace
  • Loading branch information
delner authored Mar 15, 2022
2 parents 9931c5b + c7f5ae6 commit 3cbcea6
Show file tree
Hide file tree
Showing 95 changed files with 326 additions and 283 deletions.
18 changes: 17 additions & 1 deletion docs/UpgradeGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,14 @@ Check out the table below for a list of common mappings:
| `tracer.transport_options(options)` | Removed |
| `tracer.writer` | `tracing.writer` |
| `tracer.writer_options` | `tracing.writer_options` |
| `use` | `tracing.instrument` |

<h3 id="1.0-configuration-instrumentation">Activating instrumentation</h3>

The `use` function has been renamed to `instrument`. Also, `instrument` has been namespaced to the specific feature:
- The `use` function has been renamed to `instrument`.
- `instrument` has been namespaced within the feature to which it belongs.

As an example:

```ruby
### Old 0.x ###
Expand All @@ -175,6 +179,18 @@ Datadog.configure do |c|
end
```

Similarly, if you were accessing configuration for instrumentation, you will need to use the appropriate namespace:

```ruby
### Old 0.x ###
Datadog.configuration[:rails][:service_name]
Datadog.configuration[:cucumber][:service_name]

### New 1.0 ###
Datadog.configuration.tracing[:rails][:service_name]
Datadog.configuration.ci[:cucumber][:service_name]
```

<h2 id="1.0-instrumentation">Instrumentation</h2>

<h3 id="1.0-instrumentation-service-naming">Service naming</h3>
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/appsec/contrib/rails/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def before_intialize(app)
# Middleware must be added before the application is initialized.
# Otherwise the middleware stack will be frozen.
# Sometimes we don't want to activate middleware e.g. OpenTracing, etc.
add_middleware(app) if Datadog.configuration[:rails][:middleware]
add_middleware(app) if Datadog.configuration.tracing[:rails][:middleware]
end
end

Expand Down
10 changes: 8 additions & 2 deletions lib/datadog/ci/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ def self.add_settings!(base)
end

# DEV: Alias to Datadog::Tracing::Contrib::Extensions::Configuration::Settings#instrument.
# DEV: Should be removed when `c.ci.instrument` namespacing is complete.
# DEV: Should be removed when CI implement its own `c.ci.instrument`.
define_method(:instrument) do |integration_name, options = {}, &block|
Datadog.configuration.send(:instrument, integration_name, options, &block)
Datadog.configuration.tracing.instrument(integration_name, options, &block)
end

# DEV: Alias to Datadog::Tracing::Contrib::Extensions::Configuration::Settings#instrument.
# DEV: Should be removed when CI implement its own `c.ci[]`.
define_method(:[]) do |integration_name, key = :default|
Datadog.configuration.tracing[integration_name, key]
end

# TODO: Deprecate in the next major version, as `instrument` better describes this method's purpose
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/contrib/cucumber/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def on_test_step_finished(event)
private

def configuration
Datadog.configuration[:cucumber]
Datadog.configuration.ci[:cucumber]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/contrib/rspec/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def run(example_group_instance, reporter)
private

def configuration
Datadog.configuration[:rspec]
Datadog.configuration.ci[:rspec]
end
end
end
Expand Down
9 changes: 0 additions & 9 deletions lib/datadog/core/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,6 @@ def initialize(*_)
# @return [Object,nil]
option :instance

# DEV: Alias to Datadog::Tracing::Contrib::Extensions::Configuration::Settings#instrument.
# DEV: Should be removed when `c.tracing.instrument` namespacing is complete.
define_method(:instrument) do |integration_name, options = {}, &block|
Datadog.configuration.send(:instrument, integration_name, options, &block)
end

# TODO: Deprecate in the next major version, as `instrument` better describes this method's purpose
alias_method :use, :instrument

# Automatic correlation between tracing and logging.
# @see https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#trace-correlation
# @return [Boolean]
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/core/diagnostics/environment_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def collect!(transport_responses)
private

def instrumented_integrations
Datadog.configuration.instrumented_integrations
Datadog.configuration.tracing.instrumented_integrations
end

# Capture all active integration settings into "integrationName_settingName: value" entries.
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/action_cable/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def span_options
end

def configuration
Datadog.configuration[:action_cable]
Datadog.configuration.tracing[:action_cable]
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def self.included(base)
# Instrumentation for Channel hooks.
class Tracer
def self.trace(channel, hook)
configuration = Datadog.configuration[:action_cable]
configuration = Datadog.configuration.tracing[:action_cable]

Tracing.trace("action_cable.#{hook}") do |span|
span.service = configuration[:service_name] if configuration[:service_name]
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/action_mailer/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def span_options
end

def configuration
Datadog.configuration[:action_mailer]
Datadog.configuration.tracing[:action_mailer]
end

def process(span, event, _id, payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Instrumentation

def start_processing(payload)
# trace the execution
service = Datadog.configuration[:action_pack][:service_name]
service = Datadog.configuration.tracing[:action_pack][:service_name]
type = Tracing::Metadata::Ext::HTTP::TYPE_INBOUND
span = Tracing.trace(
Ext::SPAN_ACTION_CONTROLLER,
Expand Down Expand Up @@ -80,7 +80,7 @@ def finish_processing(payload)
end

def exception_controller?(payload)
exception_controller_class = Datadog.configuration[:action_pack][:exception_controller]
exception_controller_class = Datadog.configuration.tracing[:action_pack][:exception_controller]
controller = payload.fetch(:controller)
headers = payload.fetch(:headers)

Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/action_pack/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class << self
private

def datadog_configuration
Datadog.configuration[:action_pack]
Datadog.configuration.tracing[:action_pack]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/action_view/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.included(base)
# Class methods for ActionView events.
module ClassMethods
def configuration
Datadog.configuration[:action_view]
Datadog.configuration.tracing[:action_view]
end

def record_exception(span, payload)
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/action_view/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Utils
def normalize_template_name(name)
return if name.nil?

base_path = Datadog.configuration[:action_view][:template_base_path]
base_path = Datadog.configuration.tracing[:action_view][:template_base_path]
sections_view = name.split(base_path)

if sections_view.length == 1
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/active_job/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def span_options
end

def configuration
Datadog.configuration[:active_job]
Datadog.configuration.tracing[:active_job]
end

def set_common_tags(span, payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def span_options
end

def configuration
Datadog.configuration[:active_model_serializers]
Datadog.configuration.tracing[:active_model_serializers]
end

def set_common_tags(span, payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def patch
end

def get_option(option)
Datadog.configuration[:active_model_serializers].get_option(option)
Datadog.configuration.tracing[:active_model_serializers].get_option(option)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/active_record/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def span_options
end

def configuration
Datadog.configuration[:active_record]
Datadog.configuration.tracing[:active_record]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/active_record/events/sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def span_name

def process(span, event, _id, payload)
config = Utils.connection_config(payload[:connection], payload[:connection_id])
settings = Datadog.configuration[:active_record, config]
settings = Datadog.configuration.tracing[:active_record, config]
adapter_name = Contrib::Utils::Database.normalize_vendor(config[:adapter])
service_name = if settings.service_name != Contrib::Utils::Database::VENDOR_DEFAULT
settings.service_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def start_trace_cache(payload)
tracing_context = payload.fetch(:tracing_context)

# create a new ``Span`` and add it to the tracing context
service = Datadog.configuration[:active_support][:cache_service]
service = Datadog.configuration.tracing[:active_support][:cache_service]
type = Ext::SPAN_TYPE_CACHE
span = Tracing.trace(Ext::SPAN_CACHE, service: service, span_type: type)
span.resource = payload.fetch(:action)
Expand Down
6 changes: 4 additions & 2 deletions lib/datadog/tracing/contrib/auto_instrument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ def self.patch_all!
end

Datadog.configure do |c|
c.reduce_log_verbosity
# This will activate auto-instrumentation for Rails
# Ignore any instrumentation load errors (otherwise it might spam logs)
c.tracing.ignore_integration_load_errors = true

# Activate instrumentation for each integration
integrations.each do |integration_name|
c.tracing.instrument integration_name
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/aws/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def annotate!(span, context)
end

def configuration
Datadog.configuration[:aws]
Datadog.configuration.tracing[:aws]
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/aws/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def loaded_constants
end

def get_option(option)
Datadog.configuration[:aws].get_option(option)
Datadog.configuration.tracing[:aws].get_option(option)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def post(*args, &task)
end

def datadog_configuration
Datadog.configuration[:concurrent_ruby]
Datadog.configuration.tracing[:concurrent_ruby]
end

delegate [:can_overflow?, :serialized?] => :composited_executor
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/dalli/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def request(op, *args)
private

def datadog_configuration
Datadog.configuration[:dalli, "#{hostname}:#{port}"]
Datadog.configuration.tracing[:dalli, "#{hostname}:#{port}"]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/delayed_job/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def self.flush(worker, &block)
end

def self.configuration
Datadog.configuration[:delayed_job]
Datadog.configuration.tracing[:delayed_job]
end

def self.job_name(job)
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/elasticsearch/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def perform_request(*args)
end

def datadog_configuration
Datadog.configuration[:elasticsearch]
Datadog.configuration.tracing[:elasticsearch]
end
end
# rubocop:enable Metrics/BlockLength
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/ethon/easy_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def try_parse_uri
# rubocop:enable Lint/SuppressedException

def load_datadog_configuration_for(host = :default)
@datadog_configuration = Datadog.configuration[:ethon, host]
@datadog_configuration = Datadog.configuration.tracing[:ethon, host]
end

def analytics_enabled?
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/ethon/multi_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def datadog_multi_span
end

def datadog_configuration
Datadog.configuration[:ethon]
Datadog.configuration.tracing[:ethon]
end

def analytics_enabled?
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/excon/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def build_request_options!(datum)
end

def datadog_configuration(host = :default)
Datadog.configuration[:excon, host]
Datadog.configuration.tracing[:excon, host]
end
end
end
Expand Down
Loading

0 comments on commit 3cbcea6

Please sign in to comment.