File tree 2 files changed +37
-0
lines changed
lib/datadog/tracing/contrib/lograge
spec/datadog/tracing/contrib/lograge
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,22 @@ def target_version
20
20
21
21
# patch applies our patch
22
22
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
+
23
39
::Lograge ::LogSubscribers ::Base . include ( Instrumentation )
24
40
end
25
41
end
Original file line number Diff line number Diff line change 5
5
6
6
RSpec . describe Datadog ::Tracing ::Contrib ::Lograge ::Patcher do
7
7
describe '.patch' do
8
+ before { described_class . instance_variable_get ( :@patch_only_once ) &.send ( :reset_ran_once_state_for_tests ) }
9
+
8
10
it 'adds Instrumentation to ancestors of LogSubscribers::Base class' do
9
11
described_class . patch
10
12
11
13
expect ( Lograge ::LogSubscribers ::Base . ancestors ) . to include ( Datadog ::Tracing ::Contrib ::Lograge ::Instrumentation )
12
14
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
13
34
end
14
35
end
You can’t perform that action at this time.
0 commit comments