diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderConstructorInterceptor.java
new file mode 100644
index 000000000..640b6e822
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderConstructorInterceptor.java
@@ -0,0 +1,12 @@
+package org.skywalking.apm.plugin.nutz.http.sync;
+
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
+
+public class SenderConstructorInterceptor implements InstanceConstructorInterceptor {
+
+ @Override
+ public void onConstruct(final EnhancedInstance objInst, final Object[] allArguments) {
+ objInst.setSkyWalkingDynamicField(allArguments[0]);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java
index c56aa039d..864751348 100644
--- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java
@@ -1,13 +1,11 @@
package org.skywalking.apm.plugin.nutz.http.sync;
-import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URI;
import org.nutz.http.Request;
import org.nutz.http.Request.METHOD;
import org.nutz.http.Response;
-import org.nutz.http.Sender;
import org.skywalking.apm.agent.core.conf.Config;
import org.skywalking.apm.agent.core.context.ContextCarrier;
import org.skywalking.apm.agent.core.context.ContextManager;
@@ -22,11 +20,9 @@ import org.skywalking.apm.network.trace.component.ComponentsDefine;
public class SenderSendInterceptor implements InstanceMethodsAroundInterceptor {
@Override
- public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
- MethodInterceptResult result) throws Throwable {
- Field field = Sender.class.getDeclaredField("request");
- field.setAccessible(true);
- Request req = (Request) field.get(objInst);
+ public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, final Class>[] argumentsTypes,
+ final MethodInterceptResult result) throws Throwable {
+ Request req = (Request) objInst.getSkyWalkingDynamicField();
final URI requestURL = req.getUrl().toURI();
final METHOD httpMethod = req.getMethod();
final ContextCarrier contextCarrier = new ContextCarrier();
@@ -42,7 +38,7 @@ public class SenderSendInterceptor implements InstanceMethodsAroundInterceptor {
}
@Override
- public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ public Object afterMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, final Class>[] argumentsTypes,
Object ret) throws Throwable {
Response response = (Response)ret;
int statusCode = response.getStatus();
@@ -55,8 +51,9 @@ public class SenderSendInterceptor implements InstanceMethodsAroundInterceptor {
return ret;
}
- @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
- Class>[] argumentsTypes, Throwable t) {
+ @Override
+ public void handleMethodException(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
+ final Class>[] argumentsTypes, final Throwable t) {
ContextManager.activeSpan().errorOccurred().log(t);
}
}
diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpInstrumentation.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpInstrumentation.java
index df87868db..46f1abcd4 100644
--- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpInstrumentation.java
@@ -12,41 +12,60 @@ import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
/**
- * {@link NutzHttpInstrumentation} enhance the doExecute method,handleResponse method and
- * handleResponse method of org.springframework.web.client.RestTemplate by
- * org.skywalking.apm.plugin.spring.resttemplate.sync.RestExecuteInterceptor,
- * org.skywalking.apm.plugin.spring.resttemplate.sync.RestResponseInterceptor and
- * org.skywalking.apm.plugin.spring.resttemplate.sync.RestRequestInterceptor.
- *
- * org.skywalking.apm.plugin.spring.resttemplate.sync.RestResponseInterceptor set context to header for
- * propagate trace context after execute createRequest.
+ * {@link NutzHttpInstrumentation} enhance the send
+ * method,Constructor of org.nutz.http.Sender by
+ * org.skywalking.apm.plugin.nutz.http.sync.SenderConstructorInterceptor, and
+ * org.skywalking.apm.plugin.nutz.http.sync.SenderSendInterceptor
+ * set context to header for propagate trace context around execute
+ * send.
*
* @author wendal
*/
public class NutzHttpInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "org.nutz.http.Sender";
- private static final String DO_EXECUTE_METHOD_NAME = "send";
- private static final String DO_EXECUTE_INTERCEPTOR = "org.skywalking.apm.plugin.nutz.http.sync.SenderSendInterceptor";
+ private static final String DO_SEND_METHOD_NAME = "send";
+ private static final String DO_SEND_INTERCEPTOR = "org.skywalking.apm.plugin.nutz.http.sync.SenderSendInterceptor";
+ private static final String DO_CONSTRUCTOR_INTERCEPTOR = "org.skywalking.apm.plugin.nutz.http.sync.SenderConstructorInterceptor";
@Override
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
- return new ConstructorInterceptPoint[0];
+ return new ConstructorInterceptPoint[]{
+ new ConstructorInterceptPoint() {
+ @Override
+ public ElementMatcher getConstructorMatcher() {
+ return new ElementMatcher() {
+ @Override
+ public boolean matches(MethodDescription target) {
+ return target.isConstructor() && target.getParameters().size() > 0;
+ }
+ };
+ }
+
+ @Override
+ public String getConstructorInterceptor() {
+ return DO_CONSTRUCTOR_INTERCEPTOR;
+ }
+ }
+ };
}
@Override
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
- return new InstanceMethodsInterceptPoint[] {
+ return new InstanceMethodsInterceptPoint[]{
new InstanceMethodsInterceptPoint() {
- @Override public ElementMatcher getMethodsMatcher() {
- return named(DO_EXECUTE_METHOD_NAME);
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return named(DO_SEND_METHOD_NAME);
}
-
- @Override public String getMethodsInterceptor() {
- return DO_EXECUTE_INTERCEPTOR;
+
+ @Override
+ public String getMethodsInterceptor() {
+ return DO_SEND_INTERCEPTOR;
}
-
- @Override public boolean isOverrideArgs() {
+
+ @Override
+ public boolean isOverrideArgs() {
return false;
}
}