Skip to content

OpenTelemetry API support (3.0)

Trask Stalnaker edited this page Jan 20, 2021 · 7 revisions

⚠️ This feature is in preview, as the OpenTelemetry API itself is still in beta.

Version compatibility while in preview

⚠️ While this feature is in preview, a given version of Application Insights Java Agent will only work with a single version of the OpenTelemetry API.

Application Insights Java Agent OpenTelemetry API Beta
3.0.1-BETA 0.12.0

When this feature is out of preview, older versions of OpenTelemetry API will continue to be supported by newer versions of the Application Insights Java Agent.

Enabling this feature

To enable this preview feature, add the following to your applicationinsights.json file:

{
  "preview": {
    "opentelemetryApiSupport": true
  }
}

Adding OpenTelemetry API to your application

<dependencies>
  <dependency>
    <groupId>io.opentelemetry</groupId>
    <artifactId>opentelemetry-api</artifactId>
    <version>0.12.0</version>
  </dependency>
</dependencies>

Adding custom dimensions to your request telemetry

Span.current().setAttribute("mydimension", "myvalue");

Note: if your code is inside of a Spring controller, Span.current() will reference the InProc dependency that represents the controller call. In this case, you will need to add your code to a web filter that runs before the Spring controller, at which time Span.current() will refer to the request.

Note: if you set an attribute named enduser.id, the value will be stored in the user_Id column in the Application Insights Logs table instead of as a custom dimension.