Skip to content

Commit d0d252a

Browse files
harsimartraskxiang17
authored
Read environment variables for AKS metrics otlp support (#4458)
Co-authored-by: Trask Stalnaker <[email protected]> Co-authored-by: Sean Li <[email protected]>
1 parent 5b97df6 commit d0d252a

File tree

27 files changed

+493
-134
lines changed

27 files changed

+493
-134
lines changed

.github/scripts/build-azure-monitor-dependency.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ echo "Installed version: $INSTALLED_VERSION"
3232
# Clean up
3333
echo "Cleaning up..."
3434
cd ..
35-
rm -rf azure-sdk-temp
35+
if [ -n "$CI" ]; then
36+
rm -rf azure-sdk-temp
37+
fi
3638

3739
# Update dependency versions in the current project
3840
echo "Updating dependency versions in project files..."
@@ -52,10 +54,11 @@ fi
5254
./gradlew resolveAndLockAll --write-locks
5355
./gradlew generateLicenseReport --no-build-cache
5456

55-
# this is needed to make license report pass
56-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
57-
git config user.name "github-actions[bot]"
58-
git commit -a -m "update azure-monitor-opentelemetry-autoconfigure dependency to $INSTALLED_VERSION"
57+
if [ -n "$CI" ]; then
58+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
59+
git config user.name "github-actions[bot]"
60+
git commit -a -m "update azure-monitor-opentelemetry-autoconfigure dependency to $INSTALLED_VERSION"
61+
fi
5962

6063
echo "azure-monitor-opentelemetry-autoconfigure dependency build completed successfully"
6164
echo "All project files updated to use version: $INSTALLED_VERSION"

agent/agent-tooling/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies {
2121
implementation(project(":agent:agent-profiler:agent-diagnostics"))
2222
implementation(project(":etw:java"))
2323

24-
implementation("com.azure:azure-monitor-opentelemetry-autoconfigure:1.3.0")
24+
implementation("com.azure:azure-monitor-opentelemetry-autoconfigure:1.4.0")
2525
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-bootstrap")
2626
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-tooling")
2727
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-tooling-java9")

agent/agent-tooling/gradle.lockfile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ ch.qos.logback.contrib:logback-json-classic:0.1.5=runtimeClasspath
55
ch.qos.logback.contrib:logback-json-core:0.1.5=runtimeClasspath
66
ch.qos.logback:logback-classic:1.3.15=runtimeClasspath
77
ch.qos.logback:logback-core:1.3.15=runtimeClasspath
8-
com.azure:azure-core-http-netty:1.16.0=runtimeClasspath
9-
com.azure:azure-core:1.56.0=runtimeClasspath
8+
com.azure:azure-core-http-netty:1.16.1=runtimeClasspath
9+
com.azure:azure-core:1.56.1=runtimeClasspath
1010
com.azure:azure-identity:1.17.0=runtimeClasspath
1111
com.azure:azure-json:1.5.0=runtimeClasspath
12-
com.azure:azure-monitor-opentelemetry-autoconfigure:1.3.0=runtimeClasspath
12+
com.azure:azure-monitor-opentelemetry-autoconfigure:1.4.0=runtimeClasspath
1313
com.azure:azure-sdk-bom:1.2.38=runtimeClasspath
1414
com.azure:azure-storage-blob:12.31.2=runtimeClasspath
1515
com.azure:azure-storage-common:12.30.2=runtimeClasspath
@@ -48,8 +48,8 @@ io.netty:netty-resolver-dns-classes-macos:4.2.4.Final=runtimeClasspath
4848
io.netty:netty-resolver-dns-native-macos:4.2.4.Final=runtimeClasspath
4949
io.netty:netty-resolver-dns:4.2.4.Final=runtimeClasspath
5050
io.netty:netty-resolver:4.2.4.Final=runtimeClasspath
51-
io.netty:netty-tcnative-boringssl-static:2.0.72.Final=runtimeClasspath
52-
io.netty:netty-tcnative-classes:2.0.72.Final=runtimeClasspath
51+
io.netty:netty-tcnative-boringssl-static:2.0.73.Final=runtimeClasspath
52+
io.netty:netty-tcnative-classes:2.0.73.Final=runtimeClasspath
5353
io.netty:netty-transport-classes-epoll:4.2.4.Final=runtimeClasspath
5454
io.netty:netty-transport-classes-kqueue:4.2.4.Final=runtimeClasspath
5555
io.netty:netty-transport-native-epoll:4.2.4.Final=runtimeClasspath
@@ -71,10 +71,9 @@ io.opentelemetry:opentelemetry-sdk-logs:1.53.0=runtimeClasspath
7171
io.opentelemetry:opentelemetry-sdk-metrics:1.53.0=runtimeClasspath
7272
io.opentelemetry:opentelemetry-sdk-trace:1.53.0=runtimeClasspath
7373
io.opentelemetry:opentelemetry-sdk:1.53.0=runtimeClasspath
74-
io.opentelemetry:opentelemetry-semconv:0.14.1=runtimeClasspath
75-
io.projectreactor.netty:reactor-netty-core:1.2.8=runtimeClasspath
76-
io.projectreactor.netty:reactor-netty-http:1.2.8=runtimeClasspath
77-
io.projectreactor:reactor-core:3.7.8=runtimeClasspath
74+
io.projectreactor.netty:reactor-netty-core:1.2.9=runtimeClasspath
75+
io.projectreactor.netty:reactor-netty-http:1.2.9=runtimeClasspath
76+
io.projectreactor:reactor-core:3.7.9=runtimeClasspath
7877
net.java.dev.jna:jna-platform:5.17.0=runtimeClasspath
7978
net.java.dev.jna:jna:5.17.0=runtimeClasspath
8079
net.minidev:accessors-smart:2.5.2=runtimeClasspath

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
package com.microsoft.applicationinsights.agent.internal.configuration;
55

6-
import com.azure.monitor.opentelemetry.autoconfigure.implementation.SemanticAttributes;
76
import com.azure.monitor.opentelemetry.autoconfigure.implementation.statsbeat.RpAttachType;
87
import com.azure.monitor.opentelemetry.autoconfigure.implementation.utils.HostName;
98
import com.azure.monitor.opentelemetry.autoconfigure.implementation.utils.Strings;
@@ -22,6 +21,13 @@
2221
import com.microsoft.applicationinsights.agent.internal.configuration.Configuration.SamplingOverride;
2322
import com.microsoft.applicationinsights.agent.internal.diagnostics.DiagnosticsHelper;
2423
import io.opentelemetry.api.common.AttributeKey;
24+
import io.opentelemetry.semconv.ClientAttributes;
25+
import io.opentelemetry.semconv.HttpAttributes;
26+
import io.opentelemetry.semconv.NetworkAttributes;
27+
import io.opentelemetry.semconv.ServerAttributes;
28+
import io.opentelemetry.semconv.UrlAttributes;
29+
import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes;
30+
import io.opentelemetry.semconv.incubating.NetIncubatingAttributes;
2531
import java.io.IOException;
2632
import java.net.URL;
2733
import java.net.URLDecoder;
@@ -359,44 +365,44 @@ private static void supportTelemetryProcessorsOldSemConv(Configuration config) {
359365
private static String mapAttributeKey(String oldAttributeKey) {
360366
String result = null;
361367
// Common attributes across HTTP client and server spans
362-
if (oldAttributeKey.equals(SemanticAttributes.HTTP_METHOD.getKey())) {
363-
result = SemanticAttributes.HTTP_REQUEST_METHOD.getKey();
364-
} else if (oldAttributeKey.equals(SemanticAttributes.HTTP_STATUS_CODE.getKey())) {
365-
result = SemanticAttributes.HTTP_RESPONSE_STATUS_CODE.getKey();
368+
if (oldAttributeKey.equals(HttpIncubatingAttributes.HTTP_METHOD.getKey())) {
369+
result = HttpAttributes.HTTP_REQUEST_METHOD.getKey();
370+
} else if (oldAttributeKey.equals(HttpIncubatingAttributes.HTTP_STATUS_CODE.getKey())) {
371+
result = HttpAttributes.HTTP_RESPONSE_STATUS_CODE.getKey();
366372
} else if (oldAttributeKey.startsWith("http.request.header.")
367373
|| oldAttributeKey.startsWith("http.response.header.")) {
368374
result = oldAttributeKey.replace('_', '-');
369-
} else if (oldAttributeKey.equals(SemanticAttributes.NET_PROTOCOL_NAME.getKey())) {
370-
result = SemanticAttributes.NETWORK_PROTOCOL_NAME.getKey();
371-
} else if (oldAttributeKey.equals(SemanticAttributes.NET_PROTOCOL_VERSION.getKey())) {
372-
result = SemanticAttributes.NETWORK_PROTOCOL_VERSION.getKey();
373-
} else if (oldAttributeKey.equals(SemanticAttributes.NET_SOCK_PEER_ADDR.getKey())) {
374-
result = SemanticAttributes.NETWORK_PEER_ADDRESS.getKey();
375-
} else if (oldAttributeKey.equals(SemanticAttributes.NET_SOCK_PEER_PORT.getKey())) {
376-
result = SemanticAttributes.NETWORK_PEER_PORT.getKey();
375+
} else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_PROTOCOL_NAME.getKey())) {
376+
result = NetworkAttributes.NETWORK_PROTOCOL_NAME.getKey();
377+
} else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_PROTOCOL_VERSION.getKey())) {
378+
result = NetworkAttributes.NETWORK_PROTOCOL_VERSION.getKey();
379+
} else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_SOCK_PEER_ADDR.getKey())) {
380+
result = NetworkAttributes.NETWORK_PEER_ADDRESS.getKey();
381+
} else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_SOCK_PEER_PORT.getKey())) {
382+
result = NetworkAttributes.NETWORK_PEER_PORT.getKey();
377383
}
378384

