1313import io .opentelemetry .context .Context ;
1414import io .opentelemetry .javaagent .extension .instrumentation .InstrumentationModule ;
1515import io .opentelemetry .javaagent .extension .instrumentation .TypeInstrumentation ;
16+ import io .opentelemetry .javaagent .extension .instrumentation .internal .ExperimentalInstrumentationModule ;
1617import io .opentelemetry .javaagent .instrumentation .playws .AbstractBootstrapInstrumentation ;
1718import io .opentelemetry .javaagent .instrumentation .playws .AsyncHttpClientInstrumentation ;
1819import io .opentelemetry .javaagent .instrumentation .playws .HandlerPublisherInstrumentation ;
1920import java .util .List ;
21+ import javax .annotation .Nullable ;
2022import net .bytebuddy .asm .Advice ;
23+ import net .bytebuddy .asm .Advice .AssignReturned ;
24+ import net .bytebuddy .asm .Advice .AssignReturned .ToArguments .ToArgument ;
2125import play .shaded .ahc .org .asynchttpclient .AsyncHandler ;
2226import play .shaded .ahc .org .asynchttpclient .Request ;
2327import play .shaded .ahc .org .asynchttpclient .handler .StreamedAsyncHandler ;
2428import play .shaded .ahc .org .asynchttpclient .ws .WebSocketUpgradeHandler ;
2529
2630@ AutoService (InstrumentationModule .class )
27- public class PlayWsInstrumentationModule extends InstrumentationModule {
31+ public class PlayWsInstrumentationModule extends InstrumentationModule
32+ implements ExperimentalInstrumentationModule {
2833 public PlayWsInstrumentationModule () {
2934 super ("play-ws" , "play-ws-2.1" );
3035 }
@@ -37,20 +42,25 @@ public List<TypeInstrumentation> typeInstrumentations() {
3742 new AbstractBootstrapInstrumentation ());
3843 }
3944
45+ @ Override
46+ public boolean isIndyReady () {
47+ return true ;
48+ }
49+
4050 @ SuppressWarnings ("unused" )
4151 public static class ClientAdvice {
4252
53+ @ AssignReturned .ToArguments (@ ToArgument (value = 1 , index = 1 ))
4354 @ Advice .OnMethodEnter (suppress = Throwable .class )
44- public static void methodEnter (
55+ public static Object [] methodEnter (
4556 @ Advice .Argument (0 ) Request request ,
46- @ Advice .Argument (value = 1 , readOnly = false ) AsyncHandler <?> asyncHandler ,
47- @ Advice . Local ( "otelContext" ) Context context ) {
57+ @ Advice .Argument (1 ) AsyncHandler <?> originalAsyncHandler ) {
58+ AsyncHandler <?> asyncHandler = originalAsyncHandler ;
4859 Context parentContext = currentContext ();
4960 if (!instrumenter ().shouldStart (parentContext , request )) {
50- return ;
61+ return new Object [] { null , asyncHandler } ;
5162 }
52-
53- context = instrumenter ().start (parentContext , request );
63+ Context context = instrumenter ().start (parentContext , request );
5464
5565 if (asyncHandler instanceof StreamedAsyncHandler ) {
5666 asyncHandler =
@@ -60,13 +70,15 @@ public static void methodEnter(
6070 // websocket upgrade handlers aren't supported
6171 asyncHandler = new AsyncHandlerWrapper <>(asyncHandler , request , context , parentContext );
6272 }
73+ return new Object [] {context , asyncHandler };
6374 }
6475
6576 @ Advice .OnMethodExit (onThrowable = Throwable .class , suppress = Throwable .class )
6677 public static void methodExit (
6778 @ Advice .Argument (0 ) Request request ,
68- @ Advice .Thrown Throwable throwable ,
69- @ Advice .Local ("otelContext" ) Context context ) {
79+ @ Advice .Thrown @ Nullable Throwable throwable ,
80+ @ Advice .Enter Object [] enterResult ) {
81+ Context context = (Context ) enterResult [0 ];
7082 if (context != null && throwable != null ) {
7183 instrumenter ().end (context , request , null , throwable );
7284 }
0 commit comments