示例#1
0
def store_request_trace(sender, **kwargs):
    request_trace = RequestTrace.instance()
    if not request_trace:
        return

    request_trace.stacktracer.pop_stack()

    # Calculate values before doing any cache writes, so the cache writes don't affect the results
    if request_trace.persist_details:
        details_tuples = tuple((key, module.get_details()) for key, module in request_trace.modules.items())
        all_details = dict(details for details in details_tuples if details[1] is not None)
    if request_trace.persist_log:
        speedtracer_log = request_trace.stacktracer.speedtracer_log()
    metrics = dict((key, module.get_metrics()) for key, module in request_trace.modules.items())

    if request_trace.persist_details:
        cache.set(DETAILS_PREFIX + request_trace.id, all_details, DETAILS_CACHE_TIME)
    if request_trace.persist_log:
        cache.set(TRACE_PREFIX + request_trace.id, speedtracer_log, DETAILS_CACHE_TIME)

    request_trace_complete.send(
        sender,
        metrics=metrics,
        request=getattr(request_trace, "request", None),
        response=getattr(request_trace, "response", None),
    )
示例#2
0
def store_request_trace(sender, **kwargs):
    request_trace = RequestTrace.instance()
    if not request_trace:
        return

    request_trace.stacktracer.pop_stack()

    # Calculate values before doing any cache writes, so the cache writes don't affect the results
    if request_trace.persist_details:
        details_tuples = tuple(
            (key, module.get_details())
            for key, module in request_trace.modules.items())
        all_details = dict(details for details in details_tuples
                           if details[1] is not None)
    if request_trace.persist_log:
        speedtracer_log = request_trace.stacktracer.speedtracer_log()
    metrics = dict((key, module.get_metrics())
                   for key, module in request_trace.modules.items())

    if request_trace.persist_details:
        cache.set(DETAILS_PREFIX + request_trace.id, all_details,
                  DETAILS_CACHE_TIME)
    if request_trace.persist_log:
        cache.set(TRACE_PREFIX + request_trace.id, speedtracer_log,
                  DETAILS_CACHE_TIME)

    request_trace_complete.send(sender,
                                metrics=metrics,
                                request=getattr(request_trace, 'request',
                                                None),
                                response=getattr(request_trace, 'response',
                                                 None))
示例#3
0
 def get_details(self):
     redis_nodes = RequestTrace.instance().stacktracer.get_nodes(ENTRY_TYPE)
     return [{
         'query_string': node.extra['query_string'],
         'kwargs': node.extra['kwargs'],
         'time': node.duration
     } for node in redis_nodes]
示例#4
0
 def get_details(self):
     redis_nodes = RequestTrace.instance().stacktracer.get_nodes('REDIS')
     return [{
         'operation': node.extra['operation'],
         'key': node.extra['key'],
         'time': node.duration
     } for node in redis_nodes]
示例#5
0
 def get_details(self):
     nodes = RequestTrace.instance().stacktracer.get_nodes(ENTRY_TYPE)
     return [{
         'type': node.extra['type'],
         'args': node.extra['args'],
         'kwargs': node.extra['kwargs'],
         'time': node.duration
     } for node in nodes]
示例#6
0
 def get_details(self):
     memcache_nodes = RequestTrace.instance().stacktracer.get_nodes(
         'MEMCACHE')
     return [{
         'operation': node.extra['operation'],
         'key': node.extra['key'],
         'time': node.duration
     } for node in memcache_nodes]
示例#7
0
 def executemany(self, sql, param_list):
     request_trace = RequestTrace.instance()
     if request_trace:
         request_trace.stacktracer.push_stack('SQL', sql)
     try:
         return self.cursor.executemany(sql, param_list)
     finally:
         if request_trace:
             request_trace.stacktracer.pop_stack()
示例#8
0
 def executemany(self, sql, param_list):
     request_trace = RequestTrace.instance()
     if request_trace:
         request_trace.stacktracer.push_stack('SQL', sql)
     try:
         return self.cursor.executemany(sql, param_list)
     finally:
         if request_trace:
             request_trace.stacktracer.pop_stack()
示例#9
0
 def tracing_method(original, self, *args, **kwargs):
     request_trace = RequestTrace.instance()
     if request_trace:
         entry_type, label, extra = info_func(self, *args, **kwargs)
         request_trace.stacktracer.push_stack(entry_type, label, extra=extra)
     try:
         return original(*args, **kwargs)
     finally:
         if request_trace:
             request_trace.stacktracer.pop_stack()
示例#10
0
 def execute(self, sql, params=()):
     request_trace = RequestTrace.instance()
     if request_trace:
         stack_entry = request_trace.stacktracer.push_stack('SQL', sql)
     try:
         return self.cursor.execute(sql, params)
     finally:
         if request_trace:
             request_trace.stacktracer.pop_stack()
             sql = self.db.ops.last_executed_query(self.cursor, sql, params)
             stack_entry.label = sql
