0
votes

I am trying to create a custom telemetry module in Java which can log custom http requests and responses headers. From my analysis telemetry modules are the one that has access to http request and http response objects.

I created my own telemetry module by extending the Webtelemetrymodule interface and registered the same using Application insights.xml

When my app boots I get error saying Failed to load class for my CustomTelemetry class

Am I missing something?? there isn't much documentation about telemetry modules, so any help will be greatly appreciated

Code

The below is my custom telemetry module and it's registered in ApplicationInsights.xml

public class CustomRequestTelemetryModule implements 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 Config

Blockquote

    <Add type="custompackage.CustomRequestTelemetryModule"/>

Logged Error by AI

AI: ERROR 16-05-2017 12:13, 15: Failed to create custompackage..CustomRequestTelemetryModule, class custompackage.CustomRequestTelemetryModule

TIA

1
Can you share the code of the class that failed and the code where the loading fails? - Peter
Code is provided as part of my original post now - SaiVikas

1 Answers

0
votes

The class needs to implement WebTelemetryModule along with TelemetryModule interface. Doing so resolved this issue for me.

Here's a blog that I wrote which explains how this can be done in detail https://dtechonline.wordpress.com