Include crate name and version in the publish API's log entries #2234
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR includes the crate name and version in the log entries of the publish API, to fix #2228 and to aid debugging issues in production. This is done in three steps.
First, the log entry generation code was refactored to easily allow adding new fields to it. Now, instead of hardcoding the list of fields in a
format!
macro, there is a builder with methods to add individual fields.Then, a way to attach custom log fields to a response was added. This is implemented by setting HTTP headers in the response starting withX-CratesIo-Log-Metadata-
, and by changing the middleware responsible for request logging to strip those headers and add their content to the log line instead.Then, a way to attach custom log fields to a response was added. This is implemented as a "request extension", with a convenience method in the
ResponseExt
trait to add the custom log fields to all responses generated by that request.Finally, this new feature was used to attach the crate name and version to the publish API's log entries.
r? @sgrif