Skip to content

Commit c1a16c2

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

File tree

15 files changed

+138
-49
lines changed

15 files changed

+138
-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: 22 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,21 @@ 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(
180+
CodeIncubatingAttributes.CODE_NAMESPACE,
181+
AbstractStringAssert::isNotEmpty));
169182
return span;
170183
}
171184

@@ -178,13 +191,17 @@ public List<Consumer<SpanDataAssert>> errorPageSpanAssertions(
178191
span.hasName(
179192
endpoint == NOT_FOUND ? "ErrorController.notFound" : "ErrorController.index")
180193
.hasKind(SpanKind.INTERNAL)
181-
.hasAttributesSatisfying(Attributes::isEmpty));
194+
.hasAttributes(Attributes.empty()));
182195
if (endpoint == NOT_FOUND) {
183196
spanAssertions.add(
184197
span ->
185198
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendError"))
186199
.hasKind(SpanKind.INTERNAL)
187-
.hasAttributesSatisfying(Attributes::isEmpty));
200+
.hasAttributesSatisfyingExactly(
201+
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "sendError"),
202+
satisfies(
203+
CodeIncubatingAttributes.CODE_NAMESPACE,
204+
AbstractStringAssert::isNotEmpty)));
188205
}
189206
return spanAssertions;
190207
}

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)