use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.
the class JtdsPlugin method addConnectionTransformer.
private void addConnectionTransformer(final JtdsConfig config) {
TransformCallback transformer = 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("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.ConnectionCloseInterceptor", JtdsConstants.JTDS_SCOPE);
target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.StatementCreateInterceptor", JtdsConstants.JTDS_SCOPE);
target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementCreateInterceptor", JtdsConstants.JTDS_SCOPE);
if (config.isProfileSetAutoCommit()) {
target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.TransactionSetAutoCommitInterceptor", JtdsConstants.JTDS_SCOPE);
}
if (config.isProfileCommit()) {
target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.TransactionCommitInterceptor", JtdsConstants.JTDS_SCOPE);
}
if (config.isProfileRollback()) {
target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.TransactionRollbackInterceptor", JtdsConstants.JTDS_SCOPE);
}
return target.toBytecode();
}
};
transformTemplate.transform("net.sourceforge.jtds.jdbc.ConnectionJDBC2", transformer);
transformTemplate.transform("net.sourceforge.jtds.jdbc.JtdsConnection", transformer);
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.
the class Log4jPlugin method setup.
@Override
public void setup(ProfilerPluginSetupContext context) {
final Log4jConfig config = new Log4jConfig(context.getConfig());
if (logger.isInfoEnabled()) {
logger.info("Log4jPlugin config:{}", config);
}
if (!config.isLog4jLoggingTransactionInfo()) {
logger.info("Log4j plugin is not executed because log4j transform enable config value is false.");
return;
}
transformTemplate.transform("org.apache.log4j.spi.LoggingEvent", new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
InstrumentClass mdcClass = instrumentor.getInstrumentClass(loader, "org.apache.log4j.MDC", null);
if (mdcClass == null) {
logger.warn("Can not modify. Because org.apache.log4j.MDC does not exist.");
return null;
}
if (!mdcClass.hasMethod("put", "java.lang.String", "java.lang.Object")) {
logger.warn("Can not modify. Because put method does not exist at org.apache.log4j.MDC class.");
return null;
}
if (!mdcClass.hasMethod("remove", "java.lang.String")) {
logger.warn("Can not modify. Because remove method does not exist at org.apache.log4j.MDC class.");
return null;
}
InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
if (!target.hasConstructor("java.lang.String", "org.apache.log4j.Category", "org.apache.log4j.Priority", "java.lang.Object", "java.lang.Throwable")) {
logger.warn("Can not modify. Because constructor to modify not exist at org.apache.log4j.MDC class." + "\nThere is a strong presumption that your application use under version 1.2.14 log4j." + "\nconstructor prototype : LoggingEvent(String fqnOfCategoryClass, Category logger, Priority level, Object message, Throwable throwable);");
return null;
}
if (!target.hasConstructor("java.lang.String", "org.apache.log4j.Category", "long", "org.apache.log4j.Priority", "java.lang.Object", "java.lang.Throwable")) {
logger.warn("Can not modify. Because constructor to modify not exist at org.apache.log4j.MDC class." + "\nThere is a strong presumption that your application use under version 1.2.14 log4j." + "\nconstructor prototype : LoggingEvent(String fqnOfCategoryClass, Category logger, long timeStamp, Priority level, Object message, Throwable throwable);");
return null;
}
if (!target.hasConstructor("java.lang.String", "org.apache.log4j.Category", "long", "org.apache.log4j.Level", "java.lang.Object", "java.lang.String", "org.apache.log4j.spi.ThrowableInformation", "java.lang.String", "org.apache.log4j.spi.LocationInfo", "java.util.Map")) {
logger.warn("Can not modify. Because constructor to modify not exist at org.apache.log4j.MDC class. " + "\nThere is a strong presumption that your application use under version 1.2.14 log4j." + "\nconstructor prototype : LoggingEvent(final String fqnOfCategoryClass, final Category logger, final long timeStamp, final Level level, final Object message, final String threadName, final ThrowableInformation throwable, final String ndc, final LocationInfo info, final java.util.Map properties);");
return null;
}
target.addInterceptor("com.navercorp.pinpoint.plugin.log4j.interceptor.LoggingEventOfLog4jInterceptor");
return target.toBytecode();
}
});
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.
the class LogbackPlugin method setup.
@Override
public void setup(ProfilerPluginSetupContext context) {
final LogbackConfig config = new LogbackConfig(context.getConfig());
if (logger.isInfoEnabled()) {
logger.info("LogbackPlugin config:{}", config);
}
if (!config.isLogbackLoggingTransactionInfo()) {
logger.info("Logback plugin is not executed because logback transform enable config value is false.");
return;
}
transformTemplate.transform("ch.qos.logback.classic.spi.LoggingEvent", new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
InstrumentClass mdcClass = instrumentor.getInstrumentClass(loader, "org.slf4j.MDC", null);
if (mdcClass == null) {
logger.warn("Can not modify. Because org.slf4j.MDC does not exist.");
return null;
}
if (!mdcClass.hasMethod("put", "java.lang.String", "java.lang.String")) {
logger.warn("Can not modify. Because put method does not exist at org.slf4j.MDC class.");
return null;
}
if (!mdcClass.hasMethod("remove", "java.lang.String")) {
logger.warn("Can not modify. Because remove method does not exist at org.slf4j.MDC class.");
return null;
}
InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
if (!target.hasConstructor()) {
logger.warn("Can not modify. Because constructor to modify not exist at ch.qos.logback.classic.spi.LoggingEvent class." + "\nconstructor prototype : LoggingEvent();");
return null;
}
if (!target.hasConstructor("java.lang.String", "ch.qos.logback.classic.Logger", "ch.qos.logback.classic.Level", "java.lang.String", "java.lang.Throwable", "java.lang.Object[]")) {
logger.warn("Can not modify. Because constructor to modify not exist at ch.qos.logback.classic.spi.LoggingEvent class." + "\nconstructor prototype : LoggingEvent(String fqcn, Logger logger, Level level, String message, Throwable throwable, Object[] argArray);");
return null;
}
target.addInterceptor("com.navercorp.pinpoint.plugin.logback.interceptor.LoggingEventOfLogbackInterceptor");
return target.toBytecode();
}
});
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass 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.InstrumentClass in project pinpoint by naver.
the class OraclePlugin method addPreparedStatementTransformer.
private void addPreparedStatementTransformer(final OracleConfig config) {
TransformCallback transformer = new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
if (className.equals(CLASS_PREPARED_STATEMENT)) {
if (instrumentor.exist(loader, CLASS_PREPARED_STATEMENT_WRAPPER)) {
return null;
}
}
InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor");
target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor");
int maxBindValueSize = config.getMaxSqlBindValueSize();
target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementExecuteQueryInterceptor", va(maxBindValueSize), OracleConstants.ORACLE_SCOPE);
if (config.isTraceSqlBindValue()) {
target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementBindVariableInterceptor", OracleConstants.ORACLE_SCOPE);
}
return target.toBytecode();
}
};
transformTemplate.transform(CLASS_PREPARED_STATEMENT, transformer);
transformTemplate.transform(CLASS_PREPARED_STATEMENT_WRAPPER, transformer);
}
Aggregations