Skip to content

Commit 4a5a1e2

Browse files
mccullsdevflow.devflow-routing-intake
andauthored
Remove AgentTracer.noopScope() sentinel from advice call sites (#12010)
Remove AgentTracer.noopScope() sentinel from advice call sites Replace noopScope() with null where the returned scope has no observable side effects to preserve. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent c66a0b5 commit 4a5a1e2

5 files changed

Lines changed: 11 additions & 11 deletions

File tree

dd-java-agent/instrumentation/netty/netty-4.0/src/main/java/datadog/trace/instrumentation/netty40/NettyChannelHandlerContextInstrumentation.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
66
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
77
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
8-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
98
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.spanFromContext;
109
import static datadog.trace.instrumentation.netty40.AttributeKeys.CONTEXT_ATTRIBUTE_KEY;
1110
import static datadog.trace.instrumentation.netty40.NettyChannelPipelineInstrumentation.ADDITIONAL_INSTRUMENTATION_NAMES;
@@ -75,14 +74,16 @@ public static AgentScope scopeSpan(@Advice.This final ChannelHandlerContext ctx)
7574
final AgentSpan channelSpan = spanFromContext(storedContext);
7675
if (channelSpan == null || channelSpan == activeSpan()) {
7776
// don't modify the scope
78-
return noopScope();
77+
return null;
7978
}
8079
return activateSpan(channelSpan);
8180
}
8281

8382
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
8483
public static void close(@Advice.Enter final AgentScope scope) {
85-
scope.close();
84+
if (scope != null) {
85+
scope.close();
86+
}
8687
}
8788

8889
private void muzzleCheck() {

dd-java-agent/instrumentation/netty/netty-4.1/src/main/java/datadog/trace/instrumentation/netty41/NettyChannelHandlerContextInstrumentation.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
66
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
77
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
8-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
98
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.spanFromContext;
109
import static datadog.trace.instrumentation.netty41.AttributeKeys.CONTEXT_ATTRIBUTE_KEY;
1110
import static datadog.trace.instrumentation.netty41.NettyChannelPipelineInstrumentation.ADDITIONAL_INSTRUMENTATION_NAMES;
@@ -75,14 +74,16 @@ public static AgentScope scopeSpan(@Advice.This final ChannelHandlerContext ctx)
7574
final AgentSpan channelSpan = spanFromContext(storedContext);
7675
if (channelSpan == null || channelSpan == activeSpan()) {
7776
// don't modify the scope
78-
return noopScope();
77+
return null;
7978
}
8079
return activateSpan(channelSpan);
8180
}
8281

8382
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
8483
public static void close(@Advice.Enter final AgentScope scope) {
85-
scope.close();
84+
if (scope != null) {
85+
scope.close();
86+
}
8687
}
8788

8889
private void muzzleCheck() {

dd-java-agent/instrumentation/vertx/vertx-web/vertx-web-3.4/src/main/java/datadog/trace/instrumentation/vertx_3_4/server/RouteHandlerWrapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
44
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
5-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
65
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
76
import static datadog.trace.bootstrap.instrumentation.decorator.http.HttpResourceDecorator.HTTP_RESOURCE_DECORATOR;
87
import static datadog.trace.instrumentation.vertx_3_4.server.VertxDecorator.DECORATE;
@@ -62,7 +61,7 @@ public void handle(final RoutingContext routingContext) {
6261
}
6362
setRoute(routingContext);
6463
}
65-
try (final ContextScope scope = span != null ? activateSpan(span) : noopScope()) {
64+
try (final ContextScope scope = span != null ? activateSpan(span) : null) {
6665
try {
6766
actual.handle(routingContext);
6867
} catch (final Throwable t) {

dd-java-agent/instrumentation/vertx/vertx-web/vertx-web-4.0/src/main/java/datadog/trace/instrumentation/vertx_4_0/server/RouteHandlerWrapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
44
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
5-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
65
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
76
import static datadog.trace.bootstrap.instrumentation.decorator.http.HttpResourceDecorator.HTTP_RESOURCE_DECORATOR;
87
import static datadog.trace.instrumentation.vertx_4_0.server.VertxDecorator.DECORATE;
@@ -61,7 +60,7 @@ public void handle(final RoutingContext routingContext) {
6160
setRoute(routingContext);
6261
}
6362

64-
try (final ContextScope scope = span != null ? activateSpan(span) : noopScope()) {
63+
try (final ContextScope scope = span != null ? activateSpan(span) : null) {
6564
try {
6665
actual.handle(routingContext);
6766
} catch (final Throwable t) {

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
@@ -670,7 +670,7 @@ public Context currentContext() {
670670

671671
@Override
672672
public ContextScope attach(Context context) {
673-
return noopScope();
673+
return NoopScope.INSTANCE;
674674
}
675675

676676
@Override

0 commit comments

Comments
 (0)