use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.
the class ActiveMQClientPlugin method addProducerEditor.
private void addProducerEditor(final Filter<String> excludeDestinationFilter) {
final MethodFilter methodFilter = MethodFilters.chain(MethodFilters.name("send"), MethodFilters.argAt(0, "javax.jms.Destination"), MethodFilters.argAt(1, "javax.jms.Message"));
transformTemplate.transform(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_PRODUCER_FQCN, 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.addGetter(ActiveMQClientConstants.FIELD_GETTER_ACTIVEMQ_SESSION, ActiveMQClientConstants.FIELD_ACTIVEMQ_MESSAGE_PRODUCER_SESSION);
for (InstrumentMethod method : target.getDeclaredMethods(methodFilter)) {
try {
method.addInterceptor(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_PRODUCER_SEND_INTERCEPTOR_FQCN, va(excludeDestinationFilter));
} catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn("Unsupported method " + method, e);
}
}
}
return target.toBytecode();
}
});
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.
the class GsonPlugin method setup.
@Override
public void setup(ProfilerPluginSetupContext context) {
GsonConfig config = new GsonConfig(context.getConfig());
logger.debug("[Gson] Initialized config={}", config);
if (config.isProfile()) {
transformTemplate.transform("com.google.gson.Gson", 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);
for (InstrumentMethod m : target.getDeclaredMethods(MethodFilters.name("fromJson"))) {
m.addScopedInterceptor("com.navercorp.pinpoint.plugin.gson.interceptor.FromJsonInterceptor", GSON_SCOPE);
}
for (InstrumentMethod m : target.getDeclaredMethods(MethodFilters.name("toJson"))) {
m.addScopedInterceptor("com.navercorp.pinpoint.plugin.gson.interceptor.ToJsonInterceptor", GSON_SCOPE);
}
return target.toBytecode();
}
});
}
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.
the class DedicatedClassFileTransformer method transform.
@Override
public byte[] transform(ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
try {
InstrumentClass target = context.getInstrumentClass(classLoader, className, classfileBuffer);
recipe.edit(classLoader, target);
return target.toBytecode();
} catch (PinpointException e) {
throw e;
} catch (Throwable e) {
String msg = "Fail to invoke plugin class recipe: " + toString();
throw new PinpointException(msg, e);
}
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.
the class InvokeAfterCodeGeneratorTest method testGenerate_AroundInterceptor3_NoCatchClause.
@Test
public void testGenerate_AroundInterceptor3_NoCatchClause() throws Exception {
final Class<AroundInterceptor3> aroundInterceptor3Class = AroundInterceptor3.class;
final InterceptorDefinition interceptorDefinition = interceptorDefinitionFactory.createInterceptorDefinition(aroundInterceptor3Class);
final InstrumentClass mockClass = mock(InstrumentClass.class);
Mockito.when(mockClass.getName()).thenReturn("TestClass");
final InstrumentMethod mockMethod = mock(InstrumentMethod.class);
Mockito.when(mockMethod.getName()).thenReturn("TestMethod");
Mockito.when(mockMethod.getParameterTypes()).thenReturn(new String[] { "java.lang.Object", "java.lang.Object", "java.lang.Object" });
Mockito.when(mockMethod.getReturnType()).thenReturn("java.lang.Object");
ApiMetaDataService apiMetaDataService = mock(ApiMetaDataService.class);
final InvokeAfterCodeGenerator invokeAfterCodeGenerator = new InvokeAfterCodeGenerator(100, interceptorDefinition, mockClass, mockMethod, apiMetaDataService, false, false);
final String generate = invokeAfterCodeGenerator.generate();
logger.debug("testGenerate_AroundInterceptor3_NoCatchClause:{}", generate);
Assert.assertTrue(generate.contains("($w)$1"));
Assert.assertTrue(generate.contains("($w)$2"));
Assert.assertTrue(generate.contains("($w)$3"));
Assert.assertTrue(generate.contains("($w)$_"));
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.
the class MyBatisPlugin method addInterceptorsForSqlSession.
// SqlSession implementations
private void addInterceptorsForSqlSession() {
final MethodFilter methodFilter = MethodFilters.name("selectOne", "selectList", "selectMap", "select", "insert", "update", "delete");
final String[] sqlSessionImpls = { "org.apache.ibatis.session.defaults.DefaultSqlSession", "org.mybatis.spring.SqlSessionTemplate" };
for (final String sqlSession : sqlSessionImpls) {
transformTemplate.transform(sqlSession, new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
final InstrumentClass target = instrumentor.getInstrumentClass(loader, sqlSession, classfileBuffer);
final List<InstrumentMethod> methodsToTrace = target.getDeclaredMethods(methodFilter);
for (InstrumentMethod methodToTrace : methodsToTrace) {
String sqlSessionOperationInterceptor = "com.navercorp.pinpoint.plugin.mybatis.interceptor.SqlSessionOperationInterceptor";
methodToTrace.addScopedInterceptor(sqlSessionOperationInterceptor, MYBATIS_SCOPE, ExecutionPolicy.BOUNDARY);
}
return target.toBytecode();
}
});
}
}
Aggregations