opbeat_python icon indicating copy to clipboard operation
opbeat_python copied to clipboard

Better view names for DRF/Tastpie transactions

Open roncohen opened this issue 10 years ago • 6 comments

Django Rest Framework ViewSets will show up as a single transaction even though a ViewSet might have different methods that provide different functionality.

roncohen avatar Sep 14 '15 10:09 roncohen

any updates on this?

hurrba avatar Nov 02 '15 17:11 hurrba

:+1:

dizballanze avatar Jan 19 '16 12:01 dizballanze

FYI there is a workaround here: https://gist.github.com/piquadrat/b494bd4b368ea4095dad3b629333ae58

santiagomalter avatar Jan 27 '17 13:01 santiagomalter

@santiagomalter the link is now broken, do you have any other info on the workaround? We are facing the same issue

sathoro avatar Jul 25 '17 16:07 sathoro

This is the one: https://gist.github.com/beniwohli/b494bd4b368ea4095dad3b629333ae58

jalvz avatar Jul 26 '17 09:07 jalvz

@jalvz Thanks! I ended up creating a more generic solution:

class OpbeatViewNameMiddleware(object):
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        return self.get_response(request)

    def process_view(self, request, view_func, view_args, view_kwargs):
        if (
            hasattr(request, '_opbeat_view_func') and
            hasattr(request, 'resolver_match')
        ):
            if hasattr(view_func, '__name__'):
                view_name = view_func.__name__
            else:
                view_name = view_func.__class__.__name__

            url_name = request.resolver_match.url_name

            if url_name:
                request._opbeat_transaction_name = '%s %s' % (view_name, request.resolver_match.url_name)
            else:
                request._opbeat_transaction_name = view_name

sathoro avatar Jul 26 '17 18:07 sathoro