6
6
package io .opentelemetry .javaagent .instrumentation .jsonrpc4j .v1_3 ;
7
7
8
8
import static io .opentelemetry .javaagent .extension .matcher .AgentElementMatchers .hasClassesNamed ;
9
- import static io .opentelemetry .javaagent .instrumentation .jsonrpc4j .v1_3 .JsonRpcSingletons .CLIENT_INSTRUMENTER ;
10
9
import static net .bytebuddy .matcher .ElementMatchers .isMethod ;
11
10
import static net .bytebuddy .matcher .ElementMatchers .isPrivate ;
12
11
import static net .bytebuddy .matcher .ElementMatchers .isStatic ;
13
12
import static net .bytebuddy .matcher .ElementMatchers .named ;
14
13
15
14
import 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 ;
21
15
import io .opentelemetry .javaagent .extension .instrumentation .TypeInstrumentation ;
22
16
import io .opentelemetry .javaagent .extension .instrumentation .TypeTransformer ;
23
- import java .lang .reflect .InvocationHandler ;
24
- import java .lang .reflect .Method ;
25
- import java .lang .reflect .Proxy ;
26
17
import java .util .Map ;
27
18
import net .bytebuddy .asm .Advice ;
28
19
import net .bytebuddy .description .type .TypeDescription ;
@@ -47,7 +38,7 @@ public void transform(TypeTransformer transformer) {
47
38
this .getClass ().getName () + "$CreateClientProxyAdvice" );
48
39
}
49
40
50
- @ SuppressWarnings ({"unused" , "unchecked" })
41
+ @ SuppressWarnings ({"unused" })
51
42
public static class CreateClientProxyAdvice {
52
43
53
44
@ Advice .OnMethodExit (suppress = Throwable .class )
@@ -59,47 +50,8 @@ public static <T> void onExit(
59
50
@ Advice .Return (readOnly = false ) Object proxy ) {
60
51
61
52
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
- });
53
+ JsonRpcSingletons .instrumentCreateClientProxy (
54
+ classLoader , proxyInterface , client , extraHeaders , proxy );
103
55
}
104
56
}
105
57
}
0 commit comments