Skip to content

Commit

Permalink
[opentracing] Mark datadog_span.status = 1 when set_tag('error', true) (
Browse files Browse the repository at this point in the history
#739)

* [opentracing] Mark datadog_span.status = 1 when set_tag('error', true)

* use single quoted strings instead of double
  • Loading branch information
brettlangdon authored Apr 17, 2019
1 parent 67bc474 commit 0d08e84
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lib/ddtrace/opentracer/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ def context
# @param value [String, Numeric, Boolean] the value of the tag. If it's not
# a String, Numeric, or Boolean it will be encoded with to_s
def set_tag(key, value)
# Special cases to convert opentracing tags to datadog tags
case key
when 'error'
# Opentracing supports and `error: <bool>` tag, we need to convert to span status
# DEV: Do not return, we want to still set the `error` tag as they requested
datadog_span.status = value ? Datadog::Ext::Errors::STATUS : 0
end

tap { datadog_span.set_tag(key, value) }
end

Expand Down
33 changes: 29 additions & 4 deletions spec/ddtrace/opentracer/span_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,35 @@

describe '#set_tag' do
subject(:result) { span.set_tag(key, value) }
let(:key) { 'account_id' }
let(:value) { '1234' }
before(:each) { expect(datadog_span).to receive(:set_tag).with(key, value) }
it { is_expected.to be(span) }

context 'when given arbitrary tag key and value' do
let(:key) { 'account_id' }
let(:value) { '1234' }

before(:each) { expect(datadog_span).to receive(:set_tag).with(key, value) }

it { is_expected.to be(span) }
end

context 'when given an error tag of true' do
let(:key) { 'error' }
let(:value) { true }

before(:each) { expect(datadog_span).to receive(:set_tag).with(key, value) }
before(:each) { expect(datadog_span).to receive(:'status=').with(Datadog::Ext::Errors::STATUS) }

it { is_expected.to be(span) }
end

context 'when given an error tag of false' do
let(:key) { 'error' }
let(:value) { false }

before(:each) { expect(datadog_span).to receive(:set_tag).with(key, value) }
before(:each) { expect(datadog_span).to receive(:'status=').with(0) }

it { is_expected.to be(span) }
end
end

describe '#set_baggage_item' do
Expand Down

0 comments on commit 0d08e84

Please sign in to comment.