Skip to content

Commit

Permalink
Fix overlooked reference to previous tag instance variable
Browse files Browse the repository at this point in the history
  • Loading branch information
lloeki committed Apr 14, 2022
1 parent f4ff9df commit f92df7e
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/datadog/tracing/trace_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def initialize(
sampled: nil,
sampling_priority: nil,
service: nil,
tags: nil
tags: nil,
metrics: nil
)
# Attributes
@events = events || Events.new
Expand All @@ -90,6 +91,7 @@ def initialize(

# Generic tags
set_tags(tags) if tags
set_tags(metrics) if metrics

# State
@root_span = nil
Expand Down Expand Up @@ -269,7 +271,8 @@ def fork_clone
sampled: @sampled,
sampling_priority: @sampling_priority,
service: (@service && @service.dup),
tags: @tags.dup
tags: meta.dup,
metrics: metrics.dup
)
end

Expand Down
76 changes: 75 additions & 1 deletion spec/datadog/tracing/trace_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
sample_rate: sample_rate,
sampled: sampled,
sampling_priority: sampling_priority,
service: service
service: service,
tags: tags,
metrics: metrics
}
end

Expand All @@ -46,6 +48,8 @@
let(:sampled) { true }
let(:sampling_priority) { Datadog::Tracing::Sampling::Ext::Priority::USER_KEEP }
let(:service) { 'billing-api' }
let(:tags) { { 'foo' => 'bar' } }
let(:metrics) { { 'baz' => 42.0 } }
end

shared_examples 'a span with default events' do
Expand Down Expand Up @@ -73,6 +77,14 @@
service: nil
)
end

it do
expect(trace_op.send(:meta)).to eq({})
end

it do
expect(trace_op.send(:metrics)).to eq({})
end
end

context 'given' do
Expand Down Expand Up @@ -173,6 +185,20 @@

it { expect(trace_op.service).to eq(service) }
end

context ':tags' do
subject(:options) { { tags: tags } }
let(:tags) { { 'foo' => 'bar' } }

it { expect(trace_op.send(:meta)).to eq({ 'foo' => 'bar' }) }
end

context ':metrics' do
subject(:options) { { metrics: metrics } }
let(:metrics) { { 'baz' => 42.0 } }

it { expect(trace_op.send(:metrics)).to eq({ 'baz' => 42.0 }) }
end
end
end

Expand Down Expand Up @@ -1770,6 +1796,14 @@ def span
)
end

it 'maintains the same tags' do
expect(new_trace_op.send(:meta)).to eq({ 'foo' => 'bar' })
end

it 'maintains the same metrics' do
expect(new_trace_op.send(:metrics)).to eq({ 'baz' => 42.0 })
end

it 'maintains the same events' do
old_events = trace_op.send(:events)
new_events = new_trace_op.send(:events)
Expand Down Expand Up @@ -1832,6 +1866,14 @@ def span
)
end

it 'maintains the same tags' do
expect(new_trace_op.send(:meta)).to eq({ 'foo' => 'bar' })
end

it 'maintains the same metrics' do
expect(new_trace_op.send(:metrics)).to eq({ 'baz' => 42.0 })
end

context 'and :parent_span_id has been defined' do
let(:options) { { parent_span_id: parent_span_id } }
let(:parent_span_id) { Datadog::Core::Utils.next_id }
Expand Down Expand Up @@ -1872,6 +1914,14 @@ def span
service: be_a_copy_of(service)
)
end

it 'maintains the same tags' do
expect(new_trace_op.send(:meta)).to eq({ 'foo' => 'bar' })
end

it 'maintains the same metrics' do
expect(new_trace_op.send(:metrics)).to eq({ 'baz' => 42.0 })
end
end

context 'that has started' do
Expand Down Expand Up @@ -1903,6 +1953,14 @@ def span
service: be_a_copy_of(service)
)
end

it 'maintains the same tags' do
expect(new_trace_op.send(:meta)).to eq({ 'foo' => 'bar' })
end

it 'maintains the same metrics' do
expect(new_trace_op.send(:metrics)).to eq({ 'baz' => 42.0 })
end
end

context 'that has finished' do
Expand Down Expand Up @@ -1934,6 +1992,14 @@ def span
service: be_a_copy_of(service)
)
end

it 'maintains the same tags' do
expect(new_trace_op.send(:meta)).to eq({ 'foo' => 'bar' })
end

it 'maintains the same metrics' do
expect(new_trace_op.send(:metrics)).to eq({ 'baz' => 42.0 })
end
end
end

Expand Down Expand Up @@ -1976,6 +2042,14 @@ def span
)
end

it 'maintains the same tags' do
expect(new_trace_op.send(:meta)).to eq({ 'foo' => 'bar' })
end

it 'maintains the same metrics' do
expect(new_trace_op.send(:metrics)).to eq({ 'baz' => 42.0 })
end

context 'and :parent_span_id has been defined' do
let(:options) { { parent_span_id: parent_span_id } }
let(:parent_span_id) { Datadog::Core::Utils.next_id }
Expand Down
14 changes: 14 additions & 0 deletions spec/datadog/tracing/trace_segment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@

it { is_expected.to have_attributes(service: be_a_copy_of(service)) }
end

context ':tags' do
let(:options) { { tags: tags } }
let(:tags) { { 'foo' => 'bar' } }

it { expect(trace_segment.send(:meta)).to eq({ 'foo' => 'bar' }) }
end

context ':metrics' do
let(:options) { { metrics: metrics } }
let(:metrics) { { 'foo' => 42.0 } }

it { expect(trace_segment.send(:metrics)).to eq({ 'foo' => 42.0 }) }
end
end

context 'given tags' do
Expand Down

0 comments on commit f92df7e

Please sign in to comment.