Tracing Routes

note

Tracing Routes - 图1

This help topic is in development and will be updated in the future.

If you have problems trying to figure out why your route is not being executed, Ktor provides a trace method inside the routing feature.

  1. routing {
  2. trace { application.log.trace(it.buildText()) }
  3. }

This method is executed whenever a call is done giving you a trace of the decisions taken. As an example, for this routing configuration:

  1. routing {
  2. trace { application.log.trace(it.buildText()) }
  3. get("/bar") { call.respond("/bar") }
  4. get("/baz") { call.respond("/baz") }
  5. get("/baz/x") { call.respond("/baz/x") }
  6. get("/baz/x/{optional?}") { call.respond("/baz/x/{optional?}") }
  7. get("/baz/{y}") { call.respond("/baz/{y}") }
  8. get("/baz/{y}/value") { call.respond("/baz/{y}/value") }
  9. get("/{param}") { call.respond("/{param}") }
  10. get("/{param}/x") { call.respond("/{param}/x") }
  11. get("/{param}/x/z") { call.respond("/{param}/x/z") }
  12. get("/*/extra") { call.respond("/*/extra") }
  13. }

The output if requesting /bar would be:

  1. Trace for [bar]
  2. /, segment:0 -> SUCCESS @ /bar/(method:GET))
  3. /bar, segment:1 -> SUCCESS @ /bar/(method:GET))
  4. /bar/(method:GET), segment:1 -> SUCCESS @ /bar/(method:GET))
  5. /baz, segment:0 -> FAILURE "Selector didn't match" @ /baz)
  6. /{param}, segment:0 -> FAILURE "Better match was already found" @ /{param})
  7. /*, segment:0 -> FAILURE "Better match was already found" @ /*)

note

Tracing Routes - 图2

Remember to remove or disable this function when going into production.