Skip to content

Commit ec417da

Browse files
committed
realign promise helper
1 parent 5a10177 commit ec417da

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

  • dd-java-agent/instrumentation/scala/scala-promise/scala-promise-common/src/main/java/datadog/trace/instrumentation/scala

dd-java-agent/instrumentation/scala/scala-promise/scala-promise-common/src/main/java/datadog/trace/instrumentation/scala/PromiseHelper.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,23 @@ public static <K> State executeCaptureSpan(
105105
K task,
106106
State state) {
107107
final AgentSpan span = spanFromContext(tryStore.get(resolved));
108-
if (span != null && state.getSpan() == span) {
109-
return state;
110-
}
111-
AgentScope.Continuation continuation = captureSpan(span);
112-
AgentScope.Continuation existing = null;
113-
if (null != state) {
114-
existing = state.getAndResetContinuation();
115-
} else {
116-
state = State.FACTORY.create();
117-
taskStore.put(task, state);
118-
}
119-
state.setOrCancelContinuation(continuation);
120-
if (null != existing) {
121-
existing.cancel();
108+
if (span != null) {
109+
// Check if the new Span is the same as the currently stored one
110+
if (null != state && state.getSpan() == span) {
111+
return state;
112+
}
113+
AgentScope.Continuation continuation = captureSpan(span);
114+
AgentScope.Continuation existing = null;
115+
if (null != state) {
116+
existing = state.getAndResetContinuation();
117+
} else {
118+
state = State.FACTORY.create();
119+
taskStore.put(task, state);
120+
}
121+
state.setOrCancelContinuation(continuation);
122+
if (null != existing) {
123+
existing.cancel();
124+
}
122125
}
123126
return state;
124127
}

0 commit comments

Comments
 (0)