http4s-timer Maven Central Build Status Scala Steward badge License: GPL v3


This adds timing capability to http4s, with a possible concrete implementation for New Relic

New Relic Usage

Add to your library dependencies:

"pl.datart" %% "http4s-timer-newrelic" % <version>

You should have the New Relic agent installed, with custom annotations enabled.

Changes to HttpRoutes[F]

If your initial version looks like:

val routes = HttpRoutes[IO] {
  case GET -> Root / "hello" / name =>
    Ok(Json.obj("message" -> Json.fromString(s"Hello, ${name}")))

then this should be modified to:

import pl.datart.http4s.timer._
import pl.datart.http4s.timer.newrelic._

val routes = TimedRoutes[IO]("my_routes") {
  case GET -> Root / "hello" / name =>
    "hello/:name" ->
      Ok(Json.obj("message" -> Json.fromString(s"Hello, ${name}")))

The body of each partial function now returns a tuple of path name, and the contents of the resulting HTTP response. The path name cannot be taken directly from the requested path, as many paths vary in such things like user ID, but these should not be included in the path sent to monitoring.

Changes to AuthedRoutes[F]

Similarly, you should modify any AuthedRoutes to use TimedAuthedRoutes.

Library Dependencies

The core library is dependent on "org.http4s" %% "http4s-core" % "1.0.0-M39". Starting from "1.0.0-M31" Scala 2.12 is not supported and up to version "1.0.0-M37" there is a known vulnerability, so eventually versions 1.x.y and higher of http4s-timer have dropped support for Scala 2.12.

The newrelic library is also dependent on "" % "newrelic-api" % "8.0.1"

Origin & credits

This repo is a fork of the original library from @fiadliel available at