-
Notifications
You must be signed in to change notification settings - Fork 328
Description
I am trying to add the ability to correlate request and response log messages. Currently, both the :logging
and :instrumentation
features handle the request and response independently, so there is no way to definitively correlate a "response" log message with the "request" log message that initiated it.
One idea I had was to add a request_identifier
attribute to HTTP::Request
and HTTP::Response
. The source of the value could be pluggable, although a simple SecureRandom.hex
is probably sufficient. It would be set on the Request object, and then copied over to the Response object within perform
(the copy step could be avoided if the request is added to the response object.
I was hoping I could implement this solely via the Feature
mechanism, but wrap_response
has no access to the Request and there doesn't seem to be a good way to share state between calls to wrap_request
and wrap_response
(that wouldn't be global to all requests from the client).
If the Response had full access to the Request, you could add a more generic concept like Request#call_context
(or metadata
) instead of request_identifier
. It would just be custom data for use by Features that isn't used to build the request directly. Then a Feature
would be able to add a request identifier to the Request#call_context
hash, and with access to the Request from the Response, pull the value out of the call_context
hash.
-
Is there a reason Get the request object from the response? #463 has not been implemented? I don't see why it would have to be a breaking change. You could continue to set Response#uri to keep compatibility, even though it would be redundant with
Response#request.uri
. -
Any other suggestions on how a correlation identifier could be added to separate request and response logs?