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

Elapsed and timestamp values are not available to filename_format function #2775

Closed
joshwilson-dbx opened this issue Aug 22, 2023 · 1 comment · Fixed by #2777
Closed

Elapsed and timestamp values are not available to filename_format function #2775

joshwilson-dbx opened this issue Aug 22, 2023 · 1 comment · Fixed by #2777
Milestone

Comments

@joshwilson-dbx
Copy link
Contributor

When the ProfilerMiddleware filename_format argument is a callable, the callable will only receive the WSGI environ variable. However, the default format string can use the elapsed and time values. This means that one using a format function cannot recreate a similar output pattern. In my case, I'd like to use both, but format the timestamp differently.

Example: I'd like a filename of the form 2023-08-21:14:05:05.POST.myurl.13ms.prof. I can get the timestamp by doing my own datetime.now() call, but the elapsed time is not available.

This problem is solvable by subclassing ProfilerMiddleware or writing ones own profiling middleware, but this seems like a useful thing to have in the core library so library users don't need to duplicate the __call__() code in their own projects.

I can submit a PR if this change is welcome.

joshwilson-dbx added a commit to joshwilson-dbx/werkzeug that referenced this issue Aug 31, 2023
This allows one to provide a `filename_format()` function to
`ProfileMiddleware` that receives as much info as is provided to the
format string option. Prior to this change, one could not replicate
the format string format, much less modify how it would render the
timestamp or elapsed time values.

Addresses pallets#2775
joshwilson-dbx added a commit to joshwilson-dbx/werkzeug that referenced this issue Aug 31, 2023
This allows one to provide a `filename_format()` function to
`ProfileMiddleware` that receives as much info as is provided to the
format string option. Prior to this change, one could not replicate
the format string format, much less modify how it would render the
timestamp or elapsed time values.

Addresses pallets#2775
@davidism davidism added this to the 3.0.0 milestone Sep 5, 2023
joshwilson-dbx added a commit to joshwilson-dbx/werkzeug that referenced this issue Sep 20, 2023
This provides the `elapsed` and `time` values to the
`ProfileMiddleware(filename_format=...)` function. Prior to this change,
one could not replicate the format string format, much less modify how
it would render the timestamp or elapsed time values.

These new values can be found under the `werkzeug.profiler` key in the
WSGI environ dict passed into the `filename_format()` function.

Addresses pallets#2775
@joshwilson-dbx
Copy link
Contributor Author

I think I addressed all the comments and concerns on that PR. Let me know if you'd like any further changes!

pgjones pushed a commit that referenced this issue Sep 24, 2023
This provides the `elapsed` and `time` values to the
`ProfileMiddleware(filename_format=...)` function. Prior to this change,
one could not replicate the format string format, much less modify how
it would render the timestamp or elapsed time values.

These new values can be found under the `werkzeug.profiler` key in the
WSGI environ dict passed into the `filename_format()` function.

Addresses #2775
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants