Skip to content

ClientMiddleware: document the caveats #117

Open
@iRevive

Description

ClientMiddleware could be tricky and doesn't always meet expectations.

val client: Client[IO] = ClientMiddleware.default[IO].build(...)
client.run(request).use(response => Tracer[IO].currentSpanContext.debug()) // prints None

I'm almost sure that most people would expect Tracer[IO].currentSpanContext.debug() to print an active span context there.
However, it does not work that way due to limitations: 1, 2.

What can we do?

  1. Document why it doesn't work
  2. Provide a workaround

A workaround could be the following:

  1. A text map propagator (e.g. W3CContextPropagator) must be enabled to make this work
  2. Add tracing headers to the response: resp.withHeaders(traceHeaders ++ resp.headers)
  3. A user must explicitly join the active span via Tracer[F].joinOrRoot:
client.run(request).use { response =>
  Tracer[IO].joinOrRoot(response.headers)(
    tracer.currentSpanContext.debug() // prints an active span context, all good
  )
}

This is not the case with the ServerMiddleware because HttpRoutes isn't described as a Resource but as Kleisli.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions