Beispiel #1
0
  @Override
  public void setup(ProfilerPluginSetupContext context) {
    context.addApplicationTypeDetector(new JettyDetector());
    JettyConfiguration config = new JettyConfiguration(context.getConfig());

    addServerInterceptor(config);
    addRequestEditor();
  }
Beispiel #2
0
  private void addDriverTransformer(ProfilerPluginSetupContext setupContext) {
    setupContext.addClassFileTransformer(
        "oracle.jdbc.driver.OracleDriver",
        new PinpointClassFileTransformer() {

          @Override
          public byte[] transform(
              Instrumentor instrumentContext,
              ClassLoader loader,
              String className,
              Class<?> classBeingRedefined,
              ProtectionDomain protectionDomain,
              byte[] classfileBuffer)
              throws InstrumentException {
            InstrumentClass target =
                instrumentContext.getInstrumentClass(loader, className, classfileBuffer);
            InterceptorGroup group = instrumentContext.getInterceptorGroup(GROUP_ORACLE);

            target.addGroupedInterceptor(
                "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.DriverConnectInterceptor",
                group,
                ExecutionPolicy.ALWAYS,
                new OracleJdbcUrlParser());

            return target.toBytecode();
          }
        });
  }
Beispiel #3
0
  private void addCall(ProfilerPluginSetupContext context, final OkHttpPluginConfig config) {
    context.addClassFileTransformer(
        "com.squareup.okhttp.Call",
        new TransformCallback() {

          @Override
          public byte[] doInTransform(
              Instrumentor instrumentContext,
              ClassLoader loader,
              String className,
              Class<?> classBeingRedefined,
              ProtectionDomain protectionDomain,
              byte[] classfileBuffer)
              throws InstrumentException {
            InstrumentClass target =
                instrumentContext.getInstrumentClass(loader, className, classfileBuffer);

            for (InstrumentMethod method :
                target.getDeclaredMethods(MethodFilters.name("execute", "enqueue", "cancel"))) {
              method.addInterceptor(
                  "com.navercorp.pinpoint.plugin.okhttp.interceptor.CallMethodInterceptor");
            }

            return target.toBytecode();
          }
        });
  }
Beispiel #4
0
  private void addRequestBuilder(
      ProfilerPluginSetupContext context, final OkHttpPluginConfig config) {
    context.addClassFileTransformer(
        "com.squareup.okhttp.Request$Builder",
        new TransformCallback() {

          @Override
          public byte[] doInTransform(
              Instrumentor instrumentContext,
              ClassLoader loader,
              String className,
              Class<?> classBeingRedefined,
              ProtectionDomain protectionDomain,
              byte[] classfileBuffer)
              throws InstrumentException {
            InstrumentClass target =
                instrumentContext.getInstrumentClass(loader, className, classfileBuffer);
            target.addGetter(HttpUrlGetter.class.getName(), OkHttpConstants.FIELD_HTTP_URL);

            InstrumentMethod buildMethod = target.getDeclaredMethod("build");
            if (buildMethod != null) {
              logger.debug("[OkHttp] Add Request.Builder.build interceptor.");
              buildMethod.addInterceptor(
                  "com.navercorp.pinpoint.plugin.okhttp.interceptor.RequestBuilderBuildMethodInterceptor");
            }

            return target.toBytecode();
          }
        });
  }
Beispiel #5
0
  private void addAsyncCall(ProfilerPluginSetupContext context, final OkHttpPluginConfig config) {
    context.addClassFileTransformer(
        "com.squareup.okhttp.Call$AsyncCall",
        new TransformCallback() {

          @Override
          public byte[] doInTransform(
              Instrumentor instrumentContext,
              ClassLoader loader,
              String className,
              Class<?> classBeingRedefined,
              ProtectionDomain protectionDomain,
              byte[] classfileBuffer)
              throws InstrumentException {
            InstrumentClass target =
                instrumentContext.getInstrumentClass(loader, className, classfileBuffer);
            target.addField(AsyncTraceIdAccessor.class.getName());

            InstrumentMethod executeMethod = target.getDeclaredMethod("execute");
            if (executeMethod != null) {
              logger.debug("[OkHttp] Add AsyncCall.execute interceptor.");
              executeMethod.addInterceptor(
                  "com.navercorp.pinpoint.plugin.okhttp.interceptor.AsyncCallExecuteMethodInterceptor");
            }

            return target.toBytecode();
          }
        });
  }
