Skip to content

Commit d29b4b0

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

File tree

15 files changed

+151
-49
lines changed

15 files changed

+151
-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: 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: 27 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;
@@ -160,12 +163,24 @@ public SpanDataAssert assertHandlerSpan(
160163
@Override
161164
public SpanDataAssert assertResponseSpan(
162165
SpanDataAssert span, String method, ServerEndpoint endpoint) {
166+
String methodName;
163167
if (endpoint == REDIRECT) {
164-
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendRedirect"));
168+
methodName = "sendRedirect";
169+
} else if (endpoint == ERROR || endpoint == NOT_FOUND) {
170+
methodName = "sendError";
165171
} else {
166-
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendError"));
172+
throw new AssertionError("Unexpected endpoint: " + endpoint.name());
167173
}
168-
span.hasKind(SpanKind.INTERNAL).hasAttributesSatisfying(Attributes::isEmpty);
174+
span.hasKind(SpanKind.INTERNAL)
175+
.satisfies(spanData -> assertThat(spanData.getName()).endsWith("." + methodName))
176+
.hasAttributesSatisfyingExactly(
177+
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, methodName),
178+
satisfies(
179+
CodeIncubatingAttributes.CODE_NAMESPACE,
180+
val ->
181+
val.isIn(
182+
"org.apache.catalina.connector.Response",
183+
"org.apache.catalina.connector.ResponseFacade")));
169184
return span;
170185
}
171186

@@ -178,13 +193,20 @@ public List<Consumer<SpanDataAssert>> errorPageSpanAssertions(
178193
span.hasName(
179194
endpoint == NOT_FOUND ? "ErrorController.notFound" : "ErrorController.index")
180195
.hasKind(SpanKind.INTERNAL)
181-
.hasAttributesSatisfying(Attributes::isEmpty));
196+
.hasAttributes(Attributes.empty()));
182197
if (endpoint == NOT_FOUND) {
183198
spanAssertions.add(
184199
span ->
185200
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendError"))
186201
.hasKind(SpanKind.INTERNAL)
187-
.hasAttributesSatisfying(Attributes::isEmpty));
202+
.hasAttributesSatisfyingExactly(
203+
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "sendError"),
204+
satisfies(
205+
CodeIncubatingAttributes.CODE_NAMESPACE,
206+
val ->
207+
val.isIn(
208+
"org.apache.catalina.connector.Response",
209+
"org.apache.catalina.connector.ResponseFacade"))));
188210
}
189211
return spanAssertions;
190212
}

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)