diff --git a/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/diagnostics/status/StatusFile.java b/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/diagnostics/status/StatusFile.java index 6be3ea6ed8a..3e8f00866cd 100644 --- a/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/diagnostics/status/StatusFile.java +++ b/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/diagnostics/status/StatusFile.java @@ -55,14 +55,19 @@ public class StatusFile { static final String HOME_ENV_VAR = "HOME"; // visible for testing - static final String DEFAULT_LOGDIR = "/LogFiles"; + static final String DEFAULT_LOGDIR = "LogFiles"; // visible for testing - static final String DEFAULT_APPLICATIONINSIGHTS_LOGDIR = "/ApplicationInsights"; + static final String DEFAULT_APPLICATIONINSIGHTS_LOGDIR = "ApplicationInsights"; // visible for testing static final String WINDOWS_DEFAULT_HOME_DIR = - "/home" + DEFAULT_LOGDIR + DEFAULT_APPLICATIONINSIGHTS_LOGDIR; + File.separator + + "home" + + File.separator + + DEFAULT_LOGDIR + + File.separator + + DEFAULT_APPLICATIONINSIGHTS_LOGDIR; // visible for testing static String logDir; @@ -110,11 +115,15 @@ static String initLogDir() { if (DiagnosticsHelper.isOsWindows()) { String siteLogDir = System.getProperty(SITE_LOGDIR_PROPERTY); if (siteLogDir != null && !siteLogDir.isEmpty()) { - return siteLogDir + DEFAULT_APPLICATIONINSIGHTS_LOGDIR; + return siteLogDir + File.separator + DEFAULT_APPLICATIONINSIGHTS_LOGDIR; } String homeDir = System.getenv(HOME_ENV_VAR); if (homeDir != null && !homeDir.isEmpty()) { - return homeDir + DEFAULT_LOGDIR + DEFAULT_APPLICATIONINSIGHTS_LOGDIR; + return homeDir + + File.separator + + DEFAULT_LOGDIR + + File.separator + + DEFAULT_APPLICATIONINSIGHTS_LOGDIR; } return WINDOWS_DEFAULT_HOME_DIR; } diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java index 1a28973a7d0..ea4c69d95d6 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java @@ -615,7 +615,7 @@ private static String getDefaultPath() { } if (DiagnosticsHelper.useAppSvcRpIntegrationLogging() || DiagnosticsHelper.useFunctionsRpIntegrationLogging()) { - return StatusFile.getLogDir() + "/" + DEFAULT_NAME; + return StatusFile.getLogDir() + File.separator + DEFAULT_NAME; } // azure spring cloud return DEFAULT_NAME; diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/LoggingConfigurator.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/LoggingConfigurator.java index 93b105b8110..6465d894fff 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/LoggingConfigurator.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/LoggingConfigurator.java @@ -115,6 +115,11 @@ private void configureFunctions() { Appender diagnosticAppender = configureConsoleAppender(); diagnosticLogger.addAppender(diagnosticAppender); + ApplicationInsightsDiagnosticsLogFilter filter = new ApplicationInsightsDiagnosticsLogFilter(); + filter.setContext(loggerContext); + filter.start(); + diagnosticAppender.addFilter(filter); + // errors reported by other loggers should also go to diagnostic log // (level filter for these is applied in ApplicationInsightsDiagnosticsLogFilter) rootLogger.addAppender(diagnosticAppender); diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/RuntimeConfiguration.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/RuntimeConfiguration.java index 912a1928ef0..3f3e2e28e2e 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/RuntimeConfiguration.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/RuntimeConfiguration.java @@ -22,4 +22,8 @@ public class RuntimeConfiguration { public String instrumentationLoggingLevel; public String selfDiagnosticsLevel; + + public boolean profilerEnabled; + + public long heartbeatIntervalSeconds; } diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/RuntimeConfigurator.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/RuntimeConfigurator.java index 790f33955ca..c93953b3462 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/RuntimeConfigurator.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/RuntimeConfigurator.java @@ -3,18 +3,26 @@ package com.microsoft.applicationinsights.agent.internal.init; +import static java.util.concurrent.TimeUnit.MINUTES; + import ch.qos.logback.classic.LoggerContext; +import com.azure.monitor.opentelemetry.exporter.implementation.heartbeat.HeartbeatExporter; +import com.azure.monitor.opentelemetry.exporter.implementation.models.TelemetryItem; import com.azure.monitor.opentelemetry.exporter.implementation.utils.Strings; import com.microsoft.applicationinsights.agent.internal.classicsdk.BytecodeUtilImpl; import com.microsoft.applicationinsights.agent.internal.configuration.Configuration; import com.microsoft.applicationinsights.agent.internal.exporter.AgentLogExporter; import com.microsoft.applicationinsights.agent.internal.legacyheaders.DelegatingPropagator; +import com.microsoft.applicationinsights.agent.internal.profiler.ProfilingInitializer; import com.microsoft.applicationinsights.agent.internal.sampling.DelegatingSampler; import com.microsoft.applicationinsights.agent.internal.sampling.Samplers; import com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient; +import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; import java.util.function.Supplier; import javax.annotation.Nullable; import org.slf4j.Logger; @@ -26,15 +34,26 @@ public class RuntimeConfigurator { private final TelemetryClient telemetryClient; private final Supplier agentLogExporter; + private final Configuration initialConfig; private volatile RuntimeConfiguration currentConfig; + private final Consumer> heartbeatTelemetryItemsConsumer; + private final File tempDir; + + private final AtomicBoolean profilerStarted = new AtomicBoolean(); + private final AtomicBoolean heartbeatStarted = new AtomicBoolean(); RuntimeConfigurator( TelemetryClient telemetryClient, Supplier agentLogExporter, - Configuration initialConfig) { + Configuration initialConfig, + Consumer> heartbeatTelemetryItemConsumer, + File tempDir) { this.telemetryClient = telemetryClient; this.agentLogExporter = agentLogExporter; + this.initialConfig = initialConfig; currentConfig = captureInitialConfig(initialConfig); + this.heartbeatTelemetryItemsConsumer = heartbeatTelemetryItemConsumer; + this.tempDir = tempDir; } private static RuntimeConfiguration captureInitialConfig(Configuration initialConfig) { @@ -58,6 +77,9 @@ private static RuntimeConfiguration captureInitialConfig(Configuration initialCo runtimeConfig.instrumentationLoggingLevel = initialConfig.instrumentation.logging.level; runtimeConfig.selfDiagnosticsLevel = initialConfig.selfDiagnostics.level; + + runtimeConfig.profilerEnabled = initialConfig.preview.profiler.enabled; + runtimeConfig.heartbeatIntervalSeconds = initialConfig.heartbeat.intervalSeconds; return runtimeConfig; } @@ -79,6 +101,9 @@ private static RuntimeConfiguration copy(RuntimeConfiguration config) { copy.instrumentationLoggingLevel = config.instrumentationLoggingLevel; copy.selfDiagnosticsLevel = config.selfDiagnosticsLevel; + + copy.profilerEnabled = config.profilerEnabled; + copy.heartbeatIntervalSeconds = config.heartbeatIntervalSeconds; return copy; } @@ -112,6 +137,42 @@ public void apply(RuntimeConfiguration runtimeConfig) { updateSampling(enabled, runtimeConfig.sampling, runtimeConfig.samplingPreview); } + // initialize Profiler + if (runtimeConfig.profilerEnabled && telemetryClient.getConnectionString() != null) { + // this prevents profiler being initialized more than once in Azure Spring App + if (!profilerStarted.getAndSet(true)) { + try { + ProfilingInitializer.initialize( + tempDir, + initialConfig.preview.profiler, + initialConfig.preview.gcEvents.reportingLevel, + runtimeConfig.role.name, + runtimeConfig.role.instance, + telemetryClient); + } catch (RuntimeException e) { + logger.warn("Failed to initialize profiler", e); + } + } else { + logger.debug("Profiler has already been initialized."); + } + } + + // enable Heartbeat + if (telemetryClient.getConnectionString() != null) { + // this prevents heartbeat being started more than once in Azure Spring App + if (!heartbeatStarted.getAndSet(true)) { + // interval longer than 15 minutes is not allowed since we use this data for usage telemetry + long intervalSeconds = + Math.min(runtimeConfig.heartbeatIntervalSeconds, MINUTES.toSeconds(15)); + HeartbeatExporter.start( + intervalSeconds, telemetryClient::populateDefaults, heartbeatTelemetryItemsConsumer); + } else { + logger.debug("Heartbeat has already started."); + } + } + + // TODO (heya) enable Statsbeat and need to refactor RuntimeConfiguration + updateInstrumentationLoggingLevel(runtimeConfig.instrumentationLoggingLevel); updateSelfDiagnosticsLevel(runtimeConfig.selfDiagnosticsLevel); diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/SecondEntryPoint.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/SecondEntryPoint.java index 0b4b4745f87..d40eb3543e8 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/SecondEntryPoint.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/SecondEntryPoint.java @@ -135,9 +135,7 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) { .setDiskPersistenceMaxSizeMb(configuration.preview.diskPersistenceMaxSizeMb) .build(); - // interval longer than 15 minutes is not allowed since we use this data for usage telemetry - long intervalSeconds = Math.min(configuration.heartbeat.intervalSeconds, MINUTES.toSeconds(15)); - Consumer> telemetryItemsConsumer = + Consumer> heartbeatTelemetryItemConsumer = telemetryItems -> { for (TelemetryItem telemetryItem : telemetryItems) { TelemetryObservers.INSTANCE @@ -146,13 +144,40 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) { telemetryClient.getMetricsBatchItemProcessor().trackAsync(telemetryItem); } }; - HeartbeatExporter.start( - intervalSeconds, telemetryClient::populateDefaults, telemetryItemsConsumer); + + if (telemetryClient.getConnectionString() != null) { + startupLogger.verbose("connection string is not null, start HeartbeatExporter"); + // interval longer than 15 minutes is not allowed since we use this data for usage telemetry + long intervalSeconds = + Math.min(configuration.heartbeat.intervalSeconds, MINUTES.toSeconds(15)); + HeartbeatExporter.start( + intervalSeconds, telemetryClient::populateDefaults, heartbeatTelemetryItemConsumer); + } TelemetryClient.setActive(telemetryClient); + if (configuration.preview.profiler.enabled && telemetryClient.getConnectionString() != null) { + try { + ProfilingInitializer.initialize( + tempDir, + configuration.preview.profiler, + configuration.preview.gcEvents.reportingLevel, + configuration.role.name, + configuration.role.instance, + telemetryClient); + } catch (RuntimeException e) { + startupLogger.warning("Failed to initialize profiler", e); + } + } + + // TODO (heya) remove duplicate code in both RuntimeConfigurator and SecondEntryPoint RuntimeConfigurator runtimeConfigurator = - new RuntimeConfigurator(telemetryClient, () -> agentLogExporter, configuration); + new RuntimeConfigurator( + telemetryClient, + () -> agentLogExporter, + configuration, + heartbeatTelemetryItemConsumer, + tempDir); if (configuration.sampling.percentage != null) { BytecodeUtilImpl.samplingPercentage = configuration.sampling.percentage.floatValue(); @@ -164,14 +189,6 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) { BytecodeUtilImpl.connectionStringConfiguredAtRuntime = configuration.connectionStringConfiguredAtRuntime; - if (configuration.preview.profiler.enabled) { - try { - ProfilingInitializer.initialize(tempDir, configuration, telemetryClient); - } catch (RuntimeException e) { - startupLogger.warning("Failed to initialize profiler", e); - } - } - if (ConfigurationBuilder.inAzureFunctionsConsumptionWorker()) { AzureFunctions.setup( () -> telemetryClient.getConnectionString() != null, diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/PerformanceMonitoringService.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/PerformanceMonitoringService.java index 7581dc84a73..2511e75351f 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/PerformanceMonitoringService.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/PerformanceMonitoringService.java @@ -5,6 +5,7 @@ import com.azure.monitor.opentelemetry.exporter.implementation.utils.ThreadPoolUtils; import com.microsoft.applicationinsights.agent.internal.configuration.Configuration; +import com.microsoft.applicationinsights.agent.internal.configuration.GcReportingLevel; import com.microsoft.applicationinsights.agent.internal.profiler.service.ServiceProfilerClient; import com.microsoft.applicationinsights.agent.internal.profiler.triggers.AlertingSubsystemInit; import com.microsoft.applicationinsights.agent.internal.profiler.upload.UploadService; @@ -38,7 +39,8 @@ public class PerformanceMonitoringService { private final String machineName; private final String roleName; private final TelemetryClient telemetryClient; - private final Configuration configuration; + private final Configuration.ProfilerConfiguration configuration; + private final GcReportingLevel reportingLevel; private final File tempDir; private boolean currentlyEnabled = false; @@ -58,13 +60,15 @@ public PerformanceMonitoringService( String machineName, String roleName, TelemetryClient telemetryClient, - Configuration configuration, + Configuration.ProfilerConfiguration configuration, + GcReportingLevel reportingLevel, File tempDir) { this.processId = processId; this.machineName = machineName; this.roleName = roleName; this.telemetryClient = telemetryClient; this.configuration = configuration; + this.reportingLevel = reportingLevel; this.tempDir = tempDir; } @@ -80,7 +84,7 @@ synchronized void enableProfiler( logger.warn("INITIALISING JFR PROFILING SUBSYSTEM THIS FEATURE IS IN BETA"); diagnosticEngine = null; - if (configuration.preview.profiler.enableDiagnostics) { + if (configuration.enabled) { // Initialise diagnostic service diagnosticEngine = startDiagnosticEngine(); } @@ -91,11 +95,12 @@ synchronized void enableProfiler( ThreadPoolUtils.createDaemonThreadFactory( ProfilingInitializer.class, "ServiceProfilerAlertingService")); - profiler = new Profiler(configuration.preview.profiler, tempDir); + profiler = new Profiler(configuration, tempDir); alerting = AlertingSubsystemInit.create( configuration, + reportingLevel, TelemetryObservers.INSTANCE, profiler, telemetryClient, diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilingInitializer.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilingInitializer.java index ddacfb05274..b41b5285a56 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilingInitializer.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilingInitializer.java @@ -12,6 +12,7 @@ import com.microsoft.applicationinsights.agent.internal.common.FriendlyException; import com.microsoft.applicationinsights.agent.internal.common.SystemInformation; import com.microsoft.applicationinsights.agent.internal.configuration.Configuration; +import com.microsoft.applicationinsights.agent.internal.configuration.GcReportingLevel; import com.microsoft.applicationinsights.agent.internal.httpclient.LazyHttpClient; import com.microsoft.applicationinsights.agent.internal.profiler.config.ConfigService; import com.microsoft.applicationinsights.agent.internal.profiler.config.ProfilerConfiguration; @@ -49,7 +50,8 @@ public class ProfilingInitializer { private final String roleName; private final TelemetryClient telemetryClient; private final String userAgent; - private final Configuration configuration; + private final Configuration.ProfilerConfiguration configuration; + private final GcReportingLevel reportingLevel; private final File tempDir; ////////////////////////////////////////////////////////// @@ -67,7 +69,8 @@ private ProfilingInitializer( String roleName, TelemetryClient telemetryClient, String userAgent, - Configuration configuration, + Configuration.ProfilerConfiguration configuration, + GcReportingLevel reportingLevel, File tempDir) { this.processId = processId; this.machineName = machineName; @@ -75,33 +78,40 @@ private ProfilingInitializer( this.telemetryClient = telemetryClient; this.userAgent = userAgent; this.configuration = configuration; + this.reportingLevel = reportingLevel; this.tempDir = tempDir; } public static ProfilingInitializer initialize( - File tempDir, Configuration configuration, TelemetryClient telemetryClient) { + File tempDir, + Configuration.ProfilerConfiguration configuration, + GcReportingLevel reportingLevel, + String roleName, + String roleInstance, + TelemetryClient telemetryClient) { ProfilingInitializer profilingInitializer = new ProfilingInitializer( SystemInformation.getProcessId(), - configuration.role.instance, - configuration.role.name, + roleInstance, + roleName, telemetryClient, formApplicationInsightsUserAgent(), configuration, + reportingLevel, tempDir); profilingInitializer.initialize(); return profilingInitializer; } - public synchronized void initialize() { + synchronized void initialize() { if (tempDir == null) { throw new FriendlyException( "Profile is not supported in a read-only file system.", "disable profiler or use a writable file system"); } - if (configuration.preview.profiler.enabled) { + if (configuration.enabled) { performInit(); } } @@ -126,7 +136,7 @@ private synchronized void performInit() { serviceProfilerClient = new ServiceProfilerClient( - getServiceProfilerFrontEndPoint(configuration.preview.profiler), + getServiceProfilerFrontEndPoint(configuration), telemetryClient.getInstrumentationKey(), httpPipeline, userAgent); @@ -140,7 +150,7 @@ private void startPollingForConfigUpdates() { serviceProfilerExecutorService.scheduleAtFixedRate( () -> pullProfilerSettings(configService), 5, - configuration.preview.profiler.configPollPeriodSeconds, + configuration.configPollPeriodSeconds, TimeUnit.SECONDS); } @@ -160,12 +170,10 @@ private void logProfilerPullError(Throwable e) { } } - synchronized void applyConfiguration(ProfilerConfiguration profilerConfiguration) { - if (currentlyEnabled.get() - || (profilerConfiguration.isEnabled() && profilerConfiguration.hasBeenConfigured())) { + synchronized void applyConfiguration(ProfilerConfiguration config) { + if (currentlyEnabled.get() || (config.isEnabled() && config.hasBeenConfigured())) { - AlertingConfiguration alertingConfig = - AlertConfigParser.toAlertingConfig(profilerConfiguration); + AlertingConfiguration alertingConfig = AlertConfigParser.toAlertingConfig(config); if (alertingConfig.hasAnEnabledTrigger()) { if (!currentlyEnabled.getAndSet(true)) { @@ -199,7 +207,13 @@ synchronized void disableProfiler() { synchronized void enableProfiler() { performanceMonitoringService = new PerformanceMonitoringService( - processId, machineName, roleName, telemetryClient, configuration, tempDir); + processId, + machineName, + roleName, + telemetryClient, + configuration, + reportingLevel, + tempDir); performanceMonitoringService.enableProfiler( serviceProfilerClient, serviceProfilerExecutorService); diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/AlertingSubsystemInit.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/AlertingSubsystemInit.java index 0e24d71705d..8d4cce34296 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/AlertingSubsystemInit.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/AlertingSubsystemInit.java @@ -38,7 +38,8 @@ public class AlertingSubsystemInit { private static volatile AlertingSubsystem alertingSubsystem; public static AlertingSubsystem create( - Configuration configuration, + Configuration.ProfilerConfiguration configuration, + GcReportingLevel reportingLevel, TelemetryObservers telemetryObservers, Profiler profiler, TelemetryClient telemetryClient, @@ -52,9 +53,9 @@ public static AlertingSubsystem create( alertingSubsystem = AlertingSubsystem.create(alertAction, TimeSource.DEFAULT); - if (configuration.preview.profiler.enableRequestTriggering) { + if (configuration.enableRequestTriggering) { List spanPipelines = - Arrays.stream(configuration.preview.profiler.requestTriggerEndpoints) + Arrays.stream(configuration.requestTriggerEndpoints) .map(it -> RequestAlertPipelineBuilder.build(it, alertAction, TimeSource.DEFAULT)) .collect(Collectors.toList()); @@ -68,15 +69,15 @@ public static AlertingSubsystem create( alertingSubsystem, telemetryClient, executorService, - fromGcEventMonitorConfiguration(configuration.preview)); + fromGcEventMonitorConfiguration(reportingLevel)); return alertingSubsystem; } private static GcEventInit.GcEventMonitorConfiguration fromGcEventMonitorConfiguration( - Configuration.PreviewConfiguration configuration) { - if (configuration.gcEvents.reportingLevel != null) { - return new GcEventInit.GcEventMonitorConfiguration(configuration.gcEvents.reportingLevel); + GcReportingLevel reportingLevel) { + if (reportingLevel != null) { + return new GcEventInit.GcEventMonitorConfiguration(reportingLevel); } return new GcEventInit.GcEventMonitorConfiguration(GcReportingLevel.NONE); diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/telemetry/BatchItemProcessor.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/telemetry/BatchItemProcessor.java index 9122973fd1f..bc47acd17f4 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/telemetry/BatchItemProcessor.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/telemetry/BatchItemProcessor.java @@ -5,6 +5,7 @@ import static com.azure.monitor.opentelemetry.exporter.implementation.utils.AzureMonitorMsgId.BATCH_ITEM_PROCESSOR_ERROR; +import com.azure.core.util.logging.ClientLogger; import com.azure.monitor.opentelemetry.exporter.implementation.logging.OperationLogger; import com.azure.monitor.opentelemetry.exporter.implementation.models.TelemetryItem; import com.azure.monitor.opentelemetry.exporter.implementation.pipeline.TelemetryItemExporter; @@ -26,6 +27,8 @@ // copied from io.opentelemetry.sdk.trace.export.BatchSpanProcessor public final class BatchItemProcessor { + private static final ClientLogger logger = new ClientLogger(BatchItemProcessor.class); + private static final String WORKER_THREAD_NAME = BatchItemProcessor.class.getSimpleName() + "_WorkerThread"; @@ -62,7 +65,9 @@ public static BatchItemProcessorBuilder builder(TelemetryItemExporter exporter) queue, queue.capacity(), queueName); + Thread workerThread = new DaemonThreadFactory(WORKER_THREAD_NAME).newThread(worker); + workerThread.setUncaughtExceptionHandler((t, e) -> logger.error(e.getMessage(), e)); workerThread.start(); } diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/init/RpConfigurationPollingTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/init/RpConfigurationPollingTest.java index c3b0da020c9..8235617c527 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/init/RpConfigurationPollingTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/init/RpConfigurationPollingTest.java @@ -74,7 +74,7 @@ void shouldUpdate() throws URISyntaxException { // when RuntimeConfigurator runtimeConfigurator = - new RuntimeConfigurator(telemetryClient, () -> null, config); + new RuntimeConfigurator(telemetryClient, () -> null, config, item -> {}, null); new RpConfigurationPolling(rpConfiguration, runtimeConfigurator).run(); // then @@ -117,7 +117,7 @@ void shouldBePopulatedByEnvVars() throws URISyntaxException { // when RuntimeConfigurator runtimeConfigurator = - new RuntimeConfigurator(telemetryClient, () -> null, config); + new RuntimeConfigurator(telemetryClient, () -> null, config, item -> {}, null); new RpConfigurationPolling(rpConfiguration, runtimeConfigurator).run(); // then diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilingInitializerTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilingInitializerTest.java index 29d51fc73b5..482aebc01f8 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilingInitializerTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilingInitializerTest.java @@ -6,6 +6,7 @@ import com.azure.monitor.opentelemetry.exporter.implementation.builders.MessageTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.configuration.ConnectionString; import com.microsoft.applicationinsights.agent.internal.configuration.Configuration; +import com.microsoft.applicationinsights.agent.internal.configuration.GcReportingLevel; import com.microsoft.applicationinsights.agent.internal.profiler.config.ProfilerConfiguration; import com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient; import java.io.File; @@ -220,7 +221,13 @@ private static ProfilingInitializer createProfilingInitializer() { "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://fake-ingestion-endpoint")); ProfilingInitializer profiler = - ProfilingInitializer.initialize(new File("/tmp/"), new Configuration(), client); + ProfilingInitializer.initialize( + new File("/tmp/"), + new Configuration.ProfilerConfiguration(), + GcReportingLevel.NONE, + "test-role-name", + "test-role-instance", + client); profiler = Mockito.spy(profiler); profiler.initialize();