Beispiel #6
0
  private void addPreparedStatementTransformer(
      ProfilerPluginSetupContext setupContext, final OracleConfig config) {
    PinpointClassFileTransformer transformer =
        new PinpointClassFileTransformer() {

          @Override
          public byte[] transform(
              Instrumentor instrumentContext,
              ClassLoader loader,
              String className,
              Class<?> classBeingRedefined,
              ProtectionDomain protectionDomain,
              byte[] classfileBuffer)
              throws InstrumentException {
            if (className.equals(CLASS_PREPARED_STATEMENT)) {
              if (instrumentContext.exist(loader, CLASS_PREPARED_STATEMENT_WRAPPER)) {
                return null;
              }
            }

            InstrumentClass target =
                instrumentContext.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",
                "new java.util.HashMap()");

            int maxBindValueSize = config.getMaxSqlBindValueSize();
            InterceptorGroup group = instrumentContext.getInterceptorGroup(GROUP_ORACLE);

            target.addGroupedInterceptor(
                "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementExecuteQueryInterceptor",
                group,
                maxBindValueSize);
            target.addGroupedInterceptor(
                "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementBindVariableInterceptor",
                group);

            return target.toBytecode();
          }
        };

    setupContext.addClassFileTransformer(CLASS_PREPARED_STATEMENT, transformer);
    setupContext.addClassFileTransformer(CLASS_PREPARED_STATEMENT_WRAPPER, transformer);
  }
 @Override
 public void setup(ProfilerPluginSetupContext context) {
   ProfilerConfig profilerConfig = context.getConfig();
   if (profilerConfig.isIBatisEnabled()) {
     addInterceptorsForSqlMapExecutors();
     addInterceptorsForSqlMapClientTemplate();
   }
 }
Beispiel #8
0
  @Override
  public void setup(ProfilerPluginSetupContext context) {
    OracleConfig config = new OracleConfig(context.getConfig());

    addConnectionTransformer(context, config);
    addDriverTransformer(context);
    addPreparedStatementTransformer(context, config);
    addStatementTransformer(context);
  }
Beispiel #9
0
  private void addConnectionTransformer(
      ProfilerPluginSetupContext setupContext, final OracleConfig config) {
    setupContext.addClassFileTransformer(
        "oracle.jdbc.driver.PhysicalConnection",
        new PinpointClassFileTransformer() {

          @Override
          public byte[] transform(
              Instrumentor instrumentContext,
              ClassLoader loader,
              String className,
              Class<?> classBeingRedefined,
              ProtectionDomain protectionDomain,
              byte[] classfileBuffer)
              throws InstrumentException {
            InstrumentClass target =
                instrumentContext.getInstrumentClass(loader, className, classfileBuffer);
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");

            InterceptorGroup group = instrumentContext.getInterceptorGroup(GROUP_ORACLE);

            target.addGroupedInterceptor(
                "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.ConnectionCloseInterceptor",
                group);
            target.addGroupedInterceptor(
                "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.StatementCreateInterceptor",
                group);
            target.addGroupedInterceptor(
                "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementCreateInterceptor",
                group);

            if (config.isProfileSetAutoCommit()) {
              target.addGroupedInterceptor(
                  "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.TransactionSetAutoCommitInterceptor",
                  group);
            }

            if (config.isProfileCommit()) {
              target.addGroupedInterceptor(
                  "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.TransactionCommitInterceptor",
                  group);
            }

            if (config.isProfileRollback()) {
              target.addGroupedInterceptor(
                  "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.TransactionRollbackInterceptor",
                  group);
            }

            return target.toBytecode();
          }
        });
  }
