def on_request(self, request):
        # type: (PipelineRequest[HttpRequest], Any) -> None
        parent_span = tracing_context.current_span.get()
        wrapper_class = settings.tracing_implementation()
        original_context = [parent_span, None]
        if parent_span is None and wrapper_class is not None:
            current_span_instance = wrapper_class.get_current_span()
            original_context[1] = current_span_instance
            parent_span = wrapper_class(current_span_instance)

        if parent_span is None:
            return

        only_propagate = settings.tracing_should_only_propagate()
        if only_propagate:
            self.set_header(request, parent_span)
            return

        path = urlparse(request.http_request.url).path
        if not path:
            path = "/"
        child = parent_span.span(name=path)
        child.start()

        set_span_contexts(child)
        self.parent_span_dict[child] = original_context
        self.set_header(request, child)
Example #2
0
 def end_span(self, request, response=None):
     # type: (HttpRequest, Optional[HttpResponse]) -> None
     """Ends the span that is tracing the network and updates its status."""
     span = tracing_context.current_span.get()  # type: AbstractSpan
     only_propagate = settings.tracing_should_only_propagate()
     if span and not only_propagate:
         span.set_http_attributes(request, response=response)
         if response and self._request_id in response.headers:
             span.add_attribute(self._request_id,
                                response.headers[self._request_id])
         span.finish()
         set_span_contexts(self.parent_span_dict[span])
Example #3
0
    def on_request(self, request, **kwargs):
        # type: (PipelineRequest[HttpRequest], Any) -> None
        parent_span = tracing_context.current_span.get()  # type: AbstractSpan

        if parent_span is None:
            return

        only_propagate = settings.tracing_should_only_propagate()
        if only_propagate:
            self.set_header(request, parent_span)
            return

        path = urlparse(request.http_request.url).path
        if not path:
            path = "/"
        child = parent_span.span(name=path)
        child.start()

        set_span_contexts(child)
        self.parent_span_dict[child] = parent_span
        self.set_header(request, child)
Example #4
0
def should_use_trace(parent_span):
    # type: (AbstractSpan) -> bool
    """Given Parent Span Returns whether the function should be traced"""
    only_propagate = settings.tracing_should_only_propagate()
    return bool(parent_span and not only_propagate)