Skip to content
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

Return a request ID in the error response to aid in debugging #2521

Closed
1 task
chouinar opened this issue Oct 18, 2024 · 0 comments · Fixed by #2523
Closed
1 task

Return a request ID in the error response to aid in debugging #2521

chouinar opened this issue Oct 18, 2024 · 0 comments · Fixed by #2523
Assignees

Comments

@chouinar
Copy link
Collaborator

Summary

In the event that a user encounters an error while using our API, we want to return a unique ID that lets one of our developers connect it back to log messages easily.

We already generate a request.internal_id and attach it to all log messages for a requests lifecycle, so re-using that sounds like it would work, it's just a matter of piping this through to our error_processor that constructs the error responses. We can likely use Flask contexts (g probably?) to handle getting this where it needs to go.

Acceptance criteria

  • Request ID piped through for all (4xx and 5xx) errors
@chouinar chouinar self-assigned this Oct 18, 2024
@chouinar chouinar moved this from Icebox to In Progress in Simpler.Grants.gov Product Backlog Oct 18, 2024
@chouinar chouinar moved this from In Progress to In Review in Simpler.Grants.gov Product Backlog Oct 18, 2024
chouinar added a commit that referenced this issue Oct 23, 2024
…st ID (#2523)

## Summary
Fixes #2521

### Time to review: __3 mins__

## Changes proposed
Return the internal request ID in all error responses

## Context for reviewers
A follow-up from a discussion we had yesterday. This can aid in
debugging as a user can just give us the ID and we can easily look up
the corresponding logs.

Note `g` in Flask is a request-local global context (ie. each request
has their own separate `g`) which we use for storing a few other logging
related things already safely.
https://flask.palletsprojects.com/en/3.0.x/appcontext/#storing-data

## Additional information
<img width="1082" alt="Screenshot 2024-10-18 at 12 15 49 PM"
src="https://github.com/user-attachments/assets/e47874ed-8219-447c-947c-1c1bbd48f775">

<img width="715" alt="Screenshot 2024-10-18 at 12 16 09 PM"
src="https://github.com/user-attachments/assets/f3b921e4-f52f-4882-b017-5d3275100c7f">

<img width="558" alt="Screenshot 2024-10-18 at 12 17 05 PM"
src="https://github.com/user-attachments/assets/0ea12677-8632-46d6-bf1b-153ada50add6">

An example of the logs that show the internal ID - note I trimmed out
the full error message as it's a very long stack trace.
![Screenshot 2024-10-18 at 12 17
25 PM](https://github.com/user-attachments/assets/e923f84d-e295-4719-9d80-65ac98f13ca8)

---------

Co-authored-by: nava-platform-bot <platform-admins@navapbc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

1 participant