Skip to content

Commit

Permalink
Update to OTel 1.14 (#5999)
Browse files Browse the repository at this point in the history
* Update to OTel 1.14

* Fix test

Co-authored-by: Trask Stalnaker <[email protected]>
  • Loading branch information
anuraaga and trask committed May 10, 2022
1 parent 25d929b commit d1ee692
Show file tree
Hide file tree
Showing 25 changed files with 1,065 additions and 1,037 deletions.
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data class DependencySet(val group: String, val version: String, val modules: Li
val dependencyVersions = hashMapOf<String, String>()
rootProject.extra["versions"] = dependencyVersions

val otelVersion = "1.13.0"
val otelVersion = "1.14.0"
rootProject.extra["otelVersion"] = otelVersion

// Need both BOM and groovy jars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

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 io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
Expand All @@ -17,6 +17,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.RequestListener;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -70,42 +71,40 @@ void collectsMetrics() {
listener.onEnd(context1, responseAttributes, nanos(250));

assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.client.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
attributeEntry("net.peer.name", "localhost"),
attributeEntry("net.peer.port", 1234),
attributeEntry("http.method", "GET"),
attributeEntry("http.flavor", "2.0"),
attributeEntry("http.status_code", 200));
assertThat(point).exemplars().hasSize(1);
assertThat(point.getExemplars().get(0))
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(150 /* millis */)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
equalTo(SemanticAttributes.NET_PEER_PORT, 1234),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00")))));

listener.onEnd(context2, responseAttributes, nanos(300));

assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.client.duration")
.hasDoubleHistogram()
.points()
.satisfiesExactly(point -> assertThat(point).hasSum(300 /* millis */)));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point -> point.hasSum(300 /* millis */))));
}

private static long nanos(int millis) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

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 io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
Expand All @@ -17,6 +17,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.RequestListener;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -60,96 +61,86 @@ void collectsMetrics() {
Context context1 = listener.onStart(parent, requestAttributes, nanos(100));

assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.server.active_requests")
.hasDescription(
"The number of concurrent HTTP requests that are currently in-flight")
.hasUnit("requests")
.hasLongSum()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.hasValue(1)
.attributes()
.containsOnly(
attributeEntry("http.host", "host"),
attributeEntry("http.method", "GET"),
attributeEntry("http.scheme", "https"));
assertThat(point).exemplars().hasSize(1);
assertThat(point.getExemplars().get(0))
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
.hasLongSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(1)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_HOST, "host"),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_SCHEME, "https"))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00")))));

Context context2 = listener.onStart(Context.root(), requestAttributes, nanos(150));

assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.server.active_requests")
.hasLongSum()
.points()
.satisfiesExactly(point -> assertThat(point).hasValue(2)));
.hasLongSumSatisfying(
sum -> sum.hasPointsSatisfying(point -> point.hasValue(2))));

listener.onEnd(context1, responseAttributes, nanos(250));

assertThat(metricReader.collectAllMetrics())
.hasSize(2)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.server.active_requests")
.hasLongSum()
.points()
.satisfiesExactly(point -> assertThat(point).hasValue(1)))
.anySatisfy(
.hasLongSumSatisfying(
sum -> sum.hasPointsSatisfying(point -> point.hasValue(1))),
metric ->
assertThat(metric)
.hasName("http.server.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
attributeEntry("http.scheme", "https"),
attributeEntry("http.host", "host"),
attributeEntry("http.method", "GET"),
attributeEntry("http.status_code", 200),
attributeEntry("http.flavor", "2.0"));
assertThat(point).exemplars().hasSize(1);
assertThat(point.getExemplars().get(0))
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(150 /* millis */)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
equalTo(SemanticAttributes.HTTP_HOST, "host"),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00")))));

listener.onEnd(context2, responseAttributes, nanos(300));

assertThat(metricReader.collectAllMetrics())
.hasSize(2)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.server.active_requests")
.hasLongSum()
.points()
.satisfiesExactly(point -> assertThat(point).hasValue(0)))
.anySatisfy(
.hasLongSumSatisfying(
sum -> sum.hasPointsSatisfying(point -> point.hasValue(0))),
metric ->
assertThat(metric)
.hasName("http.server.duration")
.hasDoubleHistogram()
.points()
.satisfiesExactly(point -> assertThat(point).hasSum(300 /* millis */)));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point -> point.hasSum(300 /* millis */))));
}

@Test
Expand Down Expand Up @@ -179,17 +170,17 @@ void collectsHttpRouteFromEndAttributes() {
assertThat(metric)
.hasName("http.server.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasSum(100 /* millis */)
.attributes()
.containsOnly(
attributeEntry("http.scheme", "https"),
attributeEntry("http.host", "host"),
attributeEntry("http.route", "/test/{id}"))));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(100 /* millis */)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
equalTo(SemanticAttributes.HTTP_HOST, "host"),
equalTo(
SemanticAttributes.HTTP_ROUTE, "/test/{id}")))));
}

private static long nanos(int millis) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

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 io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
Expand Down Expand Up @@ -74,56 +74,56 @@ void collectsMetrics() {
listener.onEnd(context1, responseAttributes1, nanos(250));

assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("rpc.client.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
attributeEntry("rpc.system", "grpc"),
attributeEntry("rpc.service", "myservice.EchoService"),
attributeEntry("rpc.method", "exampleMethod"),
attributeEntry("net.peer.name", "example.com"),
attributeEntry("net.peer.port", 8080),
attributeEntry("net.transport", "ip_tcp"));
assertThat(point).exemplars().hasSize(1);
assertThat(point.getExemplars().get(0))
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(150 /* millis */)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"myservice.EchoService"),
equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"),
equalTo(
SemanticAttributes.NET_PEER_NAME, "example.com"),
equalTo(SemanticAttributes.NET_PEER_PORT, 8080),
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00")))));

listener.onEnd(context2, responseAttributes2, nanos(300));

assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("rpc.client.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
attributeEntry("rpc.system", "grpc"),
attributeEntry("rpc.service", "myservice.EchoService"),
attributeEntry("rpc.method", "exampleMethod"),
attributeEntry("net.peer.ip", "127.0.0.1"),
attributeEntry("net.peer.port", 8080),
attributeEntry("net.transport", "ip_tcp"));
}));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(150 /* millis */)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"myservice.EchoService"),
equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"),
equalTo(SemanticAttributes.NET_PEER_IP, "127.0.0.1"),
equalTo(SemanticAttributes.NET_PEER_PORT, 8080),
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp")))));
}

private static long nanos(int millis) {
Expand Down
Loading

0 comments on commit d1ee692

Please sign in to comment.