Expose correct matching path in `app.before()`
See original GitHub issueDescribe the feature
This is a bit of weird title, I couldn’t come up with a better one. I am currently using javalin in a example that describes how to add elastic observability features to a java application. One of the features I wanted to add, was to refer to the value of ctx.matchedPath()
as part of the transaction name, so you can see the name like GET /foo/:bar
to keep the cardinality low, if there are millions of variants of the bar
variable. However this was not so easy as I thought, as simply calling a app.before()
handler does not work, as the matched path will be set to *
in that case.
// matched path will always be `*`
app.before(ctx -> ElasticApm.currentTransaction().setName(ctx.method() + " " + ctx.matchedPath()));
A workaround could be to add the call to set the transaction name in each registered handler (or have a functional ApmHandler
interface, that you need to extend from, which is doing this) - which I am considering now.
Maybe you have a better idea to expose the matched path on the framework level.
If not, feel free to close as usual (and also nice move to include JTE in the last release 😃
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
indeed,
app.after()
withctx.endpointHandlerPath()
works as well.Thanks David, I’ll close this one for now.
You might be looking for
ctx.endpointHandlerPath()
, which doesn’t update in filters.