예제 #1
0
def instrument_flask_app(module):
    wrap_wsgi_application(module, 'Flask.wsgi_app',
            framework=framework_details())

    wrap_function_wrapper(module, 'Flask.add_url_rule',
            _nr_wrapper_Flask_add_url_rule_input_)

    if hasattr(module.Flask, 'endpoint'):
        wrap_function_wrapper(module, 'Flask.endpoint',
                _nr_wrapper_Flask_endpoint_)

    wrap_function_wrapper(module, 'Flask.handle_http_exception',
            _nr_wrapper_Flask_handle_http_exception_)

    # Use the same wrapper for initial user exception processing and
    # fallback for unhandled exceptions.

    if hasattr(module.Flask, 'handle_user_exception'):
        wrap_function_wrapper(module, 'Flask.handle_user_exception',
                _nr_wrapper_Flask_handle_exception_)

    wrap_function_wrapper(module, 'Flask.handle_exception',
            _nr_wrapper_Flask_handle_exception_)

    # The _register_error_handler() method was only introduced in
    # Flask version 0.7.0.

    if hasattr(module.Flask, '_register_error_handler'):
        wrap_function_wrapper(module, 'Flask._register_error_handler',
                _nr_wrapper_Flask__register_error_handler_)

    # Different before/after methods were added in different versions.
    # Check for the presence of everything before patching.

    if hasattr(module.Flask, 'try_trigger_before_first_request_functions'):
        wrap_function_wrapper(module,
                'Flask.try_trigger_before_first_request_functions',
                _nr_wrapper_Flask_try_trigger_before_first_request_functions_)
        wrap_function_wrapper(module, 'Flask.before_first_request',
                _nr_wrapper_Flask_before_first_request_)

    if hasattr(module.Flask, 'preprocess_request'):
        wrap_function_trace(module, 'Flask.preprocess_request')
        wrap_function_wrapper(module, 'Flask.before_request',
                _nr_wrapper_Flask_before_request_)

    if hasattr(module.Flask, 'process_response'):
        wrap_function_trace(module, 'Flask.process_response')
        wrap_function_wrapper(module, 'Flask.after_request',
                _nr_wrapper_Flask_after_request_)

    if hasattr(module.Flask, 'do_teardown_request'):
        wrap_function_trace(module, 'Flask.do_teardown_request')
        wrap_function_wrapper(module, 'Flask.teardown_request',
                _nr_wrapper_Flask_teardown_request_)

    if hasattr(module.Flask, 'do_teardown_appcontext'):
        wrap_function_trace(module, 'Flask.do_teardown_appcontext')
        wrap_function_wrapper(module, 'Flask.teardown_appcontext',
                _nr_wrapper_Flask_teardown_appcontext_)
예제 #2
0
def instrument_falcon_app(module):
    framework = framework_details()

    wrap_handle_exception = \
            build_wrap_handle_exception(_bind_handle_exception_v2)

    wrap_wsgi_application(module, 'App.__call__', framework=framework)

    wrap_function_wrapper(module, 'App._handle_exception',
                          wrap_handle_exception)
def instrument_pyramid_router(module):
    pyramid_version = None

    try:
        import pkg_resources
        pyramid_version = pkg_resources.get_distribution('pyramid').version
    except Exception:
        pass

    wrap_wsgi_application(module,
                          'Router.__call__',
                          framework=('Pyramid', pyramid_version))
예제 #4
0
def instrument_falcon_api(module):
    framework = framework_details()

    major_version = int(framework[1].split('.')[0])
    if major_version < 2:
        wrap_handle_exception = \
                build_wrap_handle_exception(_bind_handle_exception_v1)
    else:
        wrap_handle_exception = \
                build_wrap_handle_exception(_bind_handle_exception_v2)

    wrap_wsgi_application(module, 'API.__call__', framework=framework)

    wrap_function_wrapper(module, 'API._handle_exception',
                          wrap_handle_exception)
