6
6
package io .opentelemetry .javaagent .instrumentation .pekkohttp .v1_0 .server .tapir ;
7
7
8
8
import io .opentelemetry .context .Context ;
9
- import io .opentelemetry .instrumentation .api .semconv .http .HttpServerRoute ;
10
- import io .opentelemetry .instrumentation .api .semconv .http .HttpServerRouteSource ;
11
9
import io .opentelemetry .javaagent .bootstrap .Java8BytecodeBridge ;
10
+ import io .opentelemetry .javaagent .instrumentation .pekkohttp .v1_0 .server .route .PekkoRouteHolder ;
11
+ import java .nio .charset .Charset ;
12
+ import org .apache .pekko .http .scaladsl .model .Uri ;
12
13
import org .apache .pekko .http .scaladsl .server .RequestContext ;
13
14
import org .apache .pekko .http .scaladsl .server .RouteResult ;
14
15
import scala .Function1 ;
22
23
import sttp .tapir .server .ServerEndpoint ;
23
24
24
25
public class RouteWrapper implements Function1 <RequestContext , Future <RouteResult >> {
26
+ private static final Uri .Path EMPTY = Uri .Path$ .MODULE$ .apply ("" , Charset .defaultCharset ());
25
27
private final Function1 <RequestContext , Future <RouteResult >> route ;
26
28
private final ServerEndpoint <?, ?> serverEndpoint ;
27
29
@@ -32,6 +34,12 @@ public RouteWrapper(
32
34
}
33
35
34
36
public class Finalizer implements PartialFunction <Try <RouteResult >, Unit > {
37
+ private final Uri .Path beforeMatch ;
38
+
39
+ public Finalizer (Uri .Path beforeMatch ) {
40
+ this .beforeMatch = beforeMatch ;
41
+ }
42
+
35
43
@ Override
36
44
public boolean isDefinedAt (Try <RouteResult > tryResult ) {
37
45
return tryResult .isSuccess ();
@@ -40,7 +48,8 @@ public boolean isDefinedAt(Try<RouteResult> tryResult) {
40
48
@ Override
41
49
public Unit apply (Try <RouteResult > tryResult ) {
42
50
Context context = Java8BytecodeBridge .currentContext ();
43
- if (tryResult .isSuccess ()) {
51
+ PekkoRouteHolder routeHolder = PekkoRouteHolder .get (context );
52
+ if (routeHolder != null && tryResult .isSuccess ()) {
44
53
RouteResult result = tryResult .get ();
45
54
if (result .getClass () == RouteResult .Complete .class ) {
46
55
String path =
@@ -54,7 +63,7 @@ public Unit apply(Try<RouteResult> tryResult) {
54
63
"*" ,
55
64
Option .apply ("*" ),
56
65
Option .apply ("*" ));
57
- HttpServerRoute . update ( context , HttpServerRouteSource . NESTED_CONTROLLER , path );
66
+ routeHolder . push ( beforeMatch , EMPTY , path );
58
67
}
59
68
}
60
69
return null ;
@@ -63,6 +72,6 @@ public Unit apply(Try<RouteResult> tryResult) {
63
72
64
73
@ Override
65
74
public Future <RouteResult > apply (RequestContext ctx ) {
66
- return route .apply (ctx ).andThen (new Finalizer (), ctx .executionContext ());
75
+ return route .apply (ctx ).andThen (new Finalizer (ctx . unmatchedPath () ), ctx .executionContext ());
67
76
}
68
77
}
0 commit comments