use of java.security.ProtectionDomain 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();
}
});
}
}
use of java.security.ProtectionDomain 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 java.security.ProtectionDomain 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 java.security.ProtectionDomain 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 java.security.ProtectionDomain 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