Skip to content

Commit 34da211

Browse files
committed
Don't confuse trace root with top levels
1 parent 81d8a79 commit 34da211

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

dd-trace-core/src/main/java/datadog/trace/common/metrics/ConflatingMetricsAggregator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ private boolean publish(CoreSpan<?> span, boolean isTopLevel) {
311311
span.getType(),
312312
span.getHttpStatusCode(),
313313
isSynthetic(span),
314-
span.isTopLevel(),
314+
span.getParentId() == 0,
315315
SPAN_KINDS.computeIfAbsent(
316316
spanKind, UTF8BytesString::create), // save repeated utf8 conversions
317317
getPeerTags(span, spanKind.toString()));

dd-trace-core/src/test/groovy/datadog/trace/common/metrics/ConflatingMetricAggregatorTest.groovy

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
126126
"type",
127127
HTTP_OK,
128128
false,
129-
true,
129+
false,
130130
"baz",
131131
[]
132132
), _) >> { MetricKey key, AggregateMetric value ->
@@ -197,7 +197,7 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
197197
features.supportsMetrics() >> true
198198
features.peerTags() >>> [["country"], ["country", "georegion"],]
199199
ConflatingMetricsAggregator aggregator = new ConflatingMetricsAggregator(empty,
200-
features, sink, writer, 10, queueSize, reportingInterval, SECONDS)
200+
features, HealthMetrics.NO_OP, sink, writer, 10, queueSize, reportingInterval, SECONDS)
201201
aggregator.start()
202202

203203
when:
@@ -256,7 +256,7 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
256256
features.supportsMetrics() >> true
257257
features.peerTags() >> ["peer.hostname", "_dd.base_service"]
258258
ConflatingMetricsAggregator aggregator = new ConflatingMetricsAggregator(empty,
259-
features, sink, writer, 10, queueSize, reportingInterval, SECONDS)
259+
features, HealthMetrics.NO_OP, sink, writer, 10, queueSize, reportingInterval, SECONDS)
260260
aggregator.start()
261261

262262
when:
@@ -327,7 +327,7 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
327327
"type",
328328
HTTP_OK,
329329
false,
330-
topLevel,
330+
false,
331331
"baz",
332332
[]
333333
), { AggregateMetric value ->
@@ -444,7 +444,7 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
444444
"type",
445445
HTTP_OK,
446446
false,
447-
true,
447+
false,
448448
"baz",
449449
[]
450450
), _) >> { MetricKey key, AggregateMetric value ->
@@ -458,7 +458,7 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
458458
"type",
459459
HTTP_OK,
460460
false,
461-
true,
461+
false,
462462
"baz",
463463
[]
464464
), _)
@@ -503,7 +503,7 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
503503
"type",
504504
HTTP_OK,
505505
false,
506-
true,
506+
false,
507507
"baz",
508508
[]
509509
), { AggregateMetric value ->
@@ -534,7 +534,7 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
534534
"type",
535535
HTTP_OK,
536536
false,
537-
true,
537+
false,
538538
"baz",
539539
[]
540540
), { AggregateMetric value ->
@@ -548,7 +548,7 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
548548
"type",
549549
HTTP_OK,
550550
false,
551-
true,
551+
false,
552552
"baz",
553553
[]
554554
), _)
@@ -593,7 +593,7 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
593593
"type",
594594
HTTP_OK,
595595
false,
596-
true,
596+
false,
597597
"quux",
598598
[]
599599
), { AggregateMetric value ->
@@ -631,7 +631,7 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
631631
CountDownLatch latch = new CountDownLatch(1)
632632
for (int i = 0; i < 5; ++i) {
633633
aggregator.publish([
634-
new SimpleSpan("service" + i, "operation", "resource", "type", false, true, false, 0, duration, HTTP_OK)
634+
new SimpleSpan("service" + i, "operation", "resource", "type", false, true, false, 0, duration, HTTP_OK, true)
635635
.setTag(SPAN_KIND, "garply")
636636
])
637637
}

dd-trace-core/src/test/groovy/datadog/trace/common/metrics/SimpleSpan.groovy

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class SimpleSpan implements CoreSpan<SimpleSpan> {
1313
private final String type
1414
private final boolean measured
1515
private final boolean topLevel
16+
private final boolean traceRoot
1617
private final boolean error
1718
private final short statusCode
1819

@@ -31,14 +32,16 @@ class SimpleSpan implements CoreSpan<SimpleSpan> {
3132
boolean error,
3233
long startTime,
3334
long duration,
34-
int statusCode
35+
int statusCode,
36+
boolean traceRoot = false
3537
) {
3638
this.serviceName = serviceName
3739
this.operationName = operationName
3840
this.resourceName = resourceName
3941
this.type = type
4042
this.measured = measured
4143
this.topLevel = topLevel
44+
this.traceRoot = traceRoot
4245
this.error = error
4346
this.startTime = startTime
4447
this.duration = duration
@@ -77,7 +80,7 @@ class SimpleSpan implements CoreSpan<SimpleSpan> {
7780

7881
@Override
7982
long getParentId() {
80-
return DDSpanId.ZERO
83+
return traceRoot ? DDSpanId.ZERO : 1L
8184
}
8285

8386
@Override

0 commit comments

Comments
 (0)