Skip to content

Commit b187a03

Browse files
authored
Fix continuation metrics (#8635)
Move capture and canceled continuation metrics to the same class (previously we only recorded a canceled continuation metric when pending trace was enabled, not when streaming spans) Fixed finished continuation metric (this was in the wrong place which meant it was only recorded when closing message spans)
1 parent 8e29e20 commit b187a03

File tree

7 files changed

+13
-14
lines changed

7 files changed

+13
-14
lines changed

dd-trace-core/src/main/java/datadog/trace/core/PendingTrace.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,8 @@ public void registerContinuation(final AgentScope.Continuation continuation) {
264264
}
265265

266266
@Override
267-
public void cancelContinuation(final AgentScope.Continuation continuation) {
267+
public void removeContinuation(final AgentScope.Continuation continuation) {
268268
decrementRefAndMaybeWrite(false);
269-
healthMetrics.onCancelContinuation();
270269
}
271270

272271
private PublishState decrementRefAndMaybeWrite(boolean isRootSpan) {

dd-trace-core/src/main/java/datadog/trace/core/StreamingTraceCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void registerContinuation(AgentScope.Continuation continuation) {
8282
}
8383

8484
@Override
85-
public void cancelContinuation(AgentScope.Continuation continuation) {
85+
public void removeContinuation(AgentScope.Continuation continuation) {
8686
// do nothing
8787
}
8888
}

dd-trace-core/src/main/java/datadog/trace/core/scopemanager/ContinuableScopeManager.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ public AgentScope.Continuation captureSpan(final AgentSpan span) {
107107
}
108108

109109
private AgentScope.Continuation captureSpan(final AgentSpan span, byte source) {
110-
ScopeContinuation continuation = new ScopeContinuation(this, span, source);
111-
continuation.register();
112-
healthMetrics.onCaptureContinuation();
113-
return continuation;
110+
return new ScopeContinuation(this, span, source).register();
114111
}
115112

116113
private AgentScope activate(
@@ -207,7 +204,6 @@ public void closePrevious(final boolean finishSpan) {
207204
scopeStack.cleanup();
208205
if (finishSpan) {
209206
top.span.finishWithEndToEnd();
210-
healthMetrics.onFinishContinuation();
211207
}
212208
}
213209
}

dd-trace-core/src/main/java/datadog/trace/core/scopemanager/ScopeContinuation.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ final class ScopeContinuation implements AgentScope.Continuation {
6262

6363
ScopeContinuation register() {
6464
traceCollector.registerContinuation(this);
65+
scopeManager.healthMetrics.onCaptureContinuation();
6566
return this;
6667
}
6768

@@ -95,17 +96,20 @@ public void cancel() {
9596
while (current == 0) {
9697
// no outstanding activations and hold has been removed
9798
if (COUNT.compareAndSet(this, current, CANCELLED)) {
98-
traceCollector.cancelContinuation(this);
99+
traceCollector.removeContinuation(this);
100+
scopeManager.healthMetrics.onFinishContinuation();
99101
return;
100102
}
101103
current = count;
102104
}
105+
scopeManager.healthMetrics.onCancelContinuation();
103106
}
104107

105108
void cancelFromContinuedScopeClose() {
106109
if (COUNT.compareAndSet(this, 1, CANCELLED)) {
107110
// fast path: only one activation of the continuation (no hold)
108-
traceCollector.cancelContinuation(this);
111+
traceCollector.removeContinuation(this);
112+
scopeManager.healthMetrics.onFinishContinuation();
109113
} else if (COUNT.decrementAndGet(this) == 0) {
110114
// slow path: multiple activations, all have now closed (no hold)
111115
cancel();

dd-trace-core/src/test/groovy/datadog/trace/core/PendingTraceStrictWriteTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class PendingTraceStrictWriteTest extends PendingTraceTestBase {
5656

5757
when: "continuation is finished the second time"
5858
// Yes this should be guarded by the used flag in the continuation,
59-
// so cancel it anyway to trigger the exception
60-
traceCollector.cancelContinuation(continuation)
59+
// so remove it anyway to trigger the exception
60+
traceCollector.removeContinuation(continuation)
6161

6262
then:
6363
thrown IllegalStateException

internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/AgentTraceCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
public interface AgentTraceCollector {
44
void registerContinuation(AgentScope.Continuation continuation);
55

6-
void cancelContinuation(AgentScope.Continuation continuation);
6+
void removeContinuation(AgentScope.Continuation continuation);
77
}

internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/AgentTracer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ public static class NoopAgentTraceCollector implements AgentTraceCollector {
679679
public void registerContinuation(final AgentScope.Continuation continuation) {}
680680

681681
@Override
682-
public void cancelContinuation(final AgentScope.Continuation continuation) {}
682+
public void removeContinuation(final AgentScope.Continuation continuation) {}
683683
}
684684

685685
public static class NoopAgentHistogram implements AgentHistogram {

0 commit comments

Comments
 (0)