in agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilerServiceInitializer.java [92:163]
public static synchronized void initialize(
Supplier<String> appIdSupplier,
String processId,
ServiceProfilerServiceConfig config,
String machineName,
String roleName,
TelemetryClient telemetryClient,
String userAgent,
GcEventMonitor.GcEventMonitorConfiguration gcEventMonitorConfiguration,
HttpPipeline httpPipeline) {
if (!initialized) {
initialized = true;
ProfilerServiceFactory factory = null;
try {
factory = loadProfilerServiceFactory();
} catch (RuntimeException e) {
LOGGER.error("Failed to load profiler factory", e);
}
if (factory == null) {
LOGGER.error(
"Profiling has been enabled however no profiler implementation was provided. Please install an ApplicationInsights agent which provides a profiler.");
return;
}
ScheduledExecutorService serviceProfilerExecutorService =
Executors.newScheduledThreadPool(
2,
ThreadPoolUtils.createDaemonThreadFactory(
ProfilerServiceFactory.class, "ServiceProfilerService"));
ScheduledExecutorService alertServiceExecutorService =
Executors.newScheduledThreadPool(
2,
ThreadPoolUtils.createDaemonThreadFactory(
ProfilerServiceFactory.class, "ServiceProfilerAlertingService"));
AlertingSubsystem alerting =
createAlertMonitor(
alertServiceExecutorService, telemetryClient, gcEventMonitorConfiguration);
Future<ProfilerService> future =
factory.initialize(
appIdSupplier,
sendServiceProfilerIndex(telemetryClient),
updateAlertingConfig(alerting),
processId,
config,
machineName,
telemetryClient.getInstrumentationKey(),
httpPipeline,
serviceProfilerExecutorService,
userAgent,
roleName);
serviceProfilerExecutorService.submit(
() -> {
try {
profilerService = future.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
LOGGER.error(
"Unable to obtain JFR connection, this may indicate that your JVM does not have JFR enabled. JFR profiling system will shutdown",
e);
alertServiceExecutorService.shutdown();
serviceProfilerExecutorService.shutdown();
}
});
}
}