Skip to content

Commit

Permalink
Merge pull request #3731 from DataDog/trace-disabled-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Jul 16, 2024
1 parent 63f8b18 commit 8b4b2e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/datadog/tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ def correlation
# # dd.env=prod dd.service=auth dd.version=13.8 dd.trace_id=5458478252992251 dd.span_id=7117552347370098 My message
# ```
#
# @return [String] correlation information
# @return [String] correlation information; or an empty String if Tracing is disabled (`!enabled?`)
# @public_api
def log_correlation
return '' unless enabled?

correlation.to_log_format
end

Expand Down
10 changes: 10 additions & 0 deletions spec/datadog/tracing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@
expect(log_correlation).to eq(returned)
end
# rubocop:enable RSpec/MessageChain

context 'with tracing disabled' do
before do
allow(Datadog.send(:components).tracer).to receive(:enabled).and_return(false)
end

it 'returns an empty string' do
expect(log_correlation).to eq('')
end
end
end

describe '.shutdown!' do
Expand Down

0 comments on commit 8b4b2e7

Please sign in to comment.