From 7da1889f2c165448d5861fc1d9bcb60597e41cb8 Mon Sep 17 00:00:00 2001 From: Gustavo Lima Date: Thu, 7 Sep 2017 12:20:13 -0700 Subject: [PATCH 1/5] Jedis Visitor Changes --- .../agent/redis/JedisMethodVisitorV2.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisMethodVisitorV2.java diff --git a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisMethodVisitorV2.java b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisMethodVisitorV2.java new file mode 100644 index 00000000000..c8ed7855c0b --- /dev/null +++ b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisMethodVisitorV2.java @@ -0,0 +1,60 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package com.microsoft.applicationinsights.agent.internal.agent.redis; + +import com.microsoft.applicationinsights.agent.internal.logger.InternalAgentLogger; +import com.microsoft.applicationinsights.agent.internal.agent.DefaultMethodVisitor; +import com.microsoft.applicationinsights.agent.internal.agent.ClassToMethodTransformationData; + +import org.objectweb.asm.MethodVisitor; + +/** + * The class is responsible for instrumenting Jedis client methods. + * + * Created by guslima on 9/6/2017. + */ +final class JedisMethodVisitorV2 extends DefaultMethodVisitor { + private final static String ON_ENTER_METHOD_NAME = "jedisMethodStarted"; + private final static String ON_ENTER_METHOD_SIGNATURE = "(Ljava/lang/String;)V"; + + public JedisMethodVisitorV2(int access, + String desc, + String owner, + String methodName, + MethodVisitor methodVisitor, + ClassToMethodTransformationData additionalData) { + super(false, true, 0, access, desc, owner, methodName, methodVisitor, additionalData); + } + + @Override + protected String getOnEnterMethodName() { + InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.INFO, "getOnEnterMethodName"); + return ON_ENTER_METHOD_NAME; + } + + @Override + protected String getOnEnterMethodSignature() { + InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.INFO, "getOnEnterMethodSig"); + return ON_ENTER_METHOD_SIGNATURE; + } + +} From 8f284b1618369c9c5adc32b6138999753c6696dd Mon Sep 17 00:00:00 2001 From: Gustavo Lima Date: Thu, 7 Sep 2017 12:20:53 -0700 Subject: [PATCH 2/5] Hooking up Jedis visitor --- .../internal/agent/DefaultMethodVisitor.java | 30 +++++++++++++++---- .../agent/redis/JedisClassDataProvider.java | 4 +-- .../agent/redis/JedisMethodVisitor.java | 3 ++ .../agent/redis/JedisMethodVisitorV2.java | 5 ---- .../coresync/AgentNotificationsHandler.java | 6 ++++ .../coresync/InstrumentedClassType.java | 3 +- .../impl/ImplementationsCoordinator.java | 12 ++++++++ .../agent/CoreAgentNotificationsHandler.java | 10 +++++++ 8 files changed, 60 insertions(+), 13 deletions(-) diff --git a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/DefaultMethodVisitor.java b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/DefaultMethodVisitor.java index c33316168e6..c063942166b 100644 --- a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/DefaultMethodVisitor.java +++ b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/DefaultMethodVisitor.java @@ -86,11 +86,11 @@ public DefaultMethodVisitor(MethodInstrumentationDecision decision, protected void byteCodeForMethodExit(int opcode) { Object[] args = null; - String methodSignature = FINISH_METHOD_DEFAULT_SIGNATURE; + String methodSignature = getOnExitMethodDefaultSignature(); switch (translateExitCode(opcode)) { case EXIT_WITH_EXCEPTION: args = new Object[] { getMethodName(), duplicateTopStackToTempVariable(Type.getType(Throwable.class)) }; - methodSignature = FINISH_METHOD_EXCEPTION_SIGNATURE; + methodSignature = getOnExitMethodExceptionSignature(); break; case EXIT_WITH_RETURN_VALUE: @@ -103,7 +103,7 @@ protected void byteCodeForMethodExit(int opcode) { } if (args != null) { - activateEnumMethod(ImplementationsCoordinator.class, FINISH_DETECT_METHOD_NAME, methodSignature, args); + activateEnumMethod(ImplementationsCoordinator.class, getOnExitMethodName(), methodSignature, args); } } @@ -143,8 +143,28 @@ protected void onMethodEnter() { activateEnumMethod( ImplementationsCoordinator.class, - START_DETECT_METHOD_NAME, - START_DETECT_METHOD_SIGNATURE, + getOnEnterMethodName(), + getOnEnterMethodSignature(), getMethodName()); } + + protected String getOnEnterMethodName() { + return START_DETECT_METHOD_NAME; + } + + protected String getOnEnterMethodSignature() { + return START_DETECT_METHOD_SIGNATURE; + } + + protected String getOnExitMethodName() { + return FINISH_DETECT_METHOD_NAME; + } + + protected String getOnExitMethodDefaultSignature() { + return FINISH_METHOD_DEFAULT_SIGNATURE; + } + + protected String getOnExitMethodExceptionSignature() { + return FINISH_METHOD_EXCEPTION_SIGNATURE; + } } diff --git a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisClassDataProvider.java b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisClassDataProvider.java index 675d18695a3..9828bd03168 100644 --- a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisClassDataProvider.java +++ b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisClassDataProvider.java @@ -46,13 +46,13 @@ public JedisClassDataProvider(Map classesToIns public void add() { try { ClassInstrumentationData data = - new ClassInstrumentationData(JEDIS_CLASS_NAME, InstrumentedClassType.OTHER) + new ClassInstrumentationData(JEDIS_CLASS_NAME, InstrumentedClassType.Redis) .setReportCaughtExceptions(false) .setReportExecutionTime(true); MethodVisitorFactory methodVisitorFactory = new MethodVisitorFactory() { @Override public MethodVisitor create(MethodInstrumentationDecision decision, int access, String desc, String owner, String methodName, MethodVisitor methodVisitor, ClassToMethodTransformationData additionalData) { - return new JedisMethodVisitor(access, desc, JEDIS_CLASS_NAME, methodName, methodVisitor, additionalData); + return new JedisMethodVisitorV2(access, desc, JEDIS_CLASS_NAME, methodName, methodVisitor, additionalData); } }; data.addAllMethods(false, true, methodVisitorFactory); diff --git a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisMethodVisitor.java b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisMethodVisitor.java index 5dc1389ef4e..8f83a0bc664 100644 --- a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisMethodVisitor.java +++ b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisMethodVisitor.java @@ -30,9 +30,12 @@ import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; + /** * Created by gupele on 8/6/2015. + * @deprecated Replaced with JedisMethodVisitorV2 */ +@Deprecated final class JedisMethodVisitor extends DefaultMethodVisitor { private final static String FINISH_DETECT_METHOD_NAME = "methodFinished"; private final static String FINISH_METHOD_DEFAULT_SIGNATURE = "(Ljava/lang/String;J[Ljava/lang/Object;Ljava/lang/Throwable;)V"; diff --git a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisMethodVisitorV2.java b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisMethodVisitorV2.java index c8ed7855c0b..67ca0867cbe 100644 --- a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisMethodVisitorV2.java +++ b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisMethodVisitorV2.java @@ -21,7 +21,6 @@ package com.microsoft.applicationinsights.agent.internal.agent.redis; -import com.microsoft.applicationinsights.agent.internal.logger.InternalAgentLogger; import com.microsoft.applicationinsights.agent.internal.agent.DefaultMethodVisitor; import com.microsoft.applicationinsights.agent.internal.agent.ClassToMethodTransformationData; @@ -29,8 +28,6 @@ /** * The class is responsible for instrumenting Jedis client methods. - * - * Created by guslima on 9/6/2017. */ final class JedisMethodVisitorV2 extends DefaultMethodVisitor { private final static String ON_ENTER_METHOD_NAME = "jedisMethodStarted"; @@ -47,13 +44,11 @@ public JedisMethodVisitorV2(int access, @Override protected String getOnEnterMethodName() { - InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.INFO, "getOnEnterMethodName"); return ON_ENTER_METHOD_NAME; } @Override protected String getOnEnterMethodSignature() { - InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.INFO, "getOnEnterMethodSig"); return ON_ENTER_METHOD_SIGNATURE; } diff --git a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/AgentNotificationsHandler.java b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/AgentNotificationsHandler.java index 36265492f7d..2a55f270ac1 100644 --- a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/AgentNotificationsHandler.java +++ b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/AgentNotificationsHandler.java @@ -97,6 +97,12 @@ public interface AgentNotificationsHandler { */ void preparedStatementExecuteBatchMethodStarted(String classAndMethodNames, PreparedStatement statement, String sqlStatement, int batchCounter); + /** + * Called before methods in the Jedis client class are executed. + * @param classAndMethodNames The name of the class and method separated by '.' + */ + void jedisMethodStarted(String classAndMethodNames); + /** * A 'regular' method enter. Non HTTP/SQL method * @param classAndMethodNames The name of the class and method separated by '.' diff --git a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/InstrumentedClassType.java b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/InstrumentedClassType.java index f048a93803d..a3c7750681e 100644 --- a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/InstrumentedClassType.java +++ b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/InstrumentedClassType.java @@ -27,5 +27,6 @@ public enum InstrumentedClassType { SQL, HTTP, - OTHER + OTHER, + Redis } diff --git a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/impl/ImplementationsCoordinator.java b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/impl/ImplementationsCoordinator.java index bd89047740a..4d6ada46ebd 100644 --- a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/impl/ImplementationsCoordinator.java +++ b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/impl/ImplementationsCoordinator.java @@ -175,6 +175,18 @@ public void sqlStatementMethodStarted(String name, Statement statement, String s } } + @Override + public void jedisMethodStarted(String name) { + try { + AgentNotificationsHandler implementation = getImplementation(); + if (implementation != null) { + implementation.jedisMethodStarted(name); + } + } catch (Throwable t) { + t.printStackTrace(); + } + } + @Override public void methodStarted(String name) { try { diff --git a/core/src/main/java/com/microsoft/applicationinsights/internal/agent/CoreAgentNotificationsHandler.java b/core/src/main/java/com/microsoft/applicationinsights/internal/agent/CoreAgentNotificationsHandler.java index aa0777d6aee..7f597242f19 100644 --- a/core/src/main/java/com/microsoft/applicationinsights/internal/agent/CoreAgentNotificationsHandler.java +++ b/core/src/main/java/com/microsoft/applicationinsights/internal/agent/CoreAgentNotificationsHandler.java @@ -155,6 +155,16 @@ public void httpMethodFinished(String identifier, String method, String uri, int telemetryClient.track(telemetry); } + @Override + public void jedisMethodStarted(String name) { + int index = name.lastIndexOf('#'); + if (index != -1) { + name = name.substring(0, index); + } + + startMethod(InstrumentedClassType.Redis.toString(), name, new String[]{}); + } + @Override public void methodStarted(String name) { int index = name.lastIndexOf('#'); From d62152076edf3b05f2e506fff0277c2316154945 Mon Sep 17 00:00:00 2001 From: Gustavo Lima Date: Mon, 11 Sep 2017 11:00:04 -0700 Subject: [PATCH 3/5] remove printstack --- .../agent/internal/coresync/impl/ImplementationsCoordinator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/impl/ImplementationsCoordinator.java b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/impl/ImplementationsCoordinator.java index 4d6ada46ebd..4645f6a6eb2 100644 --- a/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/impl/ImplementationsCoordinator.java +++ b/agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/impl/ImplementationsCoordinator.java @@ -183,7 +183,6 @@ public void jedisMethodStarted(String name) { implementation.jedisMethodStarted(name); } } catch (Throwable t) { - t.printStackTrace(); } } From 4685eb308537428d0ba4306812746129c9873286 Mon Sep 17 00:00:00 2001 From: Gustavo Lima Date: Mon, 11 Sep 2017 11:05:07 -0700 Subject: [PATCH 4/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25626cc984e..0a37d9bbdd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # CHANGELOG ## Version 1.0.10 +- Fixed relialibity issue with Jedis client dependency collector - Fixed Request Telemetry Sending bug with new schema - Schema updated to the latest version. Changes in internal namespace `core/src/main/java/com/microsoft/applicationinsights/internal/schemav2`. - Class `SendableData` in internal namespace deleted. From 66f90495992e4068a799fa50b6eb0eea4c220b1e Mon Sep 17 00:00:00 2001 From: Gustavo Lima Date: Mon, 11 Sep 2017 11:07:45 -0700 Subject: [PATCH 5/5] fixed typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a37d9bbdd4..fea7bbf10d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # CHANGELOG ## Version 1.0.10 -- Fixed relialibity issue with Jedis client dependency collector +- Fixed reliability issue with Jedis client dependency collector - Fixed Request Telemetry Sending bug with new schema - Schema updated to the latest version. Changes in internal namespace `core/src/main/java/com/microsoft/applicationinsights/internal/schemav2`. - Class `SendableData` in internal namespace deleted.