Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/opencensus/trace/base_span.py: 57%

30 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-06 06:04 +0000

1# Copyright 2018, 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. 

14 

15"""Module containing base class for Span.""" 

16 

17 

18class BaseSpan(object): 

19 """Base class for Opencensus spans. 

20 Subclasses of :class:`BaseSpan` must implement the below methods. 

21 """ 

22 

23 @staticmethod 

24 def on_create(callback): 

25 raise NotImplementedError 

26 

27 @property 

28 def children(self): 

29 """The child spans of the current span.""" 

30 raise NotImplementedError 

31 

32 def span(self, name='child_span'): 

33 """Create a child span for the current span and append it to the child 

34 spans list. 

35 

36 :type name: str 

37 :param name: (Optional) The name of the child span. 

38 

39 :rtype: :class: `~opencensus.trace.span.Span` 

40 :returns: A child Span to be added to the current span. 

41 """ 

42 raise NotImplementedError 

43 

44 def add_attribute(self, attribute_key, attribute_value): 

45 """Add attribute to span. 

46 

47 :type attribute_key: str 

48 :param attribute_key: Attribute key. 

49 

50 :type attribute_value:str 

51 :param attribute_value: Attribute value. 

52 """ 

53 raise NotImplementedError 

54 

55 def add_annotation(self, description, **attrs): 

56 """Add an annotation to span. 

57 

58 :type description: str 

59 :param description: A user-supplied message describing the event. 

60 The maximum length for the description is 256 bytes. 

61 

62 :type attrs: kwargs 

63 :param attrs: keyworded arguments e.g. failed=True, name='Caching' 

64 """ 

65 raise NotImplementedError 

66 

67 def add_message_event(self, message_event): 

68 """Add a message event to this span. 

69 

70 :type message_event: :class:`opencensus.trace.time_event.MessageEvent` 

71 :param message_event: The message event to attach to this span. 

72 """ 

73 raise NotImplementedError 

74 

75 def add_link(self, link): 

76 """Add a Link. 

77 

78 :type link: :class: `~opencensus.trace.link.Link` 

79 :param link: A Link object. 

80 """ 

81 raise NotImplementedError 

82 

83 def set_status(self, status): 

84 """Sets span status. 

85 

86 :type code: :class: `~opencensus.trace.status.Status` 

87 :param code: A Status object. 

88 """ 

89 raise NotImplementedError 

90 

91 def start(self): 

92 """Set the start time for a span.""" 

93 raise NotImplementedError 

94 

95 def finish(self): 

96 """Set the end time for a span.""" 

97 raise NotImplementedError 

98 

99 def __iter__(self): 

100 """Iterate through the span tree.""" 

101 raise NotImplementedError 

102 

103 def __enter__(self): 

104 """Start a span.""" 

105 raise NotImplementedError 

106 

107 def __exit__(self, exception_type, exception_value, traceback): 

108 """Finish a span.""" 

109 raise NotImplementedError