379385
// HTTP client span attributes
380386
// http.url is handled via LazyHttpUrl
381-
if (oldAttributeKey.equals(SemanticAttributes.HTTP_RESEND_COUNT.getKey())) {
382-
result = SemanticAttributes.HTTP_REQUEST_RESEND_COUNT.getKey();
387+
if (oldAttributeKey.equals("http.resend_count")) {
388+
result = HttpAttributes.HTTP_REQUEST_RESEND_COUNT.getKey();
383389
// becomes available.
384-
} else if (oldAttributeKey.equals(SemanticAttributes.NET_PEER_NAME.getKey())) {
385-
result = SemanticAttributes.SERVER_ADDRESS.getKey();
386-
} else if (oldAttributeKey.equals(SemanticAttributes.NET_PEER_PORT.getKey())) {
387-
result = SemanticAttributes.SERVER_PORT.getKey();
390+
} else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_PEER_NAME.getKey())) {
391+
result = ServerAttributes.SERVER_ADDRESS.getKey();
392+
} else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_PEER_PORT.getKey())) {
393+
result = ServerAttributes.SERVER_PORT.getKey();
388394
}
389395

390396
// HTTP server span attributes
391397
// http.target is handled via LazyHttpTarget
392-
if (oldAttributeKey.equals(SemanticAttributes.HTTP_SCHEME.getKey())) {
393-
result = SemanticAttributes.URL_SCHEME.getKey();
394-
} else if (oldAttributeKey.equals(SemanticAttributes.HTTP_CLIENT_IP.getKey())) {
395-
result = SemanticAttributes.CLIENT_ADDRESS.getKey();
396-
} else if (oldAttributeKey.equals(SemanticAttributes.NET_HOST_NAME.getKey())) {
397-
result = SemanticAttributes.SERVER_ADDRESS.getKey();
398-
} else if (oldAttributeKey.equals(SemanticAttributes.NET_HOST_PORT.getKey())) {
399-
result = SemanticAttributes.SERVER_PORT.getKey();
398+
if (oldAttributeKey.equals(HttpIncubatingAttributes.HTTP_SCHEME.getKey())) {
399+
result = UrlAttributes.URL_SCHEME.getKey();
400+
} else if (oldAttributeKey.equals(HttpIncubatingAttributes.HTTP_CLIENT_IP.getKey())) {
401+
result = ClientAttributes.CLIENT_ADDRESS.getKey();
402+
} else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_HOST_NAME.getKey())) {
403+
result = ServerAttributes.SERVER_ADDRESS.getKey();
404+
} else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_HOST_PORT.getKey())) {
405+
result = ServerAttributes.SERVER_PORT.getKey();
400406
}
401407

402408
if (result == null) {

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder;
5656
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer;
5757
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
58+
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
5859
import io.opentelemetry.sdk.autoconfigure.spi.internal.AutoConfigureListener;
5960
import io.opentelemetry.sdk.common.CompletableResultCode;
6061
import io.opentelemetry.sdk.logs.LogRecordProcessor;
@@ -274,7 +275,8 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
274275
(metricExporter, configProperties) -> {
275276
if (metricExporter
276277
instanceof AzureMonitorMetricExporterProvider.MarkerMetricExporter) {
277-
return buildMetricExporter(configuration, telemetryClient, metricFilters);
278+
return buildMetricExporter(
279+
configuration, telemetryClient, metricFilters, configProperties);
278280
} else {
279281
return metricExporter;
280282
}
@@ -365,10 +367,20 @@ private static SpanExporter buildTraceExporter(
365367
private static MetricExporter buildMetricExporter(
366368
Configuration configuration,
367369
TelemetryClient telemetryClient,
368-
List<MetricFilter> metricFilters) {
370+
List<MetricFilter> metricFilters,
371+
ConfigProperties configProperties) {
372+
373+
String otelMetricsEndpoint = configProperties.getString("otel.exporter.otlp.metrics.endpoint");
374+
String otelMetricsExporter = configProperties.getString("otel.metrics.exporter");
375+
Boolean otlpEnabled =
376+
(otelMetricsExporter != null && !otelMetricsExporter.isEmpty())
377+
&& (otelMetricsEndpoint != null && !otelMetricsEndpoint.isEmpty());
378+
369379
MetricDataMapper mapper =
370380
new MetricDataMapper(
371-
telemetryClient::populateDefaults, configuration.preview.captureHttpServer4xxAsError);
381+
telemetryClient::populateDefaults,
382+
configuration.preview.captureHttpServer4xxAsError,
383+
otlpEnabled);
372384
return new AgentMetricExporter(
373385
metricFilters, mapper, telemetryClient.getMetricsBatchItemProcessor());
374386
}

agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/PreAggregatedMetricsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void generateHttpClientMetrics() {
136136
MetricTelemetryBuilder builder = MetricTelemetryBuilder.create();
137137
MetricData metricData = metricDataCollection.iterator().next();
138138
MetricDataMapper.updateMetricPointBuilder(
139-
builder, metricData, metricData.getData().getPoints().iterator().next(), true, true);
139+
builder, metricData, metricData.getData().getPoints().iterator().next(), true, true, null);
140140
TelemetryItem telemetryItem = builder.build();
141141
MetricsData metricsData = (MetricsData) telemetryItem.getData().getBaseData();
142142

@@ -211,7 +211,7 @@ void generateRpcClientMetrics() {
211211
MetricTelemetryBuilder builder = MetricTelemetryBuilder.create();
212212
MetricData metricData = metricDataCollection.iterator().next();
213213
MetricDataMapper.updateMetricPointBuilder(
214-
builder, metricData, metricData.getData().getPoints().iterator().next(), true, true);
214+
builder, metricData, metricData.getData().getPoints().iterator().next(), true, true, null);
215215
TelemetryItem telemetryItem = builder.build();
216216
MetricsData metricsData = (MetricsData) telemetryItem.getData().getBaseData();
217217

@@ -291,7 +291,7 @@ void generateHttpServerMetrics() {
291291
MetricTelemetryBuilder builder = MetricTelemetryBuilder.create();
292292
MetricData metricData = target;
293293
MetricDataMapper.updateMetricPointBuilder(
294-
builder, metricData, metricData.getData().getPoints().iterator().next(), true, true);
294+
builder, metricData, metricData.getData().getPoints().iterator().next(), true, true, null);
295295
TelemetryItem telemetryItem = builder.build();
296296
MetricsData metricsData = (MetricsData) telemetryItem.getData().getBaseData();
297297

agent/instrumentation/applicationinsights-web-2.3/src/main/java/io/opentelemetry/javaagent/instrumentation/applicationinsightsweb/UserContextInstrumentation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static void methodEnter(
4343
@Advice.This UserContext userContext, @Advice.Argument(0) String name) {
4444
Span span = VirtualField.find(UserContext.class, Span.class).get(userContext);
4545
if (span != null) {
46-
span.setAttribute("enduser.id", name);
46+
span.setAttribute("enduser.pseudo.id", name);
4747
}
4848
}
4949
}

agent/instrumentation/applicationinsights-web-2.3/src/test/java/ApplicationInsightsWebTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void setRequestUser() {
6969
.hasAttributesSatisfyingExactly(
7070
equalTo(CodeIncubatingAttributes.CODE_NAMESPACE, "Code"),
7171
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "setUser"),
72-
equalTo(EnduserIncubatingAttributes.ENDUSER_ID, "myuser")),
72+
equalTo(EnduserIncubatingAttributes.ENDUSER_PSEUDO_ID, "myuser")),
7373
span ->
7474
span.hasName("Code.internalSetUser")
7575
.hasKind(INTERNAL)

0 commit comments

Comments
 (0)