66package io .opentelemetry .javaagent .instrumentation .jsonrpc4j .v1_3 ;
77
88import static io .opentelemetry .javaagent .extension .matcher .AgentElementMatchers .hasClassesNamed ;
9- import static io .opentelemetry .javaagent .instrumentation .jsonrpc4j .v1_3 .JsonRpcSingletons .CLIENT_INSTRUMENTER ;
109import static net .bytebuddy .matcher .ElementMatchers .isMethod ;
1110import static net .bytebuddy .matcher .ElementMatchers .isPrivate ;
1211import static net .bytebuddy .matcher .ElementMatchers .isStatic ;
1312import static net .bytebuddy .matcher .ElementMatchers .named ;
1413
1514import com .googlecode .jsonrpc4j .IJsonRpcClient ;
16- import com .googlecode .jsonrpc4j .ReflectionUtil ;
17- import io .opentelemetry .context .Context ;
18- import io .opentelemetry .context .Scope ;
19- import io .opentelemetry .instrumentation .jsonrpc4j .v1_3 .SimpleJsonRpcRequest ;
20- import io .opentelemetry .instrumentation .jsonrpc4j .v1_3 .SimpleJsonRpcResponse ;
2115import io .opentelemetry .javaagent .extension .instrumentation .TypeInstrumentation ;
2216import io .opentelemetry .javaagent .extension .instrumentation .TypeTransformer ;
23- import java .lang .reflect .InvocationHandler ;
24- import java .lang .reflect .Method ;
25- import java .lang .reflect .Proxy ;
2617import java .util .Map ;
2718import net .bytebuddy .asm .Advice ;
2819import net .bytebuddy .description .type .TypeDescription ;
@@ -47,7 +38,7 @@ public void transform(TypeTransformer transformer) {
4738 this .getClass ().getName () + "$CreateClientProxyAdvice" );
4839 }
4940
50- @ SuppressWarnings ({"unused" , "unchecked" })
41+ @ SuppressWarnings ({"unused" })
5142 public static class CreateClientProxyAdvice {
5243
5344 @ Advice .OnMethodExit (suppress = Throwable .class )
@@ -57,49 +48,9 @@ public static <T> void onExit(
5748 @ Advice .Argument (2 ) IJsonRpcClient client ,
5849 @ Advice .Argument (3 ) Map <String , String > extraHeaders ,
5950 @ Advice .Return (readOnly = false ) Object proxy ) {
60-
6151 proxy =
62- (T )
63- Proxy .newProxyInstance (
64- classLoader ,
65- new Class <?>[] {proxyInterface },
66- new InvocationHandler () {
67- @ Override
68- public Object invoke (Object proxy , Method method , Object [] args )
69- throws Throwable {
70-
71- Object arguments = ReflectionUtil .parseArguments (method , args );
72- String methodName = method .getName (); // todo
73-
74- // before invoke
75- Context parentContext = Context .current ();
76- SimpleJsonRpcRequest request = new SimpleJsonRpcRequest (method , args );
77- if (!CLIENT_INSTRUMENTER .shouldStart (parentContext , request )) {
78- return client .invoke (
79- methodName , arguments , method .getGenericReturnType (), extraHeaders );
80- }
81-
82- Context context = CLIENT_INSTRUMENTER .start (parentContext , request );
83- Scope scope = context .makeCurrent ();
84- try {
85- Object result =
86- client .invoke (
87- methodName , arguments , method .getGenericReturnType (), extraHeaders );
88- scope .close ();
89- CLIENT_INSTRUMENTER .end (
90- context ,
91- new SimpleJsonRpcRequest (method , args ),
92- new SimpleJsonRpcResponse (result ),
93- null );
94- return result ;
95- } catch (Throwable t ) {
96- // after invoke
97- scope .close ();
98- CLIENT_INSTRUMENTER .end (context , request , null , t );
99- throw t ;
100- }
101- }
102- });
52+ JsonRpcSingletons .instrumentCreateClientProxy (
53+ classLoader , proxyInterface , client , extraHeaders );
10354 }
10455 }
10556}
0 commit comments