Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove version tag if dd_service is not applied #4027

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions lib/datadog/tracing/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def start_span(
on_error: on_error,
resource: resource,
service: service,
tags: resolve_tags(tags),
tags: resolve_tags(tags, service),
type: type,
id: id,
&block
Expand All @@ -408,7 +408,7 @@ def start_span(
resource: resource,
service: service,
start_time: start_time,
tags: resolve_tags(tags),
tags: resolve_tags(tags, service),
type: type,
id: id
)
Expand All @@ -420,15 +420,20 @@ def start_span(
end
# rubocop:enable Lint/UnderscorePrefixedVariableName

def resolve_tags(tags)
if @tags.any? && tags
# Combine default tags with provided tags,
# preferring provided tags.
@tags.merge(tags)
else
# Use provided tags or default tags if none.
tags || @tags.dup
def resolve_tags(tags, service)
merged_tags = if @tags.any? && tags
# Combine default tags with provided tags,
# preferring provided tags.
@tags.merge(tags)
else
# Use provided tags or default tags if none.
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
merged_tags.delete(Core::Environment::Ext::TAG_VERSION)
end
merged_tags
end

# Manually activate and deactivate the trace, when the span completes.
Expand Down
12 changes: 12 additions & 0 deletions spec/datadog/tracing/tracer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@
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' } } }
mabdinur marked this conversation as resolved.
Show resolved Hide resolved
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')
end
end

context 'and default tags are set on the tracer' do
let(:tracer_options) { { tags: default_tags } }

Expand Down
Loading