Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Add request id to logs #777

Merged
merged 1 commit into from
Jul 1, 2022
Merged

Add request id to logs #777

merged 1 commit into from
Jul 1, 2022

Conversation

sarayourfriend
Copy link
Contributor

@sarayourfriend sarayourfriend commented Jun 29, 2022

Fixes

Part of WordPress/openverse#689 by @sarayourfriend

Description

Adds request IDs to all logs so that we can trace them easily throughout a request without having to rebuild it ourselves (we can simply query for the request ID and then follow a request's logs in their entirety).

I want to split out this part from #776 because it applies cleanly without interrupting the revert of #741 that @dhruvkb is going to work on. Getting request IDs so that we can trace logs through requests is useful at any point that we deploy next, even if we don't get in new diagnostic logging.

Initially I was going to write the filter and middleware myself but this library appears well enough maintained and is simple enough that I am not worried about adding it. It also has apparently figured out some problems and edge cases that we would inevitably run into if we hand-spun this functionality.

Testing Instructions

CI should pass. Checkout the branch locally and run the app and make a request (like to /v1/images?q=waves) and confirm you see something like this in your logs (noting the request id):

openverse-api-web-1               | [2022-06-29 05:33:18,289 - catalog.api.utils.validate_images - 103][INFO] [7d3d1f0b82334242a352eb0e4361283e] Validated images in 1.8959648609161377 
openverse-api-web-1               | [2022-06-29 05:33:18,328 - log_request_id.middleware -  47][INFO] [7d3d1f0b82334242a352eb0e4361283e] method=GET path=/v1/images/ status=200

Here, 7d3d1f0b82334242a352eb0e4361283e is the request id.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • [N/A] I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@sarayourfriend sarayourfriend requested a review from a team as a code owner June 29, 2022 05:34
@openverse-bot openverse-bot added the 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work label Jun 29, 2022
@sarayourfriend sarayourfriend added 🟨 priority: medium Not blocking but should be addressed soon 💻 aspect: code Concerns the software code in the repository dependencies Pull requests that update a dependency file 🧰 goal: internal improvement Improvement that benefits maintainers, not users and removed 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work labels Jun 29, 2022
@github-actions
Copy link

github-actions bot commented Jun 29, 2022

API Developer Docs Preview: Ready

https://wordpress.github.io/openverse-api/_preview/777

Please note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again.

You can check the GitHub pages deployment action list to see the current status of the deployments.

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! How would the request id be used?

@sarayourfriend
Copy link
Contributor Author

I added a blurb in the PR description to describe how we would use this. Essentially it is a way to be able to get all the logs from a particular request to be able to "trace" the request through the logs. Sometimes this is also called a "trace id" for the same reason. If we ever had multiple services, we can forwards this request ID to those services so that their logs also include the same request ID for the same request "session" and we would be able to tie everything together.

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition, local logs are appearing correctly.

@sarayourfriend sarayourfriend merged commit 8a47f33 into main Jul 1, 2022
@sarayourfriend sarayourfriend deleted the add/request-id-logs branch July 1, 2022 03:03
@AetherUnbound
Copy link
Contributor

This is so cool, great idea!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository dependencies Pull requests that update a dependency file 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🟨 priority: medium Not blocking but should be addressed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants