Skip to content

Commit 640b62e

Browse files
authored
Merge pull request #2137 from DataDog/compute-top-level
Compute top-level span in tracer
2 parents 4808414 + 7359c15 commit 640b62e

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

lib/datadog/tracing/metadata/ext.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ module Ext
2222

2323
TAG_KIND = 'span.kind'
2424

25+
# Set this tag to `1.0` if the span is a Service Entry span.
26+
TAG_TOP_LEVEL = '_dd.top_level'
27+
2528
# Defines constants for trace analytics
2629
# @public_api
2730
module Analytics

lib/datadog/tracing/span.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ def initialize(
110110
@duration = duration
111111

112112
@service_entry = service_entry
113+
114+
# Mark with the service entry span metric, if applicable
115+
set_metric(Metadata::Ext::TAG_TOP_LEVEL, 1.0) if service_entry
113116
end
114117

115118
# Return whether the duration is started or not

spec/datadog/tracing/span_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,32 @@
5151
end
5252
end
5353
end
54+
55+
context 'service_entry' do
56+
context 'with nil' do
57+
let(:span_options) { { service_entry: nil } }
58+
59+
it 'does not tag as top-level' do
60+
expect(span).to_not have_metadata('_dd.top_level')
61+
end
62+
end
63+
64+
context 'with false' do
65+
let(:span_options) { { service_entry: false } }
66+
67+
it 'does not tag as top-level' do
68+
expect(span).to_not have_metadata('_dd.top_level')
69+
end
70+
end
71+
72+
context 'with true' do
73+
let(:span_options) { { service_entry: true } }
74+
75+
it 'tags as top-level' do
76+
expect(span).to have_metadata('_dd.top_level' => 1.0)
77+
end
78+
end
79+
end
5480
end
5581

5682
context 'ids' do

0 commit comments

Comments
 (0)