示例#11
0
 def execute(self, sql, params=()):
     request_trace = RequestTrace.instance()
     if request_trace:
         stack_entry = request_trace.stacktracer.push_stack('SQL', sql)
     try:
         return self.cursor.execute(sql, params)
     finally:
         if request_trace:
             request_trace.stacktracer.pop_stack()
             sql = self.db.ops.last_executed_query(self.cursor, sql, params)
             stack_entry.label = sql
示例#12
0
 def resolve(self, path):
     request_trace = RequestTrace.instance()
     if request_trace:
         request_trace.stacktracer.push_stack('RESOLV', 'Resolving: ' + path)
     try:
         callbacks = self.other.resolve(path)
     finally:
         if request_trace:
             request_trace.stacktracer.pop_stack()
     # Replace the callback function with a traced copy so we can time how long the view takes.
     callbacks.func = trace_function(callbacks.func, ('VIEW', 'View: ' + callbacks.view_name, {}))
     return callbacks
示例#13
0
 def tracing_method(original, self, *args, **kwargs):
     request_trace = RequestTrace.instance()
     if request_trace:
         entry_type, label, extra = info_func(self, *args, **kwargs)
         request_trace.stacktracer.push_stack(entry_type,
                                              label,
                                              extra=extra)
     try:
         return original(*args, **kwargs)
     finally:
         if request_trace:
             request_trace.stacktracer.pop_stack()
示例#14
0
 def tracing_function(original, *args, **kwargs):
     request_trace = RequestTrace.instance()
     if request_trace:
         if callable(info):
             entry_type, label, extra = info(*args, **kwargs)
         else:
             entry_type, label, extra = info
         request_trace.stacktracer.push_stack(entry_type, label, extra)
     try:
         return original(*args, **kwargs)
     finally:
         if request_trace:
             request_trace.stacktracer.pop_stack()
示例#15
0
 def tracing_function(original, *args, **kwargs):
     request_trace = RequestTrace.instance()
     if request_trace:
         if callable(info):
             entry_type, label, extra = info(*args, **kwargs)
         else:
             entry_type, label, extra = info
         request_trace.stacktracer.push_stack(entry_type, label, extra)
     try:
         return original(*args, **kwargs)
     finally:
         if request_trace:
             request_trace.stacktracer.pop_stack()
示例#16
0
 def resolve(self, path):
     request_trace = RequestTrace.instance()
     if request_trace:
         request_trace.stacktracer.push_stack('RESOLV',
                                              'Resolving: ' + path)
     try:
         callbacks = self.other.resolve(path)
     finally:
         if request_trace:
             request_trace.stacktracer.pop_stack()
     # Replace the callback function with a traced copy so we can time how long the view takes.
     callbacks.func = trace_function(
         callbacks.func, ('VIEW', 'View: ' + callbacks.view_name, {}))
     return callbacks
示例#17
0
    def process_response(self, request, response):
        if not getattr(settings, 'SPEEDBAR_ENABLE', True):
            return response

        request_trace = RequestTrace.instance()
        # TODO: Do we also need to stash this on in case of exception?
        request_trace.response = response

        metrics = dict((key, module.get_metrics())
                       for key, module in request_trace.modules.items())

        if self.should_return_response_headers(request):
            self.add_response_headers(response, metrics)

        if self.should_return_trace_header(request):
            response['X-TraceUrl'] = reverse('speedbar_trace',
                                             args=[request_trace.id])
            request_trace.persist_log = True

        if self.should_replace_template_tags(request):
            if 'gzip' not in response.get(
                    'Content-Encoding', '') and response.get(
                        'Content-Type', '').split(';')[0] in HTML_TYPES:

                # Force render of response (from lazy TemplateResponses) before speedbar is injected
                if hasattr(response, 'render'):
                    response.render()
                content = smart_unicode(response.content)

                content = self.replace_templatetag_placeholders(
                    content, metrics)

                # Note: The URLs returned here do not exist at this point. The relevant data is added to the cache by a signal handler
                # once all page processing is finally done. This means it is possible summary values displayed and the detailed
                # break down won't quite correspond.
                if getattr(settings, 'SPEEDBAR_PANEL', True):
                    panel_url = reverse('speedbar_panel',
                                        args=[request_trace.id])
                    panel_placeholder_url = reverse(
                        'speedbar_details_for_this_request')
                    content = content.replace(panel_placeholder_url, panel_url)
                    request_trace.persist_details = True

                response.content = smart_str(content)
                if response.get('Content-Length', None):
                    response['Content-Length'] = len(response.content)
        return response
    def process_response(self, request, response):
        if not getattr(settings, 'SPEEDBAR_ENABLE', True):
            return response

        request_trace = RequestTrace.instance()
        # TODO: Do we also need to stash this on in case of exception?
        request_trace.response = response

        metrics = dict((key, module.get_metrics()) for key, module in request_trace.modules.items())

        if getattr(settings, 'SPEEDBAR_RESPONSE_HEADERS', False):
            self.add_response_headers(response, metrics)

        if hasattr(request, 'user') and request.user.is_staff:
            if getattr(settings, 'SPEEDBAR_TRACE', True):
                response['X-TraceUrl'] = reverse('speedbar_trace', args=[request_trace.id])
                request_trace.persist_log = True

            if 'gzip' not in response.get('Content-Encoding', '') and response.get('Content-Type', '').split(';')[0] in HTML_TYPES:

                # Force render of response (from lazy TemplateResponses) before speedbar is injected
                if hasattr(response, 'render'):
                    response.render()
                content = smart_unicode(response.content)

                content = self.replace_templatetag_placeholders(content, metrics)

                # Note: The URLs returned here do not exist at this point. The relevant data is added to the cache by a signal handler
                # once all page processing is finally done. This means it is possible summary values displayed and the detailed
                # break down won't quite correspond.
                if getattr(settings, 'SPEEDBAR_PANEL', True):
                    panel_url = reverse('speedbar_panel', args=[request_trace.id])
                    panel_placeholder_url = reverse('speedbar_details_for_this_request')
                    content = content.replace(panel_placeholder_url, panel_url)
                    request_trace.persist_details = True

                response.content = smart_str(content)
                if response.get('Content-Length', None):
                    response['Content-Length'] = len(response.content)
        return response
