Remove oshi-related code from shared agent code (#2682)
This commit is contained in:
parent
84e7306370
commit
af13e7d6e3
|
@ -9,6 +9,7 @@ muzzle {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
api project(':javaagent-spi')
|
||||||
implementation project(':instrumentation:oshi:library')
|
implementation project(':instrumentation:oshi:library')
|
||||||
|
|
||||||
library group: 'com.github.oshi', name: 'oshi-core', version: '5.3.1'
|
library group: 'com.github.oshi', name: 'oshi-core', version: '5.3.1'
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.javaagent.instrumentation.oshi;
|
||||||
|
|
||||||
|
import com.google.auto.service.AutoService;
|
||||||
|
import io.opentelemetry.instrumentation.api.config.Config;
|
||||||
|
import io.opentelemetry.javaagent.spi.ComponentInstaller;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ComponentInstaller} to enable oshi metrics during agent startup if oshi is present on the
|
||||||
|
* system classpath.
|
||||||
|
*/
|
||||||
|
@AutoService(ComponentInstaller.class)
|
||||||
|
public class OshiMetricsInstaller implements ComponentInstaller {
|
||||||
|
@Override
|
||||||
|
public void afterByteBuddyAgent(Config config) {
|
||||||
|
if (config.isInstrumentationEnabled(Collections.singleton("oshi"), true)) {
|
||||||
|
try {
|
||||||
|
// Call oshi.SystemInfo.getCurrentPlatformEnum() to activate SystemMetrics.
|
||||||
|
// Oshi instrumentation will intercept this call and enable SystemMetrics.
|
||||||
|
Class<?> oshiSystemInfoClass =
|
||||||
|
ClassLoader.getSystemClassLoader().loadClass("oshi.SystemInfo");
|
||||||
|
Method getCurrentPlatformEnumMethod =
|
||||||
|
oshiSystemInfoClass.getMethod("getCurrentPlatformEnum");
|
||||||
|
getCurrentPlatformEnumMethod.invoke(null);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
// OK
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,17 +9,11 @@ import static java.util.concurrent.TimeUnit.SECONDS
|
||||||
|
|
||||||
import com.google.common.base.Stopwatch
|
import com.google.common.base.Stopwatch
|
||||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||||
import oshi.PlatformEnum
|
|
||||||
import oshi.SystemInfo
|
|
||||||
|
|
||||||
class OshiTest extends AgentInstrumentationSpecification {
|
class OshiTest extends AgentInstrumentationSpecification {
|
||||||
|
|
||||||
def "test system metrics is enabled"() {
|
def "test system metrics is enabled"() {
|
||||||
setup:
|
|
||||||
PlatformEnum platform = SystemInfo.getCurrentPlatformEnum()
|
|
||||||
|
|
||||||
expect:
|
expect:
|
||||||
platform != null
|
|
||||||
// TODO (trask) is this the instrumentation library name we want?
|
// TODO (trask) is this the instrumentation library name we want?
|
||||||
findMetric("io.opentelemetry.instrumentation.oshi", "system.disk.io") != null
|
findMetric("io.opentelemetry.instrumentation.oshi", "system.disk.io") != null
|
||||||
findMetric("io.opentelemetry.instrumentation.oshi", "system.disk.operations") != null
|
findMetric("io.opentelemetry.instrumentation.oshi", "system.disk.operations") != null
|
||||||
|
|
|
@ -67,17 +67,6 @@ public class OpenTelemetryAgent {
|
||||||
System.err.println("ERROR " + thisClass.getName());
|
System.err.println("ERROR " + thisClass.getName());
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
// Call oshi.SystemInfo.getCurrentPlatformEnum() to activate SystemMetrics.
|
|
||||||
// Oshi instrumentation will intercept this call and enable SystemMetrics.
|
|
||||||
Class<?> oshiSystemInfoClass =
|
|
||||||
ClassLoader.getSystemClassLoader().loadClass("oshi.SystemInfo");
|
|
||||||
Method getCurrentPlatformEnumMethod = oshiSystemInfoClass.getMethod("getCurrentPlatformEnum");
|
|
||||||
getCurrentPlatformEnumMethod.invoke(null);
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static synchronized URL installBootstrapJar(Instrumentation inst)
|
private static synchronized URL installBootstrapJar(Instrumentation inst)
|
||||||
|
|
Loading…
Reference in New Issue