[Twisted-Python] Klein?

Robert DiFalco robert.difalco at gmail.com
Thu Mar 4 22:01:35 MST 2021


Thanks! The trick will be figuring out how to handle Python exception
vs werkzeug exception, and the branched, error handling routes etc.
Currently this is the sort of data structure I'm posting to Data Dog. But I
can make it a pluggable observer-type idiom so anything can receive these
metrics.

tags=[
    "path:{}.{}.{}".format(module, className, method),
    "blocking:{}".format(isBlocking),
    "module:{}".format(module),
    "class:{}".format(className),
    "method:{}".format(method),
    "status_code:{}".format(request_code),
    "status_code_class:{}xx".format(status_code_class),
]
metrics.timing("my.rest.endpoint", elapsed, tags=tags)

I don't have it quite right yet. It's hard to get the status code, deal
with unhandled exceptions, etc. But I'll post questions here when I'm
closer.

On Wed, Mar 3, 2021 at 11:13 PM Glyph <glyph at twistedmatrix.com> wrote:

>
>
> On Mar 1, 2021, at 12:51 PM, Robert DiFalco <robert.difalco at gmail.com>
> wrote:
>
> Is this the right place to ask klein questions?
>
>
> Absolutely, it's a Twisted org project.
>
> I'm writing a metrics plugin for Klein and I can't figure out how to
> inject a metrics handler so that I can get route, path, duration, and
> status code. What I'm doing now sucks because Klein and twisted interact in
> complex ways on Failure and status codes.
>
> # Replace the klein _call with the metrics generating call
> _app._call = _callWithMetrics
>
> Rather than replace _call with my version of _call I was hoping there was
> a cleaner way to get the start and stop with the result code of a route
> invocation. Thoughts?
>
>
> It sounds like you should contribute a patch that makes this an
> explicitly-supported pluggable entrypoint, rather than relying on a hack.
> No need to figure out a way to make it work with existing versions, the
> magic of open source is that you can change it :).
>
> Feel free to ping here when it's done to remind folks to do a review.
>
> -g
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20210304/82a7d84c/attachment.htm>


More information about the Twisted-Python mailing list