def task_postrun_handler(task_id, task, **kwargs): trace = local().current trace.record(Annotation.server_send()) trace.record(Annotation.client_recv()) log(trace) local().pop()
def pre_response(app, response, **extra): request.trace.record( Annotation.string('http.responsecode', '{0}'.format(response.status_code))) request.trace.record(Annotation.server_send()) log(request.trace) local().pop()
def __call__(self, request): self.track_start_request(request) response = None try: response = self.handler(request) finally: # request.response in case an exception is raised ? self.track_end_request(request, response or request.response) local().reset() self.trace = None return response or request.response
def pre_request(app, **extra): headers = request.headers trace = Trace(request.method + ' ' + request.url, int_or_none(headers.get('X-B3-TraceId', None)), int_or_none(headers.get('X-B3-SpanId', None)), int_or_none(headers.get('X-B3-ParentSpanId', None)), endpoint=endpoint) setattr(request, 'trace', trace) local().append(trace) trace.record(Annotation.string('http.uri', request.url)) trace.record(Annotation.server_recv())
def task_prerun_handler(task_id, task, **kwargs): request = task.request trace = Trace('Task execute %r' % task.name, int_or_none(request.headers.get('X-B3-TraceId', None)), int_or_none(request.headers.get('X-B3-SpanId', None)), int_or_none(request.headers.get('X-B3-ParentSpanId', None)), endpoint=endpoint) setattr(request, 'trace', trace) local().append(trace) trace.record(Annotation.server_recv())
def middleware(request): # Code to be executed for each request before # the view (and later middleware) are called. trace = init_trace(request) response = get_response(request) add_header_response(response) log_response(trace, response) local().reset() return response
def middleware(request): # Code to be executed for each request before # the view (and later middleware) are called. start = time.time() trace = init_trace(request) response = get_response(request) duration = time.time() - start add_header_response(response) if duration >= settings.ZIPKIN_SLOW_LOG_DURATION_EXCEED: log_response(trace, response) local().reset() return response
def wrap(event): request = event.request headers = request.headers trace = Trace(request.method + ' ' + request.path_qs, int_or_none(headers.get('X-B3-TraceId', None)), int_or_none(headers.get('X-B3-SpanId', None)), int_or_none(headers.get('X-B3-ParentSpanId', None)), endpoint=endpoint) setattr(request, 'trace', trace) local().append(trace) trace.record(Annotation.server_recv()) request.add_finished_callback(log_response(endpoint))
def pre_request(app, **extra): headers = request.headers trace = Trace( request.method + " " + request.url, int_or_none(headers.get("X-B3-TraceId", None)), int_or_none(headers.get("X-B3-SpanId", None)), int_or_none(headers.get("X-B3-ParentSpanId", None)), endpoint=endpoint, ) setattr(request, "trace", trace) local().append(trace) trace.record(Annotation.string("http.uri", request.url)) trace.record(Annotation.server_recv())
def request(self, host, handler, request_body, verbose=0): try: https = isinstance(self, xmlrpclib.SafeTransport) protocol = "https://" if https else "http://" target = "%s%s%s" % (protocol, host, handler) match = _parse_method_name.search(request_body) method = match.group(1) if match else None parent_trace = local().current self._trace = parent_trace.child("xmlrpclib") self._trace.record(Annotation.string("uri", target)) if method: self._trace.record(Annotation.string("method", method)) self._trace.record(Annotation.server_recv()) except Exception as exc: log.error(repr(exc)) try: return self.__origin.request(self, host, handler, request_body, verbose) finally: try: self._trace.record(Annotation.server_send()) except: pass
def task_send_handler(body, exchange, routing_key, headers, **kwargs): trace = local().current if not trace: logger.warn("No zipkin parent trace found, ignoring tracing task.") return forwarded_trace = trace.child_noref("subservice") headers["X-B3-TraceId"] = hex_str(forwarded_trace.trace_id) headers["X-B3-SpanId"] = hex_str(forwarded_trace.span_id) forwarded_trace.record(Annotation.client_send()) if forwarded_trace.parent_span_id is not None: headers["X-B3-ParentSpanId"] = hex_str(forwarded_trace.parent_span_id)
def pre_request(request): parent_trace = local().current if not parent_trace: return request request.trace = parent_trace.child("requests:%s %s" % (request.method, request.url)) forwarded_trace = request.trace.child_noref("subservice") request.headers['X-B3-TraceId'] = hex_str(forwarded_trace.trace_id) request.headers['X-B3-SpanId'] = hex_str(forwarded_trace.span_id) if forwarded_trace.parent_span_id is not None: request.headers['X-B3-ParentSpanId'] = \ hex_str(forwarded_trace.parent_span_id) request.trace.record(Annotation.string('http.method', request.method)) request.trace.record(Annotation.string('http.url', request.url)) request.trace.record(Annotation.string('span.kind', 'client')) request.trace.record(Annotation.server_recv()) return request
def pre_request(request): parent_trace = local().current if not parent_trace: return request url = filter_url_path(request.url) request.trace = parent_trace.child("requests:%s %s" % (request.method, url)) forwarded_trace = request.trace.child_noref("subservice") request.headers["X-B3-TraceId"] = hex_str(forwarded_trace.trace_id) request.headers["X-B3-SpanId"] = hex_str(forwarded_trace.span_id) if forwarded_trace.parent_span_id is not None: request.headers["X-B3-ParentSpanId"] = hex_str( forwarded_trace.parent_span_id) request.trace.record(Annotation.string("http.method", request.method)) request.trace.record(Annotation.string("http.url", request.url)) request.trace.record(Annotation.string("span.kind", "client")) request.trace.record(Annotation.server_recv()) return request
def wrap(request): trace = request.trace trace.record(Annotation.server_send()) log(trace) local().pop()