示例#1
0
def _django_wsgi_call(original_method, *args, **keywords):
    Timing.push_timer()
    try:
        return original_method(*args, **keywords)
    finally:
        elapsed, _ = Timing.pop_timer()
        telemetry.record('wsgi.response.latency', elapsed)
示例#2
0
def _django_wsgi_call(original_method, *args, **keywords):
    Timing.push_timer()
    try:
        return original_method(*args, **keywords)
    finally:
        elapsed, _ = Timing.pop_timer()
        telemetry.record("wsgi.response.latency", elapsed)
示例#3
0
 def decorator(*args, **keywords):
     Timing.push_timer()
     try:
         yield
     finally:
         elapsed, _ = Timing.pop_timer()
         record_telemetry(type_name, elapsed, reporter)
示例#4
0
 def decorator(*args, **keywords):
     Timing.push_timer()
     try:
         return original_method(*args, **keywords)
     finally:
         elapsed, net_elapsed = Timing.pop_timer()
         telemetry.record('wsgi.response.latency', elapsed)
示例#5
0
    def decorator(*args, **keywords):
        # The type of the returned instance depends on the url
        # but is typically urllib.addinfourl for the baked-in protocols

        if context.has_state('external'):
            # Avoid double counting nested calls. All metrics will be reported
            # relative to the outermost operation
            return f(*args, **keywords)

        url = get_parameter(1, 'fullurl', *args, **keywords)

        if hasattr(url, 'get_full_url'):
            url = url.get_full_url()

        scheme = url.split(':')[0] if ':' in url else 'unknown'

        Timing.push_timer()
        try:
            context.push_state('external')
            telemetry.count('external.{}.requests'.format(scheme))
            a = f(*args, **keywords)
            if a.getcode():
                # Not meaningful for ftp etc
                telemetry.count('external.{}.status.%ixx'.format(scheme) % floor(a.getcode() / 100))
        except:
            telemetry.count('external.{}.errors'.format(scheme))
            raise
        finally:
            context.pop_state('external')
            elapsed, _ = Timing.pop_timer()
            telemetry.record('external.{}.response.latency'.format(scheme), elapsed)

        # Return a wrapped object so we can time subsequent read, readline etc calls
        return _response_wrapper(scheme, a)
示例#6
0
def _urllib_open_wrapper(func, *args, **keywords):
    """ Wraps urllib.request.url_open """

    if not _should_be_instrumented(
            state='external', enable_if='web', disable_if='model'):
        return func(*args, **keywords)

    url = get_parameter(1, 'fullurl', *args, **keywords)

    if hasattr(url, 'get_full_url'):
        url = url.get_full_url()

    scheme = url.split(':')[0] if ':' in url else 'unknown'

    Timing.push_timer()
    try:
        context.push_state('external')
        telemetry.count('external.{}.requests'.format(scheme))
        a = func(*args, **keywords)
        if a.getcode():
            # Not meaningful for ftp etc
            telemetry.count('external.{}.status.%ixx'.format(scheme) %
                            floor(a.getcode() / 100))
    except:
        telemetry.count('external.{}.errors'.format(scheme))
        raise
    finally:
        context.pop_state('external')
        elapsed, _ = Timing.pop_timer()
        telemetry.record('external.{}.response.latency'.format(scheme),
                         elapsed)

    # Return a wrapped object so we can time subsequent read, readline etc calls
    return _response_wrapper(scheme, a)
示例#7
0
    def decorator(*args, **keywords):
        try:
            route = args[2] if args[2] else None
            context.push_tag('web.route', route)
            context.push_tag('web.method', args[1])
            telemetry.count('web.requests')
            Timing.push_timer()

            # call the request function
            response = f(*args, **keywords)

            if response.status:
                telemetry.count('web.status.%sxx' % response.status[0:1])
            return response
        except Exception as e:
            telemetry.count('web.errors')
            raise e
        finally:
            try:
                elapsed, net_elapsed = Timing.pop_timer()
                telemetry.record('web.response.latency', elapsed)
                telemetry.record('app.response.latency', net_elapsed)
                try:
                    context.pop_tag()
                    context.pop_tag()
                except:
                    logger.exception('Problem popping contexts')
            except:
                logger.exception('Teardown handler failed')
                raise
示例#8
0
def _flask_dispatch(f, *args, **keywords):
    try:
        telemetry.count('web.requests')
        Timing.push_timer()

        return f(*args, **keywords)
    finally:
        elapsed, net_elapsed = Timing.pop_timer()
        telemetry.record('web.response.latency', elapsed)
        telemetry.record('app.response.latency', net_elapsed)
示例#9
0
 def complex_wrapper(func, *args, **keywords):
     if _should_be_instrumented(state, enable_if, disable_if):
         Timing.push_timer()
         context.push_state(state)
         try:
             return func(*args, **keywords)
         finally:
             elapsed, _ = Timing.pop_timer()
             count(metric + 'requests', reporter=reporter)
             record(metric + 'latency', elapsed, reporter=reporter)
             context.pop_state(state)
     else:
         return func(*args, **keywords)
