Skip to content

OpenTelemetry instrumentation for Servant, compatible with hs-opentelemetry.

License

Notifications You must be signed in to change notification settings

cachix/hs-opentelemetry-instrumentation-servant

Repository files navigation

hs-opentelemetry-instrumentation-servant

Experimental WAI middleware to instrument OpenTelemetry spans with Servant routing information.

Why

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:

  1. Filter traces by endpoint.
  2. Compute per-endpoint metrics with the spanmetrics connector.

Usage

See the sample server in exe/Main.hs.

Demo

  1. Install devenv.

  2. Launch the processes. This launches the demo server and an instance of the OpenTelemetry Collector.

    devenv up
  3. Query the server on port 4567.

    curl http://localhost:4567/hello/there

    Verify that the trace is recorded in the OpenTelemetry Collector.

About

OpenTelemetry instrumentation for Servant, compatible with hs-opentelemetry.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published