def instrument_django_core_handlers_wsgi(module): # Wrap the WSGI application entry point. If this is also # wrapped from the WSGI script file or by the WSGI hosting # mechanism then those will take precedence. import django framework = ('Django', django.get_version()) module.WSGIHandler.__call__ = WSGIApplicationWrapper( module.WSGIHandler.__call__, framework=framework) # Wrap handle_uncaught_exception() of WSGIHandler so that # can capture exception details of any exception which # wasn't caught and dealt with by an exception middleware. # The handle_uncaught_exception() function produces a 500 # error response page and otherwise suppresses the # exception, so last chance to do this as exception will not # propogate up to the WSGI application. if hasattr(module.WSGIHandler, 'handle_uncaught_exception'): module.WSGIHandler.handle_uncaught_exception = ( wrap_handle_uncaught_exception( module.WSGIHandler.handle_uncaught_exception))
def wrapper_WSGIServer___init__(*args, **kwargs): def _bind_params(self, listener, application, *args, **kwargs): return self, listener, application, args, kwargs self, listener, application, _args, _kwargs = _bind_params( *args, **kwargs) application = WSGIApplicationWrapper(application) _args = (self, listener, application) + _args return _args, _kwargs
def _nr_wrapper_Application_wsgi_(application): # Normally Application.wsgi() returns a WSGI application, but in # the case of the Tornado worker it can return an Tornado ASYNC # application object. Not being a WSGI application object we can # not wrap it with a WSGI application wrapper as the prototype # mismatch will cause it to fail when called. # # Having to have this check in this way is a bit annoying, but # the only other alternative was to instrument separately all the # different worker types which would have been more work. Thus # tolerate having the check here. if not 'tornado.web' in sys.modules: return WSGIApplicationWrapper(application) try: import tornado.web except ImportError: return WSGIApplicationWrapper(application) if not isinstance(application, tornado.web.Application): return WSGIApplicationWrapper(application) return application
def _nr_wrapper_Application_wsgi_(application): # Normally Application.wsgi() returns a WSGI application, but in # some async frameworks a special class or coroutine is returned. We must # check for those cases and avoid insturmenting the coroutine or # specialized class. try: if 'tornado.web' in sys.modules: import tornado.web if isinstance(application, tornado.web.Application): return application except ImportError: pass if not is_coroutine_function(application): return WSGIApplicationWrapper(application) return application
def wrap_wsgi_application_entry_point(server, application, **kwargs): return (( server, WSGIApplicationWrapper(application, framework='Django'), ), kwargs)