示例#10
0
 def decorator(*args, **keywords):
     telemetry.count('external.http.requests')
     Timing.push_timer()
     try:
         a = f(*args, **keywords)
         telemetry.count('external.http.status.%ixx' % floor(a.status_code / 100))
         return a
     except:
         telemetry.count('external.http.errors')
         raise
     finally:
         elapsed, _ = Timing.pop_timer()
         telemetry.record('external.http.response.latency', elapsed)
示例#11
0
 def decorator(*args, **keywords):
     telemetry.count('external.http.requests')
     Timing.push_timer()
     try:
         a = f(*args, **keywords)
         telemetry.count('external.http.status.%ixx' %
                         floor(a.status_code / 100))
         return a
     except:
         telemetry.count('external.http.errors')
         raise
     finally:
         elapsed, _ = Timing.pop_timer()
         telemetry.record('external.http.response.latency', elapsed)
示例#12
0
def _wrapped_call(metric, func, *args, **keywords):
    """ Times and executes arbitrary method """
    state = 'external'

    if not _should_be_instrumented(state, enable_if='web', disable_if='model'):
        return func(*args, **keywords)

    Timing.push_timer()
    try:
        context.push_state(state)
        return func(*args, **keywords)
    finally:
        context.pop_state(state)
        elapsed, _ = Timing.pop_timer()
        telemetry.record(metric, elapsed)
示例#13
0
def _wrapped_call(metric, func, *args, **keywords):
    """ Times and executes arbitrary method """
    state = 'external'

    if not _should_be_instrumented(state, enable_if='web', disable_if='model'):
        return func(*args, **keywords)

    Timing.push_timer()
    try:
        context.push_state(state)
        return func(*args, **keywords)
    finally:
        context.pop_state(state)
        elapsed, _ = Timing.pop_timer()
        telemetry.record(metric, elapsed)
示例#14
0
    def decorator(*args, **keywords):
        try:
            from flask import request
            route = request.url_rule.rule if request.url_rule else None
            context.push_tag('web.route', route)
            context.push_tag('web.method', request.method)
            telemetry.count('web.requests')
            Timing.push_timer()

            return f(*args, **keywords)
        finally:
            elapsed, net_elapsed = Timing.pop_timer()
            telemetry.record('web.response.latency', elapsed)
            telemetry.record('app.response.latency', net_elapsed)
            context.pop_tag()
            context.pop_tag()
示例#15
0
 def decorator(*args, **keywords):
     method = get_parameter(0, 'method', *args, **keywords)
     url = get_parameter(1, 'url', *args, **keywords)
     with context.add_all_tags([('external.url', url), ('external.method', method)]):
         telemetry.count('external.http.requests')
         Timing.push_timer()
         try:
             a = f(*args, **keywords)
             telemetry.count('external.http.status.%ixx' % floor(a.status_code / 100))
             return a
         except:
             telemetry.count('external.http.errors')
             raise
         finally:
             elapsed, _ = Timing.pop_timer()
             telemetry.record('external.http.response.latency', elapsed)
示例#16
0
def _session_send_wrapper(func, *args, **keywords):
    if not _should_be_instrumented(state="external", enable_if="web", disable_if="model"):
        return func(*args, **keywords)

    telemetry.count("external.http.requests")
    Timing.push_timer()
    try:
        context.push_state("external")
        a = func(*args, **keywords)
        telemetry.count("external.http.status.%ixx" % floor(a.status_code / 100))
        return a
    except:
        telemetry.count("external.http.errors")
        raise
    finally:
        context.pop_state("external")
        elapsed, _ = Timing.pop_timer()
        telemetry.record("external.http.response.latency", elapsed)
示例#17
0
def _session_send_wrapper(func, *args, **keywords):
    if not _should_be_instrumented(
            state='external', enable_if='web', disable_if='model'):
        return func(*args, **keywords)

    telemetry.count('external.http.requests')
    Timing.push_timer()
    try:
        context.push_state('external')
        a = func(*args, **keywords)
        telemetry.count('external.http.status.%ixx' %
                        floor(a.status_code / 100))
        return a
    except:
        telemetry.count('external.http.errors')
        raise
    finally:
        context.pop_state('external')
        elapsed, _ = Timing.pop_timer()
        telemetry.record('external.http.response.latency', elapsed)
示例#18
0
 def process_response(self, request, response):
     elapsed, net_elapsed = Timing.pop_timer()
     if self.is_active:
         telemetry.record('web.response.latency', elapsed)
         telemetry.record('app.response.latency', net_elapsed)
         telemetry.count('web.status.%ixx' % floor(response.status_code / 100))
         context.pop_state(STATE_NAME)
         self.is_active = False
     else:
         logger.warn('process_response without request')
     return response
