Skip to content

Commit

Permalink
Rename runtime-metrics to runtime-telemetry-jmx (#8165)
Browse files Browse the repository at this point in the history
Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com>
  • Loading branch information
roberttoyonaga and opentelemetrybot committed May 16, 2023
1 parent f98a97f commit 3d0971b
Show file tree
Hide file tree
Showing 76 changed files with 970 additions and 937 deletions.
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.

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,42 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.javaagent.runtimetelemetryjfr;
package io.opentelemetry.instrumentation.javaagent.runtimemetrics.java17;

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.runtimemetrics.java17.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);
boolean defaultEnabled = config.getBoolean("otel.instrumentation.common.default-enabled", true);
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);
} else if (config.getBoolean("otel.instrumentation.runtime-metrics.enabled", defaultEnabled)) {
// 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.runtimemetrics.java17;

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.runtimemetrics.java17`:

```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.runtimemetrics.java8` 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.runtimemetrics.java17.GenerateDocs")
systemProperties.set("jfr.readme.path", project.projectDir.toString() + "/README.md")
}
tasks {
Expand Down
Loading

0 comments on commit 3d0971b

Please sign in to comment.