diff --git a/lib/datadog/tracing/trace_operation.rb b/lib/datadog/tracing/trace_operation.rb index 54f16a0e3ff..8bdcd39ffd8 100644 --- a/lib/datadog/tracing/trace_operation.rb +++ b/lib/datadog/tracing/trace_operation.rb @@ -67,7 +67,8 @@ def initialize( sampled: nil, sampling_priority: nil, service: nil, - tags: nil + tags: nil, + metrics: nil ) # Attributes @events = events || Events.new @@ -90,6 +91,7 @@ def initialize( # Generic tags set_tags(tags) if tags + set_tags(metrics) if metrics # State @root_span = nil @@ -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 diff --git a/spec/datadog/tracing/trace_operation_spec.rb b/spec/datadog/tracing/trace_operation_spec.rb index 96c0abe525e..dda4ee98d64 100644 --- a/spec/datadog/tracing/trace_operation_spec.rb +++ b/spec/datadog/tracing/trace_operation_spec.rb @@ -30,7 +30,9 @@ sample_rate: sample_rate, sampled: sampled, sampling_priority: sampling_priority, - service: service + service: service, + tags: tags, + metrics: metrics } end @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 } @@ -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 @@ -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 @@ -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 @@ -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 } diff --git a/spec/datadog/tracing/trace_segment_spec.rb b/spec/datadog/tracing/trace_segment_spec.rb index 7163d616afd..11c90e354c5 100644 --- a/spec/datadog/tracing/trace_segment_spec.rb +++ b/spec/datadog/tracing/trace_segment_spec.rb @@ -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