Skip to content

Commit 8b88cdd

Browse files
authored
Merge pull request #3788 from DataDog/backport1
2 parents 63f8b18 + 8b4b2e7 commit 8b88cdd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/datadog/tracing.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ def correlation
9696
# # dd.env=prod dd.service=auth dd.version=13.8 dd.trace_id=5458478252992251 dd.span_id=7117552347370098 My message
9797
# ```
9898
#
99-
# @return [String] correlation information
99+
# @return [String] correlation information; or an empty String if Tracing is disabled (`!enabled?`)
100100
# @public_api
101101
def log_correlation
102+
return '' unless enabled?
103+
102104
correlation.to_log_format
103105
end
104106

spec/datadog/tracing_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@
106106
expect(log_correlation).to eq(returned)
107107
end
108108
# rubocop:enable RSpec/MessageChain
109+
110+
context 'with tracing disabled' do
111+
before do
112+
allow(Datadog.send(:components).tracer).to receive(:enabled).and_return(false)
113+
end
114+
115+
it 'returns an empty string' do
116+
expect(log_correlation).to eq('')
117+
end
118+
end
109119
end
110120

111121
describe '.shutdown!' do

0 commit comments

Comments
 (0)