From 9dd239e40c3d435b94470435afa73a1d2ab3285e Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Sat, 29 Jun 2024 14:43:31 -0400 Subject: [PATCH 1/4] convert jsf javax tests from groovy to java --- .../src/main/groovy/BaseJsfTest.groovy | 277 --------------- .../src/main/groovy/ExceptionFilter.groovy | 38 -- .../src/main/groovy/GreetingForm.groovy | 29 -- .../jsf/javax/BaseJsfTest.java | 325 ++++++++++++++++++ .../jsf/javax/ExceptionFilter.java | 31 ++ .../jsf/javax/GreetingForm.java | 31 ++ .../test-app-1.2/WEB-INF/faces-config.xml | 4 +- .../resources/test-app-1.2/WEB-INF/web.xml | 4 +- .../test-app-2/WEB-INF/faces-config.xml | 4 +- .../main/resources/test-app-2/WEB-INF/web.xml | 4 +- .../mojarra12Test/groovy/Mojarra12Test.groovy | 11 - .../mojarra/Mojarra12Test.java | 15 + .../mojarra2Test/groovy/Mojarra2Test.groovy | 11 - .../instrumentation/mojarra/Mojarra2Test.java | 15 + .../myfaces12Test/groovy/Myfaces12Test.groovy | 11 - .../myfaces/Myfaces12Test.java | 15 + .../myfaces2Test/groovy/Myfaces2Test.groovy | 11 - .../instrumentation/myfaces/Myfaces2Test.java | 15 + 18 files changed, 455 insertions(+), 396 deletions(-) delete mode 100644 instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/BaseJsfTest.groovy delete mode 100644 instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/ExceptionFilter.groovy delete mode 100644 instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/GreetingForm.groovy create mode 100644 instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/BaseJsfTest.java create mode 100644 instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/ExceptionFilter.java create mode 100644 instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/GreetingForm.java delete mode 100644 instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra12Test/groovy/Mojarra12Test.groovy create mode 100644 instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra12Test/java/io/opentelemetry/javaagent/instrumentation/mojarra/Mojarra12Test.java delete mode 100644 instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra2Test/groovy/Mojarra2Test.groovy create mode 100644 instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra2Test/java/io/opentelemetry/javaagent/instrumentation/mojarra/Mojarra2Test.java delete mode 100644 instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces12Test/groovy/Myfaces12Test.groovy create mode 100644 instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces12Test/java/io/opentelemetry/javaagent/instrumentation/myfaces/Myfaces12Test.java delete mode 100644 instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces2Test/groovy/Myfaces2Test.groovy create mode 100644 instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces2Test/java/io/opentelemetry/javaagent/instrumentation/myfaces/Myfaces2Test.java diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/BaseJsfTest.groovy b/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/BaseJsfTest.groovy deleted file mode 100644 index 8eec22ce6c76..000000000000 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/BaseJsfTest.groovy +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import io.opentelemetry.api.trace.SpanKind -import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification -import io.opentelemetry.instrumentation.test.asserts.TraceAssert -import io.opentelemetry.instrumentation.test.base.HttpServerTestTrait -import io.opentelemetry.sdk.trace.data.SpanData -import io.opentelemetry.semconv.ServerAttributes -import io.opentelemetry.semconv.ClientAttributes -import io.opentelemetry.semconv.UserAgentAttributes -import io.opentelemetry.semconv.HttpAttributes -import io.opentelemetry.semconv.NetworkAttributes -import io.opentelemetry.semconv.UrlAttributes -import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest -import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse -import io.opentelemetry.testing.internal.armeria.common.HttpData -import io.opentelemetry.testing.internal.armeria.common.HttpMethod -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 org.eclipse.jetty.annotations.AnnotationConfiguration -import org.eclipse.jetty.server.Server -import org.eclipse.jetty.util.resource.Resource -import org.eclipse.jetty.webapp.WebAppContext -import org.jsoup.Jsoup -import spock.lang.Unroll - -import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.api.trace.StatusCode.ERROR - -abstract class BaseJsfTest extends AgentInstrumentationSpecification implements HttpServerTestTrait { - - def setupSpec() { - setupServer() - } - - def cleanupSpec() { - cleanupServer() - } - - @Override - Server startServer(int port) { - String jsfVersion = getJsfVersion() - - List configurationClasses = new ArrayList<>() - Collections.addAll(configurationClasses, WebAppContext.getDefaultConfigurationClasses()) - configurationClasses.add(AnnotationConfiguration.getName()) - - WebAppContext webAppContext = new WebAppContext() - webAppContext.setContextPath(getContextPath()) - webAppContext.setConfigurationClasses(configurationClasses) - // set up test application - webAppContext.setBaseResource(Resource.newSystemResource("test-app-" + jsfVersion)) - // add additional resources for test app - Resource extraResource = Resource.newSystemResource("test-app-" + jsfVersion + "-extra") - if (extraResource != null) { - webAppContext.getMetaData().addWebInfJar(extraResource) - } - webAppContext.getMetaData().getWebInfClassesDirs().add(Resource.newClassPathResource("/")) - - def jettyServer = new Server(port) - jettyServer.connectors.each { - it.setHost('localhost') - } - - jettyServer.setHandler(webAppContext) - jettyServer.start() - - return jettyServer - } - - abstract String getJsfVersion(); - - @Override - void stopServer(Server server) { - server.stop() - server.destroy() - } - - @Override - String getContextPath() { - return "/jetty-context" - } - - @Unroll - def "test #path"() { - setup: - AggregatedHttpResponse response = client.get(address.resolve(path).toString()).aggregate().join() - - expect: - response.status().code() == 200 - response.contentUtf8().trim() == "Hello" - - and: - assertTraces(1) { - trace(0, 1) { - span(0) { - name getContextPath() + "/hello.xhtml" - kind SpanKind.SERVER - hasNoParent() - attributes { - "$NetworkAttributes.NETWORK_PROTOCOL_VERSION" "1.1" - "$ServerAttributes.SERVER_ADDRESS" "localhost" - "$ServerAttributes.SERVER_PORT" port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" - "$NetworkAttributes.NETWORK_PEER_PORT" Long - "$HttpAttributes.HTTP_REQUEST_METHOD" "GET" - "$UrlAttributes.URL_SCHEME" "http" - "$UrlAttributes.URL_PATH" "/jetty-context/" + path - "$UserAgentAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT - "$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 - "$HttpAttributes.HTTP_ROUTE" "/jetty-context/" + route - "$ClientAttributes.CLIENT_ADDRESS" { it == null || it == TEST_CLIENT_IP } - } - } - } - } - - where: - path | route - "hello.jsf" | "*.jsf" - "faces/hello.xhtml" | "faces/*" - } - - def "test greeting"() { - // we need to display the page first before posting data to it - setup: - AggregatedHttpResponse response = client.get(address.resolve("greeting.jsf").toString()).aggregate().join() - def doc = Jsoup.parse(response.contentUtf8()) - - expect: - response.status().code() == 200 - doc.selectFirst("title").text() == "Hello, World!" - - and: - assertTraces(1) { - trace(0, 1) { - span(0) { - name getContextPath() + "/greeting.xhtml" - kind SpanKind.SERVER - hasNoParent() - } - } - } - clearExportedData() - - when: - // extract parameters needed to post back form - def viewState = doc.selectFirst("[name=javax.faces.ViewState]")?.val() - def formAction = doc.selectFirst("#app-form").attr("action") - def jsessionid = formAction.substring(formAction.indexOf("jsessionid=") + "jsessionid=".length()) - - then: - viewState != null - jsessionid != null - - when: - // set up form parameter for post - QueryParams formBody = QueryParams.builder() - .add("app-form", "app-form") - // value used for name is returned in app-form:output-message element - .add("app-form:name", "test") - .add("app-form:submit", "Say hello") - .add("app-form_SUBMIT", "1") // MyFaces - .add("javax.faces.ViewState", viewState) - .build() - // use the session created for first request - def request2 = AggregatedHttpRequest.of( - RequestHeaders.builder(HttpMethod.POST, address.resolve("greeting.jsf;jsessionid=" + jsessionid).toString()) - .contentType(MediaType.FORM_DATA) - .build(), - HttpData.ofUtf8(formBody.toQueryString())) - AggregatedHttpResponse response2 = client.execute(request2).aggregate().join() - def responseContent = response2.contentUtf8() - def doc2 = Jsoup.parse(responseContent) - - then: - response2.status().code() == 200 - doc2.getElementById("app-form:output-message").text() == "Hello test" - - and: - assertTraces(1) { - trace(0, 2) { - span(0) { - name getContextPath() + "/greeting.xhtml" - kind SpanKind.SERVER - hasNoParent() - } - handlerSpan(it, 1, span(0), "#{greetingForm.submit()}") - } - } - } - - def "test exception"() { - // we need to display the page first before posting data to it - setup: - AggregatedHttpResponse response = client.get(address.resolve("greeting.jsf").toString()).aggregate().join() - def doc = Jsoup.parse(response.contentUtf8()) - - expect: - response.status().code() == 200 - doc.selectFirst("title").text() == "Hello, World!" - - and: - assertTraces(1) { - trace(0, 1) { - span(0) { - name getContextPath() + "/greeting.xhtml" - kind SpanKind.SERVER - hasNoParent() - } - } - } - clearExportedData() - - when: - // extract parameters needed to post back form - def viewState = doc.selectFirst("[name=javax.faces.ViewState]").val() - def formAction = doc.selectFirst("#app-form").attr("action") - def jsessionid = formAction.substring(formAction.indexOf("jsessionid=") + "jsessionid=".length()) - - then: - viewState != null - jsessionid != null - - when: - // set up form parameter for post - QueryParams formBody = QueryParams.builder() - .add("app-form", "app-form") - // setting name parameter to "exception" triggers throwing exception in GreetingForm - .add("app-form:name", "exception") - .add("app-form:submit", "Say hello") - .add("app-form_SUBMIT", "1") // MyFaces - .add("javax.faces.ViewState", viewState) - .build() - // use the session created for first request - def request2 = AggregatedHttpRequest.of( - RequestHeaders.builder(HttpMethod.POST, address.resolve("greeting.jsf;jsessionid=" + jsessionid).toString()) - .contentType(MediaType.FORM_DATA) - .build(), - HttpData.ofUtf8(formBody.toQueryString())) - AggregatedHttpResponse response2 = client.execute(request2).aggregate().join() - - then: - response2.status().code() == 500 - def ex = new Exception("submit exception") - - and: - assertTraces(1) { - trace(0, 2) { - span(0) { - name getContextPath() + "/greeting.xhtml" - kind SpanKind.SERVER - hasNoParent() - status ERROR - errorEvent(ex.class, ex.message) - } - handlerSpan(it, 1, span(0), "#{greetingForm.submit()}", ex) - } - } - } - - void handlerSpan(TraceAssert trace, int index, Object parent, String spanName, Exception expectedException = null) { - trace.span(index) { - name spanName - kind INTERNAL - if (expectedException != null) { - status ERROR - errorEvent(expectedException.getClass(), expectedException.getMessage()) - } - childOf((SpanData) parent) - } - } -} diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/ExceptionFilter.groovy b/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/ExceptionFilter.groovy deleted file mode 100644 index 9efcd3acc017..000000000000 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/ExceptionFilter.groovy +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import javax.servlet.Filter -import javax.servlet.FilterChain -import javax.servlet.FilterConfig -import javax.servlet.ServletException -import javax.servlet.ServletRequest -import javax.servlet.ServletResponse - -class ExceptionFilter implements Filter { - @Override - void init(FilterConfig filterConfig) throws ServletException { - } - - @Override - void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - try { - chain.doFilter(request, response) - } catch (Exception exception) { - // to ease testing unwrap our exception to root cause - Exception tmp = exception - while (tmp.getCause() != null) { - tmp = tmp.getCause() - } - if (tmp.getMessage() != null && tmp.getMessage().contains("submit exception")) { - throw tmp - } - throw exception - } - } - - @Override - void destroy() { - } -} diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/GreetingForm.groovy b/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/GreetingForm.groovy deleted file mode 100644 index f8d429f4ee2a..000000000000 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/GreetingForm.groovy +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -class GreetingForm { - - String name = "" - String message = "" - - String getName() { - name - } - - void setName(String name) { - this.name = name - } - - String getMessage() { - return message - } - - void submit() { - message = "Hello " + name - if (name == "exception") { - throw new Exception("submit exception") - } - } -} diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/BaseJsfTest.java b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/BaseJsfTest.java new file mode 100644 index 000000000000..0a49aa6b36ff --- /dev/null +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/BaseJsfTest.java @@ -0,0 +1,325 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jsf.javax; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; +import static java.util.Collections.addAll; +import static org.assertj.core.api.Assertions.assertThat; + +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerUsingTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; +import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; +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; +import io.opentelemetry.semconv.UrlAttributes; +import io.opentelemetry.semconv.UserAgentAttributes; +import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest; +import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse; +import io.opentelemetry.testing.internal.armeria.common.HttpData; +import io.opentelemetry.testing.internal.armeria.common.HttpMethod; +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 java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Stream; +import javax.servlet.ServletException; +import org.eclipse.jetty.annotations.AnnotationConfiguration; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.webapp.WebAppContext; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.junit.jupiter.params.provider.ArgumentsSource; + +public abstract class BaseJsfTest extends AbstractHttpServerUsingTest { + @RegisterExtension + public static final InstrumentationExtension testing = + HttpServerInstrumentationExtension.forAgent(); + + protected abstract String getJsfVersion(); + + @BeforeAll + protected void setUp() { + startServer(); + } + + @AfterAll + protected void cleanUp() { + cleanupServer(); + } + + @Override + protected Server setupServer() throws Exception { + List configurationClasses = new ArrayList<>(); + addAll(configurationClasses, WebAppContext.getDefaultConfigurationClasses()); + configurationClasses.add(AnnotationConfiguration.class.getName()); + + WebAppContext webAppContext = new WebAppContext(); + webAppContext.setContextPath(getContextPath()); + // set up test application + webAppContext.setBaseResource(Resource.newSystemResource("test-app-" + getJsfVersion())); + // add additional resources for test app + Resource extraResource = Resource.newSystemResource("test-app-" + getJsfVersion() + "-extra"); + if (extraResource != null) { + webAppContext.getMetaData().addWebInfJar(extraResource); + } + webAppContext.getMetaData().getWebInfClassesDirs().add(Resource.newClassPathResource("/")); + + Server jettyServer = new Server(port); + jettyServer.setHandler(webAppContext); + jettyServer.start(); + + return jettyServer; + } + + @Override + protected String getContextPath() { + return "/jetty-context"; + } + + @Override + protected void stopServer(Server server) throws Exception { + server.stop(); + server.destroy(); + } + + @ParameterizedTest + @ArgumentsSource(PathTestArgs.class) + void testPath(String path, String route) { + AggregatedHttpResponse response = + client.get(address.resolve(path).toString()).aggregate().join(); + assertThat(response.status().code()).isEqualTo(200); + assertThat(response.contentUtf8().trim()).isEqualTo("Hello"); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName(getContextPath() + "/hello.xhtml") + .hasKind(SpanKind.SERVER) + .hasAttributesSatisfyingExactly( + equalTo(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"), + equalTo(ServerAttributes.SERVER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + satisfies( + NetworkAttributes.NETWORK_PEER_PORT, + val -> val.isInstanceOf(Long.class)), + equalTo(HttpAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(UrlAttributes.URL_SCHEME, "http"), + equalTo(UrlAttributes.URL_PATH, getContextPath() + "/" + path), + equalTo(UserAgentAttributes.USER_AGENT_ORIGINAL, TEST_USER_AGENT), + equalTo(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(HttpAttributes.HTTP_ROUTE, getContextPath() + "/" + route), + satisfies( + ClientAttributes.CLIENT_ADDRESS, + val -> + val.satisfiesAnyOf( + v -> assertThat(v).isEqualTo(TEST_CLIENT_IP), + v -> assertThat(v).isNull()))))); + } + + static class PathTestArgs implements ArgumentsProvider { + @Override + public Stream provideArguments(ExtensionContext context) { + return Stream.of( + Arguments.of("hello.jsf", "*.jsf"), Arguments.of("faces/hello.xhtml", "faces/*")); + } + } + + @Test + void testGreeting() { + // we need to display the page first before posting data to it + AggregatedHttpResponse response = + client.get(address.resolve("greeting.jsf").toString()).aggregate().join(); + Document doc = Jsoup.parse(response.contentUtf8()); + + assertThat(response.status().code()).isEqualTo(200); + assertThat(doc.selectFirst("title").text()).isEqualTo("Hello, World!"); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName(getContextPath() + "/greeting.xhtml") + .hasKind(SpanKind.SERVER) + .hasNoParent())); + + testing.clearData(); + + String viewState = doc.selectFirst("[name=javax.faces.ViewState]").val(); + String formAction = doc.selectFirst("#app-form").attr("action"); + String jsessionid = + formAction.substring(formAction.indexOf("jsessionid=") + "jsessionid=".length()); + + assertThat(viewState).isNotNull(); + assertThat(jsessionid).isNotNull(); + + // set up form parameter for post + QueryParams formBody = + QueryParams.builder() + .add("app-form", "app-form") + // value used for name is returned in app-form:output-message element + .add("app-form:name", "test") + .add("app-form:submit", "Say hello") + .add("app-form_SUBMIT", "1") // MyFaces + .add("javax.faces.ViewState", viewState) + .build(); + + // use the session created for first request + AggregatedHttpRequest request2 = + AggregatedHttpRequest.of( + RequestHeaders.builder( + HttpMethod.POST, + address.resolve("greeting.jsf;jsessionid=" + jsessionid).toString()) + .contentType(MediaType.FORM_DATA) + .build(), + HttpData.ofUtf8(formBody.toQueryString())); + AggregatedHttpResponse response2 = client.execute(request2).aggregate().join(); + String responseContent = response2.contentUtf8(); + Document doc2 = Jsoup.parse(responseContent); + + assertThat(response2.status().code()).isEqualTo(200); + assertThat(doc2.getElementById("app-form:output-message").text()).isEqualTo("Hello test"); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName(getContextPath() + "/greeting.xhtml") + .hasKind(SpanKind.SERVER) + .hasNoParent(), + span -> handlerSpan(trace, 0, "#{greetingForm.submit()}", null))); + } + + List> handlerSpan( + TraceAssert trace, int parentIndex, String spanName, Exception expectedException) { + List> assertions = + new ArrayList<>( + Arrays.asList( + span -> + span.hasName(spanName) + .hasKind(SpanKind.INTERNAL) + .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()))))); + } + return assertions; + } + + @Test + void testException() { + // we need to display the page first before posting data to it + AggregatedHttpResponse response = + client.get(address.resolve("greeting.jsf").toString()).aggregate().join(); + Document doc = Jsoup.parse(response.contentUtf8()); + + assertThat(response.status().code()).isEqualTo(200); + assertThat(doc.selectFirst("title").text()).isEqualTo("Hello, World!"); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName(getContextPath() + "/greeting.xhtml") + .hasKind(SpanKind.SERVER) + .hasNoParent())); + + testing.clearData(); + + String viewState = doc.selectFirst("[name=javax.faces.ViewState]").val(); + String formAction = doc.selectFirst("#app-form").attr("action"); + String jsessionid = + formAction.substring(formAction.indexOf("jsessionid=") + "jsessionid=".length()); + + assertThat(viewState).isNotNull(); + assertThat(jsessionid).isNotNull(); + + // set up form parameter for post + QueryParams formBody = + QueryParams.builder() + .add("app-form", "app-form") + // setting name parameter to "exception" triggers throwing exception in GreetingForm + .add("app-form:name", "exception") + .add("app-form:submit", "Say hello") + .add("app-form_SUBMIT", "1") // MyFaces + .add("javax.faces.ViewState", viewState) + .build(); + + // use the session created for first request + AggregatedHttpRequest request2 = + AggregatedHttpRequest.of( + RequestHeaders.builder( + HttpMethod.POST, + address.resolve("greeting.jsf;jsessionid=" + jsessionid).toString()) + .contentType(MediaType.FORM_DATA) + .build(), + HttpData.ofUtf8(formBody.toQueryString())); + AggregatedHttpResponse response2 = client.execute(request2).aggregate().join(); + + assertThat(response2.status().code()).isEqualTo(500); + ServletException ex = new ServletException("submit exception"); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName(getContextPath() + "/greeting.xhtml") + .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))); + } +} diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/ExceptionFilter.java b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/ExceptionFilter.java new file mode 100644 index 000000000000..95e807501a18 --- /dev/null +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/ExceptionFilter.java @@ -0,0 +1,31 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jsf.javax; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +public class ExceptionFilter implements Filter { + @Override + public void init(FilterConfig filterConfig) {} + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws ServletException { + try { + chain.doFilter(request, response); + } catch (Exception exception) { + throw new ServletException(exception); + } + } + + @Override + public void destroy() {} +} diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/GreetingForm.java b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/GreetingForm.java new file mode 100644 index 000000000000..2c847579a7e6 --- /dev/null +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/GreetingForm.java @@ -0,0 +1,31 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jsf.javax; + +public class GreetingForm { + + private String name = ""; + private String message = ""; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMessage() { + return message; + } + + public void submit() throws Exception { + message = "Hello " + name; + if (name.equals("exception")) { + throw new Exception("submit exception"); + } + } +} diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-1.2/WEB-INF/faces-config.xml b/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-1.2/WEB-INF/faces-config.xml index 5502993f7db5..de9a1c0a68d2 100644 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-1.2/WEB-INF/faces-config.xml +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-1.2/WEB-INF/faces-config.xml @@ -4,11 +4,11 @@ version="1.2"> greetingForm - GreetingForm + io.opentelemetry.javaagent.instrumentation.jsf.javax.GreetingForm request com.sun.facelets.FaceletViewHandler - \ No newline at end of file + diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-1.2/WEB-INF/web.xml b/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-1.2/WEB-INF/web.xml index cb64b6ae8da1..2214cec902e6 100644 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-1.2/WEB-INF/web.xml +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-1.2/WEB-INF/web.xml @@ -20,7 +20,7 @@ ExceptionFilter - ExceptionFilter + io.opentelemetry.javaagent.instrumentation.jsf.javax.ExceptionFilter @@ -33,4 +33,4 @@ .xhtml - \ No newline at end of file + diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-2/WEB-INF/faces-config.xml b/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-2/WEB-INF/faces-config.xml index 9a0ad7c89786..f83e949af4db 100644 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-2/WEB-INF/faces-config.xml +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-2/WEB-INF/faces-config.xml @@ -2,7 +2,7 @@ greetingForm - GreetingForm + io.opentelemetry.javaagent.instrumentation.jsf.javax.GreetingForm request - \ No newline at end of file + diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-2/WEB-INF/web.xml b/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-2/WEB-INF/web.xml index 191c55b09da3..32949939fbb4 100644 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-2/WEB-INF/web.xml +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/resources/test-app-2/WEB-INF/web.xml @@ -6,7 +6,7 @@ ExceptionFilter - ExceptionFilter + io.opentelemetry.javaagent.instrumentation.jsf.javax.ExceptionFilter @@ -14,4 +14,4 @@ /* - \ No newline at end of file + diff --git a/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra12Test/groovy/Mojarra12Test.groovy b/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra12Test/groovy/Mojarra12Test.groovy deleted file mode 100644 index d47c830ed0c4..000000000000 --- a/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra12Test/groovy/Mojarra12Test.groovy +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -class Mojarra12Test extends BaseJsfTest { - @Override - String getJsfVersion() { - "1.2" - } -} diff --git a/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra12Test/java/io/opentelemetry/javaagent/instrumentation/mojarra/Mojarra12Test.java b/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra12Test/java/io/opentelemetry/javaagent/instrumentation/mojarra/Mojarra12Test.java new file mode 100644 index 000000000000..991b5d9cfb25 --- /dev/null +++ b/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra12Test/java/io/opentelemetry/javaagent/instrumentation/mojarra/Mojarra12Test.java @@ -0,0 +1,15 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.mojarra; + +import io.opentelemetry.javaagent.instrumentation.jsf.javax.BaseJsfTest; + +class Mojarra12Test extends BaseJsfTest { + @Override + public String getJsfVersion() { + return "1.2"; + } +} diff --git a/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra2Test/groovy/Mojarra2Test.groovy b/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra2Test/groovy/Mojarra2Test.groovy deleted file mode 100644 index 1097bb1e6e8c..000000000000 --- a/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra2Test/groovy/Mojarra2Test.groovy +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -class Mojarra2Test extends BaseJsfTest { - @Override - String getJsfVersion() { - "2" - } -} diff --git a/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra2Test/java/io/opentelemetry/javaagent/instrumentation/mojarra/Mojarra2Test.java b/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra2Test/java/io/opentelemetry/javaagent/instrumentation/mojarra/Mojarra2Test.java new file mode 100644 index 000000000000..3d6e615ab810 --- /dev/null +++ b/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/mojarra2Test/java/io/opentelemetry/javaagent/instrumentation/mojarra/Mojarra2Test.java @@ -0,0 +1,15 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.mojarra; + +import io.opentelemetry.javaagent.instrumentation.jsf.javax.BaseJsfTest; + +class Mojarra2Test extends BaseJsfTest { + @Override + public String getJsfVersion() { + return "2"; + } +} diff --git a/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces12Test/groovy/Myfaces12Test.groovy b/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces12Test/groovy/Myfaces12Test.groovy deleted file mode 100644 index bc532d1a2cad..000000000000 --- a/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces12Test/groovy/Myfaces12Test.groovy +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -class Myfaces12Test extends BaseJsfTest { - @Override - String getJsfVersion() { - "1.2" - } -} diff --git a/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces12Test/java/io/opentelemetry/javaagent/instrumentation/myfaces/Myfaces12Test.java b/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces12Test/java/io/opentelemetry/javaagent/instrumentation/myfaces/Myfaces12Test.java new file mode 100644 index 000000000000..564091fd300f --- /dev/null +++ b/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces12Test/java/io/opentelemetry/javaagent/instrumentation/myfaces/Myfaces12Test.java @@ -0,0 +1,15 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.myfaces; + +import io.opentelemetry.javaagent.instrumentation.jsf.javax.BaseJsfTest; + +class Myfaces12Test extends BaseJsfTest { + @Override + public String getJsfVersion() { + return "1.2"; + } +} diff --git a/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces2Test/groovy/Myfaces2Test.groovy b/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces2Test/groovy/Myfaces2Test.groovy deleted file mode 100644 index bd08b6975d42..000000000000 --- a/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces2Test/groovy/Myfaces2Test.groovy +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -class Myfaces2Test extends BaseJsfTest { - @Override - String getJsfVersion() { - "2" - } -} diff --git a/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces2Test/java/io/opentelemetry/javaagent/instrumentation/myfaces/Myfaces2Test.java b/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces2Test/java/io/opentelemetry/javaagent/instrumentation/myfaces/Myfaces2Test.java new file mode 100644 index 000000000000..67c9e38861e5 --- /dev/null +++ b/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/myfaces2Test/java/io/opentelemetry/javaagent/instrumentation/myfaces/Myfaces2Test.java @@ -0,0 +1,15 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.myfaces; + +import io.opentelemetry.javaagent.instrumentation.jsf.javax.BaseJsfTest; + +class Myfaces2Test extends BaseJsfTest { + @Override + public String getJsfVersion() { + return "2"; + } +} From 9b312796f7ca35931cd5ec39fa64902b438436e8 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Tue, 2 Jul 2024 14:43:03 -0400 Subject: [PATCH 2/4] add configuration to reference classes --- .../javaagent/instrumentation/jsf/javax/BaseJsfTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/BaseJsfTest.java b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/BaseJsfTest.java index 0a49aa6b36ff..0a210c3d1844 100644 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/BaseJsfTest.java +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/BaseJsfTest.java @@ -78,6 +78,7 @@ protected Server setupServer() throws Exception { WebAppContext webAppContext = new WebAppContext(); webAppContext.setContextPath(getContextPath()); + webAppContext.setConfigurationClasses(configurationClasses); // set up test application webAppContext.setBaseResource(Resource.newSystemResource("test-app-" + getJsfVersion())); // add additional resources for test app From 91d21c2888ba65241695f3804fbfb56bf8799f97 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Tue, 2 Jul 2024 16:39:05 -0400 Subject: [PATCH 3/4] fix exception test --- .../javaagent/instrumentation/jsf/javax/ExceptionFilter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/ExceptionFilter.java b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/ExceptionFilter.java index 95e807501a18..cc40b199a976 100644 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/ExceptionFilter.java +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/ExceptionFilter.java @@ -21,8 +21,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha throws ServletException { try { chain.doFilter(request, response); - } catch (Exception exception) { - throw new ServletException(exception); + } catch (Exception unused) { + throw new ServletException("submit exception"); } } From a9fc3f275c16f469e7a93c8c70586c4e4543f420 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Thu, 4 Jul 2024 06:56:08 -0400 Subject: [PATCH 4/4] simplify exception assertion --- .../jsf/javax/BaseJsfTest.java | 38 ++----------------- .../jsf/javax/ExceptionFilter.java | 15 ++++++-- .../jsf/javax/GreetingForm.java | 4 +- 3 files changed, 18 insertions(+), 39 deletions(-) diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/BaseJsfTest.java b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/BaseJsfTest.java index 0a210c3d1844..01aaf48d159e 100644 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/BaseJsfTest.java +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/BaseJsfTest.java @@ -18,7 +18,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; @@ -36,7 +35,6 @@ import java.util.List; import java.util.function.Consumer; import java.util.stream.Stream; -import javax.servlet.ServletException; import org.eclipse.jetty.annotations.AnnotationConfiguration; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.resource.Resource; @@ -226,22 +224,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; } @@ -297,7 +280,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 -> @@ -307,20 +290,7 @@ 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))); } } diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/ExceptionFilter.java b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/ExceptionFilter.java index cc40b199a976..9360760dd739 100644 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/ExceptionFilter.java +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/ExceptionFilter.java @@ -5,6 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.jsf.javax; +import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; @@ -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 unused) { - throw new ServletException("submit 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-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/GreetingForm.java b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/GreetingForm.java index 2c847579a7e6..60e36f4a60d4 100644 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/GreetingForm.java +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/javax/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"); } } }