Skip to content

Commit 703c9da

Browse files
committed
** -> *, PekkoRouteHolder.get, isConstructor(), unused
1 parent 725071e commit 703c9da

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ public void onPush() {
145145
if (!headers.isEmpty()) {
146146
response = (HttpResponse) response.addHeaders(headers);
147147
}
148-
PekkoRouteHolder routeHolder = tracingRequest.context.get(PekkoRouteHolder.KEY);
148+
PekkoRouteHolder routeHolder = PekkoRouteHolder.get(tracingRequest.context);
149149
if (routeHolder != null) {
150-
routeHolder.pushIfNotCompletelyMatched("**");
150+
routeHolder.pushIfNotCompletelyMatched("*");
151151
HttpServerRoute.update(
152152
tracingRequest.context,
153153
HttpServerRouteSource.CONTROLLER,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void onExit(
4545
@Advice.Return PathMatcher.Matching<?> result) {
4646
// result is either matched or unmatched, we only care about the matches
4747
Context context = Java8BytecodeBridge.currentContext();
48-
PekkoRouteHolder routeHolder = context.get(PekkoRouteHolder.KEY);
48+
PekkoRouteHolder routeHolder = PekkoRouteHolder.get(context);
4949
if (routeHolder == null) {
5050
return;
5151
}

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
import io.opentelemetry.context.Context;
1111
import io.opentelemetry.context.ContextKey;
1212
import io.opentelemetry.context.ImplicitContextKeyed;
13+
import java.util.ArrayDeque;
1314
import java.util.Deque;
14-
import java.util.LinkedList;
1515
import org.apache.pekko.http.scaladsl.model.Uri;
1616

1717
public class PekkoRouteHolder implements ImplicitContextKeyed {
18-
public static final ContextKey<PekkoRouteHolder> KEY = named("opentelemetry-pekko-route");
18+
private static final ContextKey<PekkoRouteHolder> KEY = named("opentelemetry-pekko-route");
1919

2020
private StringBuilder route = new StringBuilder();
2121
private Uri.Path lastUnmatchedPath = null;
2222
private boolean lastWasMatched = false;
23-
private final Deque<State> savedStates = new LinkedList<>();
23+
private final Deque<State> savedStates = new ArrayDeque<>();
2424

2525
public static Context init(Context context) {
2626
if (context.get(KEY) != null) {
@@ -29,6 +29,10 @@ public static Context init(Context context) {
2929
return context.with(new PekkoRouteHolder());
3030
}
3131

32+
public static PekkoRouteHolder get(Context context) {
33+
return context.get(KEY);
34+
}
35+
3236
public void push(Uri.Path beforeMatch, Uri.Path afterMatch, String pathToPush) {
3337
// Only accept the suggested 'pathToPush' if:
3438
// - either this is the first match, or

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public PekkoRouteWrapper(Function1<RequestContext, Future<RouteResult>> route) {
2222
@Override
2323
public Future<RouteResult> apply(RequestContext ctx) {
2424
Context context = Java8BytecodeBridge.currentContext();
25-
PekkoRouteHolder routeHolder = context.get(PekkoRouteHolder.KEY);
25+
PekkoRouteHolder routeHolder = PekkoRouteHolder.get(context);
2626
if (routeHolder == null) {
2727
return route.apply(ctx);
2828
} else {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server.route;
77

8+
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
89
import static net.bytebuddy.matcher.ElementMatchers.named;
910

1011
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1112
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
1213
import net.bytebuddy.asm.Advice;
13-
import net.bytebuddy.description.method.MethodDescription;
1414
import net.bytebuddy.description.type.TypeDescription;
1515
import net.bytebuddy.matcher.ElementMatcher;
1616
import org.apache.pekko.http.scaladsl.server.RequestContext;
@@ -26,11 +26,11 @@ public ElementMatcher<TypeDescription> typeMatcher() {
2626

2727
@Override
2828
public void transform(TypeTransformer transformer) {
29-
transformer.applyAdviceToMethod(
30-
MethodDescription::isConstructor, this.getClass().getName() + "$ApplyAdvice");
29+
transformer.applyAdviceToMethod(isConstructor(), this.getClass().getName() + "$ApplyAdvice");
3130
transformer.applyAdviceToMethod(named("$tilde"), this.getClass().getName() + "$ApplyAdvice");
3231
}
3332

33+
@SuppressWarnings("unused")
3434
public static class ApplyAdvice {
3535

3636
@Advice.OnMethodEnter(suppress = Throwable.class)

instrumentation/pekko/pekko-http-1.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/PekkoHttpServerRouteTest.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class PekkoHttpServerRouteTest {
106106

107107
@Test def testNotMatch(): Unit = {
108108
val route = pathPrefix("foo" ~ not("bar")) { complete("ok") }
109-
test(route, "/fooish", "GET /foo**")
110-
test(route, "/fooish/123", "GET /foo**")
109+
test(route, "/fooish", "GET /foo*")
110+
test(route, "/fooish/123", "GET /foo*")
111111
}
112112

113113
@Test def testProvide(): Unit = {

0 commit comments

Comments
 (0)