Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions .github/config/latest-dep-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"com.github.etaty:rediscala_2.11#+": "1.9.0",
"com.github.etaty:rediscala_2.12#+": "1.9.0",
"com.github.etaty:rediscala_2.13#+": "1.9.0",
"com.github.oshi:oshi-core#+": "6.12.0",
"com.github.oshi:oshi-core#+": "7.0.0",
"com.google.guava:guava#+": "33.6.0-jre",
"com.google.gwt:gwt-servlet#+": "2.10.0",
"com.google.http-client:google-http-client#+": "2.1.0",
Expand All @@ -64,9 +64,9 @@
"com.oracle.database.jdbc:ojdbc8#+": "23.26.1.0.0",
"com.oracle.database.jdbc:ucp#+": "23.26.1.0.0",
"com.rabbitmq:amqp-client#+": "5.30.0",
"com.softwaremill.sttp.tapir:tapir-pekko-http-server_2.12#+": "1.13.17",
"com.softwaremill.sttp.tapir:tapir-pekko-http-server_2.13#+": "1.13.17",
"com.softwaremill.sttp.tapir:tapir-pekko-http-server_3#+": "1.13.17",
"com.softwaremill.sttp.tapir:tapir-pekko-http-server_2.12#+": "1.13.18",
"com.softwaremill.sttp.tapir:tapir-pekko-http-server_2.13#+": "1.13.18",
"com.softwaremill.sttp.tapir:tapir-pekko-http-server_3#+": "1.13.18",
"com.sparkjava:spark-core#+": "2.9.4",
"com.squareup.okhttp3:okhttp#+": "5.3.2",
"com.squareup.okhttp:okhttp#+": "2.7.5",
Expand Down Expand Up @@ -135,11 +135,11 @@
"io.dropwizard:dropwizard-client#+": "5.0.1",
"io.dropwizard:dropwizard-views#+": "5.0.1",
"io.github.rediscala:rediscala_2.13#+": "1.17.0",
"io.grpc:grpc-core#+": "1.80.0",
"io.grpc:grpc-netty#+": "1.80.0",
"io.grpc:grpc-protobuf#+": "1.80.0",
"io.grpc:grpc-services#+": "1.80.0",
"io.grpc:grpc-stub#+": "1.80.0",
"io.grpc:grpc-core#+": "1.81.0",
"io.grpc:grpc-netty#+": "1.81.0",
"io.grpc:grpc-protobuf#+": "1.81.0",
"io.grpc:grpc-services#+": "1.81.0",
"io.grpc:grpc-stub#+": "1.81.0",
"io.helidon.webserver:helidon-webserver#+": "4.4.1",
"io.javalin:javalin#+": "7.2.0",
"io.javalin:javalin#6.+": "6.7.0",
Expand Down Expand Up @@ -184,7 +184,7 @@
"io.projectreactor:reactor-test#+": "3.8.5",
"io.quarkus.platform:quarkus-bom#3.5.+": "3.5.3",
"io.quarkus.platform:quarkus-bom#3.9.+": "3.9.5",
"io.quarkus:quarkus-rest#+": "3.35.0",
"io.quarkus:quarkus-rest#+": "3.35.1",
"io.quarkus:quarkus-resteasy-reactive#+": "3.15.7",
"io.r2dbc:r2dbc-spi#+": "1.0.0.RELEASE",
"io.ratpack:ratpack-core#+": "1.9.0",
Expand Down Expand Up @@ -346,7 +346,7 @@
"org.eclipse.jetty:jetty-servlet#10.+": "10.0.26",
"org.eclipse.jetty:jetty-servlet#7.+": "7.6.21.v20160908",
"org.eclipse.jetty:jetty-webapp#10.+": "10.0.26",
"org.elasticsearch.client:elasticsearch-rest-client#+": "9.3.3",
"org.elasticsearch.client:elasticsearch-rest-client#+": "9.3.4",
"org.elasticsearch.client:elasticsearch-rest-client#6.+": "6.8.23",
"org.elasticsearch.client:elasticsearch-rest-client#6.3.+": "6.3.2",
"org.elasticsearch.client:rest#+": "5.5.3",
Expand All @@ -361,7 +361,7 @@
"org.elasticsearch.plugin:transport-netty4-client#+": "7.17.29",
"org.elasticsearch.plugin:transport-netty4-client#6.+": "6.8.23",
"org.elasticsearch.plugin:transport-netty4-client#6.4.+": "6.4.3",
"org.elasticsearch:elasticsearch#+": "9.3.3",
"org.elasticsearch:elasticsearch#+": "9.3.4",
"org.glassfish.grizzly:grizzly-http#+": "5.0.1",
"org.glassfish.grizzly:grizzly-http#4.+": "4.0.2",
"org.glassfish.grizzly:grizzly-http-server#4.+": "4.0.2",
Expand All @@ -373,7 +373,7 @@
"org.glassfish.jersey.core:jersey-server#2.+": "2.48",
"org.glassfish.jersey.inject:jersey-hk2#+": "4.0.2",
"org.glassfish.jersey.inject:jersey-hk2#2.+": "2.48",
"org.glassfish:jakarta.faces#+": "4.1.7",
"org.glassfish:jakarta.faces#+": "4.1.8",
"org.glassfish:jakarta.faces#3.+": "3.0.5",
"org.glassfish:javax.faces#+": "2.4.0",
"org.glassfish:javax.faces#2.+": "2.4.0",
Expand Down Expand Up @@ -414,9 +414,9 @@
"org.jodd:jodd-http#+": "6.3.0",
"org.mongodb:mongo-java-driver#+": "3.12.14",
"org.mongodb:mongodb-driver-async#+": "3.12.14",
"org.mongodb:mongodb-driver-core#+": "5.6.5",
"org.mongodb:mongodb-driver-reactivestreams#+": "5.6.5",
"org.mongodb:mongodb-driver-sync#+": "5.6.5",
"org.mongodb:mongodb-driver-core#+": "5.7.0",
"org.mongodb:mongodb-driver-reactivestreams#+": "5.7.0",
"org.mongodb:mongodb-driver-sync#+": "5.7.0",
"org.mybatis:mybatis#+": "3.5.19",
"org.opensearch.client:opensearch-java#+": "3.8.0",
"org.opensearch.client:opensearch-rest-client#+": "3.6.0",
Expand Down Expand Up @@ -527,20 +527,20 @@
"redis.clients:jedis#2.+": "2.10.2",
"redis.clients:jedis#3.+": "3.10.0",
"software.amazon.awssdk.crt:aws-crt#+": "0.45.2",
"software.amazon.awssdk:aws-core#+": "2.43.1",
"software.amazon.awssdk:aws-json-protocol#+": "2.43.1",
"software.amazon.awssdk:bedrockruntime#+": "2.43.1",
"software.amazon.awssdk:dynamodb#+": "2.43.1",
"software.amazon.awssdk:ec2#+": "2.43.1",
"software.amazon.awssdk:kinesis#+": "2.43.1",
"software.amazon.awssdk:lambda#+": "2.43.1",
"software.amazon.awssdk:rds#+": "2.43.1",
"software.amazon.awssdk:s3#+": "2.43.0",
"software.amazon.awssdk:secretsmanager#+": "2.43.1",
"software.amazon.awssdk:ses#+": "2.43.1",
"software.amazon.awssdk:sfn#+": "2.43.1",
"software.amazon.awssdk:sns#+": "2.43.1",
"software.amazon.awssdk:sqs#+": "2.43.1",
"software.amazon.awssdk:aws-core#+": "2.43.2",
"software.amazon.awssdk:aws-json-protocol#+": "2.43.2",
"software.amazon.awssdk:bedrockruntime#+": "2.43.2",
"software.amazon.awssdk:dynamodb#+": "2.43.2",
"software.amazon.awssdk:ec2#+": "2.43.2",
"software.amazon.awssdk:kinesis#+": "2.43.2",
"software.amazon.awssdk:lambda#+": "2.43.2",
"software.amazon.awssdk:rds#+": "2.43.2",
"software.amazon.awssdk:s3#+": "2.43.2",
"software.amazon.awssdk:secretsmanager#+": "2.43.2",
"software.amazon.awssdk:ses#+": "2.43.2",
"software.amazon.awssdk:sfn#+": "2.43.2",
"software.amazon.awssdk:sns#+": "2.43.2",
"software.amazon.awssdk:sqs#+": "2.43.2",
"tech.powerjob:powerjob-official-processors#+": "5.1.2",
"tech.powerjob:powerjob-worker#+": "5.1.2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.opentelemetry.javaagent.extension.AgentListener;
import io.opentelemetry.javaagent.extension.instrumentation.internal.AgentDistributionConfig;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import java.lang.reflect.Method;

