diff --git a/lib/datadog/core/utils/safe_dup.rb b/lib/datadog/core/utils/safe_dup.rb index d0c064c76d4..33d20c11998 100644 --- a/lib/datadog/core/utils/safe_dup.rb +++ b/lib/datadog/core/utils/safe_dup.rb @@ -24,10 +24,18 @@ def self.frozen_or_dup(v) # - then it will dup it more efficiently with +v v.frozen? ? v : +(-v) end + + def self.frozen_dup(v) + -v if v + end else def self.frozen_or_dup(v) v.frozen? ? v : v.dup end + + def self.frozen_dup(v) + v.frozen? ? v : v.dup.freeze + end end end end diff --git a/lib/datadog/tracing/correlation.rb b/lib/datadog/tracing/correlation.rb index 65dde53bf10..67d5a12ca84 100644 --- a/lib/datadog/tracing/correlation.rb +++ b/lib/datadog/tracing/correlation.rb @@ -46,18 +46,18 @@ def initialize( version: nil ) # Dup and freeze strings so they aren't modified by reference. - @env = Core::Utils::SafeDup.frozen_or_dup(env || Datadog.configuration.env).freeze - @service = Core::Utils::SafeDup.frozen_or_dup(service || Datadog.configuration.service).freeze + @env = Core::Utils::SafeDup.frozen_dup(env || Datadog.configuration.env) + @service = Core::Utils::SafeDup.frozen_dup(service || Datadog.configuration.service) @span_id = span_id || 0 - @span_name = Core::Utils::SafeDup.frozen_or_dup(span_name).freeze - @span_resource = Core::Utils::SafeDup.frozen_or_dup(span_resource).freeze - @span_service = Core::Utils::SafeDup.frozen_or_dup(span_service).freeze - @span_type = Core::Utils::SafeDup.frozen_or_dup(span_type).freeze + @span_name = Core::Utils::SafeDup.frozen_dup(span_name) + @span_resource = Core::Utils::SafeDup.frozen_dup(span_resource) + @span_service = Core::Utils::SafeDup.frozen_dup(span_service) + @span_type = Core::Utils::SafeDup.frozen_dup(span_type) @trace_id = trace_id || 0 - @trace_name = Core::Utils::SafeDup.frozen_or_dup(trace_name).freeze - @trace_resource = Core::Utils::SafeDup.frozen_or_dup(trace_resource).freeze - @trace_service = Core::Utils::SafeDup.frozen_or_dup(trace_service).freeze - @version = Core::Utils::SafeDup.frozen_or_dup(version || Datadog.configuration.version).freeze + @trace_name = Core::Utils::SafeDup.frozen_dup(trace_name) + @trace_resource = Core::Utils::SafeDup.frozen_dup(trace_resource) + @trace_service = Core::Utils::SafeDup.frozen_dup(trace_service) + @version = Core::Utils::SafeDup.frozen_dup(version || Datadog.configuration.version) end def to_log_format