Beispiel #10
0
  private void addHttpEngine(
      final ProfilerPluginSetupContext context, final OkHttpPluginConfig config) {
    context.addClassFileTransformer(
        "com.squareup.okhttp.internal.http.HttpEngine",
        new TransformCallback() {

          @Override
          public byte[] doInTransform(
              Instrumentor instrumentContext,
              ClassLoader loader,
              String className,
              Class<?> classBeingRedefined,
              ProtectionDomain protectionDomain,
              byte[] classfileBuffer)
              throws InstrumentException {
            InstrumentClass target =
                instrumentContext.getInstrumentClass(loader, className, classfileBuffer);
            target.addGetter(UserRequestGetter.class.getName(), OkHttpConstants.FIELD_USER_REQUEST);
            target.addGetter(
                UserResponseGetter.class.getName(), OkHttpConstants.FIELD_USER_RESPONSE);
            target.addGetter(ConnectionGetter.class.getName(), OkHttpConstants.FIELD_CONNECTION);

            InstrumentMethod sendRequestMethod = target.getDeclaredMethod("sendRequest");
            if (sendRequestMethod != null) {
              logger.debug("[OkHttp] Add HttpEngine.sendRequest interceptor.");
              final ObjectRecipe objectRecipe =
                  ObjectRecipe.byConstructor(
                      "com.navercorp.pinpoint.plugin.okhttp.OkHttpPluginConfig",
                      context.getConfig());
              sendRequestMethod.addInterceptor(
                  "com.navercorp.pinpoint.plugin.okhttp.interceptor.HttpEngineSendRequestMethodInterceptor",
                  va(objectRecipe));
            }

            InstrumentMethod connectMethod = target.getDeclaredMethod("connect");
            if (connectMethod != null) {
              logger.debug("[OkHttp] Add HttpEngine.connect interceptor.");
              connectMethod.addInterceptor(
                  "com.navercorp.pinpoint.plugin.okhttp.interceptor.HttpEngineConnectMethodInterceptor");
            }

            InstrumentMethod readResponseMethod = target.getDeclaredMethod("readResponse");
            if (readResponseMethod != null) {
              logger.debug("[OkHttp] Add HttpEngine.connect interceptor.");
              readResponseMethod.addInterceptor(
                  "com.navercorp.pinpoint.plugin.okhttp.interceptor.HttpEngineReadResponseMethodInterceptor",
                  va(config.isStatusCode()));
            }

            return target.toBytecode();
          }
        });
  }
Beispiel #11
0
  private void addStatementTransformer(ProfilerPluginSetupContext setupContext) {
    PinpointClassFileTransformer transformer =
        new PinpointClassFileTransformer() {

          @Override
          public byte[] transform(
              Instrumentor instrumentContext,
              ClassLoader loader,
              String className,
              Class<?> classBeingRedefined,
              ProtectionDomain protectionDomain,
              byte[] classfileBuffer)
              throws InstrumentException {
            if (className.equals(CLASS_STATEMENT)) {
              if (instrumentContext.exist(loader, CLASS_STATEMENT_WRAPPER)) {
                return null;
              }
            }

            InstrumentClass target =
                instrumentContext.getInstrumentClass(loader, className, classfileBuffer);

            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");

            InterceptorGroup group = instrumentContext.getInterceptorGroup(GROUP_ORACLE);

            target.addGroupedInterceptor(
                "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.StatementExecuteQueryInterceptor",
                group);
            target.addGroupedInterceptor(
                "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.StatementExecuteUpdateInterceptor",
                group);

            return target.toBytecode();
          }
        };

    setupContext.addClassFileTransformer(CLASS_STATEMENT, transformer);
    setupContext.addClassFileTransformer(CLASS_STATEMENT_WRAPPER, transformer);
  }
