Skip to content

Commit bb90e08

Browse files
authored
Fix some assertions (#12520)
1 parent d3f808e commit bb90e08

File tree

15 files changed

+131
-49
lines changed

15 files changed

+131
-49
lines changed

instrumentation/azure-core/azure-core-1.14/javaagent/src/testAzure/java/io/opentelemetry/javaagent/instrumentation/azurecore/v1_14/AzureSdkTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ void testSpan() {
5555
span.hasName("hello")
5656
.hasKind(SpanKind.INTERNAL)
5757
.hasStatus(StatusData.ok())
58-
.hasAttributesSatisfying(Attributes::isEmpty)));
58+
.hasAttributes(Attributes.empty())));
5959
}
6060
}

instrumentation/azure-core/azure-core-1.19/javaagent/src/testAzure/java/io/opentelemetry/javaagent/instrumentation/azurecore/v1_19/AzureSdkTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ void testSpan() {
5555
span.hasName("hello")
5656
.hasKind(SpanKind.INTERNAL)
5757
.hasStatus(StatusData.ok())
58-
.hasAttributesSatisfying(Attributes::isEmpty)));
58+
.hasAttributes(Attributes.empty())));
5959
}
6060
}

instrumentation/azure-core/azure-core-1.36/javaagent/src/testAzure/java/io/opentelemetry/javaagent/instrumentation/azurecore/v1_36/AzureSdkTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.javaagent.instrumentation.azurecore.v1_36;
77

8+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
89
import static org.assertj.core.api.Assertions.assertThat;
910

1011
import com.azure.core.annotation.ExpectedResponses;
@@ -22,6 +23,7 @@
2223
import com.azure.core.util.ClientOptions;
2324
import com.azure.core.util.Context;
2425
import com.azure.core.util.TracingOptions;
26+
import io.opentelemetry.api.common.AttributeKey;
2527
import io.opentelemetry.api.common.Attributes;
2628
import io.opentelemetry.api.trace.SpanKind;
2729
import io.opentelemetry.instrumentation.api.internal.SpanKey;
@@ -66,7 +68,8 @@ void testSpan() {
6668
span.hasName("hello")
6769
.hasKind(SpanKind.INTERNAL)
6870
.hasStatus(StatusData.unset())
69-
.hasAttributesSatisfying(Attributes::isEmpty)));
71+
.hasAttributesSatisfyingExactly(
72+
equalTo(AttributeKey.stringKey("az.namespace"), "otel.tests"))));
7073
}
7174

7275
@Test

instrumentation/azure-core/azure-core-1.36/javaagent/src/testAzure/java/io/opentelemetry/javaagent/instrumentation/azurecore/v1_36/AzureSdkTestOld.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void testSpan() {
5050
span.hasName("hello")
5151
.hasKind(SpanKind.INTERNAL)
5252
.hasStatus(StatusData.unset())
53-
.hasAttributesSatisfying(Attributes::isEmpty)));
53+
.hasAttributes(Attributes.empty())));
5454
}
5555

