2
2
import numbers
3
3
import traceback
4
4
from contextlib import contextmanager
5
- from typing import Any , AsyncContextManager , ContextManager , List , NoReturn , Optional , Set , Union
5
+ from typing import Any , Generator , List , NoReturn , Optional , Sequence , Union
6
6
7
7
8
- class BaseProvider (abc .ABC ):
9
- @abc .abstractmethod # type: ignore
10
- @contextmanager
11
- def in_subsegment (self , name = None , ** kwargs ) -> ContextManager :
12
- """Return a subsegment context manger.
8
+ class BaseSegment (abc .ABC ):
9
+ """Holds common properties and methods on segment and subsegment."""
10
+
11
+ @abc .abstractmethod
12
+ def close (self , end_time : Optional [int ] = None ):
13
+ """Close the trace entity by setting `end_time`
14
+ and flip the in progress flag to False.
13
15
14
16
Parameters
15
17
----------
16
- name: str
17
- Subsegment name
18
- kwargs: Optional[dict]
19
- Optional parameters to be propagated to segment
18
+ end_time: int
19
+ Time in epoch seconds, by default current time will be used.
20
20
"""
21
21
22
- @abc .abstractmethod # type: ignore
23
- @contextmanager
24
- def in_subsegment_async (self , name = None , ** kwargs ) -> AsyncContextManager :
25
- """Return a subsegment async context manger.
22
+ @abc .abstractmethod
23
+ def add_subsegment (self , subsegment : Any ):
24
+ """Add input subsegment as a child subsegment."""
26
25
27
- Parameters
28
- ----------
29
- name: str
30
- Subsegment name
31
- kwargs: Optional[dict]
32
- Optional parameters to be propagated to segment
33
- """
26
+ @abc .abstractmethod
27
+ def remove_subsegment (self , subsegment : Any ):
28
+ """Remove input subsegment from child subsegments."""
34
29
35
30
@abc .abstractmethod
36
31
def put_annotation (self , key : str , value : Union [str , numbers .Number , bool ]) -> NoReturn :
37
- """Annotate current active trace entity with a key-value pair.
32
+ """Annotate segment or subsegment with a key-value pair.
38
33
39
34
Note: Annotations will be indexed for later search query.
40
35
@@ -48,9 +43,8 @@ def put_annotation(self, key: str, value: Union[str, numbers.Number, bool]) -> N
48
43
49
44
@abc .abstractmethod
50
45
def put_metadata (self , key : str , value : Any , namespace : str = "default" ) -> NoReturn :
51
- """Add metadata to the current active trace entity.
52
-
53
- Note: Metadata is not indexed but can be later retrieved by BatchGetTraces API.
46
+ """Add metadata to segment or subsegment. Metadata is not indexed
47
+ but can be later retrieved by BatchGetTraces API.
54
48
55
49
Parameters
56
50
----------
@@ -63,45 +57,52 @@ def put_metadata(self, key: str, value: Any, namespace: str = "default") -> NoRe
63
57
"""
64
58
65
59
@abc .abstractmethod
66
- def patch (self , modules : Set [ str ]) -> NoReturn :
67
- """Instrument a set of supported libraries
60
+ def add_exception (self , exception : BaseException , stack : List [ traceback . StackSummary ], remote : bool = False ) :
61
+ """Add an exception to trace entities.
68
62
69
63
Parameters
70
64
----------
71
- modules: Set[str]
72
- Set of modules to be patched
73
- """
74
-
75
- @abc .abstractmethod
76
- def patch_all (self ) -> NoReturn :
77
- """Instrument all supported libraries"""
65
+ exception: Exception
66
+ Caught exception
67
+ stack: List[traceback.StackSummary]
68
+ List of traceback summaries
78
69
70
+ Output from `traceback.extract_stack()`.
71
+ remote: bool
72
+ Whether it's a client error (False) or downstream service error (True), by default False
73
+ """
79
74
80
- class BaseSegment (abc .ABC ):
81
- """Holds common properties and methods on segment and subsegment."""
82
75
76
+ class BaseProvider (abc .ABC ):
83
77
@abc .abstractmethod
84
- def close ( self , end_time : Optional [ int ] = None ):
85
- """Close the trace entity by setting `end_time`
86
- and flip the in progress flag to False .
78
+ @ contextmanager
79
+ def in_subsegment ( self , name = None , ** kwargs ) -> Generator [ BaseSegment , None , None ]:
80
+ """Return a subsegment context manger .
87
81
88
82
Parameters
89
83
----------
90
- end_time: int
91
- Time in epoch seconds, by default current time will be used.
84
+ name: str
85
+ Subsegment name
86
+ kwargs: Optional[dict]
87
+ Optional parameters to be propagated to segment
92
88
"""
93
89
94
90
@abc .abstractmethod
95
- def add_subsegment (self , subsegment : Any ):
96
- """Add input subsegment as a child subsegment."""
91
+ @contextmanager
92
+ def in_subsegment_async (self , name = None , ** kwargs ) -> Generator [BaseSegment , None , None ]:
93
+ """Return a subsegment async context manger.
97
94
98
- @abc .abstractmethod
99
- def remove_subsegment (self , subsegment : Any ):
100
- """Remove input subsegment from child subsegments."""
95
+ Parameters
96
+ ----------
97
+ name: str
98
+ Subsegment name
99
+ kwargs: Optional[dict]
100
+ Optional parameters to be propagated to segment
101
+ """
101
102
102
103
@abc .abstractmethod
103
104
def put_annotation (self , key : str , value : Union [str , numbers .Number , bool ]) -> NoReturn :
104
- """Annotate segment or subsegment with a key-value pair.
105
+ """Annotate current active trace entity with a key-value pair.
105
106
106
107
Note: Annotations will be indexed for later search query.
107
108
@@ -115,8 +116,9 @@ def put_annotation(self, key: str, value: Union[str, numbers.Number, bool]) -> N
115
116
116
117
@abc .abstractmethod
117
118
def put_metadata (self , key : str , value : Any , namespace : str = "default" ) -> NoReturn :
118
- """Add metadata to segment or subsegment. Metadata is not indexed
119
- but can be later retrieved by BatchGetTraces API.
119
+ """Add metadata to the current active trace entity.
120
+
121
+ Note: Metadata is not indexed but can be later retrieved by BatchGetTraces API.
120
122
121
123
Parameters
122
124
----------
@@ -129,17 +131,15 @@ def put_metadata(self, key: str, value: Any, namespace: str = "default") -> NoRe
129
131
"""
130
132
131
133
@abc .abstractmethod
132
- def add_exception (self , exception : BaseException , stack : List [ traceback . StackSummary ], remote : bool = False ) :
133
- """Add an exception to trace entities.
134
+ def patch (self , modules : Sequence [ str ]) -> NoReturn :
135
+ """Instrument a set of supported libraries
134
136
135
137
Parameters
136
138
----------
137
- exception: Exception
138
- Caught exception
139
- stack: List[traceback.StackSummary]
140
- List of traceback summaries
141
-
142
- Output from `traceback.extract_stack()`.
143
- remote: bool
144
- Whether it's a client error (False) or downstream service error (True), by default False
139
+ modules: Set[str]
140
+ Set of modules to be patched
145
141
"""
142
+
143
+ @abc .abstractmethod
144
+ def patch_all (self ) -> NoReturn :
145
+ """Instrument all supported libraries"""
0 commit comments