Skip to content

Add post about canonical request logs in Flask#594

Open
lhansford wants to merge 1 commit intomainfrom
canonical-request-logs-in-flask
Open

Add post about canonical request logs in Flask#594
lhansford wants to merge 1 commit intomainfrom
canonical-request-logs-in-flask

Conversation

@lhansford
Copy link
Copy Markdown
Contributor

No description provided.

@lhansford lhansford requested a review from a team as a code owner January 9, 2026 05:40
@lhansford lhansford requested review from igorbelo and removed request for a team January 9, 2026 05:40
g.start = time.time_ns()
```

When a new request starts we do two things. First is to call `clear_contextvars()` to remove any pre-existing values for the log (this shouldn't be an issue, but is good hygiene). Second is to set a marker for the time the request started, as we'll be adding the duration of the request to our log later on.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

~~nit: looks cleaner
Feel free to ignore

Suggested change
When a new request starts we do two things. First is to call `clear_contextvars()` to remove any pre-existing values for the log (this shouldn't be an issue, but is good hygiene). Second is to set a marker for the time the request started, as we'll be adding the duration of the request to our log later on.
When a new request starts we do two things-
- First is to call `clear_contextvars()` to remove any pre-existing values for the log (this shouldn't be an issue, but is good hygiene).
- Second is to set a marker for the time the request started, as we'll be adding the duration of the request to our log later on.

}
```

One core element of `bind_contextvars` is that it will apply to all logs we output during the request. So if we need to log an error message during the request, as well as the final request log, those bound attributes will be included in both logs.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

~~nit: This sounded better to me. Again feel free to ignore.

Suggested change
One core element of `bind_contextvars` is that it will apply to all logs we output during the request. So if we need to log an error message during the request, as well as the final request log, those bound attributes will be included in both logs.
One core element of `bind_contextvars` is that it will apply to all logs we output during the request. So if we log an error message during the request or the final request log, those bound attributes will be included in either of the logs.

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.

2 participants