Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Request/Response/Error Tracers #18

Open
gerryfletch opened this issue Nov 15, 2021 · 0 comments
Open

Custom Request/Response/Error Tracers #18

gerryfletch opened this issue Nov 15, 2021 · 0 comments

Comments

@gerryfletch
Copy link
Contributor

Description

It would be useful to be able to provide custom tracers, of the form:

  • Request[F] => F[Unit]
  • Response[F] => F[Unit]
  • Throwable => F[Unit]

Use Case

  • Trace the request+response body based on Content-Type encoding and, for example, do-not-trace headers
  • Write non-sensitive HTTP headers as trace properties
  • Custom traces based on Throwable properties for monitoring & alerting

API Suggestion

def server[F[_]: Trace](
  routes: HttpRoutes[F],
  withRequestTracer: Option[Request[F] => F[Unit]] = None,
  withResponseTracer: Option[Response[F] => F[Unit]] = None,
  withErrorTracer: Option[Throwable => F[Unit]] = None
)(
  implicit ev: MonadCancel[F, Throwable]
): HttpRoutes[F] =
  Kleisli { req =>
    val additionalRequestTracer = withRequestTracer.getOrElse((_: Request[F]) => ().pure[F])
    val additionalResponseTracer = withResponseTracer.getOrElse((_: Response[F]) => ().pure[F])
    val additionalErrorTracer = withErrorTracer.getOrElse((_: Throwable) => ().pure[F])
    // ...
    val addRequestFields: F[Unit] =
      Trace[F].put(
        Tags.http.method(req.method.name),
        Tags.http.url(req.uri.renderString),
      ) *> additionalRequestTracer(req)
     // etc    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant