diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/ResteasyProxyClientTest.java b/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/ResteasyProxyClientTest.java index 8ac5d557a4cd..e07af83847ab 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/ResteasyProxyClientTest.java +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/ResteasyProxyClientTest.java @@ -58,6 +58,8 @@ public int sendRequest( response = proxy.put_success(param, isTestServer, requestId); } else if (proxyMethodName.equals("get_error")) { response = proxy.get_error(param, isTestServer, requestId); + } else if (proxyMethodName.equals("get_client_error")) { + response = proxy.get_client_error(param, isTestServer, requestId); } else { throw new IllegalArgumentException("Unknown method: " + proxyMethodName); } diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/ResteasyProxyResource.java b/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/ResteasyProxyResource.java index e356796c88ea..71aec42ab442 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/ResteasyProxyResource.java +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/ResteasyProxyResource.java @@ -22,6 +22,13 @@ Response get_error( @HeaderParam("is-test-server") String isTestServer, @HeaderParam("test-request-id") String requestId); + @GET + @Path("client-error") + Response get_client_error( + @QueryParam("with") String param, + @HeaderParam("is-test-server") String isTestServer, + @HeaderParam("test-request-id") String requestId); + @GET @Path("success") Response get_success( diff --git a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpClientTest.groovy b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpClientTest.groovy index 6a076cfcab17..1096131e4ae8 100644 --- a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpClientTest.groovy +++ b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpClientTest.groovy @@ -256,9 +256,14 @@ abstract class HttpClientTest extends InstrumentationSpecification { junitTest.redirectToSecuredCopiesAuthHeader() } - def "error span"() { + def "error span for #path"() { expect: - junitTest.errorSpan() + junitTest.errorSpan(path, statusCode) + + where: + path | statusCode + "/client-error" | 400 + "/error" | 500 } def "reuse request"() { diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java index b06c933bfd53..3ec09c9725c0 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java @@ -55,6 +55,7 @@ import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.condition.DisabledIfSystemProperty; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; @TestInstance(TestInstance.Lifecycle.PER_CLASS) @@ -437,10 +438,11 @@ void redirectToSecuredCopiesAuthHeader() throws Exception { // TODO: add basic auth scenario - @Test - void errorSpan() { + @ParameterizedTest + @CsvSource({"/error,500", "/client-error,400"}) + void errorSpan(String path, int responseCode) { String method = "GET"; - URI uri = resolveAddress("/error"); + URI uri = resolveAddress(path); testing.runWithSpan( "parent", @@ -456,7 +458,9 @@ void errorSpan() { trace -> { trace.hasSpansSatisfyingExactly( span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), - span -> assertClientSpan(span, uri, method, 500, null).hasParent(trace.getSpan(0)), + span -> + assertClientSpan(span, uri, method, responseCode, null) + .hasParent(trace.getSpan(0)), span -> assertServerSpan(span).hasParent(trace.getSpan(1))); }); }