示例#19
0
 def get_details(self):
     sql_nodes = RequestTrace.instance().stacktracer.get_nodes('SQL')
     return [{
         'sql': node.label,
         'time': int(node.duration * 1000)
     } for node in sql_nodes]
示例#20
0
 def get_metrics(self):
     return RequestTrace.instance().stacktracer.get_node_metrics('SQL')
示例#21
0
 def get_details(self):
     memcache_nodes = RequestTrace.instance().stacktracer.get_nodes('MEMCACHE')
     return [{'operation': node.extra['operation'], 'key': node.extra['key'], 'time': node.duration} for node in memcache_nodes]
示例#22
0
 def get_details(self):
     redis_nodes = RequestTrace.instance().stacktracer.get_nodes('REDIS')
     return [{'operation': node.extra['operation'], 'key': node.extra['key'], 'time': node.duration} for node in redis_nodes]
示例#23
0
 def get_metrics(self):
     return RequestTrace.instance().stacktracer.get_node_metrics('SQL')
示例#24
0
 def get_metrics(self):
     return RequestTrace.instance().stacktracer.get_node_metrics(ENTRY_TYPE)
示例#25
0
 def get_details(self):
     sql_nodes = RequestTrace.instance().stacktracer.get_nodes('SQL')
     return [{'sql': node.label, 'time': int(node.duration*1000)} for node in sql_nodes]
示例#26
0
 def get_details(self):
     redis_nodes = RequestTrace.instance().stacktracer.get_nodes(ENTRY_TYPE)
     return [{'query_string': node.extra['query_string'], 'kwargs': node.extra['kwargs'], 'time': node.duration} for node in redis_nodes]
示例#27
0
 def process_request(self, request):
     if SPEEDBAR_ENABLE:
         RequestTrace.instance().stacktracer.root.label = '%s %s' % (request.method, request.path)
示例#28
0
def setup_request_tracing(sender, **kwargs):
    RequestTrace(module() for module in loaded_modules)
    RequestTrace.instance().stacktracer.push_stack("HTTP", "")
示例#29
0
def setup_request_tracing(sender, **kwargs):
    RequestTrace(module() for module in loaded_modules)
    RequestTrace.instance().stacktracer.push_stack('HTTP', '')
示例#30
0
 def process_request(self, request):
     if getattr(settings, 'SPEEDBAR_ENABLE', True):
         request_trace = RequestTrace.instance()
         request_trace.stacktracer.root.label = '%s %s' % (request.method,
                                                           request.path)
         request_trace.request = request
示例#31
0
 def get_details(self):
     nodes = RequestTrace.instance().stacktracer.get_nodes(ENTRY_TYPE)
     return [{'type': node.extra['type'], 'args': node.extra['args'], 'kwargs': node.extra['kwargs'], 'time': node.duration} for node in nodes]
示例#32
0
 def process_request(self, request):
     if getattr(settings, 'SPEEDBAR_ENABLE', True):
         RequestTrace.instance().stacktracer.root.label = '%s %s' % (request.method, request.path)
示例#33
0
 def get_metrics(self):
     return RequestTrace.instance().stacktracer.get_node_metrics(ENTRY_TYPE)
示例#34
0
 def get_details(self):
     nodes = RequestTrace.instance().stacktracer.get_nodes('CASSANDRA')
     return [{'cql': node.label, 'time': node.duration} for node in nodes]
示例#35
0
 def get_details(self):
     nodes = RequestTrace.instance().stacktracer.get_nodes('CASSANDRA')
     return [{'cql': node.label, 'time': node.duration} for node in nodes]