Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions lib/datadog/tracing/contrib/active_job/log_injection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,31 @@ module Contrib
module ActiveJob
# Active Job log injection wrapped around job execution
module LogInjection
def self.included(base)
base.class_eval do
around_perform do |_, block|
if Datadog.configuration.tracing.log_injection && logger.respond_to?(:tagged)
logger.tagged(Tracing.log_correlation, &block)
else
block.call
# Active Job 4 / 5 don't execute `perform_now` at the right point, so we do best effort log correlation tagging
module AroundPerformPatch
def self.included(base)
base.class_eval do
around_perform do |_, block|
if Datadog.configuration.tracing.log_injection && logger.respond_to?(:tagged)
logger.tagged(Tracing.log_correlation, &block)
else
block.call
end
end
end
end
end

# Active Job 6+ executes `perform_now` at the right point, so we can provide better log correlation tagging
module PerformNowPatch
def perform_now
if Datadog.configuration.tracing.log_injection && logger.respond_to?(:tagged)
logger.tagged(Tracing.log_correlation) { super }
else
super
end
end
end
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/datadog/tracing/contrib/active_job/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def patch

def inject_log_correlation
::ActiveSupport.on_load(:active_job) do
include LogInjection
if ::ActiveJob.gem_version < Gem::Version.new('6.0.0')
include LogInjection::AroundPerformPatch
else
include LogInjection::PerformNowPatch
end
end
end
end
Expand Down
Loading