Skip to content

Include crate name and version in the publish API's log entries #2234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 29, 2020

Conversation

pietroalbini
Copy link
Member

@pietroalbini pietroalbini commented Feb 29, 2020

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 with X-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

@jtgeibel
Copy link
Member

Looks like a great approach overall to me @pietroalbini. The only suggestion I have (and this seems kind of backwards but I think it makes sense) is that instead of using phantom Response headers, it may be easier to attach the metadata to the extensions TypeMap in the Request which will propagate back up the middleware stack.

Then there could either be a wrapper type for each field, or a LoggingMetadata(HashMap<&'str, String>) that fields get added to. It looks like this is already how the "metadata_length" is propograted (although it is less clear because it just uses a bare u64 type).

This change would allow the metadata to be captured and attached to the request early in an endpoint. That way if the endpoint returns early due to an error then the logging metadata has already been captured and will not be lost. I think the current implementation will not log the additional metadata if the publish fails early with a user-facing or internal server error.

@pietroalbini
Copy link
Member Author

That's a great point!

@pietroalbini
Copy link
Member Author

@jtgeibel implemented the change!

r? @jtgeibel

@rust-highfive rust-highfive assigned jtgeibel and unassigned sgrif Feb 29, 2020
@jtgeibel
Copy link
Member

This looks great!

@bors r+

@bors
Copy link
Contributor

bors commented Feb 29, 2020

📌 Commit 062645f has been approved by jtgeibel

@bors
Copy link
Contributor

bors commented Feb 29, 2020

⌛ Testing commit 062645f with merge 1778505...

@bors
Copy link
Contributor

bors commented Feb 29, 2020

☀️ Test successful - checks-travis
Approved by: jtgeibel
Pushing 1778505 to master...

@bors bors merged commit 1778505 into rust-lang:master Feb 29, 2020
@pietroalbini pietroalbini deleted the log-publish-crate branch February 29, 2020 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include the crate name in the publish API's log entry
5 participants