Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block propagation in akka-http to Future that completes on shutdown #2320

Merged
merged 1 commit into from
Jan 21, 2021
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 @@ -19,6 +19,10 @@ import spock.lang.Timeout

@Timeout(5)
abstract class AkkaHttpClientInstrumentationTest extends HttpClientTest {
@Override
boolean useStrictTraceWrites() {
return true
}

@Shared
ActorSystem system = ActorSystem.create()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package datadog.trace.instrumentation.akkahttp;

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.noopSpan;

import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import java.util.Collections;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

@Slf4j
@AutoService(Instrumenter.class)
public final class AkkaPoolMasterActorInstrumentation extends Instrumenter.Tracing {
public AkkaPoolMasterActorInstrumentation() {
super("akka-http", "akka-http-client");
}

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return named("akka.http.impl.engine.client.PoolMasterActor");
}

@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
// This is how scala names a method that is private to a class but is used in a PartialFunction
return Collections.singletonMap(
named("akka$http$impl$engine$client$PoolMasterActor$$startPoolInterface"),
AkkaPoolMasterActorInstrumentation.class.getName() + "$BlockPropagation");
}

/**
* This instrumentation ensures that the creation of a pool doesn't attach the current {@code
* Scope} to the {@code onComplete} of the {@code Future} that is only completed when the
* interface is shut down. This means that the {@code Trace} will finish fast, and not wait for
* the flush to happen.
*/
public static class BlockPropagation {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static AgentScope enter() {
return activateSpan(noopSpan());
}

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