Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/opencensus/trace/tracers/base.py: 67%
24 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-06 06:04 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-06 06:04 +0000
1# Copyright 2017, OpenCensus Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
16class Tracer(object):
17 """Base class for Opencensus tracers.
19 Subclasses of :class:`Tracer` must implement the below methods.
20 """
21 def finish(self):
22 """End the spans and send to reporters."""
23 raise NotImplementedError
25 def span(self, name='span'):
26 """Create a new span with the trace using the context information.
28 :type name: str
29 :param name: The name of the span.
31 :rtype: :class:`~opencensus.trace.span.Span`
32 :returns: The Span object.
33 """
34 raise NotImplementedError
36 def start_span(self, name='span'):
37 """Start a span.
39 :type name: str
40 :param name: The name of the span.
42 :rtype: :class:`~opencensus.trace.span.Span`
43 :returns: The Span object.
44 """
45 raise NotImplementedError
47 def end_span(self):
48 """End a span. Remove the span from the span stack, and update the
49 span_id in TraceContext as the current span_id which is the peek
50 element in the span stack.
51 """
52 raise NotImplementedError
54 def current_span(self):
55 """Return the current span."""
56 raise NotImplementedError
58 def add_attribute_to_current_span(self, attribute_key, attribute_value):
59 raise NotImplementedError
61 def list_collected_spans(self):
62 """List collected spans."""
63 raise NotImplementedError
66class NullContextManager(object):
67 """Empty object as a helper for faking Trace and Span when tracing is
68 disabled.
69 """
70 def __init__(self, span_id=None, context_tracer=None):
71 self.name = None
72 self.span_id = span_id
73 self.context_tracer = context_tracer
75 def __enter__(self):
76 return self # pragma: NO COVER
78 def __exit__(self, exc_type, exc_value, traceback):
79 pass # pragma: NO COVER
81 def span(self, name='span'):
82 return NullContextManager(context_tracer=self.context_tracer)