Skip to content

Commit

Permalink
misc(tracing) - add trace_id and span_id to lograge custom_options (g…
Browse files Browse the repository at this point in the history
…etlago#2370)

## Description

Make sure we can correlate logs with traces by including the
OpenTelemetry trace_id and span_id in the logs.
  • Loading branch information
nudded authored and abdussamadbello committed Aug 8, 2024
1 parent 7035b63 commit 9734c26
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion config/initializers/lograge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
config.colorize_logging = false

config.lograge.custom_options = lambda do |event|
# If ENV[OTEL_EXPORTER] is not set, the span context will have all zero values.
span = OpenTelemetry::Trace.current_span

{
ddsource: 'ruby',
params: event.payload[:params].reject { |k| %w[controller action].include?(k) },
organization_id: event.payload[:organization_id]
organization_id: event.payload[:organization_id],
trace_id: span.context.hex_trace_id,
span_id: span.context.hex_span_id
}
end
end

0 comments on commit 9734c26

Please sign in to comment.