Skip to content

Commit 2fc7d24

Browse files
committed
Prefer using activeSpan() over activeScope()
1 parent ebb0e55 commit 2fc7d24

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

dd-java-agent/instrumentation/akka-http/akka-http-10.0/src/main/java/datadog/trace/instrumentation/akkahttp/DatadogServerRequestResponseFlowWrapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package datadog.trace.instrumentation.akkahttp;
22

3-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope;
3+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
44

55
import akka.http.scaladsl.model.HttpRequest;
66
import akka.http.scaladsl.model.HttpResponse;
@@ -142,11 +142,11 @@ public void onPush() throws Exception {
142142
response = newResponse;
143143
}
144144
DatadogWrapperHelper.finishSpan(span, response);
145-
// Check if the active scope is still the scope from when the request came in,
145+
// Check if the active span matches the scope from when the request came in,
146146
// and close it. If it's not, then it will be cleaned up actor message
147147
// processing instrumentation that drives this state machine
148-
AgentScope activeScope = activeScope();
149-
if (activeScope == scope) {
148+
AgentSpan activeSpan = activeSpan();
149+
if (activeSpan == scope.span()) {
150150
scope.close();
151151
}
152152
}

dd-java-agent/instrumentation/pekko-http-1.0/src/main/java/datadog/trace/instrumentation/pekkohttp/DatadogServerRequestResponseFlowWrapper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package datadog.trace.instrumentation.pekkohttp;
22

3-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope;
3+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
44

55
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
6+
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
67
import java.util.Queue;
78
import java.util.concurrent.ArrayBlockingQueue;
89
import org.apache.pekko.http.scaladsl.model.HttpRequest;
@@ -113,11 +114,11 @@ public void onPush() throws Exception {
113114
final AgentScope scope = scopes.poll();
114115
if (scope != null) {
115116
DatadogWrapperHelper.finishSpan(scope.span(), response);
116-
// Check if the active scope is still the scope from when the request came in,
117+
// Check if the active span matches the scope from when the request came in,
117118
// and close it. If it's not, then it will be cleaned up actor message
118119
// processing instrumentation that drives this state machine
119-
AgentScope activeScope = activeScope();
120-
if (activeScope == scope) {
120+
AgentSpan activeSpan = activeSpan();
121+
if (activeSpan == scope.span()) {
121122
scope.close();
122123
}
123124
}

dd-java-agent/instrumentation/sslsocket/src/main/java/datadog/trace/instrumentation/sslsocket/SocketConnectInstrumentation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import datadog.trace.agent.tooling.InstrumenterModule;
1212
import datadog.trace.api.InstrumenterConfig;
1313
import datadog.trace.bootstrap.config.provider.ConfigProvider;
14-
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
14+
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
1515
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
1616
import net.bytebuddy.asm.Advice;
1717

@@ -53,8 +53,8 @@ public static final class DisableWallclockSampling {
5353

5454
@Advice.OnMethodEnter(suppress = Throwable.class)
5555
public static boolean before() {
56-
AgentScope active = AgentTracer.activeScope();
57-
if (active != null) {
56+
AgentSpan activeSpan = AgentTracer.activeSpan();
57+
if (activeSpan != null) {
5858
AgentTracer.get().getProfilingContext().onDetach();
5959
return true;
6060
}

dd-java-agent/instrumentation/undertow/undertow-2.0/src/main/java/datadog/trace/instrumentation/undertow/HandlerInstrumentation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ public static void onEnter(
7272
@Advice.Argument(value = 0, readOnly = false) HttpHandler handler,
7373
@Advice.Argument(1) final HttpServerExchange exchange,
7474
@Advice.Local("agentScope") AgentScope scope) {
75-
AgentScope currentScope = AgentTracer.activeScope();
76-
if (currentScope != null) {
77-
AgentSpan localRootSpan = currentScope.span().getLocalRootSpan();
75+
AgentSpan activeSpan = AgentTracer.activeSpan();
76+
if (activeSpan != null) {
77+
AgentSpan localRootSpan = activeSpan.getLocalRootSpan();
7878
if (DECORATE.spanName().equals(localRootSpan.getSpanName())) {
7979
// if we can here through the dispatch of an HttpHandler, rather than that of a
8080
// plain Runnable, then Connects.executeRootHandler() will still have been called,

0 commit comments

Comments
 (0)