Skip to content

Commit

Permalink
Merge pull request #4075 from DataDog/munir/fix-version-tagging
Browse files Browse the repository at this point in the history
fix: Apply DD_VERSION on all spans that use the default or global service name
  • Loading branch information
marcotc authored and TonyCTHsu committed Nov 28, 2024
1 parent 7b5fef3 commit aefcf1b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/datadog/tracing/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def resolve_tags(tags, service)
tags || @tags.dup
end
# Remove version tag if service is not the default service
if merged_tags.key?(Core::Environment::Ext::TAG_VERSION) && service != @default_service
if merged_tags.key?(Core::Environment::Ext::TAG_VERSION) && service && service != @default_service
merged_tags.delete(Core::Environment::Ext::TAG_VERSION)
end
merged_tags
Expand Down
48 changes: 39 additions & 9 deletions spec/datadog/tracing/tracer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,45 @@
expect(span.get_tag('my')).to eq('tag')
end

context 'contains version and span.service is not equal to the default tracer service' do
let(:tracer_options) { { default_service: 'global-service', tags: { version: '1.1.0' } } }
let(:service) { 'my-service' }
it 'does not set version on the span' do
expect(tracer.default_service).to eq('global-service')
expect(span.service).not_to eq('my-service')

expect(tracer.tags).to include(version: '1.1.0')
expect(span.tags).not_to include(:version)
context 'contains version and the span service name' do
let(:tracer_options) do
{ default_service: 'global-service', tags: { Datadog::Core::Environment::Ext::TAG_VERSION => '1.1.0' } }
end
let(:options) { { service: service } }

context 'is nil' do
let(:service) { nil }

it 'sets version' do
expect(tracer.default_service).to eq('global-service')
expect(span.service).to eq('global-service')

expect(tracer.tags).to include('version' => '1.1.0')
expect(span.tags).to include('version' => '1.1.0')
end
end

context 'is equal to the default tracer service' do
let(:service) { 'global-service' }

it 'sets version' do
expect(tracer.default_service).to eq('global-service')
expect(span.service).to eq('global-service')

expect(tracer.tags).to include('version' => '1.1.0')
expect(span.tags).to include('version' => '1.1.0')
end
end

context 'is not equal to the default tracer service' do
let(:service) { 'local-service' }
it 'does not set version' do
expect(tracer.default_service).to eq('global-service')
expect(span.service).to eq('local-service')

expect(tracer.tags).to include('version' => '1.1.0')
expect(span.tags).not_to include('version' => '1.1.0')
end
end
end

Expand Down

0 comments on commit aefcf1b

Please sign in to comment.