Skip to content

Commit 46fc0e4

Browse files
authored
Fixing reliability issue with JedisMethodVisitor. (#423)
* Jedis Visitor Changes * Hooking up Jedis visitor * remove printstack * Update changelog * fixed typo
1 parent 420ace2 commit 46fc0e4

File tree

9 files changed

+115
-8
lines changed

9 files changed

+115
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# CHANGELOG
22

33
## Version 1.0.10
4+
- Fixed reliability issue with Jedis client dependency collector
45
- Fixed Request Telemetry Sending bug with new schema
56
- Schema updated to the latest version. Changes in internal namespace `core/src/main/java/com/microsoft/applicationinsights/internal/schemav2`.
67
- Class `SendableData` in internal namespace deleted.

agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/DefaultMethodVisitor.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ public DefaultMethodVisitor(MethodInstrumentationDecision decision,
8686
protected void byteCodeForMethodExit(int opcode) {
8787

8888
Object[] args = null;
89-
String methodSignature = FINISH_METHOD_DEFAULT_SIGNATURE;
89+
String methodSignature = getOnExitMethodDefaultSignature();
9090
switch (translateExitCode(opcode)) {
9191
case EXIT_WITH_EXCEPTION:
9292
args = new Object[] { getMethodName(), duplicateTopStackToTempVariable(Type.getType(Throwable.class)) };
93-
methodSignature = FINISH_METHOD_EXCEPTION_SIGNATURE;
93+
methodSignature = getOnExitMethodExceptionSignature();
9494
break;
9595

9696
case EXIT_WITH_RETURN_VALUE:
@@ -103,7 +103,7 @@ protected void byteCodeForMethodExit(int opcode) {
103103
}
104104

105105
if (args != null) {
106-
activateEnumMethod(ImplementationsCoordinator.class, FINISH_DETECT_METHOD_NAME, methodSignature, args);
106+
activateEnumMethod(ImplementationsCoordinator.class, getOnExitMethodName(), methodSignature, args);
107107
}
108108
}
109109

@@ -143,8 +143,28 @@ protected void onMethodEnter() {
143143

144144
activateEnumMethod(
145145
ImplementationsCoordinator.class,
146-
START_DETECT_METHOD_NAME,
147-
START_DETECT_METHOD_SIGNATURE,
146+
getOnEnterMethodName(),
147+
getOnEnterMethodSignature(),
148148
getMethodName());
149149
}
150+
151+
protected String getOnEnterMethodName() {
152+
return START_DETECT_METHOD_NAME;
153+
}
154+
155+
protected String getOnEnterMethodSignature() {
156+
return START_DETECT_METHOD_SIGNATURE;
157+
}
158+
159+
protected String getOnExitMethodName() {
160+
return FINISH_DETECT_METHOD_NAME;
161+
}
162+
163+
protected String getOnExitMethodDefaultSignature() {
164+
return FINISH_METHOD_DEFAULT_SIGNATURE;
165+
}
166+
167+
protected String getOnExitMethodExceptionSignature() {
168+
return FINISH_METHOD_EXCEPTION_SIGNATURE;
169+
}
150170
}

agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisClassDataProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ public JedisClassDataProvider(Map<String, ClassInstrumentationData> classesToIns
4646
public void add() {
4747
try {
4848
ClassInstrumentationData data =
49-
new ClassInstrumentationData(JEDIS_CLASS_NAME, InstrumentedClassType.OTHER)
49+
new ClassInstrumentationData(JEDIS_CLASS_NAME, InstrumentedClassType.Redis)
5050
.setReportCaughtExceptions(false)
5151
.setReportExecutionTime(true);
5252
MethodVisitorFactory methodVisitorFactory = new MethodVisitorFactory() {
5353
@Override
5454
public MethodVisitor create(MethodInstrumentationDecision decision, int access, String desc, String owner, String methodName, MethodVisitor methodVisitor, ClassToMethodTransformationData additionalData) {
55-
return new JedisMethodVisitor(access, desc, JEDIS_CLASS_NAME, methodName, methodVisitor, additionalData);
55+
return new JedisMethodVisitorV2(access, desc, JEDIS_CLASS_NAME, methodName, methodVisitor, additionalData);
5656
}
5757
};
5858
data.addAllMethods(false, true, methodVisitorFactory);

agent/src/main/java/com/microsoft/applicationinsights/agent/internal/agent/redis/JedisMethodVisitor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030
import org.objectweb.asm.Opcodes;
3131
import org.objectweb.asm.Type;
3232

33+
3334
/**
3435
* Created by gupele on 8/6/2015.
36+
* @deprecated Replaced with JedisMethodVisitorV2
3537
*/
38+
@Deprecated
3639
final class JedisMethodVisitor extends DefaultMethodVisitor {
3740
private final static String FINISH_DETECT_METHOD_NAME = "methodFinished";
3841
private final static String FINISH_METHOD_DEFAULT_SIGNATURE = "(Ljava/lang/String;J[Ljava/lang/Object;Ljava/lang/Throwable;)V";
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* ApplicationInsights-Java
3+
* Copyright (c) Microsoft Corporation
4+
* All rights reserved.
5+
*
6+
* MIT License
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
8+
* software and associated documentation files (the ""Software""), to deal in the Software
9+
* without restriction, including without limitation the rights to use, copy, modify, merge,
10+
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit
11+
* persons to whom the Software is furnished to do so, subject to the following conditions:
12+
* The above copyright notice and this permission notice shall be included in all copies or
13+
* substantial portions of the Software.
14+
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16+
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
17+
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
* DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
package com.microsoft.applicationinsights.agent.internal.agent.redis;
23+
24+
import com.microsoft.applicationinsights.agent.internal.agent.DefaultMethodVisitor;
25+
import com.microsoft.applicationinsights.agent.internal.agent.ClassToMethodTransformationData;
26+
27+
import org.objectweb.asm.MethodVisitor;
28+
29+
/**
30+
* The class is responsible for instrumenting Jedis client methods.
31+
*/
32+
final class JedisMethodVisitorV2 extends DefaultMethodVisitor {
33+
private final static String ON_ENTER_METHOD_NAME = "jedisMethodStarted";
34+
private final static String ON_ENTER_METHOD_SIGNATURE = "(Ljava/lang/String;)V";
35+
36+
public JedisMethodVisitorV2(int access,
37+
String desc,
38+
String owner,
39+
String methodName,
40+
MethodVisitor methodVisitor,
41+
ClassToMethodTransformationData additionalData) {
42+
super(false, true, 0, access, desc, owner, methodName, methodVisitor, additionalData);
43+
}
44+
45+
@Override
46+
protected String getOnEnterMethodName() {
47+
return ON_ENTER_METHOD_NAME;
48+
}
49+
50+
@Override
51+
protected String getOnEnterMethodSignature() {
52+
return ON_ENTER_METHOD_SIGNATURE;
53+
}
54+
55+
}

agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/AgentNotificationsHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ public interface AgentNotificationsHandler {
9797
*/
9898
void preparedStatementExecuteBatchMethodStarted(String classAndMethodNames, PreparedStatement statement, String sqlStatement, int batchCounter);
9999

100+
/**
101+
* Called before methods in the Jedis client class are executed.
102+
* @param classAndMethodNames The name of the class and method separated by '.'
103+
*/
104+
void jedisMethodStarted(String classAndMethodNames);
105+
100106
/**
101107
* A 'regular' method enter. Non HTTP/SQL method
102108
* @param classAndMethodNames The name of the class and method separated by '.'

agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/InstrumentedClassType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
public enum InstrumentedClassType {
2828
SQL,
2929
HTTP,
30-
OTHER
30+
OTHER,
31+
Redis
3132
}

agent/src/main/java/com/microsoft/applicationinsights/agent/internal/coresync/impl/ImplementationsCoordinator.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ public void sqlStatementMethodStarted(String name, Statement statement, String s
175175
}
176176
}
177177

178+
@Override
179+
public void jedisMethodStarted(String name) {
180+
try {
181+
AgentNotificationsHandler implementation = getImplementation();
182+
if (implementation != null) {
183+
implementation.jedisMethodStarted(name);
184+
}
185+
} catch (Throwable t) {
186+
}
187+
}
188+
178189
@Override
179190
public void methodStarted(String name) {
180191
try {

core/src/main/java/com/microsoft/applicationinsights/internal/agent/CoreAgentNotificationsHandler.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ public void httpMethodFinished(String identifier, String method, String uri, int
155155
telemetryClient.track(telemetry);
156156
}
157157

158+
@Override
159+
public void jedisMethodStarted(String name) {
160+
int index = name.lastIndexOf('#');
161+
if (index != -1) {
162+
name = name.substring(0, index);
163+
}
164+
165+
startMethod(InstrumentedClassType.Redis.toString(), name, new String[]{});
166+
}
167+
158168
@Override
159169
public void methodStarted(String name) {
160170
int index = name.lastIndexOf('#');

0 commit comments

Comments
 (0)