Koa integration: resource tagging by route only works for routes defined by koa-router
A lot of our node-koa apps serve single page webapps that do client-side routing, so they don't use koa-router. When this is the case, it's hard to distinguish requests for the main payload with requests for other static assets in the APM UI.
For example in our "contacts" app, both main payload requests and static asset requests get bucketed into the same GET resource that doesn't have a route associated with it:
Both types of traces are commingled in this resource:
Static asset request:

Main payload request:

Specifically, we use koa-heartbeat and koa-static-server
This is a major pain point for my team as well. I would love some documentation using the official libraries which explains how to implement custom resource endpoints.
There are a few options depending on the specific case:
koa-heartbeat
In this case, since it's only a heartbeat I assume what is wanted is to ignore these routes. This can be done with the blacklist option of the tracer which will stop tracing these routes:
tracer.use('koa', {
blacklist: ['/healthz']
})
Custom or unsupported routers
In this case the route can be added manually in a span hook:
tracer.use('koa', {
hooks: {
request: (span, req, res) => {
span.setTag('http.route', req.myCustomRoute)
}
}
})
koa-static-server
In this case, it's not really possible to provide a relevant value since there is no route. Using the URL is not really a good option since the cardinality would be really high and the produced data would not really be valuable. If you know that there is a finite number of known static assets that do not vary a lot, then it would be possible to use the hook from above as if it was a route.
We could definitely document all of this better, but otherwise it should be possible to achieve the end goal with the existing constructs.
Please let me know if this helps!
Closing as there is no way to do this out of the box without a router that we can patch, and solutions for individual use cases were provided above.