Skip to content

Commit 5dceb0e

Browse files
committed
fix(pekko): Ensure tilde$1 onExit is run in correct order
1 parent 08a0de3 commit 5dceb0e

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server.route;
7+
8+
import org.apache.pekko.http.javadsl.server.RouteResult;
9+
import scala.PartialFunction;
10+
import scala.Unit;
11+
import scala.util.Try;
12+
13+
public class RestoreOnExit implements PartialFunction<Try<RouteResult>, Unit> {
14+
@Override
15+
public boolean isDefinedAt(Try<RouteResult> x) {
16+
return true;
17+
}
18+
19+
@Override
20+
public Unit apply(Try<RouteResult> v1) {
21+
PekkoRouteHolder.restore();
22+
return null;
23+
}
24+
}

instrumentation/pekko/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/server/route/RouteConcatenationInstrumentation.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import net.bytebuddy.asm.Advice;
1313
import net.bytebuddy.description.type.TypeDescription;
1414
import net.bytebuddy.matcher.ElementMatcher;
15+
import org.apache.pekko.http.javadsl.server.RouteResult;
16+
import org.apache.pekko.http.scaladsl.server.RequestContext;
17+
import scala.concurrent.Future;
1518

1619
public class RouteConcatenationInstrumentation implements TypeInstrumentation {
1720
@Override
@@ -39,8 +42,10 @@ public static void onEnter() {
3942
}
4043

4144
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
42-
public static void onExit() {
43-
PekkoRouteHolder.restore();
45+
public static void onExit(
46+
@Advice.Argument(value = 2) RequestContext ctx,
47+
@Advice.Return(readOnly = false) Future<RouteResult> fut) {
48+
fut = fut.andThen(new RestoreOnExit(), ctx.executionContext());
4449
}
4550
}
4651

0 commit comments

Comments
 (0)