Skip to content

Server middleware supportΒ #627

@lacarvalho91

Description

@lacarvalho91

Overview

I'd like to be able to configure a server with a middleware that would run on each request, similar to what is possible with http4s middleware.

Where this idea has come from is I've been writing servers that use otel4s to attach to existing traces (passed to the server as metadata). This works fine, but the problem is this needs to be done for every server implementation. I would instead like to be able to do this in a generic way and be able to configure the server with this behaviour.

I can't really use gRPC interceptors for this, because the state of the context in cats.mtl.Local (which otel4s and other libs use) is scoped only to the effect passed into local.

From looking into the code, we could intercept the request in the Fs2ServerCallHandler and wrap the implementation: (Request, Metadata) => F[Response] in a middleware. Then allow passing middlewares in the GeneratedCompanion.service.

Metadata

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