Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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 @@ -5,6 +5,7 @@

import static java.util.concurrent.TimeUnit.SECONDS;

import com.azure.monitor.opentelemetry.autoconfigure.implementation.AzureMonitorExporterProviderKeys;
import com.microsoft.applicationinsights.agent.internal.configuration.Configuration;
import com.microsoft.applicationinsights.agent.internal.legacyheaders.DelegatingPropagatorProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
Expand Down Expand Up @@ -115,9 +116,25 @@ public Map<String, String> apply(ConfigProperties otelConfig) {
}

String metricsExporter = otelConfig.getString("otel.metrics.exporter");
if (metricsExporter == null) {
// this overrides the default "otlp" so the exporter can be configured later
properties.put("otel.metrics.exporter", "none");
String azureMonitorName = AzureMonitorExporterProviderKeys.EXPORTER_NAME;
boolean metricsToLogAnalyticsEnabled =
otelConfig.getBoolean("applicationinsights.metrics.to.loganalytics.enabled", false);
Copy link
Member

Choose a reason for hiding this comment

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

The specifications seem to indicate that the APPLICATIONINSIGHTS_METRICS_TO_LOGANALYTICS_ENABLED should only be used in case of AKS and Auto-Attach. AKS detection can be done in this way:

Auto-Attach detection requires the Java agent JAR path . See DiagnosticHelper.initRpIntegration.(Path agentPath) and DiagnosticsHelper.setRpAttachType(Path agentPath, String markerFile) .

AiConfigCustomizer is instanciated in the SecondEntry point:

The RP integration of DiagnosticsHelper is initiliazed in the first entry point:

I am not sure that the first entry point always finishes to execute before the second one. If the first entry point always finishes to execute before the second one, you could use the RP initialization done in the first entry point from the second one. Otherwise, you could reimplement the same kind of things in the second entry point.


if (metricsToLogAnalyticsEnabled) {
if (metricsExporter == null
|| metricsExporter.isEmpty()
|| metricsExporter.equalsIgnoreCase("none")) {
// enable Azure Monitor metrics exporter by default when flag is enabled
properties.put("otel.metrics.exporter", azureMonitorName);
} else if (!metricsExporter.contains(azureMonitorName)) {
// ensure Azure Monitor exporter is included when flag is enabled
properties.put("otel.metrics.exporter", metricsExporter + "," + azureMonitorName);
}
} else {
if (metricsExporter == null) {
// preserve previous behavior: override default "otlp" so exporter can be configured later
properties.put("otel.metrics.exporter", "none");
}
}

String logsExporter = otelConfig.getString("otel.logs.exporter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ public class SmokeTestExtension
private final boolean useOtlpEndpoint;

public static SmokeTestExtension create() {
return builder().build();
SmokeTestExtensionBuilder b = builder();
String metricsToLogAnalytics =
System.getenv("APPLICATIONINSIGHTS_METRICS_TO_LOGANALYTICS_ENABLED");
if (metricsToLogAnalytics != null && metricsToLogAnalytics.equalsIgnoreCase("true")) {
b.setEnvVar("APPLICATIONINSIGHTS_METRICS_TO_LOGANALYTICS_ENABLED", "true");
}
return b.build();
}

public static SmokeTestExtensionBuilder builder() {
Expand Down