Class APMEventListener

java.lang.Object
tech.riemann.nif.apm.event.APMEventListener
All Implemented Interfaces:
EventListener, org.springframework.context.ApplicationListener<APMEvent>
Direct Known Subclasses:
AbstractAuditLogAPMEventListener, DefaultLogAPMEventListener

public abstract class APMEventListener extends Object implements org.springframework.context.ApplicationListener<APMEvent>
APM事件监听器抽象类

实现Spring的ApplicationListener接口,监听APMEvent事件

主要功能: 1. 接收APMInterceptor发布的APMEvent事件 2. 设置TraceId到当前线程上下文 3. 可选解析User-Agent信息(设备、操作系统、浏览器等) 4. 调用子类实现的handleAPMLog方法处理日志

使用场景: - 继承此类并实现handleAPMLog方法 - 可以自定义日志处理逻辑(如写入数据库、发送到消息队列等)

使用示例:

public class MyAPMEventListener extends APMEventListener {
    @Override
    public void handleAPMLog(APMLog log) {
        // 自定义处理逻辑
        myService.saveAPMLog(log);
    }
}
Author:
Kerbores(kerbores@riemann.tech)
  • Constructor Details

    • APMEventListener

      public APMEventListener()
  • Method Details

    • onApplicationEvent

      public void onApplicationEvent(@NonNull APMEvent event)
      处理APM事件

      当APMEvent事件发布时,此方法被调用

      处理流程: 1. 设置TraceId到当前线程上下文 2. 如果需要解析User-Agent,则解析并设置到APMLog 3. 调用handleAPMLog方法处理日志

      Specified by:
      onApplicationEvent in interface org.springframework.context.ApplicationListener<APMEvent>
      Parameters:
      event - APM事件
    • handleAPMLog

      public void handleAPMLog(APMLog log, @Nullable Class<?> clazz, @Nullable Method method)
      处理APM日志(带Class和Method信息)

      默认实现会调用handleAPMLog(APMLog log)方法

      Parameters:
      log - APM日志
      clazz - 被监控的类
      method - 被监控的方法
    • handleAPMLog

      public abstract void handleAPMLog(APMLog log)
      处理APM日志(抽象方法,子类必须实现)

      子类需要实现此方法来自定义日志处理逻辑

      Parameters:
      log - APM日志