Package io.openliberty.microprofile.telemetry.spi


package io.openliberty.microprofile.telemetry.spi

Open Liberty MicroProfile Telemetry Interface


OpenTelemetryAccessor provides one method: OpenTelemetryAccessor.getOpenTelemetryInfo which returns an OpenTelemetryInfo containing the OpenTelemetry object associated with the currently running application. That would be the runtime instance of OpenTelemetry if one is enabled. If there is not one enabled, it would be chosen based on the application metadata stored in the thread context. If there is no metadata on the thread, or if the application has shut down, it would return an OpenTelemetryInfo containing a no-op OpenTelemetry object. OpenTelemetryInfo provides two methods;
  • OpenTelemetryInfo.getOpenTelemetry which returns the contained OpenTelemetry object.
  • OpenTelemetryInfo.isEnabled which returns true if the contained OpenTelemetry object was enabled at the time this OpenTelemetryInfo was created and false if it was a no-op
The suggested use is to use isEnabled() when initalizing components to avoid enabling code that depends on OpenTelemetry if it is not enabled for a performance gain.

 OpenTelemetryInfo openTelemetryInfo = OpenTelemetryAccessor.getOpenTelemetryInfo();
 if (openTelemetryInfo.isEnabled()) {
     createOpenTelemetryServletFilter(openTelemetryInfo.getOpenTelemetry());
 }