How can I log every request/response body in Armeria HTTP client

466 Views Asked by At

I tried two approaches to log every HTTP body produced/received by my armeria client:

  1. using out-of-box LoggingClient decorator
decorator(LoggingClient.newDecorator())
  1. creating custom logging decorator
decorator { delegate, ctx, req ->
        ctx.log().whenRequestComplete().thenAccept { log -> logger.trace(log.toStringRequestOnly()) }
        ctx.log().whenComplete().thenAccept { log -> logger.trace(log.toStringResponseOnly()) }
        delegate.execute(ctx, req)
    }

But I see in logs only headers and other technical information. How can I log requestContent/responseContent?

It's said in armeria documentation that these fields are available only for Thrift clients:

the serialization-dependent content object of the request. ThriftCall for Thrift. null otherwise. the serialization-dependent content object of the response. ThriftReply for Thrift. null otherwise.

It's weird to me.

2

There are 2 best solutions below

0
Andrey On

I had to add com.linecorp.armeria.client.logging.ContentPreviewingClient decorator in addition to logging decorator:

decorator(ContentPreviewingClient.newDecorator(1000))
1
Kavya Vishwanath B On

LoggingClient is mostly for rpc requests. I had to use ContentPreviewingClient and access request-response payloads via requestContentPreview() and responseContentPreview()