Class APMInterceptor

java.lang.Object
tech.riemann.nif.apm.APMInterceptor
All Implemented Interfaces:
org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor

public class APMInterceptor extends Object implements org.aopalliance.intercept.MethodInterceptor
APM方法拦截器

基于AOP实现的方法性能监控拦截器

主要功能: 1. 记录方法执行时间(纳秒级精度) 2. 收集请求信息(URL、IP、Headers、User-Agent等) 3. 收集用户信息 4. 记录方法参数和返回值 5. 捕获并记录异常信息 6. 发布APM事件供监听器处理

收集的信息包括: - URL:请求地址 - IP:客户端IP - User:当前登录用户 - TraceId:链路追踪ID - Args:方法参数 - ReturnObj:返回值 - Duration:执行耗时 - Exception:是否发生异常 - Message/Stack:异常信息 - Headers:HTTP请求头 - HttpMethod:HTTP方法

Author:
Kerbores(kerbores@riemann.tech)
  • Constructor Details

    • APMInterceptor

      public APMInterceptor()
  • Method Details

    • invoke

      public Object invoke(org.aopalliance.intercept.MethodInvocation invocation) throws Throwable
      拦截方法调用

      执行流程: 1. 记录开始时间 2. 收集请求信息(Headers、IP、URL等) 3. 执行目标方法 4. 收集用户信息 5. 计算执行时间 6. 如果发生异常,记录异常信息 7. 构建APMEvent并发布

      Specified by:
      invoke in interface org.aopalliance.intercept.MethodInterceptor
      Parameters:
      invocation - 方法调用对象
      Returns:
      方法执行结果
      Throws:
      Throwable - 方法抛出的异常