Rewrite plugins by using new API
This commit is contained in:
parent
efe11cade6
commit
cea88f981d
|
|
@ -48,22 +48,18 @@ public final class Tags {
|
|||
public static final class SPAN_LAYER {
|
||||
private static StringTag SPAN_LAYER_TAG = new StringTag("span.layer");
|
||||
|
||||
private static final String RDB_LAYER = "rdb";
|
||||
private static final String DB_LAYER = "db";
|
||||
private static final String RPC_FRAMEWORK_LAYER = "rpc";
|
||||
private static final String NOSQL_LAYER = "nosql";
|
||||
private static final String HTTP_LAYER = "http";
|
||||
|
||||
public static void asRDB(Span span) {
|
||||
SPAN_LAYER_TAG.set(span, RDB_LAYER);
|
||||
public static void asDB(Span span) {
|
||||
SPAN_LAYER_TAG.set(span, DB_LAYER);
|
||||
}
|
||||
|
||||
public static void asRPCFramework(Span span) {
|
||||
SPAN_LAYER_TAG.set(span, RPC_FRAMEWORK_LAYER);
|
||||
}
|
||||
|
||||
public static void asNoSQL(Span span) {
|
||||
SPAN_LAYER_TAG.set(span, NOSQL_LAYER);
|
||||
}
|
||||
|
||||
public static void asHttp(Span span) {
|
||||
SPAN_LAYER_TAG.set(span, HTTP_LAYER);
|
||||
|
|
@ -73,18 +69,14 @@ public final class Tags {
|
|||
return SPAN_LAYER_TAG.get(span);
|
||||
}
|
||||
|
||||
public static boolean isRDB(Span span) {
|
||||
return RDB_LAYER.equals(get(span));
|
||||
public static boolean isDB(Span span) {
|
||||
return DB_LAYER.equals(get(span));
|
||||
}
|
||||
|
||||
public static boolean isRPCFramework(Span span) {
|
||||
return RPC_FRAMEWORK_LAYER.equals(get(span));
|
||||
}
|
||||
|
||||
public static boolean isNoSQL(Span span) {
|
||||
return NOSQL_LAYER.equals(get(span));
|
||||
}
|
||||
|
||||
public static boolean isHttp(Span span) {
|
||||
return HTTP_LAYER.equals(get(span));
|
||||
}
|
||||
|
|
@ -107,9 +99,24 @@ public final class Tags {
|
|||
public static final StringTag PEER_HOST = new StringTag("peer.host");
|
||||
|
||||
/**
|
||||
* DB_URL records the url of the database access.
|
||||
* PEER_PORT records remote port of the peer
|
||||
*/
|
||||
public static final StringTag DB_URL = new StringTag("db.url");
|
||||
public static final IntTag PEER_PORT = new IntTag("peer.port");
|
||||
|
||||
/**
|
||||
* PEERS records multiple host address and port of remote
|
||||
*/
|
||||
public static final StringTag PEERS = new StringTag("peers");
|
||||
|
||||
/**
|
||||
* DB_TYPE records database type, such as sql, redis, cassandra and so on.
|
||||
*/
|
||||
public static final StringTag DB_TYPE = new StringTag("db.type");
|
||||
|
||||
/**
|
||||
* DB_INSTANCE records database instance name.
|
||||
*/
|
||||
public static final StringTag DB_INSTANCE = new StringTag("db.instance");
|
||||
|
||||
/**
|
||||
* DB_STATEMENT records the sql statement of the database access.
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ public class SpanTestCase {
|
|||
Tags.ERROR.set(span1, true);
|
||||
Tags.STATUS_CODE.set(span1, 302);
|
||||
Tags.URL.set(span1, "http://127.0.0.1/serviceA");
|
||||
Tags.DB_URL.set(span1, "jdbc:127.0.0.1:user");
|
||||
Tags.DB_STATEMENT.set(span1, "select * from users");
|
||||
|
||||
Map<String, Object> tags = span1.getTags();
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ public class TraceSegmentTestCase {
|
|||
segment.archive(span1);
|
||||
|
||||
Span span2 = new Span(2, span1, "/db/sql");
|
||||
Tags.SPAN_LAYER.asNoSQL(span2);
|
||||
Tags.SPAN_LAYER.asDB(span2);
|
||||
span2.log(new NullPointerException());
|
||||
segment.archive(span2);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
package com.a.eye.skywalking.agent;
|
||||
|
||||
import com.a.eye.skywalking.agent.junction.SkyWalkingEnhanceMatcher;
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.api.conf.Config;
|
||||
import com.a.eye.skywalking.api.conf.SnifferConfigInitializer;
|
||||
import com.a.eye.skywalking.logging.EasyLogResolver;
|
||||
import com.a.eye.skywalking.api.logging.EasyLogResolver;
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.plugin.AbstractClassEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.api.plugin.PluginBootstrap;
|
||||
import com.a.eye.skywalking.api.plugin.PluginDefineCategory;
|
||||
import com.a.eye.skywalking.plugin.PluginException;
|
||||
import com.a.eye.skywalking.api.plugin.PluginException;
|
||||
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
import net.bytebuddy.description.NamedElement;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.a.eye.skywalking.api.plugin.interceptor;
|
||||
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.PluginException;
|
||||
|
||||
public class EnhanceException extends PluginException {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
|||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.StaticMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.api.util.StringUtil;
|
||||
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
import net.bytebuddy.implementation.MethodDelegation;
|
||||
|
|
@ -25,7 +26,7 @@ import static net.bytebuddy.matcher.ElementMatchers.not;
|
|||
* This class controls all enhance operations, including enhance constructors, instance methods and static methods.
|
||||
* All the enhances base on three types interceptor point: {@link ConstructorInterceptPoint}, {@link InstanceMethodsInterceptPoint} and {@link StaticMethodsInterceptPoint}
|
||||
* If plugin is going to enhance constructors, instance methods, or both,
|
||||
* {@link ClassEnhancePluginDefine} will add a field of {@link EnhancedClassInstanceContext} type.
|
||||
* {@link ClassEnhancePluginDefine} will add a field of {@link com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext} type.
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
|
|
@ -44,7 +45,6 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
* @param enhanceOriginClassName target class name
|
||||
* @param newClassBuilder byte-buddy's builder to manipulate class bytecode.
|
||||
* @return new byte-buddy's builder for further manipulation.
|
||||
* @throws PluginException
|
||||
*/
|
||||
@Override
|
||||
protected DynamicType.Builder<?> enhance(String enhanceOriginClassName, DynamicType.Builder<?> newClassBuilder) throws PluginException {
|
||||
|
|
@ -61,7 +61,6 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
* @param enhanceOriginClassName target class name
|
||||
* @param newClassBuilder byte-buddy's builder to manipulate class bytecode.
|
||||
* @return new byte-buddy's builder for further manipulation.
|
||||
* @throws PluginException
|
||||
*/
|
||||
private DynamicType.Builder<?> enhanceInstance(String enhanceOriginClassName, DynamicType.Builder<?> newClassBuilder) throws PluginException {
|
||||
ConstructorInterceptPoint[] constructorInterceptPoints = getConstructorsInterceptPoints();
|
||||
|
|
@ -150,7 +149,6 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
* @param enhanceOriginClassName target class name
|
||||
* @param newClassBuilder byte-buddy's builder to manipulate class bytecode.
|
||||
* @return new byte-buddy's builder for further manipulation.
|
||||
* @throws PluginException
|
||||
*/
|
||||
private DynamicType.Builder<?> enhanceClass(String enhanceOriginClassName, DynamicType.Builder<?> newClassBuilder) throws PluginException {
|
||||
StaticMethodsInterceptPoint[] staticMethodsInterceptPoints = getStaticMethodsInterceptPoints();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.a.eye.skywalking.api.plugin.interceptor.enhance;
|
||||
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.StaticMethodsInterceptPoint;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
public class DubboInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
/**
|
||||
* Enhance class
|
||||
* Enhance class.
|
||||
*/
|
||||
private static final String ENHANCE_CLASS = "com.alibaba.dubbo.monitor.support.MonitorFilter";
|
||||
/**
|
||||
* Intercept class
|
||||
* Intercept class.
|
||||
*/
|
||||
private static final String INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.dubbo.DubboInterceptor";
|
||||
|
||||
|
|
|
|||
|
|
@ -2,21 +2,22 @@ package com.a.eye.skywalking.plugin.dubbo;
|
|||
|
||||
import com.a.eye.skywalking.api.context.ContextCarrier;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.plugin.dubbox.BugFixActive;
|
||||
import com.a.eye.skywalking.plugin.dubbox.SWBaseBean;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.plugin.dubbox.BugFixActive;
|
||||
import com.a.eye.skywalking.plugin.dubbox.SWBaseBean;
|
||||
import com.a.eye.skywalking.trace.Span;
|
||||
import com.a.eye.skywalking.trace.tag.Tags;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.rpc.Invocation;
|
||||
import com.alibaba.dubbo.rpc.Invoker;
|
||||
import com.alibaba.dubbo.rpc.Result;
|
||||
import com.alibaba.dubbo.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
* {@link DubboInterceptor} define how to enhance class{@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}.
|
||||
* {@link DubboInterceptor} define how to enhance class {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}.
|
||||
* the context data will transport to the provider side by {@link RpcContext#attachments}.but all the version of dubbo framework below 2.8.3
|
||||
* don't support {@link RpcContext#attachments}, we support another way to support it. it is that all request parameters of dubbo service
|
||||
* need to extend {@link SWBaseBean}, and {@link DubboInterceptor} will inject the serialized context data to the {@link SWBaseBean} bean and
|
||||
|
|
@ -39,10 +40,6 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
* The serialized context data will extract from the first param that extend {@link SWBaseBean} of dubbo service
|
||||
* if the method {@link BugFixActive#active()} be called. or it will extract from {@link RpcContext#attachments}.
|
||||
* current trace segment will ref if the serialize context data is not null.
|
||||
*
|
||||
* @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance.
|
||||
* @param interceptorContext method context, includes class name, method name, etc.
|
||||
* @param result change this result, if you want to truncate the method.
|
||||
*/
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
|
|
@ -52,8 +49,15 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
Invocation invocation = (Invocation) arguments[1];
|
||||
RpcContext rpcContext = RpcContext.getContext();
|
||||
boolean isConsumer = rpcContext.isConsumerSide();
|
||||
URL requestURL = invoker.getUrl();
|
||||
|
||||
Span span = ContextManager.INSTANCE.createSpan(generateOperationName(requestURL, invocation));
|
||||
Tags.URL.set(span, generateRequestURL(requestURL, invocation));
|
||||
Tags.COMPONENT.set(span, DUBBO_COMPONENT);
|
||||
Tags.PEER_HOST.set(span, requestURL.getHost());
|
||||
Tags.PEER_PORT.set(span, requestURL.getPort());
|
||||
Tags.SPAN_LAYER.asRPCFramework(span);
|
||||
|
||||
Span span = ContextManager.INSTANCE.createSpan(generateOperationName(invoker, invocation));
|
||||
if (isConsumer) {
|
||||
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
|
|
@ -91,20 +95,12 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
ContextManager.INSTANCE.extract(new ContextCarrier().deserialize(contextDataStr));
|
||||
}
|
||||
}
|
||||
|
||||
Tags.URL.set(span, generateRequestURL(invoker, invocation));
|
||||
Tags.COMPONENT.set(span, DUBBO_COMPONENT);
|
||||
Tags.SPAN_LAYER.asRPCFramework(span);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link DubboInterceptor#afterMethod(EnhancedClassInstanceContext, InstanceMethodInvokeContext, Object)} be executed after
|
||||
* {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}, and it will check {@link Result#getException()} if is null.
|
||||
* current active span will log the exception and set true to the value of error tag if the {@link Result#getException()} is not null.
|
||||
*
|
||||
* @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance.
|
||||
* @param interceptorContext method context, includes class name, method name, etc.
|
||||
* @param ret the method's original return value.
|
||||
*/
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
|
|
@ -135,13 +131,13 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
|
||||
/**
|
||||
* Generate operation name.
|
||||
* the operation name should be like this <code>com.a.eye.skywalking.plugin.test.Test.test(String)</code>
|
||||
* the operation name should be like this <code>com.a.eye.skywalking.plugin.test.Test.test(String)</code>.
|
||||
*
|
||||
* @return operation name
|
||||
* @return operation name.
|
||||
*/
|
||||
private static String generateOperationName(Invoker<?> invoker, Invocation invocation) {
|
||||
private static String generateOperationName(URL requestURL, Invocation invocation) {
|
||||
StringBuilder operationName = new StringBuilder();
|
||||
operationName.append(invoker.getUrl().getPath());
|
||||
operationName.append(requestURL.getPath());
|
||||
operationName.append("." + invocation.getMethodName() + "(");
|
||||
for (Class<?> classes : invocation.getParameterTypes()) {
|
||||
operationName.append(classes.getSimpleName() + ",");
|
||||
|
|
@ -158,23 +154,23 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
|
||||
/**
|
||||
* Generate request url.
|
||||
* The request url may be like this <code>dubbo://127.0.0.1:20880/com.a.eye.skywalking.plugin.test.Test.test(String)</code>
|
||||
* The request url may be like this <code>dubbo://127.0.0.1:20880/com.a.eye.skywalking.plugin.test.Test.test(String)</code>.
|
||||
*
|
||||
* @return request url
|
||||
* @return request url.
|
||||
*/
|
||||
private static String generateRequestURL(Invoker<?> invoker, Invocation invocation) {
|
||||
private static String generateRequestURL(URL url, Invocation invocation) {
|
||||
StringBuilder requestURL = new StringBuilder();
|
||||
requestURL.append(invoker.getUrl().getProtocol() + "://");
|
||||
requestURL.append(invoker.getUrl().getHost());
|
||||
requestURL.append(":" + invoker.getUrl().getPort() + "/");
|
||||
requestURL.append(generateOperationName(invoker, invocation));
|
||||
requestURL.append(url.getProtocol() + "://");
|
||||
requestURL.append(url.getHost());
|
||||
requestURL.append(":" + url.getPort() + "/");
|
||||
requestURL.append(generateOperationName(url, invocation));
|
||||
return requestURL.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the serialized context data to the first request param that extend {@link SWBaseBean} of dubbo service
|
||||
* Set the serialized context data to the first request param that extend {@link SWBaseBean} of dubbo service.
|
||||
*
|
||||
* @param contextDataStr serialized context data
|
||||
* @param contextDataStr serialized context data.
|
||||
*/
|
||||
private static void fix283SendNoAttachmentIssue(Invocation invocation, String contextDataStr) {
|
||||
for (Object parameter : invocation.getArguments()) {
|
||||
|
|
@ -188,7 +184,7 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
/**
|
||||
* Fetch the serialize context data from the first request param that extend {@link SWBaseBean} of dubbo service.
|
||||
*
|
||||
* @return serialized context data
|
||||
* @return serialized context data.
|
||||
*/
|
||||
private static String fix283RecvNoAttachmentIssue(Invocation invocation) {
|
||||
for (Object parameter : invocation.getArguments()) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ package com.a.eye.skywalking.plugin.dubbox;
|
|||
/**
|
||||
* {@link BugFixActive#active} is an flag that present the dubbox version is below 2.8.3,
|
||||
* The version 2.8.3 of dubbox don't support attachment. so skywalking provided another way
|
||||
* to support the function that transport the serialized context data. the way that
|
||||
* to support the function that transport the serialized context data. The way is that
|
||||
* all parameters of dubbo service need to extend {@link SWBaseBean}, {@link com.a.eye.skywalking.plugin.dubbo.DubboInterceptor}
|
||||
* fetch the serialized context data by using {@link SWBaseBean#getContextData()}.
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
|
|
@ -19,7 +21,7 @@ public final class BugFixActive {
|
|||
}
|
||||
|
||||
|
||||
public static boolean isActive(){
|
||||
public static boolean isActive() {
|
||||
return BugFixActive.active;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import java.io.Serializable;
|
|||
*/
|
||||
public class SWBaseBean implements Serializable {
|
||||
/**
|
||||
* Serialized context data
|
||||
* Serialized context data.
|
||||
*/
|
||||
private String contextData;
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public class DubboInterceptorTest {
|
|||
public void call(TraceSegment traceSegment) {
|
||||
assertThat(traceSegment.getSpans().size(), is(1));
|
||||
assertConsumerSpan(traceSegment.getSpans().get(0));
|
||||
testParam.assertSelf("0");
|
||||
testParam.assertSelf("0", "127.0.0.1");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -143,7 +143,7 @@ public class DubboInterceptorTest {
|
|||
@Test
|
||||
public void testProviderWithAttachment() {
|
||||
when(rpcContext.isConsumerSide()).thenReturn(false);
|
||||
when(rpcContext.getAttachment(DubboInterceptor.ATTACHMENT_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1");
|
||||
when(rpcContext.getAttachment(DubboInterceptor.ATTACHMENT_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1");
|
||||
|
||||
dubboInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(classInstanceContext, methodInvokeContext, result);
|
||||
|
|
@ -156,7 +156,7 @@ public class DubboInterceptorTest {
|
|||
when(rpcContext.isConsumerSide()).thenReturn(false);
|
||||
when(BugFixActive.isActive()).thenReturn(true);
|
||||
|
||||
testParam.setContextData("302017.1487666919810.624424584.17332.1.1|1");
|
||||
testParam.setContextData("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1");
|
||||
|
||||
|
||||
dubboInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult);
|
||||
|
|
@ -175,7 +175,8 @@ public class DubboInterceptorTest {
|
|||
}
|
||||
|
||||
private void assertErrorLog(LogData logData) {
|
||||
assertThat(logData.getFields().size(), is(3));
|
||||
assertThat(logData.getFields().size(), is(4));
|
||||
assertThat(logData.getFields().get("event"), CoreMatchers.<Object>is("error"));
|
||||
assertThat(logData.getFields().get("error.kind"), CoreMatchers.<Object>is(RuntimeException.class.getName()));
|
||||
assertNull(logData.getFields().get("message"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ public class RequestParamForTestBelow283 extends SWBaseBean {
|
|||
*
|
||||
* @param expectSpanId expect span id
|
||||
*/
|
||||
public void assertSelf(String expectSpanId) {
|
||||
public void assertSelf(String expectSpanId, String expectHost) {
|
||||
assertNotNull(getContextData());
|
||||
assertThat(getContextData(), endsWith(expectSpanId));
|
||||
assertThat(getContextData(), endsWith(expectSpanId + "|" + expectHost));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,70 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.httpClient.v4;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
|
||||
import com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor;
|
||||
import com.a.eye.skywalking.model.Identification;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
/**
|
||||
* default headname of sky walking context<br/>
|
||||
*/
|
||||
public static String TRACE_HEAD_NAME = "SkyWalking-TRACING-NAME";
|
||||
|
||||
private static RPCClientInvokeMonitor rpcClientInvokeMonitor = new RPCClientInvokeMonitor();
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
Object[] allArguments = interceptorContext.allArguments();
|
||||
if (allArguments[0] == null || allArguments[1] == null) {
|
||||
// illegal args, can't trace. ignore.
|
||||
return;
|
||||
}
|
||||
HttpHost httpHost = (HttpHost) allArguments[0];
|
||||
HttpRequest httpRequest = (HttpRequest) allArguments[1];
|
||||
httpRequest
|
||||
.setHeader(
|
||||
TRACE_HEAD_NAME,
|
||||
"ContextData="
|
||||
+ rpcClientInvokeMonitor.beforeInvoke(
|
||||
Identification
|
||||
.newBuilder()
|
||||
.viewPoint(
|
||||
httpHost.toURI()
|
||||
.toString())
|
||||
.spanType(
|
||||
WebBuriedPointType
|
||||
.INSTANCE)
|
||||
.build()).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
Object[] allArguments = interceptorContext.allArguments();
|
||||
if (allArguments[0] == null || allArguments[1] == null) {
|
||||
// illegal args, can't trace. ignore.
|
||||
return ret;
|
||||
}
|
||||
rpcClientInvokeMonitor.afterInvoke();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
Object[] allArguments = interceptorContext.allArguments();
|
||||
if (allArguments[0] == null || allArguments[1] == null) {
|
||||
// illegal args, can't trace. ignore.
|
||||
return;
|
||||
}
|
||||
rpcClientInvokeMonitor.occurException(t);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.httpClient.v4;
|
||||
|
||||
import com.a.eye.skywalking.api.IBuriedPointType;
|
||||
|
||||
public enum WebBuriedPointType implements IBuriedPointType {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "W";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallType getCallType() {
|
||||
return CallType.SYNC;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.httpClient.v4.define;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
public class AbstractHttpClientPluginDefine extends HttpClientPluginDefine {
|
||||
|
||||
@Override
|
||||
public String enhanceClassName() {
|
||||
return "org.apache.http.impl.client.AbstractHttpClient";
|
||||
}
|
||||
|
||||
/**
|
||||
* version 4.2, intercept method: execute, intercept<br/>
|
||||
* public final HttpResponse execute(HttpHost target, HttpRequest request,
|
||||
* HttpContext context)<br/>
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("doExecute");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return getInstanceMethodsInterceptor();
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.httpClient.v4.define;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
public class DefaultRequestDirectorPluginDefine extends HttpClientPluginDefine {
|
||||
/**
|
||||
* DefaultRequestDirector is default implement.<br/>
|
||||
* usually use in version 4.0-4.2<br/>
|
||||
* since 4.3, this class is Deprecated.
|
||||
*/
|
||||
@Override
|
||||
public String enhanceClassName() {
|
||||
return "org.apache.http.impl.client.DefaultRequestDirector";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("execute");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return getInstanceMethodsInterceptor();
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.httpClient.v4.define;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
|
||||
public abstract class HttpClientPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getInstanceMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.httpClient.v4.HttpClientExecuteInterceptor";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.httpClient.v4.define;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
public class InternalHttpClientPluginDefine extends HttpClientPluginDefine {
|
||||
@Override
|
||||
public String enhanceClassName() {
|
||||
return "org.apache.http.impl.client.InternalHttpClient";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("doExecute");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return getInstanceMethodsInterceptor();
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.httpClient.v4.define;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
public class MinimalHttpClientPluginDefine extends HttpClientPluginDefine {
|
||||
@Override
|
||||
public String enhanceClassName() {
|
||||
return "org.apache.http.impl.client.MinimalHttpClient";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("doExecute");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return getInstanceMethodsInterceptor();
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
com.a.eye.skywalking.plugin.httpClient.v4.define.AbstractHttpClientPluginDefine
|
||||
com.a.eye.skywalking.plugin.httpClient.v4.define.InternalHttpClientPluginDefine
|
||||
com.a.eye.skywalking.plugin.httpClient.v4.define.MinimalHttpClientPluginDefine
|
||||
com.a.eye.skywalking.plugin.httpClient.v4.define.DefaultRequestDirectorPluginDefine
|
||||
com.a.eye.skywalking.plugin.httpClient.v4.define.AbstractHttpClientInstrumentation
|
||||
com.a.eye.skywalking.plugin.httpClient.v4.define.InternalHttpClientInstrumentation
|
||||
com.a.eye.skywalking.plugin.httpClient.v4.define.MinimalHttpClientInstrumentation
|
||||
com.a.eye.skywalking.plugin.httpClient.v4.define.DefaultRequestDirectorInstrumentation
|
||||
|
|
|
|||
|
|
@ -1,68 +1,74 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>skywalking-sdk-plugin</artifactId>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<version>3.0-2017</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>skywalking-sdk-plugin</artifactId>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<version>3.0-2017</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>skywalking-jdbc-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>skywalking-jdbc-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>jdbc-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<name>jdbc-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-api</artifactId>
|
||||
<version>3.0-2017</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.36</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.oracle</groupId>
|
||||
<artifactId>ojdbc14</artifactId>
|
||||
<version>10.2.0.4.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.192</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-api</artifactId>
|
||||
<version>3.0-2017</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.36</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.oracle</groupId>
|
||||
<artifactId>ojdbc14</artifactId>
|
||||
<version>10.2.0.4.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.192</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>[2.0.14,)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- 源码插件 -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<!-- 发布时自动将源码同时发布的配置 -->
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- 源码插件 -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<!-- 发布时自动将源码同时发布的配置 -->
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.jdbc;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.jdbc.define.JDBCBuriedPointType;
|
||||
import com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor;
|
||||
import com.a.eye.skywalking.model.Identification;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 连接级追踪,用于追踪用于Connection的操作追踪
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public class CallableStatementTracing {
|
||||
private static RPCClientInvokeMonitor rpcClientInvokeMonitor = new RPCClientInvokeMonitor();
|
||||
|
||||
public static <R> R execute(java.sql.CallableStatement realStatement,
|
||||
String connectInfo, String method, String sql, Executable<R> exec)
|
||||
throws SQLException {
|
||||
try {
|
||||
rpcClientInvokeMonitor.beforeInvoke(Identification
|
||||
.newBuilder()
|
||||
.viewPoint(connectInfo)
|
||||
.businessKey(
|
||||
"callableStatement."
|
||||
+ method
|
||||
+ (sql == null || sql.length() == 0 ? ""
|
||||
: ":" + sql)).spanType(JDBCBuriedPointType.INSTANCE).build());
|
||||
return exec.exe(realStatement, sql);
|
||||
} catch (SQLException e) {
|
||||
rpcClientInvokeMonitor.occurException(e);
|
||||
throw e;
|
||||
} finally {
|
||||
rpcClientInvokeMonitor.afterInvoke();
|
||||
}
|
||||
}
|
||||
|
||||
public interface Executable<R> {
|
||||
public R exe(java.sql.CallableStatement realConnection, String sql)
|
||||
throws SQLException;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.jdbc;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.jdbc.define.JDBCBuriedPointType;
|
||||
import com.a.eye.skywalking.model.Identification;
|
||||
import com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 连接级追踪,用于追踪用于Connection的操作追踪
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public class ConnectionTracing {
|
||||
private static RPCClientInvokeMonitor rpcClientInvokeMonitor = new RPCClientInvokeMonitor();
|
||||
|
||||
public static <R> R execute(java.sql.Connection realConnection,
|
||||
String connectInfo, String method, String sql, Executable<R> exec)
|
||||
throws SQLException {
|
||||
try {
|
||||
rpcClientInvokeMonitor.beforeInvoke(Identification
|
||||
.newBuilder()
|
||||
.viewPoint(connectInfo)
|
||||
.businessKey(
|
||||
"connection."
|
||||
+ method
|
||||
+ (sql == null || sql.length() == 0 ? ""
|
||||
: ":" + sql)).spanType(JDBCBuriedPointType.INSTANCE).build());
|
||||
return exec.exe(realConnection, sql);
|
||||
} catch (SQLException e) {
|
||||
rpcClientInvokeMonitor.occurException(e);
|
||||
throw e;
|
||||
} finally {
|
||||
rpcClientInvokeMonitor.afterInvoke();
|
||||
}
|
||||
}
|
||||
|
||||
public interface Executable<R> {
|
||||
public R exe(java.sql.Connection realConnection, String sql)
|
||||
throws SQLException;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.jdbc;
|
||||
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.trace.Span;
|
||||
import com.a.eye.skywalking.trace.tag.Tags;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 连接级追踪,用于追踪用于Connection的操作追踪
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public class PreparedStatementTracing {
|
||||
|
||||
public static <R> R execute(java.sql.PreparedStatement realStatement,
|
||||
String connectInfo, String method, String sql, Executable<R> exec)
|
||||
throws SQLException {
|
||||
Span span = ContextManager.INSTANCE.createSpan("JDBC/PreparedStatement/" + method);
|
||||
try {
|
||||
Tags.SPAN_LAYER.asRDB(span);
|
||||
Tags.DB_URL.set(span, connectInfo);
|
||||
Tags.DB_STATEMENT.set(span, sql);
|
||||
return exec.exe(realStatement, sql);
|
||||
} catch (SQLException e) {
|
||||
span.log(e);
|
||||
throw e;
|
||||
} finally {
|
||||
ContextManager.INSTANCE.stopSpan(span);
|
||||
}
|
||||
}
|
||||
|
||||
public interface Executable<R> {
|
||||
R exe(java.sql.PreparedStatement realConnection, String sql)
|
||||
throws SQLException;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,304 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.jdbc;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class SWConnection implements java.sql.Connection {
|
||||
private String connectInfo;
|
||||
|
||||
private final java.sql.Connection realConnection;
|
||||
|
||||
public SWConnection(String url, Properties info,
|
||||
java.sql.Connection realConnection) {
|
||||
super();
|
||||
this.connectInfo = url + "(" + info.getProperty("user") + ")";
|
||||
this.realConnection = realConnection;
|
||||
}
|
||||
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
return realConnection.unwrap(iface);
|
||||
}
|
||||
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return realConnection.isWrapperFor(iface);
|
||||
}
|
||||
|
||||
public Statement createStatement() throws SQLException {
|
||||
return new SWStatement(this, realConnection.createStatement(),
|
||||
this.connectInfo);
|
||||
}
|
||||
|
||||
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||
return new SWPreparedStatement(this,
|
||||
realConnection.prepareStatement(sql), this.connectInfo, sql);
|
||||
}
|
||||
|
||||
public CallableStatement prepareCall(String sql) throws SQLException {
|
||||
return new SWCallableStatement(this, realConnection.prepareCall(sql),
|
||||
this.connectInfo, sql);
|
||||
}
|
||||
|
||||
public String nativeSQL(String sql) throws SQLException {
|
||||
return realConnection.nativeSQL(sql);
|
||||
}
|
||||
|
||||
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
||||
realConnection.setAutoCommit(autoCommit);
|
||||
}
|
||||
|
||||
public boolean getAutoCommit() throws SQLException {
|
||||
return realConnection.getAutoCommit();
|
||||
}
|
||||
|
||||
public void commit() throws SQLException {
|
||||
ConnectionTracing.execute(realConnection, connectInfo, "commit", "",
|
||||
new ConnectionTracing.Executable<String>() {
|
||||
public String exe(java.sql.Connection realConnection,
|
||||
String sql) throws SQLException {
|
||||
realConnection.commit();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void rollback() throws SQLException {
|
||||
ConnectionTracing.execute(realConnection, connectInfo, "rollback", "",
|
||||
new ConnectionTracing.Executable<String>() {
|
||||
public String exe(java.sql.Connection realConnection,
|
||||
String sql) throws SQLException {
|
||||
realConnection.rollback();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void close() throws SQLException {
|
||||
ConnectionTracing.execute(realConnection, connectInfo, "close", "",
|
||||
new ConnectionTracing.Executable<String>() {
|
||||
public String exe(java.sql.Connection realConnection,
|
||||
String sql) throws SQLException {
|
||||
realConnection.close();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isClosed() throws SQLException {
|
||||
return realConnection.isClosed();
|
||||
}
|
||||
|
||||
public DatabaseMetaData getMetaData() throws SQLException {
|
||||
return realConnection.getMetaData();
|
||||
}
|
||||
|
||||
public void setReadOnly(boolean readOnly) throws SQLException {
|
||||
realConnection.setReadOnly(readOnly);
|
||||
}
|
||||
|
||||
public boolean isReadOnly() throws SQLException {
|
||||
return realConnection.isReadOnly();
|
||||
}
|
||||
|
||||
public void setCatalog(String catalog) throws SQLException {
|
||||
realConnection.setCatalog(catalog);
|
||||
}
|
||||
|
||||
public String getCatalog() throws SQLException {
|
||||
return realConnection.getCatalog();
|
||||
}
|
||||
|
||||
public void setTransactionIsolation(int level) throws SQLException {
|
||||
realConnection.setTransactionIsolation(level);
|
||||
}
|
||||
|
||||
public int getTransactionIsolation() throws SQLException {
|
||||
return realConnection.getTransactionIsolation();
|
||||
}
|
||||
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
return realConnection.getWarnings();
|
||||
}
|
||||
|
||||
public void clearWarnings() throws SQLException {
|
||||
realConnection.clearWarnings();
|
||||
}
|
||||
|
||||
public Statement createStatement(int resultSetType, int resultSetConcurrency)
|
||||
throws SQLException {
|
||||
return new SWStatement(this, realConnection.createStatement(
|
||||
resultSetType, resultSetConcurrency), this.connectInfo);
|
||||
}
|
||||
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType,
|
||||
int resultSetConcurrency) throws SQLException {
|
||||
return new SWPreparedStatement(this, realConnection.prepareStatement(
|
||||
sql, resultSetType, resultSetConcurrency), this.connectInfo,
|
||||
sql);
|
||||
}
|
||||
|
||||
public CallableStatement prepareCall(String sql, int resultSetType,
|
||||
int resultSetConcurrency) throws SQLException {
|
||||
return new SWCallableStatement(this, realConnection.prepareCall(sql,
|
||||
resultSetType, resultSetConcurrency), this.connectInfo, sql);
|
||||
}
|
||||
|
||||
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
||||
return realConnection.getTypeMap();
|
||||
}
|
||||
|
||||
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
|
||||
realConnection.setTypeMap(map);
|
||||
}
|
||||
|
||||
public void setHoldability(int holdability) throws SQLException {
|
||||
realConnection.setHoldability(holdability);
|
||||
}
|
||||
|
||||
public int getHoldability() throws SQLException {
|
||||
return realConnection.getHoldability();
|
||||
}
|
||||
|
||||
public Savepoint setSavepoint() throws SQLException {
|
||||
return realConnection.setSavepoint();
|
||||
}
|
||||
|
||||
public Savepoint setSavepoint(String name) throws SQLException {
|
||||
return realConnection.setSavepoint(name);
|
||||
}
|
||||
|
||||
public void rollback(final Savepoint savepoint) throws SQLException {
|
||||
ConnectionTracing.execute(realConnection, connectInfo,
|
||||
"rollback to savepoint", "", new ConnectionTracing.Executable<String>() {
|
||||
public String exe(java.sql.Connection realConnection,
|
||||
String sql) throws SQLException {
|
||||
realConnection.rollback(savepoint);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void releaseSavepoint(final Savepoint savepoint) throws SQLException {
|
||||
ConnectionTracing.execute(realConnection, connectInfo,
|
||||
"releaseSavepoint savepoint", "", new ConnectionTracing.Executable<String>() {
|
||||
public String exe(java.sql.Connection realConnection,
|
||||
String sql) throws SQLException {
|
||||
realConnection.releaseSavepoint(savepoint);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Statement createStatement(int resultSetType,
|
||||
int resultSetConcurrency, int resultSetHoldability)
|
||||
throws SQLException {
|
||||
return new SWStatement(this, realConnection.createStatement(
|
||||
resultSetType, resultSetConcurrency, resultSetHoldability),
|
||||
this.connectInfo);
|
||||
}
|
||||
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType,
|
||||
int resultSetConcurrency, int resultSetHoldability)
|
||||
throws SQLException {
|
||||
return new SWPreparedStatement(this,
|
||||
realConnection.prepareStatement(sql, resultSetType,
|
||||
resultSetConcurrency, resultSetHoldability),
|
||||
this.connectInfo, sql);
|
||||
}
|
||||
|
||||
public CallableStatement prepareCall(String sql, int resultSetType,
|
||||
int resultSetConcurrency, int resultSetHoldability)
|
||||
throws SQLException {
|
||||
return new SWCallableStatement(this, realConnection.prepareCall(sql,
|
||||
resultSetType, resultSetConcurrency, resultSetHoldability), this.connectInfo, sql);
|
||||
}
|
||||
|
||||
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
|
||||
throws SQLException {
|
||||
return new SWPreparedStatement(this, realConnection.prepareStatement(
|
||||
sql, autoGeneratedKeys), this.connectInfo, sql);
|
||||
}
|
||||
|
||||
public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
|
||||
throws SQLException {
|
||||
return new SWPreparedStatement(this, realConnection.prepareStatement(
|
||||
sql, columnIndexes), this.connectInfo, sql);
|
||||
}
|
||||
|
||||
public PreparedStatement prepareStatement(String sql, String[] columnNames)
|
||||
throws SQLException {
|
||||
return new SWPreparedStatement(this, realConnection.prepareStatement(
|
||||
sql, columnNames), this.connectInfo, sql);
|
||||
}
|
||||
|
||||
public Clob createClob() throws SQLException {
|
||||
return realConnection.createClob();
|
||||
}
|
||||
|
||||
public Blob createBlob() throws SQLException {
|
||||
return realConnection.createBlob();
|
||||
}
|
||||
|
||||
public NClob createNClob() throws SQLException {
|
||||
return realConnection.createNClob();
|
||||
}
|
||||
|
||||
public SQLXML createSQLXML() throws SQLException {
|
||||
return realConnection.createSQLXML();
|
||||
}
|
||||
|
||||
public boolean isValid(int timeout) throws SQLException {
|
||||
return realConnection.isValid(timeout);
|
||||
}
|
||||
|
||||
public void setClientInfo(String name, String value)
|
||||
throws SQLClientInfoException {
|
||||
realConnection.setClientInfo(name, value);
|
||||
}
|
||||
|
||||
public void setClientInfo(Properties properties)
|
||||
throws SQLClientInfoException {
|
||||
realConnection.setClientInfo(properties);
|
||||
}
|
||||
|
||||
public String getClientInfo(String name) throws SQLException {
|
||||
return realConnection.getClientInfo(name);
|
||||
}
|
||||
|
||||
public Properties getClientInfo() throws SQLException {
|
||||
return realConnection.getClientInfo();
|
||||
}
|
||||
|
||||
public Array createArrayOf(String typeName, Object[] elements)
|
||||
throws SQLException {
|
||||
return realConnection.createArrayOf(typeName, elements);
|
||||
}
|
||||
|
||||
public Struct createStruct(String typeName, Object[] attributes)
|
||||
throws SQLException {
|
||||
return realConnection.createStruct(typeName, attributes);
|
||||
}
|
||||
|
||||
public void setSchema(String schema) throws SQLException {
|
||||
realConnection.setSchema(schema);
|
||||
}
|
||||
|
||||
public String getSchema() throws SQLException {
|
||||
return realConnection.getSchema();
|
||||
}
|
||||
|
||||
public void abort(Executor executor) throws SQLException {
|
||||
realConnection.abort(executor);
|
||||
}
|
||||
|
||||
public void setNetworkTimeout(Executor executor, int milliseconds)
|
||||
throws SQLException {
|
||||
realConnection.setNetworkTimeout(executor, milliseconds);
|
||||
}
|
||||
|
||||
public int getNetworkTimeout() throws SQLException {
|
||||
return realConnection.getNetworkTimeout();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,518 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.jdbc;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URL;
|
||||
import java.sql.*;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class SWPreparedStatement implements PreparedStatement {
|
||||
private Connection realConnection;
|
||||
private PreparedStatement realStatement;
|
||||
private String connectInfo;
|
||||
private String sql;
|
||||
|
||||
SWPreparedStatement(Connection realConnection,
|
||||
PreparedStatement realStatement, String connectInfo,
|
||||
String sql) {
|
||||
this.realConnection = realConnection;
|
||||
this.realStatement = realStatement;
|
||||
this.connectInfo = connectInfo;
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
public ResultSet executeQuery(String sql) throws SQLException {
|
||||
return PreparedStatementTracing.execute(realStatement, connectInfo, "executeQuery", sql, new PreparedStatementTracing.Executable<ResultSet>() {
|
||||
public ResultSet exe(PreparedStatement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeQuery(sql);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int executeUpdate(String sql) throws SQLException {
|
||||
return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable<Integer>() {
|
||||
public Integer exe(PreparedStatement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeUpdate(sql);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void close() throws SQLException {
|
||||
realStatement.close();
|
||||
}
|
||||
|
||||
public int getMaxFieldSize() throws SQLException {
|
||||
return realStatement.getMaxFieldSize();
|
||||
}
|
||||
|
||||
public void setMaxFieldSize(int max) throws SQLException {
|
||||
realStatement.setMaxFieldSize(max);
|
||||
}
|
||||
|
||||
public int getMaxRows() throws SQLException {
|
||||
return realStatement.getMaxRows();
|
||||
}
|
||||
|
||||
public void setMaxRows(int max) throws SQLException {
|
||||
realStatement.setMaxRows(max);
|
||||
}
|
||||
|
||||
public void setEscapeProcessing(boolean enable) throws SQLException {
|
||||
realStatement.setEscapeProcessing(enable);
|
||||
}
|
||||
|
||||
public int getQueryTimeout() throws SQLException {
|
||||
return realStatement.getQueryTimeout();
|
||||
}
|
||||
|
||||
public void setQueryTimeout(int seconds) throws SQLException {
|
||||
realStatement.setQueryTimeout(seconds);
|
||||
}
|
||||
|
||||
public void cancel() throws SQLException {
|
||||
realStatement.cancel();
|
||||
}
|
||||
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
return realStatement.getWarnings();
|
||||
}
|
||||
|
||||
public void clearWarnings() throws SQLException {
|
||||
realStatement.clearWarnings();
|
||||
}
|
||||
|
||||
public void setCursorName(String name) throws SQLException {
|
||||
realStatement.setCursorName(name);
|
||||
}
|
||||
|
||||
public boolean execute(String sql) throws SQLException {
|
||||
return PreparedStatementTracing.execute(realStatement, connectInfo, "execute", sql, new PreparedStatementTracing.Executable<Boolean>() {
|
||||
public Boolean exe(PreparedStatement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.execute(sql);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ResultSet getResultSet() throws SQLException {
|
||||
return realStatement.getResultSet();
|
||||
}
|
||||
|
||||
public int getUpdateCount() throws SQLException {
|
||||
return realStatement.getUpdateCount();
|
||||
}
|
||||
|
||||
public boolean getMoreResults() throws SQLException {
|
||||
return realStatement.getMoreResults();
|
||||
}
|
||||
|
||||
public void setFetchDirection(int direction) throws SQLException {
|
||||
realStatement.setFetchDirection(direction);
|
||||
}
|
||||
|
||||
public int getFetchDirection() throws SQLException {
|
||||
return realStatement.getFetchDirection();
|
||||
}
|
||||
|
||||
public void setFetchSize(int rows) throws SQLException {
|
||||
realStatement.setFetchSize(rows);
|
||||
}
|
||||
|
||||
public int getFetchSize() throws SQLException {
|
||||
return realStatement.getFetchSize();
|
||||
}
|
||||
|
||||
public int getResultSetConcurrency() throws SQLException {
|
||||
return realStatement.getResultSetConcurrency();
|
||||
}
|
||||
|
||||
public int getResultSetType() throws SQLException {
|
||||
return realStatement.getResultSetType();
|
||||
}
|
||||
|
||||
public void addBatch(String sql) throws SQLException {
|
||||
realStatement.addBatch(sql);
|
||||
}
|
||||
|
||||
public void clearBatch() throws SQLException {
|
||||
realStatement.clearBatch();
|
||||
}
|
||||
|
||||
public int[] executeBatch() throws SQLException {
|
||||
return PreparedStatementTracing.execute(realStatement, connectInfo, "executeBatch", "", new PreparedStatementTracing.Executable<int[]>() {
|
||||
public int[] exe(PreparedStatement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeBatch();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
return realConnection;
|
||||
}
|
||||
|
||||
public boolean getMoreResults(int current) throws SQLException {
|
||||
return realStatement.getMoreResults(current);
|
||||
}
|
||||
|
||||
public ResultSet getGeneratedKeys() throws SQLException {
|
||||
return realStatement.getGeneratedKeys();
|
||||
}
|
||||
|
||||
public int executeUpdate(String sql, final int autoGeneratedKeys)
|
||||
throws SQLException {
|
||||
return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable<Integer>() {
|
||||
public Integer exe(PreparedStatement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeUpdate(sql, autoGeneratedKeys);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int executeUpdate(String sql, final int[] columnIndexes)
|
||||
throws SQLException {
|
||||
return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable<Integer>() {
|
||||
public Integer exe(PreparedStatement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeUpdate(sql, columnIndexes);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int executeUpdate(String sql, final String[] columnNames)
|
||||
throws SQLException {
|
||||
return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable<Integer>() {
|
||||
public Integer exe(PreparedStatement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeUpdate(sql, columnNames);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean execute(String sql, final int autoGeneratedKeys)
|
||||
throws SQLException {
|
||||
return PreparedStatementTracing.execute(realStatement, connectInfo, "execute", sql, new PreparedStatementTracing.Executable<Boolean>() {
|
||||
public Boolean exe(PreparedStatement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.execute(sql, autoGeneratedKeys);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean execute(String sql, final int[] columnIndexes) throws SQLException {
|
||||
return PreparedStatementTracing.execute(realStatement, connectInfo, "execute", sql, new PreparedStatementTracing.Executable<Boolean>() {
|
||||
public Boolean exe(PreparedStatement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.execute(sql, columnIndexes);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean execute(String sql, final String[] columnNames)
|
||||
throws SQLException {
|
||||
return PreparedStatementTracing.execute(realStatement, connectInfo, "execute", sql, new PreparedStatementTracing.Executable<Boolean>() {
|
||||
public Boolean exe(PreparedStatement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.execute(sql, columnNames);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int getResultSetHoldability() throws SQLException {
|
||||
return realStatement.getResultSetHoldability();
|
||||
}
|
||||
|
||||
public boolean isClosed() throws SQLException {
|
||||
return realStatement.isClosed();
|
||||
}
|
||||
|
||||
public void setPoolable(boolean poolable) throws SQLException {
|
||||
realStatement.setPoolable(poolable);
|
||||
}
|
||||
|
||||
public boolean isPoolable() throws SQLException {
|
||||
return realStatement.isPoolable();
|
||||
}
|
||||
|
||||
public void closeOnCompletion() throws SQLException {
|
||||
realStatement.closeOnCompletion();
|
||||
}
|
||||
|
||||
public boolean isCloseOnCompletion() throws SQLException {
|
||||
return realStatement.isCloseOnCompletion();
|
||||
}
|
||||
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
return realStatement.unwrap(iface);
|
||||
}
|
||||
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return realStatement.isWrapperFor(iface);
|
||||
}
|
||||
|
||||
public ResultSet executeQuery() throws SQLException {
|
||||
return PreparedStatementTracing.execute(realStatement, connectInfo, "executeQuery", sql, new PreparedStatementTracing.Executable<ResultSet>() {
|
||||
public ResultSet exe(PreparedStatement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeQuery();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int executeUpdate() throws SQLException {
|
||||
return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable<Integer>() {
|
||||
public Integer exe(PreparedStatement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeUpdate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setNull(int parameterIndex, int sqlType) throws SQLException {
|
||||
realStatement.setNull(parameterIndex, sqlType);
|
||||
}
|
||||
|
||||
public void setBoolean(int parameterIndex, boolean x) throws SQLException {
|
||||
realStatement.setBoolean(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setByte(int parameterIndex, byte x) throws SQLException {
|
||||
realStatement.setByte(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setShort(int parameterIndex, short x) throws SQLException {
|
||||
realStatement.setShort(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setInt(int parameterIndex, int x) throws SQLException {
|
||||
realStatement.setInt(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setLong(int parameterIndex, long x) throws SQLException {
|
||||
realStatement.setLong(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setFloat(int parameterIndex, float x) throws SQLException {
|
||||
realStatement.setFloat(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setDouble(int parameterIndex, double x) throws SQLException {
|
||||
realStatement.setDouble(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setBigDecimal(int parameterIndex, BigDecimal x)
|
||||
throws SQLException {
|
||||
realStatement.setBigDecimal(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setString(int parameterIndex, String x) throws SQLException {
|
||||
realStatement.setString(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setBytes(int parameterIndex, byte[] x) throws SQLException {
|
||||
realStatement.setBytes(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setDate(int parameterIndex, Date x) throws SQLException {
|
||||
realStatement.setDate(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setTime(int parameterIndex, Time x) throws SQLException {
|
||||
realStatement.setTime(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setTimestamp(int parameterIndex, Timestamp x)
|
||||
throws SQLException {
|
||||
realStatement.setTimestamp(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setAsciiStream(int parameterIndex, InputStream x, int length)
|
||||
throws SQLException {
|
||||
realStatement.setAsciiStream(parameterIndex, x, length);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setUnicodeStream(int parameterIndex, InputStream x, int length)
|
||||
throws SQLException {
|
||||
realStatement.setUnicodeStream(parameterIndex, x, length);
|
||||
}
|
||||
|
||||
public void setBinaryStream(int parameterIndex, InputStream x, int length)
|
||||
throws SQLException {
|
||||
realStatement.setBinaryStream(parameterIndex, x, length);
|
||||
}
|
||||
|
||||
public void clearParameters() throws SQLException {
|
||||
realStatement.clearParameters();
|
||||
}
|
||||
|
||||
public void setObject(int parameterIndex, Object x, int targetSqlType)
|
||||
throws SQLException {
|
||||
realStatement.setObject(parameterIndex, x, targetSqlType);
|
||||
}
|
||||
|
||||
public void setObject(int parameterIndex, Object x) throws SQLException {
|
||||
realStatement.setObject(parameterIndex, x);
|
||||
}
|
||||
|
||||
public boolean execute() throws SQLException {
|
||||
return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable<Boolean>() {
|
||||
public Boolean exe(PreparedStatement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addBatch() throws SQLException {
|
||||
realStatement.addBatch();
|
||||
}
|
||||
|
||||
public void setCharacterStream(int parameterIndex, Reader reader, int length)
|
||||
throws SQLException {
|
||||
realStatement.setCharacterStream(parameterIndex, reader, length);
|
||||
}
|
||||
|
||||
public void setRef(int parameterIndex, Ref x) throws SQLException {
|
||||
realStatement.setRef(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setBlob(int parameterIndex, Blob x) throws SQLException {
|
||||
realStatement.setBlob(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setClob(int parameterIndex, Clob x) throws SQLException {
|
||||
realStatement.setClob(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setArray(int parameterIndex, Array x) throws SQLException {
|
||||
realStatement.setArray(parameterIndex, x);
|
||||
}
|
||||
|
||||
public ResultSetMetaData getMetaData() throws SQLException {
|
||||
return realStatement.getMetaData();
|
||||
}
|
||||
|
||||
public void setDate(int parameterIndex, Date x, Calendar cal)
|
||||
throws SQLException {
|
||||
realStatement.setDate(parameterIndex, x, cal);
|
||||
}
|
||||
|
||||
public void setTime(int parameterIndex, Time x, Calendar cal)
|
||||
throws SQLException {
|
||||
realStatement.setTime(parameterIndex, x, cal);
|
||||
}
|
||||
|
||||
public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
|
||||
throws SQLException {
|
||||
realStatement.setTimestamp(parameterIndex, x, cal);
|
||||
}
|
||||
|
||||
public void setNull(int parameterIndex, int sqlType, String typeName)
|
||||
throws SQLException {
|
||||
realStatement.setNull(parameterIndex, sqlType, typeName);
|
||||
}
|
||||
|
||||
public void setURL(int parameterIndex, URL x) throws SQLException {
|
||||
realStatement.setURL(parameterIndex, x);
|
||||
}
|
||||
|
||||
public ParameterMetaData getParameterMetaData() throws SQLException {
|
||||
return realStatement.getParameterMetaData();
|
||||
}
|
||||
|
||||
public void setRowId(int parameterIndex, RowId x) throws SQLException {
|
||||
realStatement.setRowId(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setNString(int parameterIndex, String value)
|
||||
throws SQLException {
|
||||
realStatement.setNString(parameterIndex, value);
|
||||
}
|
||||
|
||||
public void setNCharacterStream(int parameterIndex, Reader value,
|
||||
long length) throws SQLException {
|
||||
realStatement.setNCharacterStream(parameterIndex, value, length);
|
||||
}
|
||||
|
||||
public void setNClob(int parameterIndex, NClob value) throws SQLException {
|
||||
realStatement.setNClob(parameterIndex, value);
|
||||
}
|
||||
|
||||
public void setClob(int parameterIndex, Reader reader, long length)
|
||||
throws SQLException {
|
||||
realStatement.setClob(parameterIndex, reader, length);
|
||||
}
|
||||
|
||||
public void setBlob(int parameterIndex, InputStream inputStream, long length)
|
||||
throws SQLException {
|
||||
realStatement.setBlob(parameterIndex, inputStream, length);
|
||||
}
|
||||
|
||||
public void setNClob(int parameterIndex, Reader reader, long length)
|
||||
throws SQLException {
|
||||
realStatement.setNClob(parameterIndex, reader, length);
|
||||
}
|
||||
|
||||
public void setSQLXML(int parameterIndex, SQLXML xmlObject)
|
||||
throws SQLException {
|
||||
realStatement.setSQLXML(parameterIndex, xmlObject);
|
||||
}
|
||||
|
||||
public void setObject(int parameterIndex, Object x, int targetSqlType,
|
||||
int scaleOrLength) throws SQLException {
|
||||
realStatement.setObject(parameterIndex, x, targetSqlType, scaleOrLength);
|
||||
}
|
||||
|
||||
public void setAsciiStream(int parameterIndex, InputStream x, long length)
|
||||
throws SQLException {
|
||||
realStatement.setAsciiStream(parameterIndex, x, length);
|
||||
}
|
||||
|
||||
public void setBinaryStream(int parameterIndex, InputStream x, long length)
|
||||
throws SQLException {
|
||||
realStatement.setBinaryStream(parameterIndex, x, length);
|
||||
}
|
||||
|
||||
public void setCharacterStream(int parameterIndex, Reader reader,
|
||||
long length) throws SQLException {
|
||||
realStatement.setCharacterStream(parameterIndex, reader, length);
|
||||
}
|
||||
|
||||
public void setAsciiStream(int parameterIndex, InputStream x)
|
||||
throws SQLException {
|
||||
realStatement.setAsciiStream(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setBinaryStream(int parameterIndex, InputStream x)
|
||||
throws SQLException {
|
||||
realStatement.setBinaryStream(parameterIndex, x);
|
||||
}
|
||||
|
||||
public void setCharacterStream(int parameterIndex, Reader reader)
|
||||
throws SQLException {
|
||||
realStatement.setCharacterStream(parameterIndex, reader);
|
||||
}
|
||||
|
||||
public void setNCharacterStream(int parameterIndex, Reader value)
|
||||
throws SQLException {
|
||||
realStatement.setNCharacterStream(parameterIndex, value);
|
||||
}
|
||||
|
||||
public void setClob(int parameterIndex, Reader reader) throws SQLException {
|
||||
realStatement.setClob(parameterIndex, reader);
|
||||
}
|
||||
|
||||
public void setBlob(int parameterIndex, InputStream inputStream)
|
||||
throws SQLException {
|
||||
realStatement.setBlob(parameterIndex, inputStream);
|
||||
}
|
||||
|
||||
public void setNClob(int parameterIndex, Reader reader) throws SQLException {
|
||||
realStatement.setNClob(parameterIndex, reader);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,251 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.jdbc;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLWarning;
|
||||
|
||||
|
||||
public class SWStatement implements java.sql.Statement {
|
||||
private Connection realConnection;
|
||||
private java.sql.Statement realStatement;
|
||||
private String connectInfo;
|
||||
|
||||
SWStatement(Connection realConnection, java.sql.Statement realStatement, String connectInfo) {
|
||||
this.realConnection = realConnection;
|
||||
this.realStatement = realStatement;
|
||||
this.connectInfo = connectInfo;
|
||||
}
|
||||
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
return realStatement.unwrap(iface);
|
||||
}
|
||||
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return realStatement.isWrapperFor(iface);
|
||||
}
|
||||
|
||||
public ResultSet executeQuery(String sql) throws SQLException {
|
||||
return StatementTracing.execute(realStatement, connectInfo, "executeQuery", sql, new StatementTracing.Executable<ResultSet>() {
|
||||
public ResultSet exe(java.sql.Statement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeQuery(sql);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int executeUpdate(String sql) throws SQLException {
|
||||
return StatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new StatementTracing.Executable<Integer>() {
|
||||
public Integer exe(java.sql.Statement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeUpdate(sql);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void close() throws SQLException {
|
||||
realStatement.close();
|
||||
}
|
||||
|
||||
public int getMaxFieldSize() throws SQLException {
|
||||
return realStatement.getMaxFieldSize();
|
||||
}
|
||||
|
||||
public void setMaxFieldSize(int max) throws SQLException {
|
||||
realStatement.setMaxFieldSize(max);
|
||||
}
|
||||
|
||||
public int getMaxRows() throws SQLException {
|
||||
return realStatement.getMaxRows();
|
||||
}
|
||||
|
||||
public void setMaxRows(int max) throws SQLException {
|
||||
realStatement.setMaxRows(max);
|
||||
}
|
||||
|
||||
public void setEscapeProcessing(boolean enable) throws SQLException {
|
||||
realStatement.setEscapeProcessing(enable);
|
||||
}
|
||||
|
||||
public int getQueryTimeout() throws SQLException {
|
||||
return realStatement.getQueryTimeout();
|
||||
}
|
||||
|
||||
public void setQueryTimeout(int seconds) throws SQLException {
|
||||
realStatement.setQueryTimeout(seconds);
|
||||
}
|
||||
|
||||
public void cancel() throws SQLException {
|
||||
realStatement.cancel();
|
||||
}
|
||||
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
return realStatement.getWarnings();
|
||||
}
|
||||
|
||||
public void clearWarnings() throws SQLException {
|
||||
realStatement.clearWarnings();
|
||||
}
|
||||
|
||||
public void setCursorName(String name) throws SQLException {
|
||||
realStatement.setCursorName(name);
|
||||
}
|
||||
|
||||
public boolean execute(String sql) throws SQLException {
|
||||
return StatementTracing.execute(realStatement, connectInfo, "execute", sql, new StatementTracing.Executable<Boolean>() {
|
||||
public Boolean exe(java.sql.Statement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.execute(sql);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ResultSet getResultSet() throws SQLException {
|
||||
return realStatement.getResultSet();
|
||||
}
|
||||
|
||||
public int getUpdateCount() throws SQLException {
|
||||
return realStatement.getUpdateCount();
|
||||
}
|
||||
|
||||
public boolean getMoreResults() throws SQLException {
|
||||
return realStatement.getMoreResults();
|
||||
}
|
||||
|
||||
public void setFetchDirection(int direction) throws SQLException {
|
||||
realStatement.setFetchDirection(direction);
|
||||
}
|
||||
|
||||
public int getFetchDirection() throws SQLException {
|
||||
return realStatement.getFetchDirection();
|
||||
}
|
||||
|
||||
public void setFetchSize(int rows) throws SQLException {
|
||||
realStatement.setFetchSize(rows);
|
||||
}
|
||||
|
||||
public int getFetchSize() throws SQLException {
|
||||
return realStatement.getFetchSize();
|
||||
}
|
||||
|
||||
public int getResultSetConcurrency() throws SQLException {
|
||||
return realStatement.getResultSetConcurrency();
|
||||
}
|
||||
|
||||
public int getResultSetType() throws SQLException {
|
||||
return realStatement.getResultSetType();
|
||||
}
|
||||
|
||||
public void addBatch(String sql) throws SQLException {
|
||||
realStatement.addBatch(sql);
|
||||
}
|
||||
|
||||
public void clearBatch() throws SQLException {
|
||||
realStatement.clearBatch();
|
||||
}
|
||||
|
||||
public int[] executeBatch() throws SQLException {
|
||||
return StatementTracing.execute(realStatement, connectInfo, "executeBatch", "", new StatementTracing.Executable<int[]>() {
|
||||
public int[] exe(java.sql.Statement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeBatch();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
return this.realConnection;
|
||||
}
|
||||
|
||||
public boolean getMoreResults(int current) throws SQLException {
|
||||
return realStatement.getMoreResults(current);
|
||||
}
|
||||
|
||||
public ResultSet getGeneratedKeys() throws SQLException {
|
||||
return realStatement.getGeneratedKeys();
|
||||
}
|
||||
|
||||
public int executeUpdate(String sql, final int autoGeneratedKeys)
|
||||
throws SQLException {
|
||||
return StatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new StatementTracing.Executable<Integer>() {
|
||||
public Integer exe(java.sql.Statement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeUpdate(sql, autoGeneratedKeys);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int executeUpdate(String sql, final int[] columnIndexes)
|
||||
throws SQLException {
|
||||
return StatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new StatementTracing.Executable<Integer>() {
|
||||
public Integer exe(java.sql.Statement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeUpdate(sql, columnIndexes);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int executeUpdate(String sql, final String[] columnNames)
|
||||
throws SQLException {
|
||||
return StatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new StatementTracing.Executable<Integer>() {
|
||||
public Integer exe(java.sql.Statement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.executeUpdate(sql, columnNames);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean execute(String sql, final int autoGeneratedKeys)
|
||||
throws SQLException {
|
||||
return StatementTracing.execute(realStatement, connectInfo, "execute", sql, new StatementTracing.Executable<Boolean>() {
|
||||
public Boolean exe(java.sql.Statement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.execute(sql, autoGeneratedKeys);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean execute(String sql, final int[] columnIndexes) throws SQLException {
|
||||
return StatementTracing.execute(realStatement, connectInfo, "execute", sql, new StatementTracing.Executable<Boolean>() {
|
||||
public Boolean exe(java.sql.Statement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.execute(sql, columnIndexes);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean execute(String sql, final String[] columnNames)
|
||||
throws SQLException {
|
||||
return StatementTracing.execute(realStatement, connectInfo, "execute", sql, new StatementTracing.Executable<Boolean>() {
|
||||
public Boolean exe(java.sql.Statement realStatement, String sql)
|
||||
throws SQLException {
|
||||
return realStatement.execute(sql, columnNames);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int getResultSetHoldability() throws SQLException {
|
||||
return realStatement.getResultSetHoldability();
|
||||
}
|
||||
|
||||
public boolean isClosed() throws SQLException {
|
||||
return realStatement.isClosed();
|
||||
}
|
||||
|
||||
public void setPoolable(boolean poolable) throws SQLException {
|
||||
realStatement.setPoolable(poolable);
|
||||
}
|
||||
|
||||
public boolean isPoolable() throws SQLException {
|
||||
return realStatement.isPoolable();
|
||||
}
|
||||
|
||||
public void closeOnCompletion() throws SQLException {
|
||||
realStatement.closeOnCompletion();
|
||||
}
|
||||
|
||||
public boolean isCloseOnCompletion() throws SQLException {
|
||||
return realStatement.isCloseOnCompletion();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.jdbc;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.jdbc.define.JDBCBuriedPointType;
|
||||
import com.a.eye.skywalking.model.Identification;
|
||||
import com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 连接级追踪,用于追踪用于Statement的操作追踪
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public class StatementTracing {
|
||||
private static RPCClientInvokeMonitor rpcClientInvokeMonitor = new RPCClientInvokeMonitor();
|
||||
|
||||
public static <R> R execute(java.sql.Statement realStatement,
|
||||
String connectInfo, String method, String sql, Executable<R> exec)
|
||||
throws SQLException {
|
||||
try {
|
||||
rpcClientInvokeMonitor.beforeInvoke(Identification
|
||||
.newBuilder()
|
||||
.viewPoint(connectInfo)
|
||||
.businessKey(
|
||||
"statement."
|
||||
+ method
|
||||
+ (sql == null || sql.length() == 0 ? ""
|
||||
: ":" + sql)).spanType(JDBCBuriedPointType.INSTANCE).build());
|
||||
return exec.exe(realStatement, sql);
|
||||
} catch (SQLException e) {
|
||||
rpcClientInvokeMonitor.occurException(e);
|
||||
throw e;
|
||||
} finally {
|
||||
rpcClientInvokeMonitor.afterInvoke();
|
||||
}
|
||||
}
|
||||
|
||||
public interface Executable<R> {
|
||||
public R exe(java.sql.Statement realStatement, String sql)
|
||||
throws SQLException;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.jdbc.define;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
public abstract class AbstractDatabasePluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("connect");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.jdbc.define.JDBCDriverInterceptor";
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.jdbc.define;
|
||||
|
||||
public class H2PluginDefine extends AbstractDatabasePluginDefine {
|
||||
@Override
|
||||
protected String enhanceClassName() {
|
||||
return "org.h2.Driver";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.jdbc.define;
|
||||
|
||||
import com.a.eye.skywalking.api.IBuriedPointType;
|
||||
|
||||
public enum JDBCBuriedPointType implements IBuriedPointType {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "J";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallType getCallType() {
|
||||
return CallType.LOCAL;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.jdbc.define;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.jdbc.SWConnection;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.Properties;
|
||||
|
||||
public class JDBCDriverInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
MethodInterceptResult result) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
Object ret) {
|
||||
return new SWConnection((String) interceptorContext.allArguments()[0],
|
||||
(Properties) interceptorContext.allArguments()[1], (Connection) ret);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.jdbc.define;
|
||||
|
||||
/**
|
||||
* Created by xin on 16/8/4.
|
||||
*/
|
||||
public class MysqlPluginDefine extends AbstractDatabasePluginDefine {
|
||||
@Override
|
||||
protected String enhanceClassName() {
|
||||
return "com.mysql.jdbc.Driver";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.jdbc.define;
|
||||
|
||||
/**
|
||||
* Created by xin on 16/8/4.
|
||||
*/
|
||||
public class OraclePluginDefine extends AbstractDatabasePluginDefine {
|
||||
@Override
|
||||
protected String enhanceClassName() {
|
||||
return "oracle.jdbc.OracleDriver";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
com.a.eye.skywalking.plugin.jdbc.define.H2PluginDefine
|
||||
com.a.eye.skywalking.plugin.jdbc.define.MysqlPluginDefine
|
||||
com.a.eye.skywalking.plugin.jdbc.define.OraclePluginDefine
|
||||
com.a.eye.skywalking.plugin.jdbc.define.H2Instrumentation
|
||||
com.a.eye.skywalking.plugin.jdbc.define.MysqlInstrumentation
|
||||
com.a.eye.skywalking.plugin.jdbc.define.OracleInstrumentation
|
||||
|
|
|
|||
|
|
@ -0,0 +1,107 @@
|
|||
package com.a.eye.skywalking.plugin.jdbc.connectionurl.parser;
|
||||
|
||||
import com.a.eye.skywalking.plugin.jdbc.ConnectionInfo;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class URLParserTest {
|
||||
@Test
|
||||
public void testParseMysqlJDBCURLWithHost() {
|
||||
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql//primaryhost/test");
|
||||
assertThat(connectionInfo.getDBType(), is("Mysql"));
|
||||
assertThat(connectionInfo.getDatabaseName(), is("test"));
|
||||
assertThat(connectionInfo.getHost(), is("primaryhost"));
|
||||
assertThat(connectionInfo.getPort(), is(3306));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseMysqlJDBCURLWithHostAndPort() {
|
||||
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql//primaryhost:3307/test?profileSQL=true");
|
||||
assertThat(connectionInfo.getDBType(), is("Mysql"));
|
||||
assertThat(connectionInfo.getDatabaseName(), is("test"));
|
||||
assertThat(connectionInfo.getHost(), is("primaryhost"));
|
||||
assertThat(connectionInfo.getPort(), is(3307));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseMysqlJDBCURLWithMultiHost() {
|
||||
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql//primaryhost:3307,secondaryhost1,secondaryhost2/test?profileSQL=true");
|
||||
assertThat(connectionInfo.getDBType(), is("Mysql"));
|
||||
assertThat(connectionInfo.getDatabaseName(), is("test"));
|
||||
assertThat(connectionInfo.getHosts(), is("primaryhost:3307,secondaryhost1:3306,secondaryhost2:3306,"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseMysqlJDBCURLWithConnectorJs() {
|
||||
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql:replication://master,slave1,slave2,slave3/test");
|
||||
assertThat(connectionInfo.getDBType(), is("Mysql"));
|
||||
assertThat(connectionInfo.getDatabaseName(), is("test"));
|
||||
assertThat(connectionInfo.getHosts(), is("master:3306,slave1:3306,slave2:3306,slave3:3306,"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseOracleJDBCURLWithHost() {
|
||||
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:@localhost:orcl");
|
||||
assertThat(connectionInfo.getDBType(), is("Oracle"));
|
||||
assertThat(connectionInfo.getDatabaseName(), is("orcl"));
|
||||
assertThat(connectionInfo.getHost(), is("localhost"));
|
||||
assertThat(connectionInfo.getPort(), is(1521));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseOracleJDBCURLWithHostAndPort() {
|
||||
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:@localhost:1522:orcl");
|
||||
assertThat(connectionInfo.getDBType(), is("Oracle"));
|
||||
assertThat(connectionInfo.getDatabaseName(), is("orcl"));
|
||||
assertThat(connectionInfo.getHost(), is("localhost"));
|
||||
assertThat(connectionInfo.getPort(), is(1522));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseOracleJDBCURLWithUserNameAndPassword() {
|
||||
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:scott/tiger@myhost:1521:orcl");
|
||||
assertThat(connectionInfo.getDBType(), is("Oracle"));
|
||||
assertThat(connectionInfo.getDatabaseName(), is("orcl"));
|
||||
assertThat(connectionInfo.getHost(), is("myhost"));
|
||||
assertThat(connectionInfo.getPort(), is(1521));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseH2JDBCURLWithEmbedded() {
|
||||
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:h2:file:/data/sample");
|
||||
assertThat(connectionInfo.getDBType(), is("H2"));
|
||||
assertThat(connectionInfo.getDatabaseName(), is("/data/sample"));
|
||||
assertThat(connectionInfo.getHost(), is("localhost"));
|
||||
assertThat(connectionInfo.getPort(), is(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseH2JDBCURLWithEmbeddedRunningInWindows() {
|
||||
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:h2:file:C:/data/sample");
|
||||
assertThat(connectionInfo.getDBType(), is("H2"));
|
||||
assertThat(connectionInfo.getDatabaseName(), is("C:/data/sample"));
|
||||
assertThat(connectionInfo.getHost(), is("localhost"));
|
||||
assertThat(connectionInfo.getPort(), is(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseH2JDBCURLWithMemoryMode() {
|
||||
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:h2:mem:test_mem");
|
||||
assertThat(connectionInfo.getDBType(), is("H2"));
|
||||
assertThat(connectionInfo.getDatabaseName(), is("test_mem"));
|
||||
assertThat(connectionInfo.getHost(), is("localhost"));
|
||||
assertThat(connectionInfo.getPort(), is(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseH2JDBCURL() {
|
||||
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:h2:tcp://localhost:8084/~/sample");
|
||||
assertThat(connectionInfo.getDBType(), is("H2"));
|
||||
assertThat(connectionInfo.getDatabaseName(), is("sample"));
|
||||
assertThat(connectionInfo.getHost(), is("localhost"));
|
||||
assertThat(connectionInfo.getPort(), is(8084));
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,9 @@ import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorIn
|
|||
import redis.clients.jedis.HostAndPort;
|
||||
|
||||
import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO;
|
||||
import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_HOST;
|
||||
import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_HOSTS;
|
||||
import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_PORT;
|
||||
|
||||
/**
|
||||
* {@link JedisClusterConstructorWithHostAndPortArgInterceptor} will record the host and port information that fetch
|
||||
|
|
@ -23,6 +25,7 @@ public class JedisClusterConstructorWithHostAndPortArgInterceptor implements Ins
|
|||
HostAndPort hostAndPort = (HostAndPort) interceptorContext.allArguments()[0];
|
||||
redisConnInfo.append(hostAndPort.toString()).append(";");
|
||||
context.set(KEY_OF_REDIS_CONN_INFO, redisConnInfo.toString());
|
||||
context.set(KEY_OF_REDIS_HOSTS, hostAndPort.getHost());
|
||||
context.set(KEY_OF_REDIS_HOST, hostAndPort.getHost());
|
||||
context.set(KEY_OF_REDIS_PORT, hostAndPort.getPort());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,11 @@ public class JedisClusterConstructorWithListHostAndPortArgInterceptor implements
|
|||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
StringBuilder redisConnInfo = new StringBuilder();
|
||||
StringBuilder redisHost = new StringBuilder();
|
||||
Set<HostAndPort> hostAndPorts = (Set<HostAndPort>) interceptorContext.allArguments()[0];
|
||||
for (HostAndPort hostAndPort : hostAndPorts) {
|
||||
redisConnInfo.append(hostAndPort.toString()).append(";");
|
||||
redisHost.append(hostAndPort.getHost()).append(";");
|
||||
}
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO, redisConnInfo.toString());
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, redisHost);
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, redisConnInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public class JedisConstructorWithShardInfoArgInterceptor implements InstanceCons
|
|||
JedisShardInfo shardInfo = (JedisShardInfo) interceptorContext.allArguments()[0];
|
||||
redisConnInfo = shardInfo.getHost() + ":" + shardInfo.getPort();
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO, redisConnInfo);
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, shardInfo.getHost());
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOST, shardInfo.getHost());
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_PORT, shardInfo.getPort());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,13 +14,14 @@ public class JedisConstructorWithStringArgInterceptor implements InstanceConstru
|
|||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
String redisConnInfo;
|
||||
redisConnInfo = (String) interceptorContext.allArguments()[0];
|
||||
String host = (String) interceptorContext.allArguments()[0];
|
||||
int port = 6379;
|
||||
if (interceptorContext.allArguments().length > 1) {
|
||||
redisConnInfo += ":" + interceptorContext.allArguments()[1];
|
||||
port = (Integer) interceptorContext.allArguments()[1];
|
||||
}
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO, redisConnInfo);
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, interceptorContext.allArguments()[0]);
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO, host + ":" + port);
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOST, host);
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_PORT, port);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public class JedisConstructorWithUriArgInterceptor implements InstanceConstructo
|
|||
URI uri = (URI) interceptorContext.allArguments()[0];
|
||||
redisConnInfo = uri.getHost() + ":" + uri.getPort();
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO, redisConnInfo);
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, uri.getHost());
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOST, uri.getHost());
|
||||
context.set(JedisMethodInterceptor.KEY_OF_REDIS_PORT, uri.getPort());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
|||
import com.a.eye.skywalking.api.plugin.interceptor.assist.NoCocurrencyAceessObject;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.api.util.StringUtil;
|
||||
import com.a.eye.skywalking.trace.Span;
|
||||
import com.a.eye.skywalking.trace.tag.Tags;
|
||||
|
||||
|
|
@ -20,9 +21,26 @@ public class JedisMethodInterceptor extends NoCocurrencyAceessObject {
|
|||
*/
|
||||
protected static final String KEY_OF_REDIS_CONN_INFO = "REDIS_CONNECTION_INFO";
|
||||
/**
|
||||
* The key name that redis host in {@link EnhancedClassInstanceContext#context}.
|
||||
* The key name that multiple redis hosts in {@link EnhancedClassInstanceContext#context}.
|
||||
*/
|
||||
protected static final String KEY_OF_REDIS_HOSTS = "KEY_OF_REDIS_HOSTS";
|
||||
/**
|
||||
* The key name that redis host in {@link EnhancedClassInstanceContext#context}.
|
||||
* it will be null if the value that fetch from {@link EnhancedClassInstanceContext#context}
|
||||
* by using {@link #KEY_OF_REDIS_HOSTS} is not null.
|
||||
*/
|
||||
protected static final String KEY_OF_REDIS_HOST = "KEY_OF_REDIS_HOST";
|
||||
/**
|
||||
* The key name that redis port in {@link EnhancedClassInstanceContext#context}.
|
||||
* It can not be null if the value that fetch from {@link EnhancedClassInstanceContext#context} by
|
||||
* using {@link #KEY_OF_REDIS_HOST} is not null.
|
||||
*/
|
||||
protected static final String KEY_OF_REDIS_PORT = "KEY_OF_REDIS_PORT";
|
||||
/**
|
||||
* Redis component
|
||||
*/
|
||||
private static final String REDIS_COMPONENT = "Redis";
|
||||
|
||||
|
||||
@Override
|
||||
public void beforeMethod(final EnhancedClassInstanceContext context, final InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
|
|
@ -30,18 +48,32 @@ public class JedisMethodInterceptor extends NoCocurrencyAceessObject {
|
|||
@Override
|
||||
public void run() {
|
||||
Span span = ContextManager.INSTANCE.createSpan(context.get(KEY_OF_REDIS_CONN_INFO, String.class) + " " + interceptorContext.methodName());
|
||||
Tags.COMPONENT.set(span, "Redis");
|
||||
Tags.PEER_HOST.set(span, (String) context.get(KEY_OF_REDIS_HOSTS));
|
||||
|
||||
Tags.COMPONENT.set(span, REDIS_COMPONENT);
|
||||
Tags.DB_TYPE.set(span, REDIS_COMPONENT);
|
||||
tagPeer(span, context);
|
||||
Tags.SPAN_LAYER.asDB(span);
|
||||
|
||||
if (interceptorContext.allArguments().length > 0
|
||||
&& interceptorContext.allArguments()[0] instanceof String) {
|
||||
span.setTag("operation_key", (String) interceptorContext.allArguments()[0]);
|
||||
Tags.DB_STATEMENT.set(span, interceptorContext.methodName() + " " + interceptorContext.allArguments()[0]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* set peer host information for the current active span.
|
||||
*/
|
||||
private void tagPeer(Span span, EnhancedClassInstanceContext context) {
|
||||
String redisHosts = (String) context.get(KEY_OF_REDIS_HOSTS);
|
||||
if (!StringUtil.isEmpty(redisHosts)) {
|
||||
Tags.PEERS.set(span, (String) context.get(KEY_OF_REDIS_HOSTS));
|
||||
} else {
|
||||
Tags.PEER_HOST.set(span, (String) context.get(KEY_OF_REDIS_HOST));
|
||||
Tags.PEER_PORT.set(span, (Integer) context.get(KEY_OF_REDIS_PORT));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
this.whenExist(context, new Runnable() {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ public class ConsumerFetchRequestURLInterceptor implements InstanceMethodsAround
|
|||
private static final String CONTEXT_NAME_OF_REQUEST_URL = "REQUEST_URL";
|
||||
|
||||
/**
|
||||
* Fetch the request url from the first param of all constructor, and put request url into {@link EnhancedClassInstanceContext#context}.
|
||||
* Fetch the request url from the first param of all constructor, and put request
|
||||
* url into {@link EnhancedClassInstanceContext#context}.
|
||||
*
|
||||
* @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance.
|
||||
* @param interceptorContext method context, includes class name, method name, etc.
|
||||
|
|
|
|||
|
|
@ -13,20 +13,21 @@ import com.weibo.api.motan.rpc.Response;
|
|||
import com.weibo.api.motan.rpc.URL;
|
||||
|
||||
/**
|
||||
* {@link ConsumerInvokeInterceptor} create span by fetch request url from {@link EnhancedClassInstanceContext#context} and
|
||||
* transport serialized context data to provider side through {@link Request#setAttachment(String, String)}.
|
||||
* {@link ConsumerInvokeInterceptor} create span by fetch request url from
|
||||
* {@link EnhancedClassInstanceContext#context} and transport serialized context
|
||||
* data to provider side through {@link Request#setAttachment(String, String)}.
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class ConsumerInvokeInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
/**
|
||||
* Context name of request url in {@link EnhancedClassInstanceContext#context}
|
||||
* Context name of request url in {@link EnhancedClassInstanceContext#context}.
|
||||
*/
|
||||
private static final String CONTEXT_NAME_OF_REQUEST_URL = "REQUEST_URL";
|
||||
|
||||
/**
|
||||
* Attachment key of the serialized context data
|
||||
* Attachment key of the serialized context data.
|
||||
*/
|
||||
private static final String ATTACHMENT_KEY_OF_CONTEXT_DATA = "contextData";
|
||||
|
||||
|
|
@ -81,13 +82,11 @@ public class ConsumerInvokeInterceptor implements InstanceMethodsAroundIntercept
|
|||
/**
|
||||
* Generate operation name.
|
||||
*
|
||||
* @return operation name
|
||||
* @return operation name.
|
||||
*/
|
||||
private static String generateOperationName(URL serviceURI, Request request) {
|
||||
StringBuilder viewPoint = new StringBuilder(serviceURI.getPath());
|
||||
viewPoint.append("." + request.getMethodName());
|
||||
viewPoint.append("(" + request.getParamtersDesc() + ")");
|
||||
return viewPoint.toString();
|
||||
return new StringBuilder(serviceURI.getPath()).append(".").append(request.getMethodName()).append("(")
|
||||
.append(request.getParamtersDesc()).append(")").toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ public class ProviderInterceptor implements InstanceConstructorInterceptor, Inst
|
|||
* The key name that the serialized context data stored in {@link Request#getAttachments()}
|
||||
*/
|
||||
private static final String ATTACHMENT_KEY_OF_CONTEXT_DATA = "contextData";
|
||||
/**
|
||||
* Motan component
|
||||
*/
|
||||
private static final String MOTAN_COMPONENT = "Motan";
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
|
|
@ -47,7 +51,7 @@ public class ProviderInterceptor implements InstanceConstructorInterceptor, Inst
|
|||
if (url != null) {
|
||||
com.weibo.api.motan.rpc.Request request = (com.weibo.api.motan.rpc.Request) interceptorContext.allArguments()[0];
|
||||
Span span = ContextManager.INSTANCE.createSpan(generateViewPoint(url, request));
|
||||
Tags.COMPONENT.set(span, "Motan");
|
||||
Tags.COMPONENT.set(span, MOTAN_COMPONENT);
|
||||
Tags.URL.set(span, url.getIdentity());
|
||||
Tags.PEER_PORT.set(span, url.getPort());
|
||||
Tags.PEER_HOST.set(span, url.getHost());
|
||||
|
|
|
|||
|
|
@ -14,14 +14,25 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
|
||||
/**
|
||||
* {@link ConsumerInstrumentation} presents that skywalking use {@link ConsumerInvokeInterceptor}
|
||||
* to intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)} and use {@link ConsumerFetchRequestURLInterceptor}
|
||||
* to intercept{@link ConsumerFetchRequestURLInterceptor}
|
||||
* to intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)} and use
|
||||
* {@link ConsumerFetchRequestURLInterceptor} to intercept{@link ConsumerFetchRequestURLInterceptor}.
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class ConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
/**
|
||||
* Enhance class.
|
||||
*/
|
||||
private static final String ENHANCE_CLASS = "com.weibo.api.motan.cluster.support.ClusterSpi";
|
||||
/**
|
||||
* Class that intercept for fetch request url.
|
||||
*/
|
||||
private static final String FETCH_REQUEST_URL_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerFetchRequestURLInterceptor";
|
||||
private static final String INVOKE_INTECEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerInvokeInterceptor";
|
||||
/**
|
||||
* Class that intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)}.
|
||||
*/
|
||||
private static final String INVOKE_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerInvokeInterceptor";
|
||||
|
||||
@Override
|
||||
protected String enhanceClassName() {
|
||||
|
|
@ -53,7 +64,7 @@ public class ConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDe
|
|||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return INVOKE_INTECEPT_CLASS;
|
||||
return INVOKE_INTERCEPT_CLASS;
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,23 +12,25 @@ import static net.bytebuddy.matcher.ElementMatchers.any;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
/**
|
||||
* {@link ProviderInstrumentation} presents that skywalking will use {@link com.a.eye.skywalking.plugin.motan.ProviderInterceptor}
|
||||
* to intercept all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} and {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}
|
||||
* {@link ProviderInstrumentation} presents that skywalking will use
|
||||
* {@link com.a.eye.skywalking.plugin.motan.ProviderInterceptor} to intercept
|
||||
* all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} and
|
||||
* {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}.
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class ProviderInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
/**
|
||||
* Enhance class
|
||||
* Enhance class.
|
||||
*/
|
||||
private static final String ENHANCE_CLASS = "com.weibo.api.motan.rpc.AbstractProvider";
|
||||
/**
|
||||
* Class that intercept all constructor of ${@link com.weibo.api.motan.rpc.AbstractProvider}
|
||||
* Class that intercept all constructor of ${@link com.weibo.api.motan.rpc.AbstractProvider}.
|
||||
*/
|
||||
private static final String CONSTRUCTOR_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ProviderInterceptor";
|
||||
/**
|
||||
* Class that intercept {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}
|
||||
* Class that intercept {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}.
|
||||
*/
|
||||
private static final String PROVIDER_INVOKE_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ProviderInterceptor";
|
||||
|
||||
|
|
|
|||
|
|
@ -14,12 +14,18 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* {@link TomcatInterceptor} fetch the serialized context data by use {@link HttpServletRequest#getHeader(String)}.
|
||||
* {@link TomcatInterceptor} fetch the serialized context data by using {@link HttpServletRequest#getHeader(String)}.
|
||||
* The {@link com.a.eye.skywalking.trace.TraceSegment#primaryRef} of current trace segment will reference to the trace segment id
|
||||
* of the previous level if the serialized context is not null.
|
||||
*/
|
||||
public class TomcatInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
/**
|
||||
* Header name that the serialized context data stored in {@link HttpServletRequest#getHeader(String)}.
|
||||
*/
|
||||
public static final String HEADER_NAME_OF_CONTEXT_DATA = "SKYWALKING_CONTEXT_DATA";
|
||||
/**
|
||||
* Tomcat component.
|
||||
*/
|
||||
public static final String TOMCAT_COMPONENT = "Tomcat";
|
||||
|
||||
/**
|
||||
|
|
@ -37,6 +43,7 @@ public class TomcatInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
|
||||
Span span = ContextManager.INSTANCE.createSpan(request.getRequestURI());
|
||||
Tags.COMPONENT.set(span, TOMCAT_COMPONENT);
|
||||
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_SERVER);
|
||||
Tags.URL.set(span, request.getRequestURL().toString());
|
||||
Tags.SPAN_LAYER.asHttp(span);
|
||||
|
||||
|
|
@ -52,8 +59,12 @@ public class TomcatInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
|
||||
Span span = ContextManager.INSTANCE.activeSpan();
|
||||
Tags.STATUS_CODE.set(span, response.getStatus());
|
||||
ContextManager.INSTANCE.stopSpan();
|
||||
|
||||
if (response.getStatus() != 200) {
|
||||
Tags.ERROR.set(span, true);
|
||||
}
|
||||
|
||||
ContextManager.INSTANCE.stopSpan();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,15 +14,21 @@ import org.apache.catalina.connector.Response;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
/**
|
||||
* {@link TomcatInstrumentation} presents that skywalking use class {@link TomcatInterceptor} to
|
||||
* {@link TomcatInstrumentation} presents that skywalking using class {@link TomcatInterceptor} to
|
||||
* intercept {@link org.apache.catalina.core.StandardEngineValve#invoke(Request, Response)}.
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class TomcatInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
/**
|
||||
* Enhance class.
|
||||
*/
|
||||
private static final String ENHANCE_CLASS = "org.apache.catalina.core.StandardEngineValve";
|
||||
|
||||
/**
|
||||
* Intercept class.
|
||||
*/
|
||||
private static final String INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.tomcat78x.TomcatInterceptor";
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public class TomcatInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testWithSerializedContextData() {
|
||||
when(request.getHeader(TomcatInterceptor.HEADER_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1");
|
||||
when(request.getHeader(TomcatInterceptor.HEADER_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1");
|
||||
|
||||
tomcatInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult);
|
||||
tomcatInterceptor.afterMethod(classInstanceContext, methodInvokeContext, null);
|
||||
|
|
@ -114,7 +114,8 @@ public class TomcatInterceptorTest {
|
|||
}
|
||||
|
||||
private void assertSpanLog(LogData logData) {
|
||||
assertThat(logData.getFields().size(), is(3));
|
||||
assertThat(logData.getFields().size(), is(4));
|
||||
assertThat(logData.getFields().get("event"), CoreMatchers.<Object>is("error"));
|
||||
assertThat(logData.getFields().get("error.kind"), CoreMatchers.<Object>is(RuntimeException.class.getName()));
|
||||
assertNull(logData.getFields().get("message"));
|
||||
}
|
||||
|
|
@ -129,6 +130,7 @@ public class TomcatInterceptorTest {
|
|||
assertThat(Tags.COMPONENT.get(span), is("Tomcat"));
|
||||
assertThat(Tags.URL.get(span), is("http://localhost:8080/test/testRequestURL"));
|
||||
assertThat(Tags.STATUS_CODE.get(span), is(200));
|
||||
assertThat(Tags.SPAN_KIND.get(span), is(Tags.SPAN_KIND_SERVER));
|
||||
assertTrue(Tags.SPAN_LAYER.isHttp(span));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue