Skip to content
MS-jgol edited this page Mar 31, 2020 · 5 revisions

Overview

One of the major goals of 3.0 is to simplify the onboarding experience.

Adding the Application Insights Java SDK to your application is no longer required, as the 3.0 agent auto-collects requests, dependencies and logs all on its own.

But don't worry, you can still send custom telemetry from your application if you wish, and the 3.0 agent will track and correlate it along with all of the auto-collected telemetry.

Quick start

1. Download the agent

Download applicationinsights-agent-3.0.0-PRIVATEPREVIEW.jar

2. Point the JVM to the agent

Add -javaagent:path/to/applicationinsights-agent-3.0.0-PRIVATEPREVIEW.jar to your application's JVM args

TODO add link with additional help for modifying different application servers' JVM args

3. Point the agent to your Application Insights resource

Set the environment variable APPLICATIONINSIGHTS_CONNECTION_STRING, e.g.

export APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=00000000-0000-0000-0000-000000000000

You can find the connection string in your Application Insights resource, e.g. Application Insights Connection String

4. That's it!

Now start up your application and go to your Application Insights resource in the Azure portal to see your monitoring data. Note: it may take a few minutes for your monitoring data to show up in the portal.

Sending custom telemetry from your application

Our goal in 3.0+ is to allow you to send your custom telemetry using standard APIs.

We plan to initially support Micrometer, OpenTelemetry API, and the popular logging frameworks.

Application Insights Java 3.0 will automatically capture telemetry that is sent to these APIs, and correlate it along with all of the auto-collected telemetry.

For this reason, we are not planning to release an SDK with Application Insights 3.0 at this time.

Application Insights Java 3.0 is already listening for telemetry that is sent to the Application Insights Java SDK 2.x. We have no plans to remove this support, as it is an important part of the upgrade story for existing 2.x users, and it fills an important gap in our custom telemetry support until OpenTelemetry API is GA.

Sending custom telemetry using Application Insights Java SDK 2.x

Add applicationinsights-core-2.5.1.jar to your application (all 2.x versions are supported by Application Insights Java 3.0, but it's worth using the latest if you have a choice), e.g.

  <dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>applicationinsights-core</artifactId>
    <version>2.5.1</version>
  </dependency>

Create a TelemetryClient, e.g.

private static final TelemetryClient telemetryClient = new TelemetryClient();

and use that for sending custom telemetry.

Events

telemetryClient.trackEvent("WinGame");

Metrics

  telemetryClient.trackMetric("queueLength", 42.0);

Dependencies

  boolean success = false;
  long startTime = System.currentTimeMillis();
  try {
      success = dependency.call();
  } finally {
      long endTime = System.currentTimeMillis();
      RemoteDependencyTelemetry telemetry = new RemoteDependencyTelemetry();
      telemetry.setTimestamp(new Date(startTime));
      telemetry.setDuration(new Duration(endTime - startTime));
      telemetryClient.trackDependency(telemetry);
  }

Logs

You can send custom log telemetry via your favorite logging framework.

Or you can also use Application Insights Java SDK 2.x:

  telemetryClient.trackTrace(message, SeverityLevel.Warning, properties);

Exceptions

You can send custom exception telemetry via your favorite logging framework.

Or you can also use Application Insights Java SDK 2.x:

  try {
      ...
  } catch (Exception e) {
      telemetryClient.trackException(e);
  }

For configuring and troubleshooting Application Insights' Java SDK:

ApplicationInsights.xml