|
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; |
| 9 | +import static io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_3.JsonRpcSingletons.instrumentCreateClientProxy; |
10 | 10 | import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
11 | 11 | import static net.bytebuddy.matcher.ElementMatchers.isPrivate;
|
12 | 12 | import static net.bytebuddy.matcher.ElementMatchers.isStatic;
|
13 | 13 | import static net.bytebuddy.matcher.ElementMatchers.named;
|
14 | 14 |
|
15 | 15 | import com.googlecode.jsonrpc4j.IJsonRpcClient;
|
16 |
| -import io.opentelemetry.context.Context; |
17 |
| -import io.opentelemetry.context.Scope; |
18 | 16 | import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
19 | 17 | import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
20 |
| -import java.lang.reflect.InvocationHandler; |
21 |
| -import java.lang.reflect.InvocationTargetException; |
22 |
| -import java.lang.reflect.Method; |
23 |
| -import java.lang.reflect.Proxy; |
24 | 18 | import java.util.Map;
|
25 | 19 | import net.bytebuddy.asm.Advice;
|
26 | 20 | import net.bytebuddy.description.type.TypeDescription;
|
@@ -58,50 +52,5 @@ public static <T> void onExit(
|
58 | 52 |
|
59 | 53 | proxy = instrumentCreateClientProxy(classLoader, proxyInterface, client, extraHeaders, proxy);
|
60 | 54 | }
|
61 |
| - |
62 |
| - @SuppressWarnings({"unchecked"}) |
63 |
| - public static <T> T instrumentCreateClientProxy( |
64 |
| - ClassLoader classLoader, |
65 |
| - Class<T> proxyInterface, |
66 |
| - IJsonRpcClient client, |
67 |
| - Map<String, String> extraHeaders, |
68 |
| - Object proxy) { |
69 |
| - |
70 |
| - return (T) |
71 |
| - Proxy.newProxyInstance( |
72 |
| - classLoader, |
73 |
| - new Class<?>[] {proxyInterface}, |
74 |
| - new InvocationHandler() { |
75 |
| - @Override |
76 |
| - public Object invoke(Object proxy1, Method method, Object[] args) throws Throwable { |
77 |
| - // before invoke |
78 |
| - Context parentContext = Context.current(); |
79 |
| - JsonRpcClientRequest request = new JsonRpcClientRequest(method, args); |
80 |
| - if (!CLIENT_INSTRUMENTER.shouldStart(parentContext, request)) { |
81 |
| - try { |
82 |
| - return method.invoke(proxy, args); |
83 |
| - } catch (InvocationTargetException exception) { |
84 |
| - throw exception.getCause(); |
85 |
| - } |
86 |
| - } |
87 |
| - |
88 |
| - Context context = CLIENT_INSTRUMENTER.start(parentContext, request); |
89 |
| - Object result; |
90 |
| - try (Scope scope = context.makeCurrent()) { |
91 |
| - result = method.invoke(proxy, args); |
92 |
| - } catch (Throwable t) { |
93 |
| - // after invoke |
94 |
| - CLIENT_INSTRUMENTER.end(context, request, null, t); |
95 |
| - throw t; |
96 |
| - } |
97 |
| - CLIENT_INSTRUMENTER.end( |
98 |
| - context, |
99 |
| - new JsonRpcClientRequest(method, args), |
100 |
| - new JsonRpcClientResponse(result), |
101 |
| - null); |
102 |
| - return result; |
103 |
| - } |
104 |
| - }); |
105 |
| - } |
106 | 55 | }
|
107 | 56 | }
|
0 commit comments