def instrument_bottle(module):
    global module_bottle
    module_bottle = module

    framework_details = ('Bottle', getattr(module, '__version__'))

    if hasattr(module.Bottle, 'wsgi'):  # version >= 0.9
        wrap_wsgi_application(module,
                              'Bottle.wsgi',
                              framework=framework_details)
    elif hasattr(module.Bottle, '__call__'):  # version < 0.9
        wrap_wsgi_application(module,
                              'Bottle.__call__',
                              framework=framework_details)

    if (hasattr(module, 'Route')
            and hasattr(module.Route, '_make_callback')):  # version >= 0.10
        wrap_out_function(module, 'Route._make_callback',
                          output_wrapper_Route_make_callback)
    elif hasattr(module.Bottle, '_match'):  # version >= 0.9
        wrap_out_function(module, 'Bottle._match', output_wrapper_Bottle_match)
    elif hasattr(module.Bottle, 'match_url'):  # version < 0.9
        wrap_out_function(module, 'Bottle.match_url',
                          output_wrapper_Bottle_match)

    wrap_object_attribute(module, 'Bottle.error_handler',
                          proxy_Bottle_error_handler)

    if hasattr(module, 'auth_basic'):
        wrap_function_wrapper(module, 'auth_basic', wrapper_auth_basic)

    if hasattr(module, 'SimpleTemplate'):
        wrap_function_trace(module, 'SimpleTemplate.render')

    if hasattr(module, 'MakoTemplate'):
        wrap_function_trace(module, 'MakoTemplate.render')

    if hasattr(module, 'CheetahTemplate'):
        wrap_function_trace(module, 'CheetahTemplate.render')

    if hasattr(module, 'Jinja2Template'):
        wrap_function_trace(module, 'Jinja2Template.render')

    if hasattr(module, 'SimpleTALTemplate'):
        wrap_function_trace(module, 'SimpleTALTemplate.render')
예제 #6
0
def instrument_ariadne_wsgi(module):
    if hasattr(module, "GraphQL"):
        wrap_wsgi_application(module,
                              "GraphQL.__call__",
                              framework=framework_details())
예제 #7
0
def instrument_flask_app(module):
    wrap_wsgi_application(module, "Flask.wsgi_app", framework=framework_details)

    wrap_function_wrapper(module, "Flask.add_url_rule", _nr_wrapper_Flask_add_url_rule_input_)

    if hasattr(module.Flask, "endpoint"):
        wrap_function_wrapper(module, "Flask.endpoint", _nr_wrapper_Flask_endpoint_)

    wrap_function_wrapper(module, "Flask.handle_http_exception", _nr_wrapper_Flask_handle_http_exception_)

    # Use the same wrapper for initial user exception processing and
    # fallback for unhandled exceptions.

    if hasattr(module.Flask, "handle_user_exception"):
        wrap_function_wrapper(module, "Flask.handle_user_exception", _nr_wrapper_Flask_handle_exception_)

    wrap_function_wrapper(module, "Flask.handle_exception", _nr_wrapper_Flask_handle_exception_)

    # The _register_error_handler() method was only introduced in
    # Flask version 0.7.0.
    if hasattr(module.Flask, "_register_error_handler"):
        wrap_function_wrapper(
            module,
            "Flask._register_error_handler",
            _nr_wrapper_Flask__register_error_handler_,
        )

    # The method changed name to register_error_handler() in
    # Flask version 2.0.0.
    elif hasattr(module.Flask, "register_error_handler"):
        wrap_function_wrapper(
            module,
            "Flask.register_error_handler",
            _nr_wrapper_Flask_register_error_handler_,
        )

    # Different before/after methods were added in different versions.
    # Check for the presence of everything before patching.

    if hasattr(module.Flask, "try_trigger_before_first_request_functions"):
        wrap_function_wrapper(
            module,
            "Flask.try_trigger_before_first_request_functions",
            _nr_wrapper_Flask_try_trigger_before_first_request_functions_,
        )
        wrap_function_wrapper(
            module,
            "Flask.before_first_request",
            _nr_wrapper_Flask_before_first_request_,
        )

    if hasattr(module.Flask, "preprocess_request"):
        wrap_function_trace(module, "Flask.preprocess_request")
        wrap_function_wrapper(module, "Flask.before_request", _nr_wrapper_Flask_before_request_)

    if hasattr(module.Flask, "process_response"):
        wrap_function_trace(module, "Flask.process_response")
        wrap_function_wrapper(module, "Flask.after_request", _nr_wrapper_Flask_after_request_)

    if hasattr(module.Flask, "do_teardown_request"):
        wrap_function_trace(module, "Flask.do_teardown_request")
        wrap_function_wrapper(module, "Flask.teardown_request", _nr_wrapper_Flask_teardown_request_)

    if hasattr(module.Flask, "do_teardown_appcontext"):
        wrap_function_trace(module, "Flask.do_teardown_appcontext")
        wrap_function_wrapper(module, "Flask.teardown_appcontext", _nr_wrapper_Flask_teardown_appcontext_)
def instrument_cherrypy__cptree(module):
    wrap_wsgi_application(module,
                          "Application.__call__",
                          framework=framework_details())
def instrument_cherrypy__cpwsgi(module):
    wrap_wsgi_application(module,
                          "CPWSGIApp.__call__",
                          framework=framework_details())