Skip to content

Commit e0d8227

Browse files
committed
fixing some existing tests (not done yet), merge in sdk update change for testing
1 parent 98122ef commit e0d8227

File tree

10 files changed

+56
-41
lines changed

10 files changed

+56
-41
lines changed

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: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ public class SecondEntryPoint
9090
private static final ClientLogger startupLogger =
9191
new ClientLogger("com.microsoft.applicationinsights.agent");
9292
private static File tempDir;
93-
94-
private static final String METRICS_TO_LOG_ANALYTICS_ENABLED =
95-
"APPLICATIONINSIGHTS_METRICS_TO_LOGANALYTICS_ENABLED";
93+
private static final String SENT_TO_AMW = "SENT_TO_AMW";
9694

9795
@Nullable private static AzureMonitorLogFilteringProcessor logFilteringProcessor;
9896

@@ -376,12 +374,12 @@ private static MetricExporter buildMetricExporter(
376374
boolean otlpEnabled = (otelMetricsExporter != null && !otelMetricsExporter.isEmpty()) &&
377375
(otelMetricsEndpoint != null && !otelMetricsEndpoint.isEmpty());
378376

379-
String metricsToLAEnvVar = System.getenv(METRICS_TO_LOG_ANALYTICS_ENABLED);
380-
boolean metricsToLAEnabled = metricsToLAEnvVar == null || "true".equalsIgnoreCase(metricsToLAEnvVar);
381-
377+
// Set system property that MetricDataMapper can read
378+
System.setProperty(SENT_TO_AMW, Boolean.toString(otlpEnabled));
379+
382380
MetricDataMapper mapper =
383381
new MetricDataMapper(
384-
telemetryClient::populateDefaults, configuration.preview.captureHttpServer4xxAsError, otlpEnabled, metricsToLAEnabled);
382+
telemetryClient::populateDefaults, configuration.preview.captureHttpServer4xxAsError);
385383
return new AgentMetricExporter(
386384
metricFilters, mapper, telemetryClient.getMetricsBatchItemProcessor());
387385
}

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.psuedo.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)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name=azure-monitor-opentelemetry-autoconfigure
2+
version=1.4.0-beta.1

smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private static void validateMetricData(
175175
String expectedSuccess = Integer.parseInt(resultCode) < 400 ? "True" : "False";
176176
Map<String, String> properties = metricData.getProperties();
177177
if ("client".equals(type)) {
178-
assertThat(properties).hasSize(9);
178+
assertThat(properties).hasSize(10);
179179
assertThat(properties.get("_MS.MetricId")).isEqualTo("dependencies/duration");
180180
assertThat(properties.get("dependency/resultCode")).isEqualTo(resultCode);
181181
assertThat(properties.get("Dependency.Success")).isEqualTo(expectedSuccess);
@@ -184,7 +184,7 @@ private static void validateMetricData(
184184
assertThat(properties.get("Dependency.Type")).isEqualTo("Http");
185185
assertThat(properties.get("operation/synthetic")).isEqualTo("False");
186186
} else {
187-
assertThat(properties).hasSize(7);
187+
assertThat(properties).hasSize(8);
188188
assertThat(properties.get("_MS.MetricId")).isEqualTo("requests/duration");
189189
assertThat(properties.get("request/resultCode")).isEqualTo(resultCode);
190190
assertThat(properties.get("Request.Success")).isEqualTo(expectedSuccess);
@@ -193,6 +193,7 @@ private static void validateMetricData(
193193
assertThat(properties.get("cloud/roleInstance")).isEqualTo("testroleinstance");
194194
assertThat(properties.get("cloud/roleName")).isEqualTo("testrolename");
195195
assertThat(properties.get("_MS.IsAutocollected")).isEqualTo("True");
196+
assertThat(properties.get("_MS.SentToAMW")).isEqualTo("false");
196197
}
197198

198199
@Environment(TOMCAT_8_JAVA_8)

smoke-tests/apps/OpenTelemetryApiSupport/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public String root() {
1919
public String testApi() {
2020
Span.current().setAttribute("myattr1", "myvalue1");
2121
Span.current().setAttribute("myattr2", "myvalue2");
22-
Span.current().setAttribute("enduser.id", "myuser");
22+
Span.current().setAttribute("enduser.pseudo.id", "myuser");
23+
Span.current().setAttribute("session.id", "mysession");
2324
Span.current().updateName("myspanname");
2425
return "OK!";
2526
}

smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ void testApi() throws Exception {
5454
.isEqualTo("testroleinstance");
5555
assertThat(telemetry.rddEnvelope1.getTags())
5656
.hasEntrySatisfying("ai.internal.sdkVersion", v -> assertThat(v).startsWith("java:3."));
57-
assertThat(telemetry.rddEnvelope1.getTags()).containsEntry("ai.user.id", "myuser");
57+
assertThat(telemetry.rddEnvelope1.getTags()).containsEntry("ai.user.authUserId", "myuser");
58+
assertThat(telemetry.rddEnvelope1.getTags()).containsEntry("ai.user.id", "mypseudo");
59+
assertThat(telemetry.rddEnvelope1.getTags()).containsEntry("ai.session.id", "mysession");
5860

5961
SmokeTestExtension.assertParentChild(
6062
telemetry.rd,

smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ void testApi() throws Exception {
5050

5151
assertThat(telemetry.rdEnvelope.getTags())
5252
.hasEntrySatisfying("ai.internal.sdkVersion", v -> assertThat(v).startsWith("java:3."));
53-
assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.user.id", "myuser");
53+
assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.user.authUserId", "myuser");
54+
assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.user.id", "mypseudo");
55+
assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.session.id", "mysession");
5456
}
5557

5658
@Test

smoke-tests/apps/OpenTelemetryMetric/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryMetricTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ private void validateCounterMetric(String name) throws Exception {
189189
assertThat(properties1).containsEntry("tag2", "def");
190190
assertThat(properties1).containsEntry("name", "apple");
191191
assertThat(properties1).containsEntry("color", "green");
192+
assertThat(properties1).containsEntry("_MS.SentToAMW", "false");
192193

193194
// validate tags
194195
Map<String, String> tags2 = envelope2.getTags();
@@ -211,6 +212,7 @@ private void validateCounterMetric(String name) throws Exception {
211212
assertThat(properties2).containsEntry("tag2", "def");
212213
assertThat(properties2).containsEntry("name", "apple");
213214
assertThat(properties2).containsEntry("color", "red");
215+
assertThat(properties2).containsEntry("_MS.SentToAMW", "false");
214216

215217
// validate tags
216218
Map<String, String> tags3 = envelope3.getTags();
@@ -233,6 +235,7 @@ private void validateCounterMetric(String name) throws Exception {
233235
assertThat(properties3).containsEntry("tag2", "def");
234236
assertThat(properties3).containsEntry("name", "lemon");
235237
assertThat(properties3).containsEntry("color", "yellow");
238+
assertThat(properties3).containsEntry("_MS.SentToAMW", "false");
236239
}
237240

238241
@Environment(TOMCAT_8_JAVA_8)

0 commit comments

Comments
 (0)