Skip to content

Commit

Permalink
[#3266] Fix HTTP request span names.
Browse files Browse the repository at this point in the history
HTTP requests for which no specific route matches
shall get a fixed tracing span name, not one
corresponding to the request path.

Signed-off-by: Carsten Lohmann <[email protected]>
  • Loading branch information
calohmn committed May 20, 2022
1 parent c499825 commit 491e2f6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ protected void onStartupSuccess() {
* This method creates a router instance along with a route matching all request. That route is initialized with the
* following handlers and failure handlers:
* <ol>
* <li>a default failure handler,</li>
* <li>a handler to keep track of the tracing span created for the request by means of the Vert.x/Quarkus
* instrumentation,</li>
* <li>a handler to add a Micrometer {@code Timer.Sample} to the routing context,</li>
* <li>a handler to log when the connection is closed prematurely,</li>
* <li>a default failure handler,</li>
* <li>a handler limiting the body size of requests to the maximum payload size set in the <em>config</em>
* properties.</li>
* </ol>
Expand All @@ -269,9 +269,17 @@ protected void onStartupSuccess() {
*/
protected Router createRouter() {

// route (failure) handlers are added in a specific order here!
final Router router = Router.router(vertx);
final Route matchAllFailuresRoute = router.route();
// failure handler is added on a separate route for which no name is set, otherwise all tracing spans
// of failed HTTP requests would get that route name as span name
matchAllFailuresRoute.failureHandler(new DefaultFailureHandler());

final Route matchAllRoute = router.route();
// the handlers and failure handlers are added here in a specific order!
// route name will be used as HTTP request tracing span name,
// ensuring a fixed name is set in case no other route matches (otherwise the span name would unsuitably be set to the request path)
matchAllRoute.setName("/* (default route)");
// 1. handler to keep track of the tracing span created by the Vert.x/Quarkus instrumentation (set as active span there)
matchAllRoute.handler(HttpServerSpanHelper.getRouteHandlerForAdoptingActiveSpan(tracer, getCustomTags()));

Expand All @@ -289,10 +297,7 @@ protected Router createRouter() {
ctx.next();
});

// 4. default handler for failed routes
matchAllRoute.failureHandler(new DefaultFailureHandler());

// 5. BodyHandler with request size limit
// 4. BodyHandler with request size limit
log.info("limiting size of inbound request body to {} bytes", getConfig().getMaxPayloadSize());
final BodyHandler bodyHandler = BodyHandler.create(DEFAULT_UPLOADS_DIRECTORY)
.setBodyLimit(getConfig().getMaxPayloadSize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ protected Future<Void> onStartupSuccess() {
* This method creates a router instance along with a route matching all request. That route is initialized with the
* following handlers and failure handlers:
* <ul>
* <li>a default failure handler,</li>
* <li>a handler to keep track of the tracing span created for the request by means of the Vert.x/Quarkus
* instrumentation,</li>
* <li>a default failure handler,</li>
* <li>a handler limiting the body size of requests to the maximum payload size set in the <em>config</em>
* properties.</li>
* <li>the authentication handler, set via {@link #setAuthHandler(AuthenticationHandler)}.</li>
Expand All @@ -189,18 +189,24 @@ protected Future<Void> onStartupSuccess() {
*/
protected Router createRouter() {

// route (failure) handlers are added in a specific order here!
final Router router = Router.router(vertx);
final Route matchAllFailuresRoute = router.route();
// failure handler is added on a separate route for which no name is set, otherwise all tracing spans
// of failed HTTP requests would get that route name as span name
matchAllFailuresRoute.failureHandler(new DefaultFailureHandler());

final Route matchAllRoute = router.route();
// the handlers and failure handlers are added here in a specific order!
// route name will be used as HTTP request tracing span name,
// ensuring a fixed name is set in case no other route matches (otherwise the span name would unsuitably be set to the request path)
matchAllRoute.setName("/* (default route)");
// 1. handler to keep track of the tracing span created by the Vert.x/Quarkus instrumentation (set as active span there)
matchAllRoute.handler(HttpServerSpanHelper.getRouteHandlerForAdoptingActiveSpan(tracer, getCustomTags()));
// 2. default handler for failed routes
matchAllRoute.failureHandler(new DefaultFailureHandler());
// 3. BodyHandler with request size limit
// 2. BodyHandler with request size limit
log.info("limiting size of inbound request body to {} bytes", getConfig().getMaxPayloadSize());
matchAllRoute.handler(BodyHandler.create().setUploadsDirectory(DEFAULT_UPLOADS_DIRECTORY)
.setBodyLimit(getConfig().getMaxPayloadSize()));
// 4. AuthHandler
// 3. AuthHandler
addAuthHandler(router);
return router;
}
Expand Down

0 comments on commit 491e2f6

Please sign in to comment.