Beispiel #12
0
  @Override
  public void setup(ProfilerPluginSetupContext context) {
    final OkHttpPluginConfig config = new OkHttpPluginConfig(context.getConfig());
    logger.debug("[OkHttp] Initialized config={}", config);

    logger.debug("[OkHttp] Add Call class.");
    addCall(context, config);
    logger.debug("[OkHttp] Add Dispatcher class.");
    addDispatcher(context, config);
    logger.debug("[OkHttp] Add AsyncCall class.");
    addAsyncCall(context, config);
    addHttpEngine(context, config);
    addRequestBuilder(context, config);
  }
Beispiel #13
0
  @Override
  public void setup(ProfilerPluginSetupContext context) {
    final UserPluginConfig config = new UserPluginConfig(context.getConfig());

    // add user include methods
    for (String fullQualifiedMethodName : config.getIncludeList()) {
      try {
        addUserIncludeClass(context, fullQualifiedMethodName);
        if (logger.isDebugEnabled()) {
          logger.debug("Add user include class interceptor {}", fullQualifiedMethodName);
        }
      } catch (Exception e) {
        logger.warn("Failed to add user include class(" + fullQualifiedMethodName + ").", e);
      }
    }
  }
Beispiel #14
0
  private void addUserIncludeClass(
      ProfilerPluginSetupContext context, final String fullQualifiedMethodName) {
    final String className = toClassName(fullQualifiedMethodName);
    final String methodName = toMethodName(fullQualifiedMethodName);

    context.addClassFileTransformer(
        className,
        new PinpointClassFileTransformer() {

          @Override
          public byte[] transform(
              PinpointInstrument instrumentContext,
              ClassLoader classLoader,
              String className,
              Class<?> classBeingRedefined,
              ProtectionDomain protectionDomain,
              byte[] classfileBuffer)
              throws InstrumentException {
            InstrumentClass target =
                instrumentContext.getInstrumentClass(classLoader, className, classfileBuffer);

            for (InstrumentMethod method :
                target.getDeclaredMethods(MethodFilters.name(methodName))) {
              try {
                method.addInterceptor(
                    "com.navercorp.pinpoint.plugin.user.interceptor.UserIncludeMethodInterceptor");
              } catch (Exception e) {
                if (logger.isWarnEnabled()) {
                  logger.warn("Unsupported method " + method, e);
                }
              }
            }

            return target.toBytecode();
          }
        });
  }
Beispiel #15
0
  private void addDispatcher(ProfilerPluginSetupContext context, final OkHttpPluginConfig config) {
    context.addClassFileTransformer(
        "com.squareup.okhttp.Dispatcher",
        new TransformCallback() {

          @Override
          public byte[] doInTransform(
              Instrumentor instrumentContext,
              ClassLoader loader,
              String className,
              Class<?> classBeingRedefined,
              ProtectionDomain protectionDomain,
              byte[] classfileBuffer)
              throws InstrumentException {
            InstrumentClass target =
                instrumentContext.getInstrumentClass(loader, className, classfileBuffer);

            for (InstrumentMethod method :
                target.getDeclaredMethods(MethodFilters.name("execute", "cancel"))) {
              logger.debug("[OkHttp] Add Dispatcher.execute | cancel interceptor.");
              method.addInterceptor(
                  OkHttpConstants.BASIC_METHOD_INTERCEPTOR,
                  va(OkHttpConstants.OK_HTTP_CLIENT_INTERNAL));
            }
            InstrumentMethod enqueueMethod =
                target.getDeclaredMethod("enqueue", "com.squareup.okhttp.Call$AsyncCall");
            if (enqueueMethod != null) {
              logger.debug("[OkHttp] Add Dispatcher.enqueue interceptor.");
              enqueueMethod.addInterceptor(
                  "com.navercorp.pinpoint.plugin.okhttp.interceptor.DispatcherEnqueueMethodInterceptor");
            }

            return target.toBytecode();
          }
        });
  }