Fix oshi latest dep test
MODIFY
instrumentation/oshi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/oshi/OshiMetricsInstaller.java
instrumentation/oshi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/oshi/OshiMetricsInstaller.java
@@ -26,12 +26,21 @@ public class OshiMetricsInstaller implements AgentListener {
// Oshi instrumentation will intercept this call and enable SystemMetrics.
Class<?> oshiSystemInfoClass =
ClassLoader.getSystemClassLoader().loadClass("oshi.SystemInfo");
- Method getCurrentPlatformEnumMethod =
- oshiSystemInfoClass.getMethod("getCurrentPlatformEnum");
+ Method getCurrentPlatformEnumMethod = getCurrentPlatformMethod(oshiSystemInfoClass);
getCurrentPlatformEnumMethod.invoke(null);
} catch (Throwable ex) {
// OK
}
}
}
+
+ private static Method getCurrentPlatformMethod(Class<?> oshiSystemInfoClass)
+ throws NoSuchMethodException {
+ try {
+ return oshiSystemInfoClass.getMethod("getCurrentPlatformEnum");
+ } catch (NoSuchMethodException exception) {
+ // renamed in oshi 6.0.0
+ return oshiSystemInfoClass.getMethod("getCurrentPlatform");
+ }
+ }
}

MODIFY
instrumentation/oshi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/oshi/SystemInfoInstrumentation.java
instrumentation/oshi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/oshi/SystemInfoInstrumentation.java
@@ -32,7 +32,10 @@ public class SystemInfoInstrumentation implements TypeInstrumentation {
@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
- isMethod().and(isPublic()).and(isStatic()).and(named("getCurrentPlatformEnum")),
+ isMethod()
+ .and(isPublic())
+ .and(isStatic())
+ .and(named("getCurrentPlatformEnum").or(named("getCurrentPlatform"))),
this.getClass().getName() + "$GetCurrentPlatformEnumAdvice");
}

Fix oshi latest dep test (#4993)