-
Notifications
You must be signed in to change notification settings - Fork 399
Description
Description
When using datadog/auto_instrument in a Rails application (as recommended in the documentation), there's a timing issue that makes certain configuration options ineffective when set in config/initializers/datadog.rb.
The Problem
The auto_instrument Railtie runs with before: :load_config_initializers, which means:
auto_instrumenttriggerspatch_all!- Each integration is patched with default settings
- Then Rails loads initializers
- User's
Datadog.configureblock runs, but patching has already occurred
This means any configuration option that affects how patching is done (not just runtime behavior) cannot be configured via the initializer.
Affected Options
1. rack integration - request_queuing
# rack/configuration/settings.rb
option :request_queuing do |o|
o.type :bool
o.default false
# No o.env - cannot be configured via environment variable
endWorkaround required:
# Monkey-patch because the option cannot be set before patching
class Datadog::Tracing::Contrib::Rack::Configuration::Settings
def request_queuing = true
end2. graphql integration - with_unified_tracer
# graphql/configuration/settings.rb
option :with_unified_tracer do |o|
o.env Ext::ENV_WITH_UNIFIED_TRACER # Has ENV var
o.type :bool
o.default false
endThis option does have an ENV var (DD_TRACE_GRAPHQL_WITH_UNIFIED_TRACER), so it can be configured before patching occurs. However, this is not immediately obvious from the documentation, which shows configuration via Datadog.configure block:
c.tracing.instrument :graphql, with_unified_tracer: trueThis does not work with auto_instrument because patching happens before the initializer runs.
3. diagnostics.startup_logs.enabled
Similarly, this setting:
Datadog.configure do |c|
c.diagnostics.startup_logs.enabled = false
endHas no effect when using auto_instrument because startup logs are emitted before the initializer runs. The only way to disable them is via DD_TRACE_STARTUP_LOGS=false in the shell environment (note: using dotenv/.env files doesn't work either, as those are also loaded after auto_instrument runs).
Questions
-
Is this timing behavior intentional? The Railtie comment says "user supplied config will take precedence", but this is only true for runtime configuration, not patching-time configuration.
-
For options that affect patching behavior, should ENV vars be added? For example,
request_queuinghas no ENV var, making it impossible to configure properly withauto_instrument. -
If we omit
require: 'datadog/auto_instrument'from the Gemfile to gain control over configuration timing, do we need to manually instrument every integration? For example:Datadog.configure do |c| c.tracing.instrument :rails c.tracing.instrument :rack, request_queuing: true c.tracing.instrument :active_record c.tracing.instrument :redis c.tracing.instrument :sidekiq c.tracing.instrument :graphql, with_unified_tracer: true # ... every other integration we use? end
Or is there a way to trigger auto-instrumentation after our configuration is set?
-
Could the documentation be clearer about this limitation? Currently, the docs show configuration via
Datadog.configureblocks without mentioning that certain options must be set via ENV vars when usingauto_instrument.
Environment
datadoggem version: 2.x- Ruby version: 3.2.2
- Rails version: 7.0
Expected Behavior
Configuration set in config/initializers/datadog.rb should be respected for all options, including those that affect patching behavior.
Actual Behavior
Options that affect patching behavior are ignored because patching occurs before initializers run.