Skip to content

Commit

Permalink
Enable exception tests on vert.x (#2914)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored May 6, 2021
1 parent 9e9fe11 commit 5670024
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,9 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
.listen(port) { startFuture.complete() }
}
}

@Override
boolean hasExceptionOnServerSpan(HttpServerTest.ServerEndpoint endpoint) {
return endpoint != EXCEPTION && super.hasExceptionOnServerSpan(endpoint)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package server

import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
Expand Down Expand Up @@ -53,25 +54,21 @@ class VertxRxHttpServerTest extends HttpServerTest<Vertx> implements AgentTestTr
server.close()
}

@Override
boolean testException() {
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/807
return false
}

@Override
boolean testPathParam() {
return true
}

@Override
boolean testNotFound() {
return false
}

@Override
String expectedServerSpanName(ServerEndpoint endpoint) {
return endpoint == PATH_PARAM ? "/path/:id/param" : endpoint.getPath()
switch (endpoint) {
case PATH_PARAM:
return "/path/:id/param"
case NOT_FOUND:
return "HTTP GET"
default:
return endpoint.getPath()
}
}

protected Class<AbstractVerticle> verticle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import io.opentelemetry.instrumentation.api.tracer.ServerSpan;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -26,8 +30,8 @@ public RoutingContextHandlerWrapper(Handler<RoutingContext> handler) {

@Override
public void handle(RoutingContext context) {
Span serverSpan = ServerSpan.fromContextOrNull(Context.current());
try {
Span serverSpan = ServerSpan.fromContextOrNull(Context.current());
if (serverSpan != null) {
// TODO should update only SERVER span using
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/465
Expand All @@ -36,6 +40,24 @@ public void handle(RoutingContext context) {
} catch (Exception ex) {
log.error("Failed to update server span name with vert.x route", ex);
}
handler.handle(context);
try {
handler.handle(context);
} catch (Throwable throwable) {
if (serverSpan != null) {
serverSpan.recordException(unwrapThrowable(throwable));
}
throw throwable;
}
}

private Throwable unwrapThrowable(Throwable throwable) {
if (throwable.getCause() != null
&& (throwable instanceof ExecutionException
|| throwable instanceof CompletionException
|| throwable instanceof InvocationTargetException
|| throwable instanceof UndeclaredThrowableException)) {
return unwrapThrowable(throwable.getCause());
}
return throwable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package server

import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM

import io.opentelemetry.instrumentation.test.AgentTestTrait
Expand Down Expand Up @@ -48,30 +49,26 @@ class VertxHttpServerTest extends HttpServerTest<Vertx> implements AgentTestTrai
server.close()
}

@Override
boolean testException() {
// TODO(anuraaga): https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/807
return false
}

@Override
boolean testPathParam() {
return true
}

@Override
boolean testNotFound() {
return false
}

@Override
boolean testConcurrency() {
return true
}

@Override
String expectedServerSpanName(ServerEndpoint endpoint) {
return endpoint == PATH_PARAM ? "/path/:id/param" : endpoint.getPath()
switch (endpoint) {
case PATH_PARAM:
return "/path/:id/param"
case NOT_FOUND:
return "HTTP GET"
default:
return endpoint.getPath()
}
}

}

0 comments on commit 5670024

Please sign in to comment.