-
Notifications
You must be signed in to change notification settings - Fork 1k
Spring boot runtime metrics native reduced #13173
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
Merged
trask
merged 35 commits into
open-telemetry:main
from
zeitlinger:spring-boot-runtime-metrics-naive-reduced
Feb 14, 2025
Merged
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
646ec13
spring boot runtime metrics for java 17+
zeitlinger d94f2d6
spring boot runtime metrics for java 8
zeitlinger 6b9c026
spring boot runtime metrics for java 8
zeitlinger 7792de6
fix native
zeitlinger b262de9
use spring shutdown hook
zeitlinger e10e8c1
disable threads
zeitlinger 17dd251
disable threads
zeitlinger 697c197
test more metric types
zeitlinger a4eec27
add metadata
zeitlinger 66a8a9a
fix jfr and native image
zeitlinger c659bcb
fix jfr and native image
zeitlinger f0c06cd
review
zeitlinger 1b3b510
test more metrics
zeitlinger 3f64db1
test more metrics
zeitlinger bcd43e6
format
zeitlinger 215d857
use newer graalvm
zeitlinger 638af92
init at build time
zeitlinger b51bec3
init at build time
zeitlinger b7e8dbc
disable jfr for native for now
zeitlinger fca99a5
fix jfr
zeitlinger 4d9792e
fix buffer pools
zeitlinger 611404a
fix buffer pools
zeitlinger 52e3632
extract metrics providers
zeitlinger b805da9
exclude JFR from native image at build time
zeitlinger 67fb8d2
format
zeitlinger c5790fd
Update instrumentation/spring/spring-boot-autoconfigure/src/main/java…
zeitlinger 8cc8c00
format
zeitlinger a6a87c5
fix java version parsing
zeitlinger a1bd518
fix java version parsing
zeitlinger 1eea5d3
Update instrumentation/runtime-telemetry/runtime-telemetry-java8/libr…
zeitlinger 59c1425
cleanup
zeitlinger 53a3e6a
cleanup
zeitlinger 6a1e1b2
pr review
zeitlinger 3c10824
pr review
zeitlinger 838af2e
pr review
zeitlinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 3 additions & 1 deletion
4
...o.opentelemetry.instrumentation/opentelemetry-instrumentation-api/native-image.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
Args=\ | ||
--initialize-at-build-time=io.opentelemetry.instrumentation.api.internal.cache.concurrentlinkedhashmap.ConcurrentLinkedHashMap | ||
--initialize-at-build-time=io.opentelemetry.instrumentation.api.internal.cache.concurrentlinkedhashmap.ConcurrentLinkedHashMap \ | ||
--initialize-at-build-time=io.opentelemetry.instrumentation.api.internal.cache.MapBackedCache \ | ||
--initialize-at-build-time=io.opentelemetry.api.internal.InternalAttributeKeyImpl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...y/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/java8/RuntimeMetrics.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.runtimemetrics.java8; | ||
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.runtimemetrics.java8.internal.JmxRuntimeMetricsUtil; | ||
import java.io.Closeable; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** The entry point class for runtime metrics support using JMX. */ | ||
public final class RuntimeMetrics implements Closeable { | ||
zeitlinger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
zeitlinger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
private static final Logger logger = Logger.getLogger(RuntimeMetrics.class.getName()); | ||
|
||
private final AtomicBoolean isClosed = new AtomicBoolean(); | ||
private final List<AutoCloseable> observables; | ||
|
||
RuntimeMetrics(List<AutoCloseable> observables) { | ||
this.observables = Collections.unmodifiableList(observables); | ||
} | ||
|
||
/** | ||
* Create and start {@link RuntimeMetrics}. | ||
* | ||
* <p>Listens for select JMX beans, extracts data, and records to various metrics. Recording will | ||
* continue until {@link #close()} is called. | ||
* | ||
* @param openTelemetry the {@link OpenTelemetry} instance used to record telemetry | ||
*/ | ||
public static RuntimeMetrics create(OpenTelemetry openTelemetry) { | ||
return new RuntimeMetricsBuilder(openTelemetry).build(); | ||
} | ||
|
||
/** | ||
* Create a builder for configuring {@link RuntimeMetrics}. | ||
* | ||
* @param openTelemetry the {@link OpenTelemetry} instance used to record telemetry | ||
*/ | ||
public static RuntimeMetricsBuilder builder(OpenTelemetry openTelemetry) { | ||
return new RuntimeMetricsBuilder(openTelemetry); | ||
} | ||
|
||
/** Stop recording JMX metrics. */ | ||
@Override | ||
public void close() { | ||
if (!isClosed.compareAndSet(false, true)) { | ||
logger.log(Level.WARNING, "RuntimeMetrics is already closed"); | ||
return; | ||
} | ||
|
||
JmxRuntimeMetricsUtil.closeObservers(observables); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...ain/java/io/opentelemetry/instrumentation/runtimemetrics/java8/RuntimeMetricsBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.runtimemetrics.java8; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.api.incubator.config.internal.InstrumentationConfig; | ||
import io.opentelemetry.instrumentation.runtimemetrics.java8.internal.JmxRuntimeMetricsFactory; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
/** Builder for {@link RuntimeMetrics}. */ | ||
public final class RuntimeMetricsBuilder { | ||
|
||
private final OpenTelemetry openTelemetry; | ||
|
||
private boolean enableExperimentalJmxTelemetry = false; | ||
private Consumer<Runnable> shutdownHook = | ||
runnable -> { | ||
Runtime.getRuntime() | ||
.addShutdownHook(new Thread(runnable, "OpenTelemetry RuntimeMetricsShutdownHook")); | ||
}; | ||
|
||
RuntimeMetricsBuilder(OpenTelemetry openTelemetry) { | ||
this.openTelemetry = openTelemetry; | ||
} | ||
|
||
/** Enable all JMX telemetry collection. */ | ||
@CanIgnoreReturnValue | ||
public RuntimeMetricsBuilder enableExperimentalJmxTelemetry() { | ||
enableExperimentalJmxTelemetry = true; | ||
return this; | ||
} | ||
|
||
/** Build and start an {@link RuntimeMetrics} with the config from this builder. */ | ||
public RuntimeMetrics build() { | ||
List<AutoCloseable> observables = | ||
JmxRuntimeMetricsFactory.buildObservables(openTelemetry, enableExperimentalJmxTelemetry); | ||
return new RuntimeMetrics(observables); | ||
} | ||
|
||
/** Set a custom shutdown hook for the {@link RuntimeMetrics}. */ | ||
@CanIgnoreReturnValue | ||
public RuntimeMetricsBuilder setShutdownHook(Consumer<Runnable> shutdownHook) { | ||
this.shutdownHook = shutdownHook; | ||
return this; | ||
} | ||
|
||
public void startFromInstrumentationConfig(InstrumentationConfig config) { | ||
zeitlinger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
boolean defaultEnabled = config.getBoolean("otel.instrumentation.common.default-enabled", true); | ||
if (!config.getBoolean("otel.instrumentation.runtime-telemetry.enabled", defaultEnabled)) { | ||
// nothing is enabled | ||
return; | ||
} | ||
|
||
if (config.getBoolean( | ||
"otel.instrumentation.runtime-telemetry.emit-experimental-telemetry", false)) { | ||
this.enableExperimentalJmxTelemetry(); | ||
} | ||
|
||
RuntimeMetrics runtimeMetrics = this.build(); | ||
shutdownHook.accept(runtimeMetrics::close); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.