5656
private static com.azure.core.util.tracing.Tracer createAzTracer() {

instrumentation/grails-3.0/javaagent/src/test/java/test/GrailsTest.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM;
1515
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT;
1616
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
17+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
18+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
1719

1820
import grails.boot.GrailsApp;
1921
import grails.boot.config.GrailsAutoConfiguration;
@@ -27,6 +29,7 @@
2729
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
2830
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
2931
import io.opentelemetry.sdk.trace.data.StatusData;
32+
import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes;
3033
import java.util.ArrayList;
3134
import java.util.Arrays;
3235
import java.util.Collection;
@@ -35,6 +38,7 @@
3538
import java.util.Locale;
3639
import java.util.Map;
3740
import java.util.function.Consumer;
41+
import org.assertj.core.api.AbstractStringAssert;
3842
import org.junit.jupiter.api.extension.RegisterExtension;
3943
import org.springframework.boot.autoconfigure.SpringBootApplication;
4044
import org.springframework.boot.autoconfigure.web.ServerProperties;
@@ -160,12 +164,19 @@ public SpanDataAssert assertHandlerSpan(
160164
@Override
161165
public SpanDataAssert assertResponseSpan(
162166
SpanDataAssert span, String method, ServerEndpoint endpoint) {
167+
String methodName;
163168
if (endpoint == REDIRECT) {
164-
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendRedirect"));
169+
methodName = "sendRedirect";
170+
} else if (endpoint == ERROR || endpoint == NOT_FOUND) {
171+
methodName = "sendError";
165172
} else {
166-
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendError"));
173+
throw new AssertionError("Unexpected endpoint: " + endpoint.name());
167174
}
168-
span.hasKind(SpanKind.INTERNAL).hasAttributesSatisfying(Attributes::isEmpty);
175+
span.hasKind(SpanKind.INTERNAL)
176+
.satisfies(spanData -> assertThat(spanData.getName()).endsWith("." + methodName))
177+
.hasAttributesSatisfyingExactly(
178+
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, methodName),
179+
satisfies(CodeIncubatingAttributes.CODE_NAMESPACE, AbstractStringAssert::isNotEmpty));
169180
return span;
170181
}
171182

@@ -178,13 +189,17 @@ public List<Consumer<SpanDataAssert>> errorPageSpanAssertions(
178189
span.hasName(
179190
endpoint == NOT_FOUND ? "ErrorController.notFound" : "ErrorController.index")
180191
.hasKind(SpanKind.INTERNAL)
181-
.hasAttributesSatisfying(Attributes::isEmpty));
192+
.hasAttributes(Attributes.empty()));
182193
if (endpoint == NOT_FOUND) {
183194
spanAssertions.add(
184195
span ->
185196
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendError"))
186197
.hasKind(SpanKind.INTERNAL)
187-
.hasAttributesSatisfying(Attributes::isEmpty));
198+
.hasAttributesSatisfyingExactly(
199+
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "sendError"),
200+
satisfies(
201+
CodeIncubatingAttributes.CODE_NAMESPACE,
202+
AbstractStringAssert::isNotEmpty)));
188203
}
189204
return spanAssertions;
190205
}

