diff --git a/instrumentation/jsf/jsf-jakarta-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/jakarta/BaseJsfTest.java b/instrumentation/jsf/jsf-jakarta-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/jakarta/BaseJsfTest.java index bbb95e05d69e..d375a64b6e12 100644 --- a/instrumentation/jsf/jsf-jakarta-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/jakarta/BaseJsfTest.java +++ b/instrumentation/jsf/jsf-jakarta-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/jakarta/BaseJsfTest.java @@ -17,7 +17,6 @@ import io.opentelemetry.sdk.testing.assertj.TraceAssert; import io.opentelemetry.sdk.trace.data.StatusData; import io.opentelemetry.semconv.ClientAttributes; -import io.opentelemetry.semconv.ExceptionAttributes; import io.opentelemetry.semconv.HttpAttributes; import io.opentelemetry.semconv.NetworkAttributes; import io.opentelemetry.semconv.ServerAttributes; @@ -30,7 +29,6 @@ import io.opentelemetry.testing.internal.armeria.common.MediaType; import io.opentelemetry.testing.internal.armeria.common.QueryParams; import io.opentelemetry.testing.internal.armeria.common.RequestHeaders; -import jakarta.servlet.ServletException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -257,7 +255,7 @@ void testException() { AggregatedHttpResponse response2 = client.execute(request2).aggregate().join(); assertThat(response2.status().code()).isEqualTo(500); - ServletException ex = new ServletException("submit exception"); + IllegalStateException expectedException = new IllegalStateException("submit exception"); testing.waitAndAssertTraces( trace -> @@ -267,21 +265,8 @@ void testException() { .hasKind(SpanKind.SERVER) .hasNoParent() .hasStatus(StatusData.error()) - .hasEventsSatisfyingExactly( - event -> - event - .hasName("exception") - .hasAttributesSatisfyingExactly( - equalTo( - ExceptionAttributes.EXCEPTION_TYPE, - ex.getClass().getName()), - satisfies( - ExceptionAttributes.EXCEPTION_STACKTRACE, - stacktrace -> stacktrace.contains("submit exception")), - satisfies( - ExceptionAttributes.EXCEPTION_MESSAGE, - message -> message.endsWith(ex.getMessage())))), - span -> handlerSpan(trace, 0, "#{greetingForm.submit()}", ex))); + .hasException(expectedException), + span -> handlerSpan(trace, 0, "#{greetingForm.submit()}", expectedException))); } List> handlerSpan( @@ -295,22 +280,7 @@ List> handlerSpan( .hasParent(trace.getSpan(parentIndex)))); if (expectedException != null) { - assertions.add( - span -> - span.hasStatus(StatusData.error()) - .hasEventsSatisfyingExactly( - event -> - event - .hasName("exception") - .hasAttributesSatisfyingExactly( - equalTo( - ExceptionAttributes.EXCEPTION_TYPE, - expectedException.getClass().getName()), - satisfies( - ExceptionAttributes.EXCEPTION_MESSAGE, - message -> - message.startsWithIgnoringCase( - expectedException.getMessage()))))); + assertions.add(span -> span.hasStatus(StatusData.error()).hasException(expectedException)); } return assertions; } diff --git a/instrumentation/jsf/jsf-jakarta-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/jakarta/ExceptionFilter.java b/instrumentation/jsf/jsf-jakarta-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/jakarta/ExceptionFilter.java index 7e4d7a187499..217a0c38beea 100644 --- a/instrumentation/jsf/jsf-jakarta-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/jakarta/ExceptionFilter.java +++ b/instrumentation/jsf/jsf-jakarta-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/jakarta/ExceptionFilter.java @@ -11,6 +11,7 @@ import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; +import java.io.IOException; public class ExceptionFilter implements Filter { @Override @@ -18,11 +19,19 @@ public void init(FilterConfig filterConfig) {} @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws ServletException { + throws ServletException, IOException { try { chain.doFilter(request, response); - } catch (Exception exception) { - throw new ServletException(exception); + } catch (ServletException exception) { + // to ease testing unwrap our exception to root cause + Throwable tmp = exception; + while (tmp.getCause() != null) { + tmp = tmp.getCause(); + } + if (tmp.getMessage() != null && tmp.getMessage().contains("submit exception")) { + throw (IllegalStateException) tmp; + } + throw exception; } } diff --git a/instrumentation/jsf/jsf-jakarta-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/jakarta/GreetingForm.java b/instrumentation/jsf/jsf-jakarta-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/jakarta/GreetingForm.java index 6fbcf41fb355..8ca071c34972 100644 --- a/instrumentation/jsf/jsf-jakarta-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/jakarta/GreetingForm.java +++ b/instrumentation/jsf/jsf-jakarta-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/jakarta/GreetingForm.java @@ -22,10 +22,10 @@ public String getMessage() { return message; } - public void submit() throws Exception { + public void submit() { message = "Hello " + name; if (name.equals("exception")) { - throw new Exception("submit exception"); + throw new IllegalStateException("submit exception"); } } }