Skip to content

storey247/ApplicationInsights-Java-Helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ApplicationInsights-Java-Helpers

  • Got a code block or method that you want to easily track as a dependency in ApplicationInsights?
  • Does ApplicationInsights not track your Http Requests as dependencies correctly?
  • Are you using Azure Functions and struggling to track your exceptions correctly?

Fear not, this helper library will give you a nice handy wrapper to work with 😁

Dependencies

Maven

<dependency>
  <groupId>com.github.storey247/applicationinsights-java-helpers</groupId>
  <artifactId>com.storey247.applicationinsights-java-helpers</artifactId>
  <version>0.1.0-snaphot</version>
</dependency>

Getting started

Tracking code blocks as dependencies

If you have a block of code that you want to track as a dependency, lets say you are calling another sdk for instance:

TelemetryClient telemetry = new TelemetryClient();
TelemetryClientHelper helper = new TelemetryClientHelper(telemetry);
helper.monitorDependency("myDependency", "doingSomeWork", () -> {
    // some Callable that may throw or return
});

By wrapping your code in this block you will start to see telemetry metrics being logged automatically into ApplicationInsights. You will recieve such metrics as:

  • If the dependency block executed successfully
  • How long the execution of the block took
  • Any exceptions that occurred will automatically be logging into AppInsights too

Telemetry events will be logged using the string values passed to the monitorDependency method

Tracking http calls as dependencies

If you have an external service that you want to call (an api for instance) and want that to be automatically tracked in your telemetry, then you can use the `` method:

TelemetryClient telemetry = new TelemetryClient();
TelemetryClientHelper helper = new TelemetryClientHelper(telemetry);

HttpUriRequest request = new HttpGet("http://wibble.com/api");

try(CloseableHttpClient httpClient = HttpClients.createDefault()) {
    helper.monitorHttpDependency("myDependency", "callingSomeHttpEndpoint", httpClient, request);
}

By calling your upstream services using this code you will recieve such metrics as:

  • If the dependency block executed successfully (status code 2xx)
  • Result code
  • The Http verb that was used for the dependency (HTTP - GET in the example above)
  • The number of ms that the http call took
  • Any exceptions that occurred will automatically be logging into AppInsights too

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages