예제 #1
0
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()
예제 #2
0
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()
예제 #3
0
 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
예제 #4
0
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())
예제 #5
0
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())
예제 #6
0
    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
예제 #7
0
    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
예제 #8
0
    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))
예제 #9
0
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())
예제 #10
0
파일: impl.py 프로젝트: Gandi/python-zipkin
    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
예제 #11
0
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)
예제 #12
0
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
예제 #13
0
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
예제 #14
0
    def wrap(request):
        trace = request.trace
        trace.record(Annotation.server_send())

        log(trace)
        local().pop()