Skip to content

Commit

Permalink
Silence profiler warning on jdk21 (#1470)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored Oct 11, 2023
1 parent aa42837 commit 8e6abe9
Showing 1 changed file with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,33 @@ public void onStartupFailure(Throwable throwable) {
delegate.onStartupFailure(throwable);
}

private static final String METRICS_RETRY_LOGGER_PROPERTY =
"org.apache.http.impl.execchain.RetryExec";
private static final String LOGGER_PREFIX = "io.opentelemetry.javaagent.slf4j.simpleLogger.log.";

private static void addCustomLoggingConfiguration() {
// metrics exporter sometimes logs "Broken pipe (Write failed)" at INFO; usually in
// docker-based environments
// most likely docker resets long-running connections and the exporter has to retry, and it
// always succeeds after retrying and metrics are exported correctly
// limit default logging level to WARN unless debug mode is on or the user has overridden it
String metricsRetryLoggerLevel = System.getProperty(METRICS_RETRY_LOGGER_PROPERTY);
if (metricsRetryLoggerLevel == null && !isDebugMode()) {
System.setProperty(METRICS_RETRY_LOGGER_PROPERTY, "WARN");
if (!isDebugMode()) {
// metrics exporter sometimes logs "Broken pipe (Write failed)" at INFO; usually in
// docker-based environments
// most likely docker resets long-running connections and the exporter has to retry, and it
// always succeeds after retrying and metrics are exported correctly
// limit default logging level to WARN unless debug mode is on or the user has overridden it
setLogLevelIfNotSet("org.apache.http.impl.execchain.RetryExec", "WARN");

// Silence the following warning on jdk21, this warning should go away with an update to jfr
// parser
// [otel.javaagent 2023-10-09 14:38:17:665 +0000] [JFR Recording Sequencer] WARN
// org.openjdk.jmc.flightrecorder.internal.parser.v1.ValueReaders$ReflectiveReader - Could not
// find field with name 'virtual' in reader for 'thread'
setLogLevelIfNotSet(
"org.openjdk.jmc.flightrecorder.internal.parser.v1.ValueReaders$ReflectiveReader",
"ERROR");
}
}

private static void setLogLevelIfNotSet(String className, String logLevel) {
String loggerProperty = LOGGER_PREFIX + className;
String currentLogLevel = System.getProperty(loggerProperty);
if (currentLogLevel == null) {
System.setProperty(loggerProperty, logLevel);
}
}

Expand Down

0 comments on commit 8e6abe9

Please sign in to comment.