22import numbers
33import traceback
44from 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
66
77
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.
1315
1416 Parameters
1517 ----------
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.
2020 """
2121
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."""
2625
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."""
3429
3530 @abc .abstractmethod
3631 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.
3833
3934 Note: Annotations will be indexed for later search query.
4035
@@ -48,9 +43,8 @@ def put_annotation(self, key: str, value: Union[str, numbers.Number, bool]) -> N
4843
4944 @abc .abstractmethod
5045 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.
5448
5549 Parameters
5650 ----------
@@ -63,45 +57,52 @@ def put_metadata(self, key: str, value: Any, namespace: str = "default") -> NoRe
6357 """
6458
6559 @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.
6862
6963 Parameters
7064 ----------
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
7869
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+ """
7974
80- class BaseSegment (abc .ABC ):
81- """Holds common properties and methods on segment and subsegment."""
8275
76+ class BaseProvider (abc .ABC ):
8377 @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 .
8781
8882 Parameters
8983 ----------
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
9288 """
9389
9490 @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.
9794
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+ """
101102
102103 @abc .abstractmethod
103104 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.
105106
106107 Note: Annotations will be indexed for later search query.
107108
@@ -115,8 +116,9 @@ def put_annotation(self, key: str, value: Union[str, numbers.Number, bool]) -> N
115116
116117 @abc .abstractmethod
117118 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.
120122
121123 Parameters
122124 ----------
@@ -129,17 +131,15 @@ def put_metadata(self, key: str, value: Any, namespace: str = "default") -> NoRe
129131 """
130132
131133 @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
134136
135137 Parameters
136138 ----------
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
145141 """
142+
143+ @abc .abstractmethod
144+ def patch_all (self ) -> NoReturn :
145+ """Instrument all supported libraries"""
0 commit comments