Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport: Return empty log correlation when tracing is disabled #3731 #3788

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading