From 6db62860d654a2486dbbfc798935529f22e8437e Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 29 Aug 2025 11:07:00 -0700 Subject: [PATCH 1/5] enduser.id and enduser.pseudo.id --- .../applicationinsightsweb/UserContextInstrumentation.java | 2 +- .../src/test/java/ApplicationInsightsWebTest.java | 2 +- .../applicationinsights/smoketestapp/TestController.java | 1 + .../OpenTelemetryApiSupportControllerSpansEnabledTest.java | 3 ++- .../smoketest/OpenTelemetryApiSupportTest.java | 3 ++- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/agent/instrumentation/applicationinsights-web-2.3/src/main/java/io/opentelemetry/javaagent/instrumentation/applicationinsightsweb/UserContextInstrumentation.java b/agent/instrumentation/applicationinsights-web-2.3/src/main/java/io/opentelemetry/javaagent/instrumentation/applicationinsightsweb/UserContextInstrumentation.java index adeec540796..6363d883040 100644 --- a/agent/instrumentation/applicationinsights-web-2.3/src/main/java/io/opentelemetry/javaagent/instrumentation/applicationinsightsweb/UserContextInstrumentation.java +++ b/agent/instrumentation/applicationinsights-web-2.3/src/main/java/io/opentelemetry/javaagent/instrumentation/applicationinsightsweb/UserContextInstrumentation.java @@ -43,7 +43,7 @@ public static void methodEnter( @Advice.This UserContext userContext, @Advice.Argument(0) String name) { Span span = VirtualField.find(UserContext.class, Span.class).get(userContext); if (span != null) { - span.setAttribute("enduser.id", name); + span.setAttribute("enduser.pseudo.id", name); } } } diff --git a/agent/instrumentation/applicationinsights-web-2.3/src/test/java/ApplicationInsightsWebTest.java b/agent/instrumentation/applicationinsights-web-2.3/src/test/java/ApplicationInsightsWebTest.java index b7d0e1a2c0c..a8064d8ae83 100644 --- a/agent/instrumentation/applicationinsights-web-2.3/src/test/java/ApplicationInsightsWebTest.java +++ b/agent/instrumentation/applicationinsights-web-2.3/src/test/java/ApplicationInsightsWebTest.java @@ -69,7 +69,7 @@ void setRequestUser() { .hasAttributesSatisfyingExactly( equalTo(CodeIncubatingAttributes.CODE_NAMESPACE, "Code"), equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "setUser"), - equalTo(EnduserIncubatingAttributes.ENDUSER_ID, "myuser")), + equalTo(EnduserIncubatingAttributes.ENDUSER_PSEUDO_ID, "myuser")), span -> span.hasName("Code.internalSetUser") .hasKind(INTERNAL) diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java index f4e1ff7b1b0..3b98166641c 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java @@ -20,6 +20,7 @@ public String testApi() { Span.current().setAttribute("myattr1", "myvalue1"); Span.current().setAttribute("myattr2", "myvalue2"); Span.current().setAttribute("enduser.id", "myuser"); + Span.current().setAttribute("enduser.pseudo.id", "mypseudo"); Span.current().updateName("myspanname"); return "OK!"; } diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java index 1bc05995639..5b61d008f7a 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java @@ -54,7 +54,8 @@ void testApi() throws Exception { .isEqualTo("testroleinstance"); assertThat(telemetry.rddEnvelope1.getTags()) .hasEntrySatisfying("ai.internal.sdkVersion", v -> assertThat(v).startsWith("java:3.")); - assertThat(telemetry.rddEnvelope1.getTags()).containsEntry("ai.user.id", "myuser"); + assertThat(telemetry.rddEnvelope1.getTags()).containsEntry("ai.user.authUserId", "myuser"); + assertThat(telemetry.rddEnvelope1.getTags()).containsEntry("ai.user.id", "mypseudo"); SmokeTestExtension.assertParentChild( telemetry.rd, diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java index 0953e282707..04d78068b95 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java @@ -50,7 +50,8 @@ void testApi() throws Exception { assertThat(telemetry.rdEnvelope.getTags()) .hasEntrySatisfying("ai.internal.sdkVersion", v -> assertThat(v).startsWith("java:3.")); - assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.user.id", "myuser"); + assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.user.authUserId", "myuser"); + assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.user.id", "mypseudo"); } @Test From 343e99c00b70491378faa29c89744eddd4cb898b Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 28 Aug 2025 12:28:50 -0700 Subject: [PATCH 2/5] session.id --- .../applicationinsights/smoketestapp/TestController.java | 1 + .../OpenTelemetryApiSupportControllerSpansEnabledTest.java | 1 + .../smoketest/OpenTelemetryApiSupportTest.java | 1 + 3 files changed, 3 insertions(+) diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java index 3b98166641c..bf59ec2117e 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java @@ -21,6 +21,7 @@ public String testApi() { Span.current().setAttribute("myattr2", "myvalue2"); Span.current().setAttribute("enduser.id", "myuser"); Span.current().setAttribute("enduser.pseudo.id", "mypseudo"); + Span.current().setAttribute("session.id", "mysession"); Span.current().updateName("myspanname"); return "OK!"; } diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java index 5b61d008f7a..5d5578e3218 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java @@ -56,6 +56,7 @@ void testApi() throws Exception { .hasEntrySatisfying("ai.internal.sdkVersion", v -> assertThat(v).startsWith("java:3.")); assertThat(telemetry.rddEnvelope1.getTags()).containsEntry("ai.user.authUserId", "myuser"); assertThat(telemetry.rddEnvelope1.getTags()).containsEntry("ai.user.id", "mypseudo"); + assertThat(telemetry.rddEnvelope1.getTags()).containsEntry("ai.session.id", "mysession"); SmokeTestExtension.assertParentChild( telemetry.rd, diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java index 04d78068b95..bb90b290cec 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java @@ -52,6 +52,7 @@ void testApi() throws Exception { .hasEntrySatisfying("ai.internal.sdkVersion", v -> assertThat(v).startsWith("java:3.")); assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.user.authUserId", "myuser"); assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.user.id", "mypseudo"); + assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.session.id", "mysession"); } @Test From 0c8cf85e379c673ee13bd7534bb73b170efe0daf Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 29 Aug 2025 10:42:35 -0700 Subject: [PATCH 3/5] Remove dependency on autoconfigure SemanticAttributes copy --- .../configuration/ConfigurationBuilder.java | 60 ++++++++++--------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java index a420aebe94b..ed66c6aa00f 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java @@ -3,7 +3,6 @@ package com.microsoft.applicationinsights.agent.internal.configuration; -import com.azure.monitor.opentelemetry.autoconfigure.implementation.SemanticAttributes; import com.azure.monitor.opentelemetry.autoconfigure.implementation.statsbeat.RpAttachType; import com.azure.monitor.opentelemetry.autoconfigure.implementation.utils.HostName; import com.azure.monitor.opentelemetry.autoconfigure.implementation.utils.Strings; @@ -22,6 +21,13 @@ import com.microsoft.applicationinsights.agent.internal.configuration.Configuration.SamplingOverride; import com.microsoft.applicationinsights.agent.internal.diagnostics.DiagnosticsHelper; import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.semconv.ClientAttributes; +import io.opentelemetry.semconv.HttpAttributes; +import io.opentelemetry.semconv.NetworkAttributes; +import io.opentelemetry.semconv.ServerAttributes; +import io.opentelemetry.semconv.UrlAttributes; +import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes; +import io.opentelemetry.semconv.incubating.NetIncubatingAttributes; import java.io.IOException; import java.net.URL; import java.net.URLDecoder; @@ -359,44 +365,44 @@ private static void supportTelemetryProcessorsOldSemConv(Configuration config) { private static String mapAttributeKey(String oldAttributeKey) { String result = null; // Common attributes across HTTP client and server spans - if (oldAttributeKey.equals(SemanticAttributes.HTTP_METHOD.getKey())) { - result = SemanticAttributes.HTTP_REQUEST_METHOD.getKey(); - } else if (oldAttributeKey.equals(SemanticAttributes.HTTP_STATUS_CODE.getKey())) { - result = SemanticAttributes.HTTP_RESPONSE_STATUS_CODE.getKey(); + if (oldAttributeKey.equals(HttpIncubatingAttributes.HTTP_METHOD.getKey())) { + result = HttpAttributes.HTTP_REQUEST_METHOD.getKey(); + } else if (oldAttributeKey.equals(HttpIncubatingAttributes.HTTP_STATUS_CODE.getKey())) { + result = HttpAttributes.HTTP_RESPONSE_STATUS_CODE.getKey(); } else if (oldAttributeKey.startsWith("http.request.header.") || oldAttributeKey.startsWith("http.response.header.")) { result = oldAttributeKey.replace('_', '-'); - } else if (oldAttributeKey.equals(SemanticAttributes.NET_PROTOCOL_NAME.getKey())) { - result = SemanticAttributes.NETWORK_PROTOCOL_NAME.getKey(); - } else if (oldAttributeKey.equals(SemanticAttributes.NET_PROTOCOL_VERSION.getKey())) { - result = SemanticAttributes.NETWORK_PROTOCOL_VERSION.getKey(); - } else if (oldAttributeKey.equals(SemanticAttributes.NET_SOCK_PEER_ADDR.getKey())) { - result = SemanticAttributes.NETWORK_PEER_ADDRESS.getKey(); - } else if (oldAttributeKey.equals(SemanticAttributes.NET_SOCK_PEER_PORT.getKey())) { - result = SemanticAttributes.NETWORK_PEER_PORT.getKey(); + } else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_PROTOCOL_NAME.getKey())) { + result = NetworkAttributes.NETWORK_PROTOCOL_NAME.getKey(); + } else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_PROTOCOL_VERSION.getKey())) { + result = NetworkAttributes.NETWORK_PROTOCOL_VERSION.getKey(); + } else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_SOCK_PEER_ADDR.getKey())) { + result = NetworkAttributes.NETWORK_PEER_ADDRESS.getKey(); + } else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_SOCK_PEER_PORT.getKey())) { + result = NetworkAttributes.NETWORK_PEER_PORT.getKey(); } // HTTP client span attributes // http.url is handled via LazyHttpUrl - if (oldAttributeKey.equals(SemanticAttributes.HTTP_RESEND_COUNT.getKey())) { - result = SemanticAttributes.HTTP_REQUEST_RESEND_COUNT.getKey(); + if (oldAttributeKey.equals("http.resend_count")) { + result = HttpAttributes.HTTP_REQUEST_RESEND_COUNT.getKey(); // becomes available. - } else if (oldAttributeKey.equals(SemanticAttributes.NET_PEER_NAME.getKey())) { - result = SemanticAttributes.SERVER_ADDRESS.getKey(); - } else if (oldAttributeKey.equals(SemanticAttributes.NET_PEER_PORT.getKey())) { - result = SemanticAttributes.SERVER_PORT.getKey(); + } else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_PEER_NAME.getKey())) { + result = ServerAttributes.SERVER_ADDRESS.getKey(); + } else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_PEER_PORT.getKey())) { + result = ServerAttributes.SERVER_PORT.getKey(); } // HTTP server span attributes // http.target is handled via LazyHttpTarget - if (oldAttributeKey.equals(SemanticAttributes.HTTP_SCHEME.getKey())) { - result = SemanticAttributes.URL_SCHEME.getKey(); - } else if (oldAttributeKey.equals(SemanticAttributes.HTTP_CLIENT_IP.getKey())) { - result = SemanticAttributes.CLIENT_ADDRESS.getKey(); - } else if (oldAttributeKey.equals(SemanticAttributes.NET_HOST_NAME.getKey())) { - result = SemanticAttributes.SERVER_ADDRESS.getKey(); - } else if (oldAttributeKey.equals(SemanticAttributes.NET_HOST_PORT.getKey())) { - result = SemanticAttributes.SERVER_PORT.getKey(); + if (oldAttributeKey.equals(HttpIncubatingAttributes.HTTP_SCHEME.getKey())) { + result = UrlAttributes.URL_SCHEME.getKey(); + } else if (oldAttributeKey.equals(HttpIncubatingAttributes.HTTP_CLIENT_IP.getKey())) { + result = ClientAttributes.CLIENT_ADDRESS.getKey(); + } else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_HOST_NAME.getKey())) { + result = ServerAttributes.SERVER_ADDRESS.getKey(); + } else if (oldAttributeKey.equals(NetIncubatingAttributes.NET_HOST_PORT.getKey())) { + result = ServerAttributes.SERVER_PORT.getKey(); } if (result == null) { From 474f8d0164b0ffe5e5e27aca90770f41b4648e68 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 29 Aug 2025 11:05:29 -0700 Subject: [PATCH 4/5] Update to Azure SDK latest snapshot --- .github/workflows/build-common.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-common.yml b/.github/workflows/build-common.yml index 3a744dcb52c..c01397f634a 100644 --- a/.github/workflows/build-common.yml +++ b/.github/workflows/build-common.yml @@ -10,7 +10,7 @@ on: env: # set this to : to build and test with an unreleased # version of the azure-monitor-opentelemetry-autoconfigure dependency - AZURE_MONITOR_OPENTELEMETRY_AUTOCONFIGURE_SNAPSHOT: + AZURE_MONITOR_OPENTELEMETRY_AUTOCONFIGURE_SNAPSHOT: trask/azure-sdk-for-java:semconv2 jobs: spotless: From 5bc1745674e0e9aac4130a407588e327a04b6b66 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 29 Aug 2025 13:39:52 -0700 Subject: [PATCH 5/5] test --- .github/workflows/build-common.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-common.yml b/.github/workflows/build-common.yml index c01397f634a..15bf7e63633 100644 --- a/.github/workflows/build-common.yml +++ b/.github/workflows/build-common.yml @@ -10,7 +10,7 @@ on: env: # set this to : to build and test with an unreleased # version of the azure-monitor-opentelemetry-autoconfigure dependency - AZURE_MONITOR_OPENTELEMETRY_AUTOCONFIGURE_SNAPSHOT: trask/azure-sdk-for-java:semconv2 + AZURE_MONITOR_OPENTELEMETRY_AUTOCONFIGURE_SNAPSHOT: Azure/azure-sdk-for-java:main jobs: spotless: