question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose correct matching path in `app.before()`

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
spinscalecommented, Sep 16, 2020

indeed, app.after() with ctx.endpointHandlerPath() works as well.

Thanks David, I’ll close this one for now.

0reactions
tipsycommented, Sep 16, 2020

You might be looking for ctx.endpointHandlerPath(), which doesn’t update in filters.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Difference between app.use and app.get in express.js
app.use() will only see whether url starts with specified path. But, app.all() will match the complete path.
Read more >
Configuring Routes and Domains | Cloud Foundry Docs
Use the cf CLI cf map-route command to associate an app and route. ... use a route to match requests until the route...
Read more >
Regular expressions in paths - NGINX Ingress Controller
In NGINX, regular expressions follow a first match policy. In order to enable more accurate path matching, ingress-nginx first orders the paths by...
Read more >
The Art of Routing in Flask - Hackers and Slackers
Flask's "Hello world" example defines a route listening at the root our app and executes a view function called home() : from flask...
Read more >
Working with routes for HTTP APIs - Amazon API Gateway
Routes consist of two parts: an HTTP method and a resource path—for example, ... Match for a route and method with a greedy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found