Skip to content

Commit c2f7701

Browse files
authored
Emit stable OpenTelemetry HTTP metrics (#3676)
1 parent 649ae37 commit c2f7701

File tree

13 files changed

+57
-75
lines changed

13 files changed

+57
-75
lines changed

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-exporter:1.0.0-beta.21")
24+
implementation("com.azure:azure-monitor-opentelemetry-exporter:1.0.0-beta.22")
2525
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-bootstrap")
2626
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-tooling")
2727
compileOnly("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-common-bootstrap")

agent/agent-tooling/gradle.lockfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ com.azure:azure-core-http-netty:1.14.2=runtimeClasspath
99
com.azure:azure-core:1.48.0=runtimeClasspath
1010
com.azure:azure-identity:1.12.1=runtimeClasspath
1111
com.azure:azure-json:1.1.0=runtimeClasspath
12-
com.azure:azure-monitor-opentelemetry-exporter:1.0.0-beta.21=runtimeClasspath
12+
com.azure:azure-monitor-opentelemetry-exporter:1.0.0-beta.22=runtimeClasspath
1313
com.azure:azure-sdk-bom:1.2.23=runtimeClasspath
1414
com.azure:azure-storage-blob:12.25.4=runtimeClasspath
1515
com.azure:azure-storage-common:12.24.4=runtimeClasspath

licenses/more-licenses.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# agent
33
## Dependency License Report
4-
_2024-05-06 19:10:34 UTC_
4+
_2024-05-06 12:02:06 PDT_
55
## Apache License, Version 2.0
66

77
**1** **Group:** `com.fasterxml.jackson.core` **Name:** `jackson-annotations` **Version:** `2.17.1`
@@ -350,7 +350,7 @@ _2024-05-06 19:10:34 UTC_
350350
> - **POM Project URL**: [https://github.com/Azure/azure-sdk-for-java](https://github.com/Azure/azure-sdk-for-java)
351351
> - **POM License**: MIT License - [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT)
352352
353-
**67** **Group:** `com.azure` **Name:** `azure-monitor-opentelemetry-exporter` **Version:** `1.0.0-beta.21`
353+
**67** **Group:** `com.azure` **Name:** `azure-monitor-opentelemetry-exporter` **Version:** `1.0.0-beta.22`
354354
> - **POM License**: MIT License - [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT)
355355
356356
**68** **Group:** `com.azure` **Name:** `azure-storage-blob` **Version:** `12.25.4`

smoke-tests/apps/ConnectionStringOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ConnectionStringOverridesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ private static void testApp(String iKey) throws Exception {
9898
// and metrics too
9999

100100
List<Envelope> clientMetrics =
101-
testing.mockedIngestion.waitForMetricItems("http.client.request.duration", 1);
101+
testing.mockedIngestion.waitForStandardMetricItems("dependencies/duration", 1);
102102
List<Envelope> serverMetrics =
103-
testing.mockedIngestion.waitForMetricItems("http.server.request.duration", 1);
103+
testing.mockedIngestion.waitForStandardMetricItems("requests/duration", 1);
104104

105105
verifyHttpClientPreAggregatedMetrics(clientMetrics, iKey);
106106
verifyHttpServerPreAggregatedMetrics(serverMetrics, iKey);

smoke-tests/apps/DetectUnexpectedOtelMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DetectUnexpectedOtelMetricsTest.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,10 @@
1414
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1515

1616
import com.microsoft.applicationinsights.smoketest.schemav2.Data;
17-
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
1817
import com.microsoft.applicationinsights.smoketest.schemav2.MetricData;
1918
import java.util.ArrayList;
2019
import java.util.List;
21-
import java.util.concurrent.ExecutionException;
22-
import java.util.concurrent.TimeUnit;
2320
import java.util.concurrent.TimeoutException;
24-
import java.util.function.Predicate;
2521
import org.junit.jupiter.api.Test;
2622
import org.junit.jupiter.api.extension.RegisterExtension;
2723

@@ -47,6 +43,8 @@ abstract class DetectUnexpectedOtelMetricsTest {
4743
EXPECTED_METRIC_NAMES.add("% Of Max Heap Memory Used");
4844
EXPECTED_METRIC_NAMES.add("GC Total Count");
4945
EXPECTED_METRIC_NAMES.add("GC Total Time");
46+
EXPECTED_METRIC_NAMES.add("http.server.request.duration");
47+
EXPECTED_METRIC_NAMES.add("http.client.request.duration");
5048
}
5149

5250
@Test
@@ -66,29 +64,6 @@ void testApp() throws Exception {
6664
.isInstanceOf(TimeoutException.class);
6765
}
6866

69-
// wait for at least one unexpected otel metrics for failure case or timeout for success
70-
public List<Envelope> waitForItemsUnexpectedOtelMetric(String type, Predicate<Envelope> condition)
71-
throws InterruptedException, ExecutionException, TimeoutException {
72-
return testing.mockedIngestion.waitForItems(
73-
new Predicate<Envelope>() {
74-
@Override
75-
public boolean test(Envelope input) {
76-
if (!input.getData().getBaseType().equals(type)) {
77-
return false;
78-
}
79-
MetricData md = (MetricData) ((Data<?>) input.getData()).getBaseData();
80-
if ("_OTELRESOURCE_".equals(md.getMetrics().get(0).getName())
81-
|| md.getProperties().containsKey("_MS.MetricId")) {
82-
return false;
83-
}
84-
return condition.test(input);
85-
}
86-
},
87-
1,
88-
10,
89-
TimeUnit.SECONDS);
90-
}
91-
9267
@Environment(TOMCAT_8_JAVA_8)
9368
static class Tomcat8Java8Test extends DetectUnexpectedOtelMetricsTest {}
9469

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ private void testHttpUrlConnectionAndSynthetic(boolean synthetic) throws Excepti
4545
verifyHttpclientRequestsAndDependencies("https://mock.codes/200?q=spaces%20test");
4646

4747
List<Envelope> clientMetrics =
48-
testing.mockedIngestion.waitForMetricItems("http.client.request.duration", 3);
48+
testing.mockedIngestion.waitForStandardMetricItems("dependencies/duration", 3);
4949
List<Envelope> serverMetrics =
50-
testing.mockedIngestion.waitForMetricItems("http.server.request.duration", 1);
50+
testing.mockedIngestion.waitForStandardMetricItems("requests/duration", 1);
5151

5252
verifyHttpClientPreAggregatedMetrics(clientMetrics);
5353
verifyHttpServerPreAggregatedMetrics(serverMetrics, synthetic);

smoke-tests/apps/InstrumentationKeyOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/InstrumentationKeyOverridesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ private static void testApp(String iKey) throws Exception {
8888
// and metrics too
8989

9090
List<Envelope> clientMetrics =
91-
testing.mockedIngestion.waitForMetricItems("http.client.request.duration", 1);
91+
testing.mockedIngestion.waitForStandardMetricItems("dependencies/duration", 1);
9292
List<Envelope> serverMetrics =
93-
testing.mockedIngestion.waitForMetricItems("http.server.request.duration", 1);
93+
testing.mockedIngestion.waitForStandardMetricItems("requests/duration", 1);
9494

9595
verifyHttpClientPreAggregatedMetrics(clientMetrics, iKey);
9696
verifyHttpServerPreAggregatedMetrics(serverMetrics, iKey);

smoke-tests/apps/OtlpMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OtlpTest.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,21 @@ public void testOtlpTelemetry() throws Exception {
4646
MetricData metricData = (MetricData) ((Data<?>) metricEnvelope.getData()).getBaseData();
4747
assertThat(metricData.getMetrics().get(0).getName()).isEqualTo("histogram-test-otlp-exporter");
4848

49+
// verify stable otel metric sent to Application Insights endpoint
50+
List<Envelope> stableOtelMetrics =
51+
testing.mockedIngestion.waitForItems("MetricData", OtlpTest::isStableOtelMetric, 1);
52+
Envelope stableOtelMetricEnvelope = stableOtelMetrics.get(0);
53+
assertThat(
54+
((MetricData) ((Data<?>) stableOtelMetricEnvelope.getData()).getBaseData())
55+
.getMetrics()
56+
.get(0)
57+
.getName())
58+
.isEqualTo("http.server.request.duration");
59+
4960
// verify pre-aggregated standard metric sent to Application Insights endpoint
50-
List<Envelope> standardMetricsList =
51-
testing.mockedIngestion.waitForItems("MetricData", OtlpTest::isStandardMetric, 1);
52-
Envelope standardMetricEnvelope = standardMetricsList.get(0);
61+
List<Envelope> standardMetrics =
62+
testing.mockedIngestion.waitForStandardMetricItems("requests/duration", 1);
63+
Envelope standardMetricEnvelope = standardMetrics.get(0);
5364
MetricData standardMetricData =
5465
(MetricData) ((Data<?>) standardMetricEnvelope.getData()).getBaseData();
5566
assertThat(standardMetricData.getMetrics().get(0).getName())
@@ -95,10 +106,11 @@ private static boolean isHistogramMetric(Envelope envelope) {
95106
return false;
96107
}
97108

98-
private static boolean isStandardMetric(Envelope envelope) {
109+
private static boolean isStableOtelMetric(Envelope envelope) {
99110
if (envelope.getData().getBaseType().equals("MetricData")) {
100111
MetricData data = (MetricData) ((Data<?>) envelope.getData()).getBaseData();
101-
return data.getMetrics().get(0).getName().equals("http.server.request.duration");
112+
return data.getMetrics().get(0).getName().equals("http.server.request.duration")
113+
&& data.getProperties().get("http.response.status_code") != null;
102114
}
103115
return false;
104116
}

smoke-tests/apps/PreAggMetricsWithRoleNameOverridesAndSampling/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/PreAggMetricsWithRoleNameOverridesAndSamplingTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ private void testApp(String roleName) throws Exception {
6666
for (Envelope envelope : metricsEnvelops) {
6767
MetricData metricData = (MetricData) ((Data<?>) envelope.getData()).getBaseData();
6868
String name = metricData.getMetrics().get(0).getName();
69-
if ("http.client.request.duration".equals(name)) {
69+
if ("http.client.request.duration".equals(name)
70+
&& "dependencies/duration".equals(metricData.getProperties().get("_MS.MetricId"))) {
7071
clientMetrics.add(envelope);
71-
} else if ("http.server.request.duration".equals(name)) {
72+
} else if ("http.server.request.duration".equals(name)
73+
&& "requests/duration".equals(metricData.getProperties().get("_MS.MetricId"))) {
7274
serverMetrics.add(envelope);
7375
}
7476
}

smoke-tests/apps/RoleNameOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AksRoleNameOverridesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ private static void verifyRoleNameAndInstance(String roleName, String roleInstan
5757
assertThat(mdList.get(0).getTags()).containsEntry("ai.cloud.roleInstance", roleInstance);
5858

5959
List<Envelope> clientMetrics =
60-
testing.mockedIngestion.waitForMetricItems("http.client.request.duration", 1);
60+
testing.mockedIngestion.waitForStandardMetricItems("dependencies/duration", 1);
6161
Map<String, String> clientTags = clientMetrics.get(0).getTags();
6262
assertThat(clientTags.get("ai.cloud.role")).isEqualTo(roleName);
6363
assertThat(clientTags.get("ai.cloud.roleInstance")).isEqualTo(roleInstance);
6464

6565
List<Envelope> serverMetrics =
66-
testing.mockedIngestion.waitForMetricItems("http.server.request.duration", 1);
66+
testing.mockedIngestion.waitForStandardMetricItems("requests/duration", 1);
6767
Map<String, String> serverTags = serverMetrics.get(0).getTags();
6868
assertThat(serverTags.get("ai.cloud.role")).isEqualTo(roleName);
6969
assertThat(serverTags.get("ai.cloud.roleInstance")).isEqualTo(roleInstance);

0 commit comments

Comments
 (0)