File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
lib/datadog/tracing/contrib/lograge
spec/datadog/tracing/contrib/lograge Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,22 @@ def target_version
2020
2121 # patch applies our patch
2222 def patch
23+ # ActiveSupport::TaggedLogging is the default Rails logger since Rails 5
24+ if defined? ( ::ActiveSupport ::TaggedLogging ::Formatter ) &&
25+ ::Lograge ::LogSubscribers ::ActionController
26+ . logger &.formatter . is_a? ( ::ActiveSupport ::TaggedLogging ::Formatter )
27+
28+ Datadog . logger . error (
29+ 'Lograge and ActiveSupport::TaggedLogging (the default Rails log formatter) are not compatible: ' \
30+ 'Lograge does not account for Rails log tags, creating polluted logs and breaking log formatting. ' \
31+ 'Traces and Logs correlation may not work. ' \
32+ 'Either: 1. Disable tagged logging in your Rails configuration ' \
33+ '`config.logger = ActiveSupport::Logger.new(STDOUT); ' \
34+ 'config.active_job.logger = ActiveSupport::Logger.new(STDOUT)` ' \
35+ 'or 2. Use the `semantic_logger` gem instead of `lograge`.'
36+ )
37+ end
38+
2339 ::Lograge ::LogSubscribers ::Base . include ( Instrumentation )
2440 end
2541 end
Original file line number Diff line number Diff line change 55
66RSpec . describe Datadog ::Tracing ::Contrib ::Lograge ::Patcher do
77 describe '.patch' do
8+ before { described_class . instance_variable_get ( :@patch_only_once ) &.send ( :reset_ran_once_state_for_tests ) }
9+
810 it 'adds Instrumentation to ancestors of LogSubscribers::Base class' do
911 described_class . patch
1012
1113 expect ( Lograge ::LogSubscribers ::Base . ancestors ) . to include ( Datadog ::Tracing ::Contrib ::Lograge ::Instrumentation )
1214 end
15+
16+ context 'without Rails tagged logging' do
17+ it 'does not log incompatibility error' do
18+ expect ( Datadog . logger ) . to_not receive ( :error )
19+
20+ described_class . patch
21+ end
22+ end
23+
24+ context 'with Rails tagged logging' do
25+ it 'logs an incompatibility error' do
26+ logger = ActiveSupport ::TaggedLogging . new ( Logger . new ( File ::NULL ) )
27+ stub_const ( 'Lograge::LogSubscribers::ActionController' , double ( 'controller' , logger : logger ) )
28+
29+ expect ( Datadog . logger ) . to receive ( :error ) . with ( /ActiveSupport::TaggedLogging/ )
30+
31+ described_class . patch
32+ end
33+ end
1334 end
1435end
You can’t perform that action at this time.
0 commit comments