From 8b4b2e77697fb381c4419519d9e9b5f2a0ac7337 Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Wed, 26 Jun 2024 15:11:19 -0400 Subject: [PATCH] Merge pull request #3731 from DataDog/trace-disabled-fix --- lib/datadog/tracing.rb | 4 +++- spec/datadog/tracing_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing.rb b/lib/datadog/tracing.rb index 26cbd3ddadb..12001319861 100644 --- a/lib/datadog/tracing.rb +++ b/lib/datadog/tracing.rb @@ -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 diff --git a/spec/datadog/tracing_spec.rb b/spec/datadog/tracing_spec.rb index dfd63111196..74914b6ea7b 100644 --- a/spec/datadog/tracing_spec.rb +++ b/spec/datadog/tracing_spec.rb @@ -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