-
Notifications
You must be signed in to change notification settings - Fork 399
Description
Gem Name
datadog
Gem Version(s)
No response
Describe the goal of the feature
Add a configuration option to allow users to select which attributes are included in log correlation output. Currently, Datadog::Tracing.log_correlation outputs all attributes (env, service, version, trace_id, span_id, ddsource), but users should be able to configure which attributes to include.
For example, a configuration like:
Datadog.configure do |c|
c.tracing.log_injection_attributes = [:trace_id]
# or
c.tracing.log_injection_attributes = [:trace_id, :span_id]
endThis would allow users to reduce verbose log output from:
[dd.env=staging dd.service=myapp dd.version=abc123 dd.trace_id=695e73f5000000002247803521dfbe4b dd.span_id=942369122839116 ddsource=ruby]
To a more concise format like:
[dd.trace_id=695e73f5000000002247803521dfbe4b]
Is your feature request related to a problem?
Yes. The current log correlation injection produces verbose log output that significantly increases log volume and storage costs. In many environments, only trace_id is needed for log-to-trace correlation in Datadog, while other attributes like env, service, version, and ddsource are already configured at the log pipeline level or are redundant.
This is particularly problematic for high-throughput applications where the additional characters per log line accumulate to substantial storage overhead.
Describe alternatives you've considered
- Setting env and version to nil: This only removes those two attributes; service, span_id, and ddsource are still always included.
- Disabling automatic log injection and implementing custom log formatter: This requires significant custom code and maintenance overhead for each project.
- Post-processing logs to strip unwanted attributes: This adds complexity to the log pipeline and doesn't address the root cause.
Describe alternatives you've considered
No response
Additional context
The to_log_format method in lib/datadog/tracing/correlation.rb currently hardcodes all attributes:
def to_log_format
attributes = []
attributes << "#{LOG_ATTR_ENV}=#{env}" unless env.nil?
attributes << "#{LOG_ATTR_SERVICE}=#{service}"
attributes << "#{LOG_ATTR_VERSION}=#{version}" unless version.nil?
attributes << "#{LOG_ATTR_TRACE_ID}=#{trace_id}"
attributes << "#{LOG_ATTR_SPAN_ID}=#{span_id}"
attributes << "#{LOG_ATTR_SOURCE}=#{Core::Logging::Ext::DD_SOURCE}"
attributes.join(' ')
endA possible implementation could introduce a new configuration option that filters which attributes are included in the output.
How does Datadog help you?
No response