Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename runtime-metrics to runtime-telemetry-jmx #8165

Merged
merged 12 commits into from
May 16, 2023
2 changes: 1 addition & 1 deletion docs/supported-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ These are the supported libraries and frameworks:
| [Java Executors](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html) | Java 8+ | N/A | Context propagation |
| [Java Http Client](https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/package-summary.html) | Java 11+ | [opentelemetry-java-http-client](../instrumentation/java-http-client/library) | [HTTP Client Spans], [HTTP Client Metrics] |
| [java.util.logging](https://docs.oracle.com/javase/8/docs/api/java/util/logging/package-summary.html) | Java 8+ | N/A | none |
| [Java Platform](https://docs.oracle.com/javase/8/docs/api/java/lang/management/ManagementFactory.html) | Java 8+ | [opentelemetry-runtime-metrics](../instrumentation/runtime-metrics/library),<br>[opentelemetry-resources](../instrumentation/resources/library) | [JVM Runtime Metrics] |
| [Java Platform](https://docs.oracle.com/javase/8/docs/api/java/lang/management/ManagementFactory.html) | Java 8+ | [opentelemetry-runtime-metrics-java8](../instrumentation/runtime-metrics/runtime-metrics-java8/library),[opentelemetry-runtime-metrics-java17](../instrumentation/runtime-metrics/runtime-metrics-java17/library),<br>[opentelemetry-resources](../instrumentation/resources/library) | [JVM Runtime Metrics] |
| [JAX-RS](https://javaee.github.io/javaee-spec/javadocs/javax/ws/rs/package-summary.html) | 0.5+ | N/A | Provides `http.route` [2], Controller Spans [3] |
| [JAX-RS Client](https://javaee.github.io/javaee-spec/javadocs/javax/ws/rs/client/package-summary.html) | 1.1+ | N/A | [HTTP Client Spans], [HTTP Client Metrics] |
| [JAX-WS](https://jakarta.ee/specifications/xml-web-services/2.3/apidocs/javax/xml/ws/package-summary.html) | 2.0+ (not including 3.x yet) | N/A | Provides `http.route` [2], Controller Spans [3] |
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/jmx-metrics/javaagent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To control the time interval between MBean detection attempts, one can use the `

## Predefined metrics

JMX is a popular metrics technology used throughout the JVM (see [runtime metrics](../../runtime-metrics/library/README.md)), application servers, third-party libraries, and applications.
JMX is a popular metrics technology used throughout the JVM (see [runtime metrics](../../runtime-metrics/runtime-metrics-java8/library/README.md)), application servers, third-party libraries, and applications.
JMX Metric Insight comes with a number of predefined configurations containing curated sets of JMX metrics for frequently used application servers or frameworks.
To enable collection of the predefined metrics, specify a list of targets as the value for the `otel.jmx.target.system` property. For example

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ otelJava {
}

dependencies {
implementation(project(":instrumentation:runtime-telemetry-jfr:library"))
implementation(project(":instrumentation:runtime-metrics:runtime-metrics-java17:library"))
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
}

tasks {
test {
jvmArgs("-Dotel.instrumentation.runtime-telemetry-jfr.enabled=true")
jvmArgs("-Dotel.instrumentation.runtime-metrics-java17.enabled=true")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,41 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.javaagent.runtimetelemetryjfr;
package io.opentelemetry.instrumentation.javaagent.runtimemetricsjava17;

import com.google.auto.service.AutoService;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.runtimetelemetryjfr.JfrTelemetry;
import io.opentelemetry.instrumentation.runtimemetricsjava17.RuntimeMetrics;
import io.opentelemetry.javaagent.extension.AgentListener;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;

/** An {@link AgentListener} that enables runtime metrics during agent startup. */
@AutoService(AgentListener.class)
public class RuntimeMetricsInstallerJfr implements AgentListener {
public class Java17RuntimeMetricsInstaller implements AgentListener {

@Override
public void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredSdk) {
ConfigProperties config = autoConfiguredSdk.getConfig();

OpenTelemetry openTelemetry = GlobalOpenTelemetry.get();
JfrTelemetry jfrTelemetry = null;
RuntimeMetrics runtimeMetrics = null;
/*
By default don't use any JFR metrics. May change this once semantic conventions are updated.
If enabled, default to only the metrics not already covered by runtime-telemetry-jmx
If enabled, default to only the metrics not already covered by runtime-metrics-java8
*/

if (config.getBoolean("otel.instrumentation.runtime-telemetry-jfr.enable-all", false)) {
jfrTelemetry = JfrTelemetry.builder(openTelemetry).enableAllFeatures().build();
} else if (config.getBoolean("otel.instrumentation.runtime-telemetry-jfr.enabled", false)) {
jfrTelemetry = JfrTelemetry.create(openTelemetry);
if (config.getBoolean("otel.instrumentation.runtime-metrics-java17.enable-all", false)) {
runtimeMetrics = RuntimeMetrics.builder(openTelemetry).enableAllFeatures().build();
} else if (config.getBoolean("otel.instrumentation.runtime-metrics-java17.enabled", false)) {
runtimeMetrics = RuntimeMetrics.create(openTelemetry);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should enable both JMX+JFR default metrics if otel.instrumentation.runtime-metrics.enabled is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah we talked a bit about this here. It was decided that we'd wait for the semantic conventions to be updated first in-case the JFR metrics end up changing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I see.
At the very least, let's add a condition checking otel.instrumentation.runtime-metrics.enabled somewhere in this method -- the current version of that is impossible to turn off on java 17+

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's a good point. I'll add the same check that's done in Java8RuntimeMetricsInstaller before enabling the JMX gathered metrics.

} else {
// This only uses metrics gathered by JMX
runtimeMetrics = RuntimeMetrics.builder(openTelemetry).disableAllFeatures().build();
}
if (jfrTelemetry != null) {
JfrTelemetry finalJfrTelemetry = jfrTelemetry;
if (runtimeMetrics != null) {
RuntimeMetrics finalJfrTelemetry = runtimeMetrics;
Thread cleanupTelemetry = new Thread(() -> finalJfrTelemetry.close());
Runtime.getRuntime().addShutdownHook(cleanupTelemetry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.javaagent.runtimemetrics

import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import spock.util.concurrent.PollingConditions

class RuntimeMetricsTest extends AgentInstrumentationSpecification {
class JmxRuntimeMetricsTest extends AgentInstrumentationSpecification {

def "test runtime metrics is enabled"() {
when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.javaagent.runtimetelemetryjfr;
package io.opentelemetry.instrumentation.javaagent.runtimemetricsjava17;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static org.awaitility.Awaitility.await;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@

The main entry point is the `JfrTelemetry` class in the package `io.opentelemetry.instrumentation.runtimetelemetryjfr`:
The main entry point is the `RuntimeMetrics` class in the package `io.opentelemetry.instrumentation.runtimemetricsjava17`:

```java
// Initialize JfrTelemetry
JfrTelemetry jfrTelemetry = JfrTelemetry.create(openTelemetry);
RuntimeMetrics runtimeMetrics = RuntimeMetrics.create(openTelemetry);

// Close JfrTelemetry to stop listening for JFR events
jfrTelemetry.close();
runtimeMetrics.close();
```

`JfrTelemetry` works by subscribing to certain JFR events, and using relevant bits of information
`RuntimeMetrics` uses two underlying implementations to gather the full set of metric data, JFR and JMX.
The metrics gathered by the two implementations are mutually exclusive and the union of them produces
the full set of available metrics.
The JMX component is reused from the `io.opentelemetry.instrumentation.runtimemetricsjava8` package.
The JFR component uses JFR streaming and is only available in JAVA 17.
It works by subscribing to certain JFR events, and using relevant bits of information
from the events to produce telemetry data like metrics. The code is divided into "handlers", which
listen for specific events and produce relevant telemetry. The handlers are organized into
features (i.e `JfrFeature`), which represent a category of telemetry and can be toggled on and
off. `JfrTelemetry` evaluates which features are enabled, and only listens for the events required
off. `RuntimeMetrics` evaluates which features are enabled, and only listens for the events required
by the handlers associated with those features.

Enable or disable a feature as follows:

```
JfrTelemetry jfrTelemetry = JfrTelemetry.builder(openTelemetry)
RuntimeMetrics runtimeMetrics = RuntimeMetrics.builder(openTelemetry)
.enableFeature(JfrFeature.BUFFER_METRICS)
.disableFeature(JfrFeature.LOCK_METRICS)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ otelJava {
}

dependencies {
implementation(project(":instrumentation:runtime-metrics:runtime-metrics-java8:library"))
testImplementation("io.github.netmikey.logunit:logunit-jul:1.1.3")
}
tasks.create("generateDocs", JavaExec::class) {
group = "build"
description = "Generate table for README.md"
classpath = sourceSets.test.get().runtimeClasspath
mainClass.set("io.opentelemetry.instrumentation.runtimetelemetryjfr.GenerateDocs")
mainClass.set("io.opentelemetry.instrumentation.runtimemetricsjava17.GenerateDocs")
systemProperties.set("jfr.readme.path", project.projectDir.toString() + "/README.md")
}
tasks {
Expand Down
Loading