/**
* An {@link AgentListener} that enables oshi metrics during agent startup if oshi is present on the
Expand All @@ -26,24 +25,15 @@ public void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredSdk) {
}

try {
// Call oshi.SystemInfo.getCurrentPlatformEnum() to activate SystemMetrics.
// Instantiate oshi.SystemInfo to activate SystemMetrics.
// Oshi instrumentation will intercept this call and enable SystemMetrics.
// (The static getCurrentPlatformEnum()/getCurrentPlatform() entry points used in older
// versions were both removed in oshi 7.0.0.)
Class<?> oshiSystemInfoClass =
ClassLoader.getSystemClassLoader().loadClass("oshi.SystemInfo");
Method getCurrentPlatformEnumMethod = getCurrentPlatformMethod(oshiSystemInfoClass);
getCurrentPlatformEnumMethod.invoke(null);
} catch (Throwable ignored) {
oshiSystemInfoClass.getConstructor().newInstance();
} catch (Throwable t) {
// OK
}
}

private static Method getCurrentPlatformMethod(Class<?> oshiSystemInfoClass)
throws NoSuchMethodException {
try {
return oshiSystemInfoClass.getMethod("getCurrentPlatformEnum");
} catch (NoSuchMethodException ignored) {
// renamed in oshi 6.0.0
return oshiSystemInfoClass.getMethod("getCurrentPlatform");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

package io.opentelemetry.javaagent.instrumentation.oshi;

import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.isStatic;
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
Expand All @@ -24,16 +23,18 @@ public ElementMatcher<TypeDescription> typeMatcher() {

@Override
public void transform(TypeTransformer transformer) {
// Instrument the no-arg constructor: prior versions exposed static
// getCurrentPlatformEnum()/getCurrentPlatform() entry points, but oshi 7.0.0 removed both, so
// we trigger registration on instantiation instead (works across all supported versions).
transformer.applyAdviceToMethod(
isPublic().and(isStatic()).and(namedOneOf("getCurrentPlatformEnum", "getCurrentPlatform")),
getClass().getName() + "$GetCurrentPlatformEnumAdvice");
isConstructor().and(takesArguments(0)), getClass().getName() + "$ConstructAdvice");
}

@SuppressWarnings("unused")
public static class GetCurrentPlatformEnumAdvice {
public static class ConstructAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void onEnter() {
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static void onExit() {
MetricsRegistration.register();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.Meter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import oshi.SystemInfo;
Expand All @@ -19,6 +20,32 @@
public final class ProcessMetrics {
private static final AttributeKey<String> TYPE_KEY = AttributeKey.stringKey("type");

// getResidentSetSize() was deprecated in oshi 6.11.0 and removed in 7.0.0; the replacement
// getResidentMemory() was added in 6.11.0.
private static final Method RESIDENT_MEMORY_METHOD = findResidentMemoryMethod();

private static Method findResidentMemoryMethod() {
for (String name : new String[] {"getResidentMemory", "getResidentSetSize"}) {
try {
return OSProcess.class.getMethod(name);
} catch (NoSuchMethodException e) {
// try next
}
}
return null;
}

private static long getResidentMemory(OSProcess process) {
if (RESIDENT_MEMORY_METHOD == null) {
return 0;
}
try {
return (long) RESIDENT_MEMORY_METHOD.invoke(process);
} catch (ReflectiveOperationException e) {
return 0;
}
}

/** Register observers for java runtime metrics. */
public static List<AutoCloseable> registerObservers(OpenTelemetry openTelemetry) {
Meter meter = openTelemetry.getMeterProvider().get("io.opentelemetry.oshi");
Expand All @@ -34,7 +61,7 @@ public static List<AutoCloseable> registerObservers(OpenTelemetry openTelemetry)
.buildWithCallback(
r -> {
processInfo.updateAttributes();
r.record(processInfo.getResidentSetSize(), Attributes.of(TYPE_KEY, "rss"));
r.record(getResidentMemory(processInfo), Attributes.of(TYPE_KEY, "rss"));
r.record(processInfo.getVirtualSize(), Attributes.of(TYPE_KEY, "vms"));
}));

Expand Down
Loading