From cea88f981daf14c130f0453973a86489ecf8e565 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Fri, 24 Feb 2017 15:01:38 +0800 Subject: [PATCH] Rewrite plugins by using new API --- .../com/a/eye/skywalking/trace/tag/Tags.java | 37 +- .../a/eye/skywalking/trace/SpanTestCase.java | 1 - .../trace/TraceSegmentTestCase.java | 2 +- .../eye/skywalking/agent/SkyWalkingAgent.java | 7 +- .../plugin/interceptor/EnhanceException.java | 1 + .../enhance/ClassEnhancePluginDefine.java | 6 +- ...assInstanceMethodsEnhancePluginDefine.java | 1 + .../plugin/dubbo/DubboInstrumentation.java | 4 +- .../plugin/dubbo/DubboInterceptor.java | 56 +- .../plugin/dubbox/BugFixActive.java | 6 +- .../skywalking/plugin/dubbox/SWBaseBean.java | 2 +- .../plugin/dubbo/DubboInterceptorTest.java | 9 +- .../dubbo/RequestParamForTestBelow283.java | 4 +- .../v4/HttpClientExecuteInterceptor.java | 70 -- .../httpClient/v4/WebBuriedPointType.java | 18 - .../AbstractHttpClientPluginDefine.java | 36 - .../DefaultRequestDirectorPluginDefine.java | 34 - .../v4/define/HttpClientPluginDefine.java | 15 - .../InternalHttpClientPluginDefine.java | 29 - .../define/MinimalHttpClientPluginDefine.java | 29 - .../src/main/resources/skywalking-plugin.def | 8 +- .../skywalking-sdk-plugin/jdbc-plugin/pom.xml | 128 +- .../plugin/jdbc/CallableStatementTracing.java | 42 - .../api/plugin/jdbc/ConnectionTracing.java | 42 - .../plugin/jdbc/PreparedStatementTracing.java | 36 - .../api/plugin/jdbc/SWCallableStatement.java | 1039 ----------------- .../api/plugin/jdbc/SWConnection.java | 304 ----- .../api/plugin/jdbc/SWPreparedStatement.java | 518 -------- .../api/plugin/jdbc/SWStatement.java | 251 ---- .../api/plugin/jdbc/StatementTracing.java | 42 - .../define/AbstractDatabasePluginDefine.java | 32 - .../plugin/jdbc/define/H2PluginDefine.java | 8 - .../jdbc/define/JDBCBuriedPointType.java | 19 - .../jdbc/define/JDBCDriverInterceptor.java | 32 - .../plugin/jdbc/define/MysqlPluginDefine.java | 11 - .../jdbc/define/OraclePluginDefine.java | 11 - .../src/main/resources/skywalking-plugin.def | 6 +- .../connectionurl/parser/URLParserTest.java | 107 ++ ...structorWithHostAndPortArgInterceptor.java | 5 +- ...ctorWithListHostAndPortArgInterceptor.java | 4 +- ...onstructorWithShardInfoArgInterceptor.java | 3 +- ...isConstructorWithStringArgInterceptor.java | 11 +- ...JedisConstructorWithUriArgInterceptor.java | 3 +- .../jedis/v2/JedisMethodInterceptor.java | 42 +- .../ConsumerFetchRequestURLInterceptor.java | 3 +- .../motan/ConsumerInvokeInterceptor.java | 17 +- .../plugin/motan/ProviderInterceptor.java | 6 +- .../motan/define/ConsumerInstrumentation.java | 19 +- .../motan/define/ProviderInstrumentation.java | 12 +- .../plugin/tomcat78x/TomcatInterceptor.java | 15 +- .../define/TomcatInstrumentation.java | 8 +- .../tomcat78x/TomcatInterceptorTest.java | 6 +- 52 files changed, 365 insertions(+), 2792 deletions(-) delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/HttpClientExecuteInterceptor.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/WebBuriedPointType.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/AbstractHttpClientPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/DefaultRequestDirectorPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/HttpClientPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/InternalHttpClientPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/MinimalHttpClientPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/CallableStatementTracing.java delete mode 100755 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/ConnectionTracing.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/PreparedStatementTracing.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWCallableStatement.java delete mode 100755 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWConnection.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWPreparedStatement.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWStatement.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/StatementTracing.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/AbstractDatabasePluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/H2PluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCBuriedPointType.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCDriverInterceptor.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/MysqlPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/OraclePluginDefine.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/test/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParserTest.java diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/Tags.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/Tags.java index 67e841e45..6f80d42c2 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/Tags.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/Tags.java @@ -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. diff --git a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/SpanTestCase.java b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/SpanTestCase.java index f1b05855b..517a4bfcb 100644 --- a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/SpanTestCase.java +++ b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/SpanTestCase.java @@ -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 tags = span1.getTags(); diff --git a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java index 46843831f..51e6947b9 100644 --- a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java +++ b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java @@ -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); diff --git a/skywalking-sniffer/skywalking-agent/src/main/java/com/a/eye/skywalking/agent/SkyWalkingAgent.java b/skywalking-sniffer/skywalking-agent/src/main/java/com/a/eye/skywalking/agent/SkyWalkingAgent.java index 21868ecc7..74a72a64b 100644 --- a/skywalking-sniffer/skywalking-agent/src/main/java/com/a/eye/skywalking/agent/SkyWalkingAgent.java +++ b/skywalking-sniffer/skywalking-agent/src/main/java/com/a/eye/skywalking/agent/SkyWalkingAgent.java @@ -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; diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/EnhanceException.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/EnhanceException.java index dec61a839..4e3139f1b 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/EnhanceException.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/EnhanceException.java @@ -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 { diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassEnhancePluginDefine.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassEnhancePluginDefine.java index cd0f92858..4dfd7709e 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassEnhancePluginDefine.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassEnhancePluginDefine.java @@ -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(); diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java index 9a3888775..8f5cb2a0e 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java @@ -1,5 +1,6 @@ package com.a.eye.skywalking.api.plugin.interceptor.enhance; + import com.a.eye.skywalking.api.plugin.interceptor.StaticMethodsInterceptPoint; /** diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java index 0890dcdcc..330b2cc63 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java @@ -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"; diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java index 304db4ebb..1ec77436d 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java @@ -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 com.a.eye.skywalking.plugin.test.Test.test(String) + * the operation name should be like this com.a.eye.skywalking.plugin.test.Test.test(String). * - * @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 dubbo://127.0.0.1:20880/com.a.eye.skywalking.plugin.test.Test.test(String) + * The request url may be like this dubbo://127.0.0.1:20880/com.a.eye.skywalking.plugin.test.Test.test(String). * - * @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()) { diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java index 12e316218..e09f536b2 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java @@ -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; } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java index 5f478d1ca..eaf6f71fe 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java @@ -10,7 +10,7 @@ import java.io.Serializable; */ public class SWBaseBean implements Serializable { /** - * Serialized context data + * Serialized context data. */ private String contextData; diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java index 26b88e7b0..7e6cfb214 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java @@ -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.is("error")); assertThat(logData.getFields().get("error.kind"), CoreMatchers.is(RuntimeException.class.getName())); assertNull(logData.getFields().get("message")); } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java index 3ca038a17..7c3783b82 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java @@ -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)); } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/HttpClientExecuteInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/HttpClientExecuteInterceptor.java deleted file mode 100644 index 514dd6151..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/HttpClientExecuteInterceptor.java +++ /dev/null @@ -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
- */ - 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); - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/WebBuriedPointType.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/WebBuriedPointType.java deleted file mode 100644 index b4e60faa7..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/WebBuriedPointType.java +++ /dev/null @@ -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; - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/AbstractHttpClientPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/AbstractHttpClientPluginDefine.java deleted file mode 100644 index 33f7505fe..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/AbstractHttpClientPluginDefine.java +++ /dev/null @@ -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
- * public final HttpResponse execute(HttpHost target, HttpRequest request, - * HttpContext context)
- * - */ - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("doExecute"); - } - - @Override - public String getMethodsInterceptor() { - return getInstanceMethodsInterceptor(); - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/DefaultRequestDirectorPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/DefaultRequestDirectorPluginDefine.java deleted file mode 100644 index 540b2fbbf..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/DefaultRequestDirectorPluginDefine.java +++ /dev/null @@ -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.
- * usually use in version 4.0-4.2
- * 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 getMethodsMatcher() { - return named("execute"); - } - - @Override - public String getMethodsInterceptor() { - return getInstanceMethodsInterceptor(); - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/HttpClientPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/HttpClientPluginDefine.java deleted file mode 100644 index fd1616114..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/HttpClientPluginDefine.java +++ /dev/null @@ -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"; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/InternalHttpClientPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/InternalHttpClientPluginDefine.java deleted file mode 100644 index 832c3390d..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/InternalHttpClientPluginDefine.java +++ /dev/null @@ -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 getMethodsMatcher() { - return named("doExecute"); - } - - @Override - public String getMethodsInterceptor() { - return getInstanceMethodsInterceptor(); - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/MinimalHttpClientPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/MinimalHttpClientPluginDefine.java deleted file mode 100644 index 100a8a37f..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/MinimalHttpClientPluginDefine.java +++ /dev/null @@ -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 getMethodsMatcher() { - return named("doExecute"); - } - - @Override - public String getMethodsInterceptor() { - return getInstanceMethodsInterceptor(); - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def index 200935980..da07902ec 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def @@ -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 diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/pom.xml b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/pom.xml index 43e773797..db239652d 100755 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/pom.xml +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/pom.xml @@ -1,68 +1,74 @@ - - skywalking-sdk-plugin - com.a.eye - 3.0-2017 - - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + skywalking-sdk-plugin + com.a.eye + 3.0-2017 + + 4.0.0 - skywalking-jdbc-plugin - jar + skywalking-jdbc-plugin + jar - jdbc-plugin - http://maven.apache.org + jdbc-plugin + http://maven.apache.org - - UTF-8 - + + UTF-8 + - - - com.a.eye - skywalking-api - 3.0-2017 - - - mysql - mysql-connector-java - 5.1.36 - test - - - com.oracle - ojdbc14 - 10.2.0.4.0 - test - - - com.h2database - h2 - 1.4.192 - test - - + + + com.a.eye + skywalking-api + 3.0-2017 + + + mysql + mysql-connector-java + 5.1.36 + test + + + com.oracle + ojdbc14 + 10.2.0.4.0 + test + + + com.h2database + h2 + 1.4.192 + provided + + + mysql + mysql-connector-java + [2.0.14,) + provided + + - - - - org.apache.maven.plugins - maven-deploy-plugin - - - - org.apache.maven.plugins - maven-source-plugin - - - - attach-sources - - jar - - - - - - + + + + org.apache.maven.plugins + maven-deploy-plugin + + + + org.apache.maven.plugins + maven-source-plugin + + + + attach-sources + + jar + + + + + + diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/CallableStatementTracing.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/CallableStatementTracing.java deleted file mode 100644 index 48dc1b55e..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/CallableStatementTracing.java +++ /dev/null @@ -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 execute(java.sql.CallableStatement realStatement, - String connectInfo, String method, String sql, Executable 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 { - public R exe(java.sql.CallableStatement realConnection, String sql) - throws SQLException; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/ConnectionTracing.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/ConnectionTracing.java deleted file mode 100755 index d100efa44..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/ConnectionTracing.java +++ /dev/null @@ -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 execute(java.sql.Connection realConnection, - String connectInfo, String method, String sql, Executable 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 { - public R exe(java.sql.Connection realConnection, String sql) - throws SQLException; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/PreparedStatementTracing.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/PreparedStatementTracing.java deleted file mode 100644 index d20d97106..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/PreparedStatementTracing.java +++ /dev/null @@ -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 execute(java.sql.PreparedStatement realStatement, - String connectInfo, String method, String sql, Executable 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 exe(java.sql.PreparedStatement realConnection, String sql) - throws SQLException; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWCallableStatement.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWCallableStatement.java deleted file mode 100644 index 70141c53d..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWCallableStatement.java +++ /dev/null @@ -1,1039 +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; -import java.util.Map; - -public class SWCallableStatement implements CallableStatement { - private Connection realConnection; - private CallableStatement realStatement; - private String connectInfo; - private String sql; - - SWCallableStatement(Connection realConnection, - CallableStatement realStatement, String connectInfo, - String sql) { - this.realConnection = realConnection; - this.realStatement = realStatement; - this.connectInfo = connectInfo; - this.sql = sql; - } - - public ResultSet executeQuery() throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeQuery", sql, new CallableStatementTracing.Executable() { - public ResultSet exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.executeQuery(); - } - }); - } - - public int executeUpdate() throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeUpdate", sql, new CallableStatementTracing.Executable() { - public Integer exe( - CallableStatement 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 CallableStatementTracing.execute(realStatement, connectInfo, - "execute", sql, new CallableStatementTracing.Executable() { - public Boolean exe( - CallableStatement 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); - } - - public ResultSet executeQuery(String sql) throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeQuery", sql, new CallableStatementTracing.Executable() { - public ResultSet exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.executeQuery(sql); - } - }); - } - - public int executeUpdate(String sql) throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeUpdate", sql, new CallableStatementTracing.Executable() { - public Integer exe( - CallableStatement 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 CallableStatementTracing.execute(realStatement, connectInfo, - "execute", sql, new CallableStatementTracing.Executable() { - public Boolean exe( - CallableStatement 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(); - } - - public void clearBatch() throws SQLException { - realStatement.clearBatch(); - } - - public int[] executeBatch() throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeBatch", "", new CallableStatementTracing.Executable() { - public int[] exe( - CallableStatement 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 CallableStatementTracing.execute(realStatement, connectInfo, - "executeUpdate", sql, new CallableStatementTracing.Executable() { - public Integer exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql, autoGeneratedKeys); - } - }); - } - - public int executeUpdate(String sql, final int[] columnIndexes) - throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeUpdate", sql, new CallableStatementTracing.Executable() { - public Integer exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql, columnIndexes); - } - }); - } - - public int executeUpdate(String sql, final String[] columnNames) - throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeUpdate", sql, new CallableStatementTracing.Executable() { - public Integer exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql, columnNames); - } - }); - } - - public boolean execute(String sql, final int autoGeneratedKeys) - throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "execute", sql, new CallableStatementTracing.Executable() { - public Boolean exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql, autoGeneratedKeys); - } - }); - } - - public boolean execute(String sql, final int[] columnIndexes) throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "execute", sql, new CallableStatementTracing.Executable() { - public Boolean exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql, columnIndexes); - } - }); - } - - public boolean execute(String sql, final String[] columnNames) - throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "execute", sql, new CallableStatementTracing.Executable() { - public Boolean exe( - CallableStatement 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 unwrap(Class iface) throws SQLException { - return realStatement.unwrap(iface); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - return realStatement.isWrapperFor(iface); - } - - public void registerOutParameter(int parameterIndex, int sqlType) - throws SQLException { - realStatement.registerOutParameter(parameterIndex, sqlType); - } - - public void registerOutParameter(int parameterIndex, int sqlType, int scale) - throws SQLException { - realStatement.registerOutParameter(parameterIndex, sqlType, scale); - } - - public boolean wasNull() throws SQLException { - return realStatement.wasNull(); - } - - public String getString(int parameterIndex) throws SQLException { - return realStatement.getString(parameterIndex); - } - - public boolean getBoolean(int parameterIndex) throws SQLException { - return realStatement.getBoolean(parameterIndex); - } - - public byte getByte(int parameterIndex) throws SQLException { - return realStatement.getByte(parameterIndex); - } - - public short getShort(int parameterIndex) throws SQLException { - return realStatement.getShort(parameterIndex); - } - - public int getInt(int parameterIndex) throws SQLException { - return realStatement.getInt(parameterIndex); - } - - public long getLong(int parameterIndex) throws SQLException { - return realStatement.getLong(parameterIndex); - } - - public float getFloat(int parameterIndex) throws SQLException { - return realStatement.getFloat(parameterIndex); - } - - public double getDouble(int parameterIndex) throws SQLException { - return realStatement.getDouble(parameterIndex); - } - - @Deprecated - public BigDecimal getBigDecimal(int parameterIndex, int scale) - throws SQLException { - return realStatement.getBigDecimal(parameterIndex, scale); - } - - public byte[] getBytes(int parameterIndex) throws SQLException { - return realStatement.getBytes(parameterIndex); - } - - public Date getDate(int parameterIndex) throws SQLException { - return realStatement.getDate(parameterIndex); - } - - public Time getTime(int parameterIndex) throws SQLException { - return realStatement.getTime(parameterIndex); - } - - public Timestamp getTimestamp(int parameterIndex) throws SQLException { - return realStatement.getTimestamp(parameterIndex); - } - - public Object getObject(int parameterIndex) throws SQLException { - return realStatement.getObject(parameterIndex); - } - - public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { - return realStatement.getBigDecimal(parameterIndex); - } - - public Object getObject(int parameterIndex, Map> map) - throws SQLException { - return realStatement.getObject(parameterIndex, map); - } - - public Ref getRef(int parameterIndex) throws SQLException { - return realStatement.getRef(parameterIndex); - } - - public Blob getBlob(int parameterIndex) throws SQLException { - return realStatement.getBlob(parameterIndex); - } - - public Clob getClob(int parameterIndex) throws SQLException { - return realStatement.getClob(parameterIndex); - } - - public Array getArray(int parameterIndex) throws SQLException { - return realStatement.getArray(parameterIndex); - } - - public Date getDate(int parameterIndex, Calendar cal) throws SQLException { - return realStatement.getDate(parameterIndex, cal); - } - - public Time getTime(int parameterIndex, Calendar cal) throws SQLException { - return realStatement.getTime(parameterIndex, cal); - } - - public Timestamp getTimestamp(int parameterIndex, Calendar cal) - throws SQLException { - return realStatement.getTimestamp(parameterIndex, cal); - } - - public void registerOutParameter(int parameterIndex, int sqlType, - String typeName) throws SQLException { - realStatement.registerOutParameter(parameterIndex, sqlType, typeName); - } - - public void registerOutParameter(String parameterName, int sqlType) - throws SQLException { - realStatement.registerOutParameter(parameterName, sqlType); - } - - public void registerOutParameter(String parameterName, int sqlType, - int scale) throws SQLException { - realStatement.registerOutParameter(parameterName, sqlType, scale); - } - - public void registerOutParameter(String parameterName, int sqlType, - String typeName) throws SQLException { - realStatement.registerOutParameter(parameterName, sqlType, typeName); - } - - public URL getURL(int parameterIndex) throws SQLException { - return realStatement.getURL(parameterIndex); - } - - public void setURL(String parameterName, URL val) throws SQLException { - realStatement.setURL(parameterName, val); - } - - public void setNull(String parameterName, int sqlType) throws SQLException { - realStatement.setNull(parameterName, sqlType); - } - - public void setBoolean(String parameterName, boolean x) throws SQLException { - realStatement.setBoolean(parameterName, x); - } - - public void setByte(String parameterName, byte x) throws SQLException { - realStatement.setByte(parameterName, x); - } - - public void setShort(String parameterName, short x) throws SQLException { - realStatement.setShort(parameterName, x); - } - - public void setInt(String parameterName, int x) throws SQLException { - realStatement.setInt(parameterName, x); - } - - public void setLong(String parameterName, long x) throws SQLException { - realStatement.setLong(parameterName, x); - } - - public void setFloat(String parameterName, float x) throws SQLException { - realStatement.setFloat(parameterName, x); - } - - public void setDouble(String parameterName, double x) throws SQLException { - realStatement.setDouble(parameterName, x); - } - - public void setBigDecimal(String parameterName, BigDecimal x) - throws SQLException { - realStatement.setBigDecimal(parameterName, x); - } - - public void setString(String parameterName, String x) throws SQLException { - realStatement.setString(parameterName, x); - } - - public void setBytes(String parameterName, byte[] x) throws SQLException { - realStatement.setBytes(parameterName, x); - } - - public void setDate(String parameterName, Date x) throws SQLException { - realStatement.setDate(parameterName, x); - } - - public void setTime(String parameterName, Time x) throws SQLException { - realStatement.setTime(parameterName, x); - } - - public void setTimestamp(String parameterName, Timestamp x) - throws SQLException { - realStatement.setTimestamp(parameterName, x); - } - - public void setAsciiStream(String parameterName, InputStream x, int length) - throws SQLException { - realStatement.setAsciiStream(parameterName, x, length); - } - - public void setBinaryStream(String parameterName, InputStream x, int length) - throws SQLException { - realStatement.setBinaryStream(parameterName, x, length); - } - - public void setObject(String parameterName, Object x, int targetSqlType, - int scale) throws SQLException { - realStatement.setObject(parameterName, x, targetSqlType, scale); - } - - public void setObject(String parameterName, Object x, int targetSqlType) - throws SQLException { - realStatement.setObject(parameterName, x, targetSqlType); - } - - public void setObject(String parameterName, Object x) throws SQLException { - realStatement.setObject(parameterName, x); - } - - public void setCharacterStream(String parameterName, Reader reader, - int length) throws SQLException { - realStatement.setCharacterStream(parameterName, reader, length); - } - - public void setDate(String parameterName, Date x, Calendar cal) - throws SQLException { - realStatement.setDate(parameterName, x, cal); - } - - public void setTime(String parameterName, Time x, Calendar cal) - throws SQLException { - realStatement.setTime(parameterName, x, cal); - } - - public void setTimestamp(String parameterName, Timestamp x, Calendar cal) - throws SQLException { - realStatement.setTimestamp(parameterName, x, cal); - } - - public void setNull(String parameterName, int sqlType, String typeName) - throws SQLException { - realStatement.setNull(parameterName, sqlType, typeName); - } - - public String getString(String parameterName) throws SQLException { - return realStatement.getString(parameterName); - } - - public boolean getBoolean(String parameterName) throws SQLException { - return realStatement.getBoolean(parameterName); - } - - public byte getByte(String parameterName) throws SQLException { - return realStatement.getByte(parameterName); - } - - public short getShort(String parameterName) throws SQLException { - return realStatement.getShort(parameterName); - } - - public int getInt(String parameterName) throws SQLException { - return realStatement.getInt(parameterName); - } - - public long getLong(String parameterName) throws SQLException { - return realStatement.getLong(parameterName); - } - - public float getFloat(String parameterName) throws SQLException { - return realStatement.getFloat(parameterName); - } - - public double getDouble(String parameterName) throws SQLException { - return realStatement.getDouble(parameterName); - } - - public byte[] getBytes(String parameterName) throws SQLException { - return realStatement.getBytes(parameterName); - } - - public Date getDate(String parameterName) throws SQLException { - return realStatement.getDate(parameterName); - } - - public Time getTime(String parameterName) throws SQLException { - return realStatement.getTime(parameterName); - } - - public Timestamp getTimestamp(String parameterName) throws SQLException { - return realStatement.getTimestamp(parameterName); - } - - public Object getObject(String parameterName) throws SQLException { - return realStatement.getObject(parameterName); - } - - public BigDecimal getBigDecimal(String parameterName) throws SQLException { - return realStatement.getBigDecimal(parameterName); - } - - public Object getObject(String parameterName, Map> map) - throws SQLException { - return realStatement.getObject(parameterName, map); - } - - public Ref getRef(String parameterName) throws SQLException { - return realStatement.getRef(parameterName); - } - - public Blob getBlob(String parameterName) throws SQLException { - return realStatement.getBlob(parameterName); - } - - public Clob getClob(String parameterName) throws SQLException { - return realStatement.getClob(parameterName); - } - - public Array getArray(String parameterName) throws SQLException { - return realStatement.getArray(parameterName); - } - - public Date getDate(String parameterName, Calendar cal) throws SQLException { - return realStatement.getDate(parameterName, cal); - } - - public Time getTime(String parameterName, Calendar cal) throws SQLException { - return realStatement.getTime(parameterName, cal); - } - - public Timestamp getTimestamp(String parameterName, Calendar cal) - throws SQLException { - return realStatement.getTimestamp(parameterName, cal); - } - - public URL getURL(String parameterName) throws SQLException { - return realStatement.getURL(parameterName); - } - - public RowId getRowId(int parameterIndex) throws SQLException { - return realStatement.getRowId(parameterIndex); - } - - public RowId getRowId(String parameterName) throws SQLException { - return realStatement.getRowId(parameterName); - } - - public void setRowId(String parameterName, RowId x) throws SQLException { - realStatement.setRowId(parameterName, x); - } - - public void setNString(String parameterName, String value) - throws SQLException { - realStatement.setNString(parameterName, value); - } - - public void setNCharacterStream(String parameterName, Reader value, - long length) throws SQLException { - realStatement.setNCharacterStream(parameterName, value, length); - } - - public void setNClob(String parameterName, NClob value) throws SQLException { - realStatement.setNClob(parameterName, value); - } - - public void setClob(String parameterName, Reader reader, long length) - throws SQLException { - realStatement.setClob(parameterName, reader, length); - } - - public void setBlob(String parameterName, InputStream inputStream, - long length) throws SQLException { - realStatement.setBlob(parameterName, inputStream, length); - } - - public void setNClob(String parameterName, Reader reader, long length) - throws SQLException { - realStatement.setNClob(parameterName, reader, length); - } - - public NClob getNClob(int parameterIndex) throws SQLException { - return realStatement.getNClob(parameterIndex); - } - - public NClob getNClob(String parameterName) throws SQLException { - return realStatement.getNClob(parameterName); - } - - public void setSQLXML(String parameterName, SQLXML xmlObject) - throws SQLException { - realStatement.setSQLXML(parameterName, xmlObject); - } - - public SQLXML getSQLXML(int parameterIndex) throws SQLException { - return realStatement.getSQLXML(parameterIndex); - } - - public SQLXML getSQLXML(String parameterName) throws SQLException { - return realStatement.getSQLXML(parameterName); - } - - public String getNString(int parameterIndex) throws SQLException { - return realStatement.getNString(parameterIndex); - } - - public String getNString(String parameterName) throws SQLException { - return realStatement.getNString(parameterName); - } - - public Reader getNCharacterStream(int parameterIndex) throws SQLException { - return realStatement.getNCharacterStream(parameterIndex); - } - - public Reader getNCharacterStream(String parameterName) throws SQLException { - return realStatement.getNCharacterStream(parameterName); - } - - public Reader getCharacterStream(int parameterIndex) throws SQLException { - return realStatement.getCharacterStream(parameterIndex); - } - - public Reader getCharacterStream(String parameterName) throws SQLException { - return realStatement.getCharacterStream(parameterName); - } - - public void setBlob(String parameterName, Blob x) throws SQLException { - realStatement.setBlob(parameterName, x); - } - - public void setClob(String parameterName, Clob x) throws SQLException { - realStatement.setClob(parameterName, x); - } - - public void setAsciiStream(String parameterName, InputStream x, long length) - throws SQLException { - realStatement.setAsciiStream(parameterName, x, length); - } - - public void setBinaryStream(String parameterName, InputStream x, long length) - throws SQLException { - realStatement.setBinaryStream(parameterName, x, length); - } - - public void setCharacterStream(String parameterName, Reader reader, - long length) throws SQLException { - realStatement.setCharacterStream(parameterName, reader, length); - } - - public void setAsciiStream(String parameterName, InputStream x) - throws SQLException { - realStatement.setAsciiStream(parameterName, x); - } - - public void setBinaryStream(String parameterName, InputStream x) - throws SQLException { - realStatement.setBinaryStream(parameterName, x); - } - - public void setCharacterStream(String parameterName, Reader reader) - throws SQLException { - realStatement.setCharacterStream(parameterName, reader); - } - - public void setNCharacterStream(String parameterName, Reader value) - throws SQLException { - realStatement.setNCharacterStream(parameterName, value); - } - - public void setClob(String parameterName, Reader reader) - throws SQLException { - realStatement.setClob(parameterName, reader); - } - - public void setBlob(String parameterName, InputStream inputStream) - throws SQLException { - realStatement.setBlob(parameterName, inputStream); - } - - public void setNClob(String parameterName, Reader reader) - throws SQLException { - realStatement.setNClob(parameterName, reader); - } - - public T getObject(int parameterIndex, Class type) - throws SQLException { - return realStatement.getObject(parameterIndex, type); - } - - public T getObject(String parameterName, Class type) - throws SQLException { - return realStatement.getObject(parameterName, type); - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWConnection.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWConnection.java deleted file mode 100755 index d95766a2d..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWConnection.java +++ /dev/null @@ -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 unwrap(Class 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() { - 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() { - 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() { - 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> getTypeMap() throws SQLException { - return realConnection.getTypeMap(); - } - - public void setTypeMap(Map> 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() { - 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() { - 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(); - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWPreparedStatement.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWPreparedStatement.java deleted file mode 100644 index 12cec2459..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWPreparedStatement.java +++ /dev/null @@ -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() { - 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() { - 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() { - 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() { - 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() { - 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() { - 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() { - 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() { - 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() { - 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() { - 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 unwrap(Class 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() { - 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() { - 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() { - 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); - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWStatement.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWStatement.java deleted file mode 100644 index 1a3cd2b49..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWStatement.java +++ /dev/null @@ -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 unwrap(Class 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() { - 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() { - 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() { - 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() { - 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() { - 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() { - 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() { - 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() { - 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() { - 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() { - 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(); - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/StatementTracing.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/StatementTracing.java deleted file mode 100644 index 1ee9749de..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/StatementTracing.java +++ /dev/null @@ -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 execute(java.sql.Statement realStatement, - String connectInfo, String method, String sql, Executable 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 { - public R exe(java.sql.Statement realStatement, String sql) - throws SQLException; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/AbstractDatabasePluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/AbstractDatabasePluginDefine.java deleted file mode 100644 index e0f452d45..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/AbstractDatabasePluginDefine.java +++ /dev/null @@ -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 getMethodsMatcher() { - return named("connect"); - } - - @Override - public String getMethodsInterceptor() { - return "com.a.eye.skywalking.plugin.jdbc.define.JDBCDriverInterceptor"; - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/H2PluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/H2PluginDefine.java deleted file mode 100644 index 14c32bd17..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/H2PluginDefine.java +++ /dev/null @@ -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"; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCBuriedPointType.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCBuriedPointType.java deleted file mode 100644 index a1aa965d2..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCBuriedPointType.java +++ /dev/null @@ -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; - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCDriverInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCDriverInterceptor.java deleted file mode 100644 index 577e43622..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCDriverInterceptor.java +++ /dev/null @@ -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) { - - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/MysqlPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/MysqlPluginDefine.java deleted file mode 100644 index c286ac49f..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/MysqlPluginDefine.java +++ /dev/null @@ -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"; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/OraclePluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/OraclePluginDefine.java deleted file mode 100644 index 05fb9e3c0..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/OraclePluginDefine.java +++ /dev/null @@ -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"; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def index 8c34d4f78..7949e2865 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def @@ -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 diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/test/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParserTest.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/test/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParserTest.java new file mode 100644 index 000000000..39836172e --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/test/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParserTest.java @@ -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)); + } +} \ No newline at end of file diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java index 661c65087..8c2ddecd4 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java @@ -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()); } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java index 1f4ef4650..1dd91e9ff 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java @@ -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 hostAndPorts = (Set) 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); } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java index 25edc5591..6a337c79d 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java @@ -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()); } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java index c01440ff0..e6d2550f2 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java @@ -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); } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java index 25599a212..5bea6db7e 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java @@ -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()); } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisMethodInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisMethodInterceptor.java index 377f78cae..59adabd6a 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisMethodInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisMethodInterceptor.java @@ -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() { diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java index 214f9b537..5a1693763 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java @@ -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. diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java index a0d269888..ce2b845fc 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java @@ -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(); } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java index 0413cb985..72f53665b 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java @@ -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()); diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java index cf90c0f1a..adef99556 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java @@ -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; } }}; } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java index 29ee2f2b5..5a629023b 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java @@ -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"; diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptor.java index ef9421ea6..b690b3168 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptor.java @@ -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; } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatInstrumentation.java index c512d84ff..36c120ac5 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatInstrumentation.java @@ -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 diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java index fbe643dda..61f8501d8 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java @@ -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.is("error")); assertThat(logData.getFields().get("error.kind"), CoreMatchers.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)); }