use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod in project pinpoint by naver.
the class HystrixCommandTransformer method doInTransform.
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classfileBuffer);
target.addField("com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor");
InstrumentMethod queue = target.getDeclaredMethod("queue");
if (queue != null) {
queue.addInterceptor("com.navercorp.pinpoint.plugin.hystrix.interceptor.HystrixCommandQueueInterceptor");
}
// pre 1.4.0 - R executeCommand()
InstrumentMethod executeCommand = target.getDeclaredMethod("executeCommand");
if (executeCommand != null) {
executeCommand.addInterceptor("com.navercorp.pinpoint.plugin.hystrix.interceptor.HystrixCommandExecuteCommandInterceptor");
}
// pre 1.4.0 - R getFallbackOrThrowException(HystrixEventType, FailureType, String, Exception)
InstrumentMethod getFallbackOrThrowException = target.getDeclaredMethod("getFallbackOrThrowException", "com.netflix.hystrix.HystrixEventType", "com.netflix.hystrix.exception.HystrixRuntimeException$FailureType", "java.lang.String", "java.lang.Exception");
if (getFallbackOrThrowException != null) {
getFallbackOrThrowException.addInterceptor("com.navercorp.pinpoint.plugin.hystrix.interceptor.HystrixCommandGetFallbackOrThrowExceptionInterceptor");
}
return target.toBytecode();
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod in project pinpoint by naver.
the class JavassistClassTest method testDeclaredMethods.
@Test
public void testDeclaredMethods() throws InstrumentException {
InstrumentEngine engine = newJavassistEngine();
InstrumentContext instrumentContext = mock(InstrumentContext.class);
String testObjectName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
byte[] testObjectByteCode = readByteCode(testObjectName);
InstrumentClass testObject = engine.getClass(instrumentContext, null, testObjectName, testObjectByteCode);
Assert.assertEquals(testObject.getName(), testObjectName);
int findMethodCount = 0;
for (InstrumentMethod methodInfo : testObject.getDeclaredMethods()) {
if (!methodInfo.getName().equals("callA")) {
continue;
}
String[] parameterTypes = methodInfo.getParameterTypes();
if (parameterTypes == null || parameterTypes.length == 0) {
findMethodCount++;
}
}
Assert.assertEquals(findMethodCount, 1);
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod in project pinpoint by naver.
the class JavassistClassTest method testBeforeAddInterceptor.
@Test
public void testBeforeAddInterceptor() throws Exception {
final TestClassLoader loader = getTestClassLoader();
final String javassistClassName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
loader.addTransformer(javassistClassName, new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
try {
logger.info("modify className:{} cl:{}", className, classLoader);
InstrumentClass aClass = instrumentor.getInstrumentClass(classLoader, javassistClassName, classfileBuffer);
String methodName = "callA";
InstrumentMethod callaMethod = aClass.getDeclaredMethod(methodName);
callaMethod.addInterceptor("com.navercorp.pinpoint.test.javasssit.TestBeforeInterceptor");
byte[] bytes = aClass.toBytecode();
return bytes;
} catch (Throwable e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
}
});
Class<?> testObjectClazz = loader.loadClass(javassistClassName);
final String methodName = "callA";
logger.info("class:{}", testObjectClazz.toString());
logger.info("class cl:{}", testObjectClazz.getClassLoader());
final Object testObject = testObjectClazz.newInstance();
Method callA = testObjectClazz.getMethod(methodName);
callA.invoke(testObject);
Interceptor interceptor = getInterceptor(loader, 0);
assertEqualsIntField(interceptor, "call", 1);
assertEqualsObjectField(interceptor, "className", "com.navercorp.pinpoint.test.javasssit.mock.TestObject");
assertEqualsObjectField(interceptor, "methodName", methodName);
assertEqualsObjectField(interceptor, "args", null);
assertEqualsObjectField(interceptor, "target", testObject);
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod in project pinpoint by naver.
the class ActiveMQClientPlugin method addMessageDispatchChannelEditor.
private void addMessageDispatchChannelEditor() {
TransformCallback messageDispatchChannelTransformer = new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
// MessageDispatchChannel is an interface (5.4.0+)
if (!target.isInterceptable()) {
return null;
}
final InstrumentMethod enqueue = target.getDeclaredMethod("enqueue", "org.apache.activemq.command.MessageDispatch");
if (enqueue != null) {
enqueue.addInterceptor(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_DISPATCH_CHANNEL_ENQUEUE_INTERCEPTOR_FQCN);
}
final InstrumentMethod dequeue = target.getDeclaredMethod("dequeue", "long");
if (dequeue != null) {
dequeue.addInterceptor(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_DISPATCH_CHANNEL_DEQUEUE_INTERCEPTOR_FQCN);
}
return target.toBytecode();
}
};
transformTemplate.transform(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_DISPATCH_CHANNEL_FQCN, messageDispatchChannelTransformer);
transformTemplate.transform(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_DISPATCH_CHANNEL_FIFO_FQCN, messageDispatchChannelTransformer);
transformTemplate.transform(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_DISPATCH_CHANNEL_SIMPLE_PRIORITY_FQCN, messageDispatchChannelTransformer);
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod in project pinpoint by naver.
the class HttpClientPlugin method addHttpRequestClass.
private void addHttpRequestClass(final HttpClientPluginConfig config) {
transformTemplate.transform("com.google.api.client.http.HttpRequest", new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
InstrumentMethod execute = target.getDeclaredMethod("execute");
if (execute != null) {
execute.addInterceptor("com.navercorp.pinpoint.plugin.google.httpclient.interceptor.HttpRequestExecuteMethodInterceptor");
}
if (config.isAsync()) {
InstrumentMethod executeAsync = target.getDeclaredMethod("executeAsync", "java.util.concurrent.Executor");
if (executeAsync != null) {
executeAsync.addInterceptor("com.navercorp.pinpoint.plugin.google.httpclient.interceptor.HttpRequestExecuteAsyncMethodInterceptor");
}
for (InstrumentClass nestedClass : target.getNestedClasses(ClassFilters.chain(ClassFilters.enclosingMethod("executeAsync", "java.util.concurrent.Executor"), ClassFilters.interfaze("java.util.concurrent.Callable")))) {
logger.debug("Find nested class {}", target.getName());
instrumentor.transform(loader, nestedClass.getName(), new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
target.addField(AsyncTraceIdAccessor.class.getName());
InstrumentMethod constructor = target.getConstructor("com.google.api.client.http.HttpRequest");
if (constructor != null) {
logger.debug("Add constuctor interceptor for nested class {}", target.getName());
constructor.addInterceptor("com.navercorp.pinpoint.plugin.google.httpclient.interceptor.HttpRequestExecuteAsyncMethodInnerClassConstructorInterceptor");
}
InstrumentMethod m = target.getDeclaredMethod("call");
if (m != null) {
logger.debug("Add method interceptor for nested class {}.{}", target.getName(), m.getName());
m.addInterceptor("com.navercorp.pinpoint.plugin.google.httpclient.interceptor.HttpRequestExecuteAsyncMethodInnerClassCallMethodInterceptor");
}
return target.toBytecode();
}
});
}
}
return target.toBytecode();
}
});
}
Aggregations