Skip to content

Commit d633e89

Browse files
committed
Fix some assertions
1 parent 68ee2f6 commit d633e89

File tree

15 files changed

+89
-37
lines changed

15 files changed

+89
-37
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void testSpan() {
4545
span.hasName("hello")
4646
.hasKind(SpanKind.INTERNAL)
4747
.hasStatus(StatusData.unset())
48-
.hasAttributesSatisfying(Attributes::isEmpty)));
48+
.hasAttributes(Attributes.empty())));
4949
}
5050

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

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public SpanDataAssert assertResponseSpan(
165165
} else {
166166
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendError"));
167167
}
168-
span.hasKind(SpanKind.INTERNAL).hasAttributesSatisfying(Attributes::isEmpty);
168+
span.hasKind(SpanKind.INTERNAL).hasAttributes(Attributes.empty());
169169
return span;
170170
}
171171

@@ -178,13 +178,13 @@ public List<Consumer<SpanDataAssert>> errorPageSpanAssertions(
178178
span.hasName(
179179
endpoint == NOT_FOUND ? "ErrorController.notFound" : "ErrorController.index")
180180
.hasKind(SpanKind.INTERNAL)
181-
.hasAttributesSatisfying(Attributes::isEmpty));
181+
.hasAttributes(Attributes.empty()));
182182
if (endpoint == NOT_FOUND) {
183183
spanAssertions.add(
184184
span ->
185185
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendError"))
186186
.hasKind(SpanKind.INTERNAL)
187-
.hasAttributesSatisfying(Attributes::isEmpty));
187+
.hasAttributes(Attributes.empty()));
188188
}
189189
return spanAssertions;
190190
}

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)