Skip to content

Commit 1ea84d8

Browse files
harsimargithub-actions[bot]
authored andcommitted
check for exporter env vars and pass to metricdatamapper
1 parent 86fb6b1 commit 1ea84d8

File tree

1 file changed

+10
-3
lines changed
  • agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init

1 file changed

+10
-3
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/SecondEntryPoint.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
7070
import io.opentelemetry.sdk.trace.export.SpanExporter;
7171
import io.opentelemetry.sdk.trace.samplers.SamplingDecision;
72+
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
7273
import java.io.File;
7374
import java.util.ArrayList;
7475
import java.util.Collections;
@@ -274,7 +275,7 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
274275
(metricExporter, configProperties) -> {
275276
if (metricExporter
276277
instanceof AzureMonitorMetricExporterProvider.MarkerMetricExporter) {
277-
return buildMetricExporter(configuration, telemetryClient, metricFilters);
278+
return buildMetricExporter(configuration, telemetryClient, metricFilters, configProperties);
278279
} else {
279280
return metricExporter;
280281
}
@@ -365,10 +366,16 @@ private static SpanExporter buildTraceExporter(
365366
private static MetricExporter buildMetricExporter(
366367
Configuration configuration,
367368
TelemetryClient telemetryClient,
368-
List<MetricFilter> metricFilters) {
369+
List<MetricFilter> metricFilters, ConfigProperties configProperties) {
370+
371+
String otelMetricsEndpoint = configProperties.getString("otel.metrics.exporter.otlp.endpoint");
372+
String otelMetricsExporter = configProperties.getString("otel.metrics.exporter");
373+
boolean otlpEnabled = (otelMetricsExporter != null && !otelMetricsExporter.isEmpty()) &&
374+
(otelMetricsEndpoint != null && !otelMetricsEndpoint.isEmpty());
375+
369376
MetricDataMapper mapper =
370377
new MetricDataMapper(
371-
telemetryClient::populateDefaults, configuration.preview.captureHttpServer4xxAsError);
378+
telemetryClient::populateDefaults, configuration.preview.captureHttpServer4xxAsError, otlpEnabled);
372379
return new AgentMetricExporter(
373380
metricFilters, mapper, telemetryClient.getMetricsBatchItemProcessor());
374381
}

0 commit comments

Comments
 (0)