instrumentation/graphql-java/graphql-java-common/testing/src/main/java/io/opentelemetry/instrumentation/graphql/AbstractGraphqlTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ void parseError() {
238238
span.hasName("GraphQL Operation")
239239
.hasKind(SpanKind.INTERNAL)
240240
.hasNoParent()
241-
.hasAttributesSatisfying(Attributes::isEmpty)
241+
.hasAttributes(Attributes.empty())
242242
.hasStatus(StatusData.error())
243243
.hasEventsSatisfyingExactly(
244244
event ->
@@ -280,7 +280,7 @@ void validationError() {
280280
span.hasName("GraphQL Operation")
281281
.hasKind(SpanKind.INTERNAL)
282282
.hasNoParent()
283-
.hasAttributesSatisfying(Attributes::isEmpty)
283+
.hasAttributes(Attributes.empty())
284284
.hasStatus(StatusData.error())
285285
.hasEventsSatisfyingExactly(
286286
event ->

instrumentation/jetty/jetty-11.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jetty/v11_0/JettyHandlerTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM;
1515
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT;
1616
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS;
17+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1718
import static org.assertj.core.api.Assertions.assertThat;
1819

1920
import com.google.common.collect.Sets;
20-
import io.opentelemetry.api.common.Attributes;
2121
import io.opentelemetry.api.trace.SpanKind;
2222
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
2323
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest;
@@ -26,6 +26,7 @@
2626
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
2727
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
2828
import io.opentelemetry.semconv.HttpAttributes;
29+
import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes;
2930
import jakarta.servlet.DispatcherType;
3031
import jakarta.servlet.ServletException;
3132
import jakarta.servlet.http.HttpServletRequest;
@@ -89,12 +90,19 @@ protected void configure(HttpServerTestOptions options) {
8990
@Override
9091
protected SpanDataAssert assertResponseSpan(
9192
SpanDataAssert span, String method, ServerEndpoint endpoint) {
93+
String methodName;
9294
if (endpoint == REDIRECT) {
93-
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendRedirect"));
95+
methodName = "sendRedirect";
9496
} else if (endpoint == ERROR) {
95-
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendError"));
97+
methodName = "sendError";
98+
} else {
99+
throw new AssertionError("Unexpected endpoint: " + endpoint.name());
96100
}
97-
span.hasKind(SpanKind.INTERNAL).hasAttributesSatisfying(Attributes::isEmpty);
101+
span.hasKind(SpanKind.INTERNAL)
102+
.satisfies(spanData -> assertThat(spanData.getName()).endsWith("." + methodName))
103+
.hasAttributesSatisfyingExactly(
104+
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, methodName),
105+
equalTo(CodeIncubatingAttributes.CODE_NAMESPACE, "org.eclipse.jetty.server.Response"));
98106
return span;
99107
}
100108

instrumentation/jetty/jetty-12.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jetty/v12_0/Jetty12HandlerTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM;
1515
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT;
1616
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS;
17+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1718
import static org.assertj.core.api.Assertions.assertThat;
1819

1920
import com.google.common.collect.Sets;
20-
import io.opentelemetry.api.common.Attributes;
2121
import io.opentelemetry.api.trace.SpanKind;
2222
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
2323
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest;
@@ -26,6 +26,7 @@
2626
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
2727
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
2828
import io.opentelemetry.semconv.HttpAttributes;
29+
import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes;
2930
import java.io.IOException;
3031
import java.nio.charset.StandardCharsets;
3132
import java.util.Collections;
@@ -69,12 +70,19 @@ protected void configure(HttpServerTestOptions options) {
6970
@Override
7071
protected SpanDataAssert assertResponseSpan(
7172
SpanDataAssert span, String method, ServerEndpoint endpoint) {
73+
String methodName;
7274
if (endpoint == REDIRECT) {
73-
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendRedirect"));
75+
methodName = "sendRedirect";
7476
} else if (endpoint == ERROR) {
75-
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendError"));
77+
methodName = "sendError";
78+
} else {
79+
throw new AssertionError("Unexpected endpoint: " + endpoint.name());
7680
}
77-
span.hasKind(SpanKind.INTERNAL).hasAttributesSatisfying(Attributes::isEmpty);
81+
span.hasKind(SpanKind.INTERNAL)
82+
.satisfies(spanData -> assertThat(spanData.getName()).endsWith("." + methodName))
83+
.hasAttributesSatisfyingExactly(
84+
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, methodName),
85+
equalTo(CodeIncubatingAttributes.CODE_NAMESPACE, "org.eclipse.jetty.server.Response"));
7886
return span;
7987
}
8088

instrumentation/jetty/jetty-8.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jetty/v8_0/JettyHandlerTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM;
1515
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT;
1616
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS;
17+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1718
import static org.assertj.core.api.Assertions.assertThat;
1819

1920
import com.google.common.collect.Sets;
20-
import io.opentelemetry.api.common.Attributes;
2121
import io.opentelemetry.api.trace.SpanKind;
2222
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
2323
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest;
@@ -26,6 +26,7 @@
2626
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
2727
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
2828
import io.opentelemetry.semconv.HttpAttributes;
29+
import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes;
2930
import java.io.IOException;
3031
import java.io.Writer;
3132
import java.util.Collections;
@@ -89,12 +90,19 @@ protected void configure(HttpServerTestOptions options) {
8990
@Override
9091
protected SpanDataAssert assertResponseSpan(
9192
SpanDataAssert span, String method, ServerEndpoint endpoint) {
93+
String methodName;
9294
if (endpoint == REDIRECT) {
93-
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendRedirect"));
95+
methodName = "sendRedirect";
9496
} else if (endpoint == ERROR) {
95-
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendError"));
97+
methodName = "sendError";
98+
} else {
99+
throw new AssertionError("Unexpected endpoint: " + endpoint.name());
96100
}
97-
span.hasKind(SpanKind.INTERNAL).hasAttributesSatisfying(Attributes::isEmpty);
101+
span.hasKind(SpanKind.INTERNAL)
102+
.satisfies(spanData -> assertThat(spanData.getName()).endsWith("." + methodName))
103+
.hasAttributesSatisfyingExactly(
104+
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, methodName),
105+
equalTo(CodeIncubatingAttributes.CODE_NAMESPACE, "org.eclipse.jetty.server.Response"));
98106
return span;
99107
}
100108

instrumentation/spring/spring-webmvc/spring-webmvc-common/testing/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/boot/AbstractSpringBootBasedTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ protected List<Consumer<SpanDataAssert>> errorPageSpanAssertions(
149149
span ->
150150
span.hasName("BasicErrorController.error")
151151
.hasKind(SpanKind.INTERNAL)
152-
.hasAttributesSatisfying(Attributes::isEmpty));
152+
.hasAttributes(Attributes.empty()));
153153
return spanAssertions;
154154
}
155155

0 commit comments

Comments
 (0)