Logging request's attributes in server log

We are running tapir with caliban, which acts very well together. But graphql is served on one path and that makes path logging useless for us, while there is a notion of operation name in graphql, which we want to log instead. Plus we have a user id which is authenticated in request interceptor, which we put in request attributes. Now we want to log some request’s attrs in server logs, to get smth like this:

2022-12-23T09:10:09.097413674Z DEBUG [ZScheduler-0] s.t.s.http4s.Http4sDefaultServerLog - Request: POST /api/graphql, handled by: POST *, took: 14085ms; response: 200; operation name: weatherForecast; user:  x123456

I think it would be best to create a custom GraphqlLoggingInterceptor - similarly to the one which performs authentication.

In fact, this might be even slightly easier: providing a custom ServerLog implementation should do the trick. The methods receive the whole request as a parameter, so you should be able to get all that you need.

The operation names comes in a query parameter? If so, it shouldn’t be a problem to log this as well. You can then substitute the ServerLog implementation using the CustomiseInterceptors.serverLog method.