示例#19
0
 def process_response(self, request, response):
     elapsed, net_elapsed = Timing.pop_timer()
     if self.is_active:
         telemetry.record("web.response.latency", elapsed)
         telemetry.record("app.response.latency", net_elapsed)
         telemetry.count("web.status.%ixx" % floor(response.status_code / 100))
         context.pop_state(STATE_NAME)
         self.is_active = False
     else:
         logger.warn("process_response without request")
     return response
 def test_historically_named_timing(self):
     Timing.push_timer()
     time.sleep(0.1)
     Timing.push_timer()
     time.sleep(0.1)
     self.assertAlmostEqual(0.1, Timing.pop_timer()[0], delta=0.03)
     self.assertAlmostEqual(0.2, Timing.pop_timer()[0], delta=0.03)
 def test_historically_named_timing(self):
     Timing.push_timer()
     time.sleep(0.1)
     Timing.push_timer()
     time.sleep(0.1)
     self.assertAlmostEqual(0.1, Timing.pop_timer()[0], delta=0.03)
     self.assertAlmostEqual(0.2, Timing.pop_timer()[0], delta=0.03)
示例#22
0
    def decorator(*args, **keywords):
        try:
            telemetry.count('web.requests')
            Timing.push_timer()

            # call the request function
            response = f(*args, **keywords)

            if response.status:
                telemetry.count('web.status.%sxx' % response.status[0:1])
            return response
        except Exception as e:
            telemetry.count('web.errors')
            raise e
        finally:
            try:
                elapsed, net_elapsed = Timing.pop_timer()
                telemetry.record('web.response.latency', elapsed)
                telemetry.record('app.response.latency', net_elapsed)
            except:
                logger.exception('Teardown handler failed')
                raise
示例#23
0
    def decorator(*args, **keywords):
        try:
            telemetry.count('web.requests')
            Timing.push_timer()

            # call the request function
            response = f(*args, **keywords)

            if response.status:
                telemetry.count('web.status.%sxx' % response.status[0:1])
            return response
        except Exception as e:
            telemetry.count('web.errors')
            raise e
        finally:
            try:
                elapsed, net_elapsed = Timing.pop_timer()
                telemetry.record('web.response.latency', elapsed)
                telemetry.record('app.response.latency', net_elapsed)
            except:
                logger.exception('Teardown handler failed')
                raise
示例#24
0
    def decorator(*args, **keywords):
        # The type of the returned instance depends on the url
        # but is typically urllib.addinfourl for the baked-in protocols

        if context.has_state('external'):
            # Avoid double counting nested calls. All metrics will be reported
            # relative to the outermost operation
            return f(*args, **keywords)

        url = get_parameter(1, 'fullurl', *args, **keywords)

        if hasattr(url, 'get_full_url'):
            url = url.get_full_url()

        scheme = url.split(':')[0] if ':' in url else 'unknown'

        Timing.push_timer()
        try:
            context.push_state('external')
            telemetry.count('external.{}.requests'.format(scheme))
            a = f(*args, **keywords)
            if a.getcode():
                # Not meaningful for ftp etc
                telemetry.count('external.{}.status.%ixx'.format(scheme) %
                                floor(a.getcode() / 100))
        except:
            telemetry.count('external.{}.errors'.format(scheme))
            raise
        finally:
            context.pop_state('external')
            elapsed, _ = Timing.pop_timer()
            telemetry.record('external.{}.response.latency'.format(scheme),
                             elapsed)

        # Return a wrapped object so we can time subsequent read, readline etc calls
        return _response_wrapper(scheme, a)
    def test_stack_timing(self):
        times = 10

        Timing.push_timer()
        time.sleep(0.1)

        for i in range(times):
            Timing.push_timer()
            time.sleep(0.1)
            t, _ = Timing.pop_timer()
            self.assertAlmostEqual(0.1, t, delta=0.03)

        elapsed_time, net_time = Timing.pop_timer()

        self.assertAlmostEqual(0.1 + times * 0.1, elapsed_time, delta=0.03)
        self.assertAlmostEqual(0.1, net_time, delta=0.03)
    def test_stack_timing(self):
        times = 10

        Timing.push_timer()
        time.sleep(0.1)

        for i in range(times):
            Timing.push_timer()
            time.sleep(0.1)
            t, _ = Timing.pop_timer()
            self.assertAlmostEqual(0.1, t, delta=0.03)

        elapsed_time, net_time = Timing.pop_timer()

        self.assertAlmostEqual(0.1 + times * 0.1, elapsed_time, delta=0.03)
        self.assertAlmostEqual(0.1, net_time, delta=0.03)
示例#27
0
 def process_request(self, request):
     self.is_active = True
     Timing.push_timer()
     context.push_state(STATE_NAME)
     telemetry.count("web.requests")
示例#28
0
 def process_request(self, request):
     self.is_active = True
     Timing.push_timer()
     context.push_state(STATE_NAME)
     telemetry.count('web.requests')