Open julyvee opened 11 months ago
Hey, I mostly agree with this solution. However, I wish the "formatting" would be extendable, which is not something doable in the current state
I wish I could integrate third-party tools, like otel, perhaps in those timers and not just change the way it's being parsed
This might be a little oos for your proposed feature but I want to have some time with the way this Middleware behaves optionally, avoiding BaseHTTPMiddleware upcoming depreciation
Is your feature request related to a problem? Please describe. The timing middleware currently always outputs its information as a string, which is supposed to be logged for example. You can define any method that takes a string argument as the callable. But in my case I want to send the timing information to a metrics server and I have to write custom logic to parse this timing information out of the formatted string.
Describe the solution you'd like I would like alternate options for outputs, for example a data class containing all the timing information and then I would specify a callable which takes this class as an argument.
Describe alternatives you've considered Alternatively, a string output but in JSON format would be more easily parsable.
Additional context The JSON format string and support for self defined message formatters was actually already implemented in the original repository, but the PR never got merged: https://github.com/dmontagu/fastapi-utils/pull/141