Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.spanFromContext;
import static datadog.trace.instrumentation.netty40.AttributeKeys.CONTEXT_ATTRIBUTE_KEY;
import static datadog.trace.instrumentation.netty40.NettyChannelPipelineInstrumentation.ADDITIONAL_INSTRUMENTATION_NAMES;
Expand Down Expand Up @@ -75,14 +74,16 @@ public static AgentScope scopeSpan(@Advice.This final ChannelHandlerContext ctx)
final AgentSpan channelSpan = spanFromContext(storedContext);
if (channelSpan == null || channelSpan == activeSpan()) {
// don't modify the scope
return noopScope();
return null;

@mcculls mcculls Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note returning noopScope() had no effect on the active scope (unlike activating noopSpan) - so returning null instead has the same behaviour, and matches the convention in the rest of the codebase.

}
return activateSpan(channelSpan);
}

@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
public static void close(@Advice.Enter final AgentScope scope) {
scope.close();
if (scope != null) {
scope.close();
}
}

private void muzzleCheck() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.spanFromContext;
import static datadog.trace.instrumentation.netty41.AttributeKeys.CONTEXT_ATTRIBUTE_KEY;
import static datadog.trace.instrumentation.netty41.NettyChannelPipelineInstrumentation.ADDITIONAL_INSTRUMENTATION_NAMES;
Expand Down Expand Up @@ -75,14 +74,16 @@ public static AgentScope scopeSpan(@Advice.This final ChannelHandlerContext ctx)
final AgentSpan channelSpan = spanFromContext(storedContext);
if (channelSpan == null || channelSpan == activeSpan()) {
// don't modify the scope
return noopScope();
return null;
}
return activateSpan(channelSpan);
}

@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
public static void close(@Advice.Enter final AgentScope scope) {
scope.close();
if (scope != null) {
scope.close();
}
}

private void muzzleCheck() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.bootstrap.instrumentation.decorator.http.HttpResourceDecorator.HTTP_RESOURCE_DECORATOR;
import static datadog.trace.instrumentation.vertx_3_4.server.VertxDecorator.DECORATE;
Expand Down Expand Up @@ -62,7 +61,7 @@ public void handle(final RoutingContext routingContext) {
}
setRoute(routingContext);
}
try (final ContextScope scope = span != null ? activateSpan(span) : noopScope()) {
try (final ContextScope scope = span != null ? activateSpan(span) : null) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this is safe - try-with-resources allows use of null without causing an NPE

try {
actual.handle(routingContext);
} catch (final Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.bootstrap.instrumentation.decorator.http.HttpResourceDecorator.HTTP_RESOURCE_DECORATOR;
import static datadog.trace.instrumentation.vertx_4_0.server.VertxDecorator.DECORATE;
Expand Down Expand Up @@ -61,7 +60,7 @@ public void handle(final RoutingContext routingContext) {
setRoute(routingContext);
}

try (final ContextScope scope = span != null ? activateSpan(span) : noopScope()) {
try (final ContextScope scope = span != null ? activateSpan(span) : null) {
try {
actual.handle(routingContext);
} catch (final Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ public Context currentContext() {

@Override
public ContextScope attach(Context context) {
return noopScope();
return NoopScope.INSTANCE;
}

@Override
Expand Down
Loading