Exemplo n.º 1
0
    def start_span(self, name='span'):
        """Start a span.

        :type name: str
        :param name: The name of the span.

        :rtype: :class:`~opencensus.trace.span.Span`
        :returns: The Span object.
        """
        parent_span = self.current_span()

        # If a span has remote parent span, then the parent_span.span_id
        # should be the span_id from the request header.
        if parent_span is None:
            parent_span = base.NullContextManager(
                span_id=self.span_context.span_id)

        span = trace_span.Span(name,
                               parent_span=parent_span,
                               context_tracer=self)
        with self._spans_list_condition:
            self._spans_list.append(span)
        self.span_context.span_id = span.span_id
        execution_context.set_current_span(span)
        span.start()
        return span
Exemplo n.º 2
0
    def __init__(
            self,
            name=None,
            parent_span=None,
            attributes=None,
            start_time=None,
            end_time=None,
            span_id=None,
            stack_trace=None,
            annotations=None,
            message_events=None,
            links=None,
            status=None,
            same_process_as_parent_span=None,
            context_tracer=None,
            span_kind=None):
        self.name = name
        self.parent_span = parent_span
        self.start_time = start_time
        self.end_time = end_time

        self.span_id = generate_span_id()
        self.parent_span = base.NullContextManager()

        self.attributes = {}
        self.stack_trace = stack_trace
        self.annotations = annotations
        self.message_events = message_events
        self.links = []
        self.status = status
        self.same_process_as_parent_span = same_process_as_parent_span
        self._child_spans = []
        self.context_tracer = context_tracer
        self.span_kind = span_kind
Exemplo n.º 3
0
    def __init__(self,
                 name,
                 parent_span=None,
                 attributes=None,
                 start_time=None,
                 end_time=None,
                 span_id=None,
                 stack_trace=None,
                 annotations=None,
                 message_events=None,
                 links=None,
                 status=None,
                 same_process_as_parent_span=None,
                 context_tracer=None,
                 span_kind=SpanKind.UNSPECIFIED):
        self.name = name
        self.parent_span = parent_span
        self.start_time = start_time
        self.end_time = end_time

        if span_id is None:
            span_id = generate_span_id()

        if attributes is None:
            self.attributes = BoundedDict(MAX_NUM_ATTRIBUTES)
        else:
            self.attributes = BoundedDict.from_map(MAX_NUM_ATTRIBUTES,
                                                   attributes)

        # Do not manipulate spans directly using the methods in Span Class,
        # make sure to use the Tracer.
        if parent_span is None:
            parent_span = base.NullContextManager()

        if annotations is None:
            self.annotations = BoundedList(MAX_NUM_ANNOTATIONS)
        else:
            self.annotations = BoundedList.from_seq(MAX_NUM_LINKS, annotations)

        if message_events is None:
            self.message_events = BoundedList(MAX_NUM_MESSAGE_EVENTS)
        else:
            self.message_events = BoundedList.from_seq(MAX_NUM_LINKS,
                                                       message_events)

        if links is None:
            self.links = BoundedList(MAX_NUM_LINKS)
        else:
            self.links = BoundedList.from_seq(MAX_NUM_LINKS, links)

        self.status = status_module.Status.as_ok(
        ) if status is None else status
        self.span_id = span_id
        self.stack_trace = stack_trace
        self.same_process_as_parent_span = same_process_as_parent_span
        self._child_spans = []
        self.context_tracer = context_tracer
        self.span_kind = span_kind
        for callback in Span._on_create_callbacks:
            callback(self)
Exemplo n.º 4
0
    def start_span(self, name='span'):
        """Start a span.

        :type name: str
        :param name: The name of the span.

        :rtype: :class:`~opencensus.trace.trace_span.Span`
        :returns: The Span object.
        """
        return base.NullContextManager(context_tracer=self)
Exemplo n.º 5
0
    def span(self, name='span'):
        """Create a new span with the trace using the context information.

        :type name: str
        :param name: The name of the span.

        :rtype: :class:`~opencensus.trace.trace_span.Span`
        :returns: The Span object.
        """
        return base.NullContextManager(context_tracer=self)
Exemplo n.º 6
0
    def __init__(
            self,
            name,
            parent_span=None,
            attributes=None,
            start_time=None,
            end_time=None,
            span_id=None,
            stack_trace=None,
            time_events=None,
            links=None,
            status=None,
            same_process_as_parent_span=None,
            context_tracer=None,
            span_kind=SpanKind.UNSPECIFIED):
        self.name = name
        self.parent_span = parent_span
        self.start_time = start_time
        self.end_time = end_time

        if span_id is None:
            span_id = generate_span_id()

        if attributes is None:
            attributes = {}

        # Do not manipulate spans directly using the methods in Span Class,
        # make sure to use the Tracer.
        if parent_span is None:
            parent_span = base.NullContextManager()

        if time_events is None:
            time_events = []

        if links is None:
            links = []

        self.attributes = attributes
        self.span_id = span_id
        self.stack_trace = stack_trace
        self.time_events = time_events
        self.links = links
        self.status = status
        self.same_process_as_parent_span = same_process_as_parent_span
        self._child_spans = []
        self.context_tracer = context_tracer
        self.span_kind = span_kind
        for callback in Span._on_create_callbacks:
            callback(self)
Exemplo n.º 7
0
 def current_span(self):
     """Return the current span."""
     return base.NullContextManager(context_tracer=self)
Exemplo n.º 8
0
 def end_span(self):
     """End a span. Remove the span from the span stack, and update the
     span_id in TraceContext as the current span_id which is the peek
     element in the span stack.
     """
     return base.NullContextManager(context_tracer=self)