在 Application insight 中添加自定义遥测模块

Adding custom telemetry module in Application insight

我正在尝试在 Java 中创建自定义遥测模块,它可以记录自定义 http 请求和响应 headers。根据我的分析,遥测模块是可以访问 http 请求和 http 响应的模块 objects。

我通过扩展 Webtelemetrymodule 接口创建了自己的遥测模块,并使用 Application insights.xml

进行了注册

当我的应用程序启动时,我收到错误提示无法为我的 CustomTelemetry classclass

加载 class

我是不是漏掉了什么??关于遥测模块的文档不多,因此将不胜感激

代码

下面是我的自定义遥测模块,它已在 ApplicationInsights.xml

中注册

public class CustomRequestTelemetryModule 实现 WebTelemetryModule {

public static final String REQUEST_ID_HEADER = "CUSTOM_HEADER";



@Override
public void onBeginRequest(ServletRequest request, ServletResponse response) {

}

@Override
public void onEndRequest(ServletRequest req, ServletResponse res) {

    //logger.info("Inside Custom Telemetry Module");

    HttpServletResponse response = (HttpServletResponse)res;

    String REQID = response.getHeader("REQUEST_ID_HEADER");

    RequestTelemetryContext context = ThreadContext.getRequestTelemetryContext();
    RequestTelemetry telemetry = context.getHttpRequestTelemetry();

    //telemetry.setId(REQID);
    telemetry.getProperties().put("ID",REQID);



}

}

Application Insight 配置

Blockquote

    <Add type="custompackage.CustomRequestTelemetryModule"/>

AI 记录的错误

AI:错误 16-05-2017 12:13,15:无法创建自定义包..CustomRequestTelemetryModule,class custompackage.CustomRequestTelemetryModule

TIA

class 需要实现 WebTelemetryModule 和 TelemetryModule 接口。这样做为我解决了这个问题。

这是我写的一篇博客,详细解释了如何做到这一点 https://dtechonline.wordpress.com