Skip to content

Commit

Permalink
Remove Core::Utils::SafeDup.frozen_dup
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Apr 11, 2024
1 parent a00c911 commit 64499fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 34 deletions.
7 changes: 3 additions & 4 deletions lib/datadog/tracing/correlation.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require_relative 'utils'
require_relative 'metadata/ext'
require_relative '../core/logging/ext'

module Datadog
Expand Down Expand Up @@ -36,11 +35,11 @@ def initialize(
version: nil
)
# Dup and freeze strings so they aren't modified by reference.
@env = Core::Utils::SafeDup.frozen_dup(env || Datadog.configuration.env)
@service = Core::Utils::SafeDup.frozen_dup(service || Datadog.configuration.service)
@env = env || Datadog.configuration.env
@service = service || Datadog.configuration.service
@span_id = (span_id || 0).to_s
@trace_id = trace_id || 0
@version = Core::Utils::SafeDup.frozen_dup(version || Datadog.configuration.version)
@version = version || Datadog.configuration.version
end

def to_h
Expand Down
46 changes: 16 additions & 30 deletions spec/datadog/tracing/correlation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@
let(:env) { 'dev' }
let(:service) { 'acme-api' }
let(:span_id) { Datadog::Tracing::Utils.next_id }
let(:span_name) { 'active_record.sql' }
let(:span_resource) { 'SELECT * FROM users;' }
let(:span_service) { 'acme-mysql' }
let(:span_type) { 'db' }
let(:trace_id) { Datadog::Tracing::Utils::TraceId.next_id }
let(:trace_name) { 'rack.request' }
let(:trace_resource) { 'GET /users' }
let(:trace_service) { 'acme-api' }
let(:version) { '0.1' }
end

Expand All @@ -52,10 +45,10 @@
)
end

it 'has frozen copies of strings' do
expect(identifier.env).to be_a_frozen_copy_of(default_env)
expect(identifier.service).to be_a_frozen_copy_of(default_service)
expect(identifier.version).to be_a_frozen_copy_of(default_version)
it 'has strings' do
expect(identifier.env).to eq(default_env)
expect(identifier.service).to eq(default_service)
expect(identifier.version).to eq(default_version)
end
end

Expand All @@ -66,14 +59,7 @@
instance_double(
Datadog::Tracing::TraceDigest,
span_id: span_id,
span_name: span_name,
span_resource: span_resource,
span_service: span_service,
span_type: span_type,
trace_id: trace_id,
trace_name: trace_name,
trace_resource: trace_resource,
trace_service: trace_service
)
end

Expand All @@ -87,10 +73,10 @@
)
end

it 'has frozen copies of strings' do
expect(identifier.env).to be_a_frozen_copy_of(default_env)
expect(identifier.service).to be_a_frozen_copy_of(default_service)
expect(identifier.version).to be_a_frozen_copy_of(default_version)
it 'has strings' do
expect(identifier.env).to eq(default_env)
expect(identifier.service).to eq(default_service)
expect(identifier.version).to eq(default_version)
end
end
end
Expand All @@ -110,10 +96,10 @@
)
end

it 'has frozen copies of strings' do
expect(identifier.env).to be_a_frozen_copy_of(default_env)
expect(identifier.service).to be_a_frozen_copy_of(default_service)
expect(identifier.version).to be_a_frozen_copy_of(default_version)
it 'has strings' do
expect(identifier.env).to eq(default_env)
expect(identifier.service).to eq(default_service)
expect(identifier.version).to eq(default_version)
end
end

Expand All @@ -140,10 +126,10 @@
)
end

it 'has frozen copies of strings' do
expect(identifier.env).to be_a_frozen_copy_of(env)
expect(identifier.service).to be_a_frozen_copy_of(service)
expect(identifier.version).to be_a_frozen_copy_of(version)
it 'has strings' do
expect(identifier.env).to eq(env)
expect(identifier.service).to eq(service)
expect(identifier.version).to eq(version)
end
end
end
Expand Down

0 comments on commit 64499fa

Please sign in to comment.