File tree 2 files changed +35
-0
lines changed
lib/datadog/tracing/contrib/lograge
spec/datadog/tracing/contrib/lograge
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,19 @@ 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? ( ::Rails ::VERSION ::MAJOR ) && ::Rails ::VERSION ::MAJOR >= 5
25
+ Datadog . logger . error (
26
+ 'Lograge and ActiveSupport::TaggedLogging (the default Rails logger) are not compatible: ' \
27
+ 'Lograge does not account for Rails log tags, creating polluted logs and breaking log formatting. ' \
28
+ 'Traces and Logs correlation may not work. ' \
29
+ 'Either: 1. Disable tagged logging in your Rails configuration ' \
30
+ '`config.logger = ActiveSupport::Logger.new(STDOUT); ' \
31
+ 'config.active_job.logger = ActiveSupport::Logger.new(STDOUT)` ' \
32
+ 'or 2. Use the `semantic_logger` gem instead of `lograge`.'
33
+ )
34
+ end
35
+
23
36
::Lograge ::LogSubscribers ::Base . include ( Instrumentation )
24
37
end
25
38
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 'with older Rails' do
17
+ it 'does not log incompatibility error' do
18
+ stub_const ( 'Rails::VERSION::MAJOR' , 4 )
19
+
20
+ expect ( Datadog . logger ) . to_not receive ( :error )
21
+
22
+ described_class . patch
23
+ end
24
+ end
25
+
26
+ context 'with Rails with tagged logging' do
27
+ it 'logs an incompatibility error' do
28
+ stub_const ( 'Rails::VERSION::MAJOR' , 5 )
29
+
30
+ expect ( Datadog . logger ) . to receive ( :error ) . with ( /ActiveSupport::TaggedLogging/ )
31
+
32
+ described_class . patch
33
+ end
34
+ end
13
35
end
14
36
end
You can’t perform that action at this time.
0 commit comments