Experimental WAI middleware to instrument OpenTelemetry spans with Servant routing information.
This middleware adds the http.route
attribute to the span created by the WAI OpenTelemetry middleware.
Dynamic path segments in this attribute are replaced by their placeholder name.
For example, imagine the following Servant API:
-- GET /hello/:name
type Api = "hello" :> Capture "name" Text :> Get '[JSON] Text
The WAI instrumentation can capture the path segments of the requested URL.
This is recorded as http.target
.
But by querying Servant, we can figure out which paths segments are dynamic vs static and replace them with the symbol defined in the API.
In this case, there
is replaced by :name
.
http.target |
http.route |
---|---|
hello/there | hello/:name |
The WAI middleware will detect this attribute and will use it to update the name of the entire span.
The main use-cases for this are to:
- Filter traces by endpoint.
- Compute per-endpoint metrics with the
spanmetrics
connector.
See the sample server in exe/Main.hs
.
-
Install
devenv
. -
Launch the processes. This launches the demo server and an instance of the OpenTelemetry Collector.
devenv up
-
Query the server on port
4567
.curl http://localhost:4567/hello/there
Verify that the trace is recorded in the OpenTelemetry Collector.