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

migrate to indy scala concurrent plugin #1367

Merged
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 @@ -22,10 +22,9 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.scala.concurrent;
package co.elastic.apm.agent.scalaconcurrent;

import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
import co.elastic.apm.agent.bci.VisibleForAdvice;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import net.bytebuddy.asm.Advice;
Expand All @@ -44,7 +43,6 @@

public abstract class FutureInstrumentation extends TracerAwareInstrumentation {

@VisibleForAdvice
@SuppressWarnings("WeakerAccess")
public static final WeakConcurrentMap<Object, AbstractSpan<?>> promisesToContext =
new WeakConcurrentMap.WithInlinedExpunction<>();
Expand All @@ -55,11 +53,6 @@ public Collection<String> getInstrumentationGroupNames() {
return Arrays.asList("scala-future", "experimental");
}

@Override
public boolean indyPlugin() {
return false;
}

public static class ConstructorInstrumentation extends FutureInstrumentation {

@Override
Expand All @@ -72,7 +65,7 @@ public ElementMatcher<? super MethodDescription> getMethodMatcher() {
return isConstructor();
}

@Advice.OnMethodExit(suppress = Throwable.class)
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static void onExit(@Advice.This Object thiz) {
final AbstractSpan<?> context = tracer.getActive();
if (context != null) {
Expand All @@ -97,25 +90,25 @@ public ElementMatcher<? super MethodDescription> getMethodMatcher() {
return named("run").and(returns(void.class));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter(@Advice.This Object thiz, @Nullable @Advice.Local("context") AbstractSpan<?> context) {
context = promisesToContext.remove(thiz);
@Nullable
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static Object onEnter(@Advice.This Object thiz) {
AbstractSpan<?> context = promisesToContext.remove(thiz);
if (context != null) {
context.activate();
// decrements the reference we incremented to avoid that the parent context gets recycled before the promise is run
// because we have activated it, we can be sure it doesn't get recycled until we deactivate in the OnMethodExit advice
context.decrementReferences();
}
return context;
}

@Advice.OnMethodExit(suppress = Throwable.class)
public static void onExit(@Nullable @Advice.Local("context") AbstractSpan<?> context) {
if (context != null) {
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static void onExit(@Advice.Enter @Nullable Object abstractSpanObj) {
if (abstractSpanObj instanceof AbstractSpan<?>) {
AbstractSpan<?> context = (AbstractSpan<?>) abstractSpanObj;
context.deactivate();
}
}

}

}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
co.elastic.apm.agent.scala.concurrent.FutureInstrumentation$ConstructorInstrumentation
co.elastic.apm.agent.scala.concurrent.FutureInstrumentation$RunInstrumentation
co.elastic.apm.agent.scalaconcurrent.FutureInstrumentation$ConstructorInstrumentation
co.elastic.apm.agent.scalaconcurrent.FutureInstrumentation$RunInstrumentation
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.elastic.apm.agent.scala.concurrent
package co.elastic.apm.agent.scalaconcurrent

import java.util.concurrent.Executors

Expand Down