Skip to content

Commit d7e71dc

Browse files
committed
Emit log message for incompatible Lograge setup
1 parent 6b50227 commit d7e71dc

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Diff for: lib/datadog/tracing/contrib/lograge/patcher.rb

+13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ 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?(::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+
2336
::Lograge::LogSubscribers::Base.include(Instrumentation)
2437
end
2538
end

Diff for: spec/datadog/tracing/contrib/lograge/patcher_spec.rb

+22
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,32 @@
55

66
RSpec.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 '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
1335
end
1436
end

0 commit comments

Comments
 (0)