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 authored Jun 26, 2024
2 parents 4d44edd + e5bade4 commit dea7ae9
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 @@ -119,9 +119,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 @@ -136,6 +136,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 dea7ae9

Please sign in to comment.