Skip to content

Commit

Permalink
Merge pull request #4027 from DataDog/munir/remove-version-tag-in-som…
Browse files Browse the repository at this point in the history
…e-scenarios
  • Loading branch information
marcotc authored Oct 25, 2024
2 parents 321f513 + a8025b1 commit 96294fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/datadog/tracing/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,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 @@ -420,7 +420,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 @@ -432,15 +432,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' } } }
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

0 comments on commit 96294fa

Please sign in to comment.