Skip to content

Commit 1c21bf7

Browse files
committed
encapsulate virtual field use in util class
1 parent db122af commit 1c21bf7

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/route/PathMatcherInstrumentation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void onEnter(
4040
@Advice.Argument(0) Uri.Path prefix, @Advice.Return PathMatcher<?> result) {
4141
// store the path being matched inside a VirtualField on the given matcher, so it can be used
4242
// for constructing the route
43-
VirtualFields.PATH_MATCHER_ROUTE.set(result, prefix.toString());
43+
PathMatcherUtil.setMatched(result, prefix.toString());
4444
}
4545
}
4646
}

instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/route/PathMatcherStaticInstrumentation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static void onExit(
4747
}
4848
// if present use the matched path that was remembered in PathMatcherInstrumentation,
4949
// otherwise just use a *
50-
String prefix = VirtualFields.PATH_MATCHER_ROUTE.get(pathMatcher);
50+
String prefix = PathMatcherUtil.getMatched(pathMatcher);
5151
if (prefix == null) {
5252
if (PathMatchers.Slash$.class == pathMatcher.getClass()) {
5353
prefix = "/";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.akkahttp.server.route;
7+
8+
import akka.http.scaladsl.server.PathMatcher;
9+
import io.opentelemetry.instrumentation.api.util.VirtualField;
10+
11+
public class PathMatcherUtil {
12+
13+
private static final VirtualField<PathMatcher<?>, String> PATH_MATCHER_ROUTE =
14+
VirtualField.find(PathMatcher.class, String.class);
15+
16+
public static void setMatched(PathMatcher<?> matcher, String route) {
17+
PATH_MATCHER_ROUTE.set(matcher, route);
18+
}
19+
20+
public static String getMatched(PathMatcher<?> matcher) {
21+
return PATH_MATCHER_ROUTE.get(matcher);
22+
}
23+
24+
private PathMatcherUtil() {}
25+
}

instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/route/VirtualFields.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)