back to all blogsSee all blog posts

Send logs and metrics to OpenTelemetry in 24.0.0.9-beta

image of author
David Mueller on Aug 27, 2024
Post available in languages:

In this release, the MicroProfile Telemetry 2.0 beta feature helps improve the observability of your Java applications by using OpenTelemetry to collect and export logs, metrics, and traces in a standardized way. A minor update for the WebSocket 2.2 beta feature is also included.

The Open Liberty 24.0.0.9-beta includes the following beta features (along with all GA features):

Send Liberty metrics to OpenTelemetry

MicroProfile Telemetry 2.0 provides the latest OpenTelemetry technology. In addition to distributed tracing, the feature now allows OpenTelemetry to collect and export metrics and logs.

When the MicroProfile Telemetry 2.0 beta feature (mpTelemetry-2.0) is enabled, Open Liberty can now forward runtime component statistics that are captured by the Performance Monitoring 1.0 feature (monitor-1.0) to the MicroProfile Telemetry 2.0 runtime. This statistical data is registered as metrics in the telemetry runtime and can then be forwarded to any OpenTelemetry Protocol (OTLP) compatible metric consumer to meet your monitoring needs.

The following runtime components are supported:

  • ThreadPool

  • Sessions

  • RequestTiming

  • ConnectionPool

To collect and export metrics, enable OpenTelemetry by using the following system property or environment variable:

  • System property: otel.sdk.disabled=false

  • Environment variable: OTEL_SDK_DISABLED=false

You can set configuration properties in any of the config sources that are available to MicroProfile Config.

Enable the mpTelemetry-2.0 feature and any features that are associated with your chosen supported runtime components. The mpTelemetry-2.0 feature automatically enables the monitor-1.0 feature.

For example, the ConnectionPool component requires the following configuration:

<featureManager>
   <feature>mpTelemetry-2.0</feature>
   <feature>jdbc-4.3</feature>
</featureManager>

By default, all OpenTelemetry data is exported to OTLP. You can set a different exporter by specifying the following system property or environment variable:

  • System property: otel.metrics.exporter

  • Environment variable: OTEL_METRICS_EXPORTER

You can also optionally configure the metric export interval configuration variable. The value is specified in milliseconds and the default is 60000 (60 seconds).

  • System property: otel.metric.export.interval

  • Environment variable: OTEL_METRIC_EXPORT_INTERVAL

For more information about the available configuration properties, see MicroProfile Config properties: MicroProfile Telemetry.

Send logs to OpenTelemetry

The mpTelemetry-2.0 feature can now collect Open Liberty runtime log sources (messages, traces, ffdcs) and application logs generated through the java.util.logging package (JUL).

To enable the MicroProfile Telemetry 2.0 feature to collect all logs, add the following configuration to your server.xml file:

<features>
   <feature>mpTelemetry-2.0</feature>
</features>

<mpTelemetry source="message, trace, ffdc"/>

If the mpTelemetry configuration element or the source attribute is not configured, the message source is set by default. In this case, only messages are collected. If the source attribute is specified empty (source=""), no logs are sent to OpenTelemetry.

To collect and export runtime-level logs, enable OpenTelemetry by using the following system property or environment variable:

  • System property: otel.sdk.disabled=false

  • Environment variable: OTEL_SDK_DISABLED=false

You can set configuration properties in any of the config sources that are available to MicroProfile Config.

To separately configure multiple applications in a server, you can configure OpenTelemetry with application configuration. However, you cannot collect runtime-level logs this way.

By default, all OpenTelemetry data is exported to OTLP. You can set a different exporter by specifying the following system property or environment variable:

  • System property: otel.logs.exporter

  • Environment variable: OTEL_LOGS_EXPORTER

For more information about the available configuration properties, see MicroProfile Config properties: MicroProfile Telemetry.

Avoid type errors with WebSocket 2.2

To avoid type errors, this beta release of the WebSocket 2.2 feature (websocket-2.2) limits the MaxMessageSize to Integer#MAX_VALUE for the OnMessage annotation. The websocket-2.2 feature was previously released in beta in the 24.0.0.8-beta.

To enable this beta feature, add the following code to your server.xml file.

<featureManager>
    <feature>websocket-2.2</feature>
</featureManager>

For more information, such as the Javadoc, specification documents, and other details, see Jakarta WebSocket 2.2.

Try it now

To try out these features, update your build tools to pull the Open Liberty All Beta Features package instead of the main release. The beta works with Java SE 22, Java SE 21, Java SE 17, Java SE 11, and Java SE 8.

If you’re using Maven, you can install the All Beta Features package using:

<plugin>
    <groupId>io.openliberty.tools</groupId>
    <artifactId>liberty-maven-plugin</artifactId>
    <version>3.10.3</version>
    <configuration>
        <runtimeArtifact>
          <groupId>io.openliberty.beta</groupId>
          <artifactId>openliberty-runtime</artifactId>
          <version>24.0.0.9-beta</version>
          <type>zip</type>
        </runtimeArtifact>
    </configuration>
</plugin>

You must also add dependencies to your pom.xml file for the beta version of the APIs that are associated with the beta features that you want to try. For example, the following block adds dependencies for two example beta APIs:

<dependency>
    <groupId>org.example.spec</groupId>
    <artifactId>exampleApi</artifactId>
    <version>7.0</version>
    <type>pom</type>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>example.platform</groupId>
    <artifactId>example.example-api</artifactId>
    <version>11.0.0</version>
    <scope>provided</scope>
</dependency>

Or for Gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'io.openliberty.tools:liberty-gradle-plugin:3.8.3'
    }
}
apply plugin: 'liberty'
dependencies {
    libertyRuntime group: 'io.openliberty.beta', name: 'openliberty-runtime', version: '[24.0.0.9-beta,)'
}

Or if you’re using container images:

FROM icr.io/appcafe/open-liberty:beta

Or take a look at our Downloads page.

If you’re using IntelliJ IDEA, Visual Studio Code or Eclipse IDE, you can also take advantage of our open source Liberty developer tools to enable effective development, testing, debugging, and application management all from within your IDE.

For more information on using a beta release, refer to the Installing Open Liberty beta releases documentation.

We welcome your feedback

Let us know what you think on our mailing list. If you hit a problem, post a question on StackOverflow. If you hit a bug, please raise an issue.