Skip to content
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

Stop collecting oshi perf counters when initialization fails #2047

Merged
merged 4 commits into from
Jan 13, 2022
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem;
import com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient;
import com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryUtil;
import java.util.concurrent.atomic.AtomicBoolean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import oshi.SystemInfo;
Expand All @@ -45,6 +46,7 @@ public class OshiPerformanceCounter implements PerformanceCounter {

private volatile OSProcess processInfo;
private volatile CentralProcessor processor;
private static final AtomicBoolean hasError = new AtomicBoolean();

@Override
public String getId() {
Expand All @@ -55,10 +57,22 @@ public String getId() {
public void report(TelemetryClient telemetryClient) {
if (processInfo == null || processor == null) {
// lazy initializing these because they add to slowness during startup
SystemInfo systemInfo = new SystemInfo();
OperatingSystem osInfo = systemInfo.getOperatingSystem();
processInfo = osInfo.getProcess(osInfo.getProcessId());
processor = systemInfo.getHardware().getProcessor();
try {
SystemInfo systemInfo = new SystemInfo();
OperatingSystem osInfo = systemInfo.getOperatingSystem();
processInfo = osInfo.getProcess(osInfo.getProcessId());
processor = systemInfo.getHardware().getProcessor();
} catch (Error ex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's log this at debug level

// e.g. icm 253155448: NoClassDefFoundError
// e.g. icm 276640835: ExceptionInInitializerError
hasError.set(true);
return;
}
}

// stop collecting oshi perf counters when initialization fails.
if (hasError.get()) {
return;
}
trask marked this conversation as resolved.
Show resolved Hide resolved

long currCollectionTimeMillis = System.currentTimeMillis();
Expand Down