Remove a couple of TODOs from instrumentation-api metrics tests
MODIFY
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsTest.java
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsTest.java
@@ -7,7 +7,6 @@ package io.opentelemetry.instrumentation.api.instrumenter.http;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
-import static org.awaitility.Awaitility.await;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
@@ -17,9 +16,8 @@ import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.RequestListener;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
-import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
-import java.util.Collection;
+import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
@@ -29,7 +27,10 @@ class HttpClientMetricsTest {
void collectsMetrics() {
InMemoryMetricReader metricReader = InMemoryMetricReader.create();
SdkMeterProvider meterProvider =
- SdkMeterProvider.builder().registerMetricReader(metricReader).build();
+ SdkMeterProvider.builder()
+ .registerMetricReader(metricReader)
+ .setMinimumCollectionInterval(Duration.ZERO)
+ .build();
RequestListener listener = HttpClientMetrics.get().create(meterProvider.get("test"));
@@ -63,32 +64,16 @@ class HttpClientMetricsTest {
Context context1 = listener.start(parent, requestAttributes, nanos(100));
- // TODO(anuraaga): Remove await from this file after 1.8.0 hopefully fixes
- // https://github.com/open-telemetry/opentelemetry-java/issues/3725
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).isEmpty();
- });
+ assertThat(metricReader.collectAllMetrics()).isEmpty();
Context context2 = listener.start(Context.root(), requestAttributes, nanos(150));
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).isEmpty();
- });
+ assertThat(metricReader.collectAllMetrics()).isEmpty();
listener.end(context1, responseAttributes, nanos(250));
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).hasSize(1);
- assertThat(metrics)
+ assertThat(metricReader.collectAllMetrics())
+ .hasSize(1)
.anySatisfy(
metric ->
assertThat(metric)
@@ -111,25 +96,18 @@ class HttpClientMetricsTest {
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
- });
listener.end(context2, responseAttributes, nanos(300));
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).hasSize(1);
- assertThat(metrics)
+ assertThat(metricReader.collectAllMetrics())
+ .hasSize(1)
.anySatisfy(
metric ->
assertThat(metric)
.hasName("http.client.duration")
.hasDoubleHistogram()
.points()
- .satisfiesExactly(
- point -> assertThat(point).hasSum(300 /* millis */)));
- });
+ .satisfiesExactly(point -> assertThat(point).hasSum(300 /* millis */)));
}
private static long nanos(int millis) {

MODIFY
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java
@@ -7,7 +7,6 @@ package io.opentelemetry.instrumentation.api.instrumenter.http;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
-import static org.awaitility.Awaitility.await;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
@@ -17,9 +16,8 @@ import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.RequestListener;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
-import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
-import java.util.Collection;
+import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
@@ -29,7 +27,10 @@ class HttpServerMetricsTest {
void collectsMetrics() {
InMemoryMetricReader metricReader = InMemoryMetricReader.create();
SdkMeterProvider meterProvider =
- SdkMeterProvider.builder().registerMetricReader(metricReader).build();
+ SdkMeterProvider.builder()
+ .registerMetricReader(metricReader)
+ .setMinimumCollectionInterval(Duration.ZERO)
+ .build();
RequestListener listener = HttpServerMetrics.get().create(meterProvider.get("test"));
@@ -62,14 +63,8 @@ class HttpServerMetricsTest {
Context context1 = listener.start(parent, requestAttributes, nanos(100));
- // TODO(anuraaga): Remove await from this file after 1.8.0 hopefully fixes
- // https://github.com/open-telemetry/opentelemetry-java/issues/3725
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).hasSize(1);
- assertThat(metrics)
+ assertThat(metricReader.collectAllMetrics())
+ .hasSize(1)
.anySatisfy(
metric ->
assertThat(metric)
@@ -93,16 +88,11 @@ class HttpServerMetricsTest {
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
- });
Context context2 = listener.start(Context.root(), requestAttributes, nanos(150));
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).hasSize(1);
- assertThat(metrics)
+ assertThat(metricReader.collectAllMetrics())
+ .hasSize(1)
.anySatisfy(
metric ->
assertThat(metric)
@@ -110,24 +100,18 @@ class HttpServerMetricsTest {
.hasLongSum()
.points()
.satisfiesExactly(point -> assertThat(point).hasValue(2)));
- });
listener.end(context1, responseAttributes, nanos(250));
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).hasSize(2);
- assertThat(metrics)
+ assertThat(metricReader.collectAllMetrics())
+ .hasSize(2)
.anySatisfy(
metric ->
assertThat(metric)
.hasName("http.server.active_requests")
.hasLongSum()
.points()
- .satisfiesExactly(point -> assertThat(point).hasValue(1)));
- assertThat(metrics)
+ .satisfiesExactly(point -> assertThat(point).hasValue(1)))
.anySatisfy(
metric ->
assertThat(metric)
@@ -151,33 +135,25 @@ class HttpServerMetricsTest {
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
- });
listener.end(context2, responseAttributes, nanos(300));
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).hasSize(2);
- assertThat(metrics)
+ assertThat(metricReader.collectAllMetrics())
+ .hasSize(2)
.anySatisfy(
metric ->
assertThat(metric)
.hasName("http.server.active_requests")
.hasLongSum()
.points()
- .satisfiesExactly(point -> assertThat(point).hasValue(0)));
- assertThat(metrics)
+ .satisfiesExactly(point -> assertThat(point).hasValue(0)))
.anySatisfy(
metric ->
assertThat(metric)
.hasName("http.server.duration")
.hasDoubleHistogram()
.points()
- .satisfiesExactly(
- point -> assertThat(point).hasSum(300 /* millis */)));
- });
+ .satisfiesExactly(point -> assertThat(point).hasSum(300 /* millis */)));
}
private static long nanos(int millis) {

MODIFY
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetricsTest.java
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetricsTest.java
package io.opentelemetry.instrumentation.api.instrumenter.rpc;
+import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.awaitility.Awaitility.await;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
@@ -17,11 +16,9 @@ import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.RequestListener;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
-import io.opentelemetry.sdk.metrics.data.MetricData;
-import io.opentelemetry.sdk.testing.assertj.MetricAssertions;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
-import java.util.Collection;
+import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
@@ -31,7 +28,10 @@ class RpcClientMetricsTest {
void collectsMetrics() {
InMemoryMetricReader metricReader = InMemoryMetricReader.createDelta();
SdkMeterProvider meterProvider =
- SdkMeterProvider.builder().registerMetricReader(metricReader).build();
+ SdkMeterProvider.builder()
+ .registerMetricReader(metricReader)
+ .setMinimumCollectionInterval(Duration.ZERO)
+ .build();
RequestListener listener = RpcClientMetrics.get().create(meterProvider.get("test"));
@@ -69,42 +69,26 @@ class RpcClientMetricsTest {
Context context1 = listener.start(parent, requestAttributes, nanos(100));
- // TODO(anuraaga): Remove await from this file after 1.8.0 hopefully fixes
- // https://github.com/open-telemetry/opentelemetry-java/issues/3725
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).isEmpty();
- });
+ assertThat(metricReader.collectAllMetrics()).isEmpty();
Context context2 = listener.start(Context.root(), requestAttributes, nanos(150));
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).isEmpty();
- });
+ assertThat(metricReader.collectAllMetrics()).isEmpty();
listener.end(context1, responseAttributes1, nanos(250));
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).hasSize(1);
- assertThat(metrics)
+ assertThat(metricReader.collectAllMetrics())
+ .hasSize(1)
.anySatisfy(
metric ->
- MetricAssertions.assertThat(metric)
+ assertThat(metric)
.hasName("rpc.client.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
- MetricAssertions.assertThat(point)
+ assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
@@ -114,31 +98,26 @@ class RpcClientMetricsTest {
attributeEntry("net.peer.name", "example.com"),
attributeEntry("net.peer.port", 8080),
attributeEntry("net.transport", "ip_tcp"));
- MetricAssertions.assertThat(point).exemplars().hasSize(1);
- MetricAssertions.assertThat(point.getExemplars().get(0))
+ assertThat(point).exemplars().hasSize(1);
+ assertThat(point.getExemplars().get(0))
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
- });
listener.end(context2, responseAttributes2, nanos(300));
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).hasSize(1);
- assertThat(metrics)
+ assertThat(metricReader.collectAllMetrics())
+ .hasSize(1)
.anySatisfy(
metric ->
- MetricAssertions.assertThat(metric)
+ assertThat(metric)
.hasName("rpc.client.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
- MetricAssertions.assertThat(point)
+ assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
@@ -149,7 +128,6 @@ class RpcClientMetricsTest {
attributeEntry("net.peer.port", 8080),
attributeEntry("net.transport", "ip_tcp"));
}));
- });
}
private static long nanos(int millis) {

MODIFY
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetricsTest.java
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetricsTest.java
package io.opentelemetry.instrumentation.api.instrumenter.rpc;
+import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.awaitility.Awaitility.await;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
@@ -17,11 +16,9 @@ import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.RequestListener;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
-import io.opentelemetry.sdk.metrics.data.MetricData;
-import io.opentelemetry.sdk.testing.assertj.MetricAssertions;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
-import java.util.Collection;
+import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
@@ -31,7 +28,10 @@ class RpcServerMetricsTest {
void collectsMetrics() {
InMemoryMetricReader metricReader = InMemoryMetricReader.createDelta();
SdkMeterProvider meterProvider =
- SdkMeterProvider.builder().registerMetricReader(metricReader).build();
+ SdkMeterProvider.builder()
+ .registerMetricReader(metricReader)
+ .setMinimumCollectionInterval(Duration.ZERO)
+ .build();
RequestListener listener = RpcServerMetrics.get().create(meterProvider.get("test"));
@@ -69,42 +69,26 @@ class RpcServerMetricsTest {
Context context1 = listener.start(parent, requestAttributes, nanos(100));
- // TODO(anuraaga): Remove await from this file after 1.8.0 hopefully fixes
- // https://github.com/open-telemetry/opentelemetry-java/issues/3725
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).isEmpty();
- });
+ assertThat(metricReader.collectAllMetrics()).isEmpty();
Context context2 = listener.start(Context.root(), requestAttributes, nanos(150));
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).isEmpty();
- });
+ assertThat(metricReader.collectAllMetrics()).isEmpty();
listener.end(context1, responseAttributes1, nanos(250));
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).hasSize(1);
- assertThat(metrics)
+ assertThat(metricReader.collectAllMetrics())
+ .hasSize(1)
.anySatisfy(
metric ->
- MetricAssertions.assertThat(metric)
+ assertThat(metric)
.hasName("rpc.server.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
- MetricAssertions.assertThat(point)
+ assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
@@ -113,31 +97,26 @@ class RpcServerMetricsTest {
attributeEntry("rpc.method", "exampleMethod"),
attributeEntry("net.host.name", "example.com"),
attributeEntry("net.transport", "ip_tcp"));
- MetricAssertions.assertThat(point).exemplars().hasSize(1);
- MetricAssertions.assertThat(point.getExemplars().get(0))
+ assertThat(point).exemplars().hasSize(1);
+ assertThat(point.getExemplars().get(0))
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
- });
listener.end(context2, responseAttributes2, nanos(300));
- await()
- .untilAsserted(
- () -> {
- Collection<MetricData> metrics = metricReader.collectAllMetrics();
- assertThat(metrics).hasSize(1);
- assertThat(metrics)
+ assertThat(metricReader.collectAllMetrics())
+ .hasSize(1)
.anySatisfy(
metric ->
- MetricAssertions.assertThat(metric)
+ assertThat(metric)
.hasName("rpc.server.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
- MetricAssertions.assertThat(point)
+ assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
@@ -147,7 +126,6 @@ class RpcServerMetricsTest {
attributeEntry("net.host.ip", "127.0.0.1"),
attributeEntry("net.transport", "ip_tcp"));
}));
- });
}
private static long nanos(int millis) {

Remove a couple of TODOs from instrumentation-api metrics tests (#5255)