2
2
import numbers
3
3
import traceback
4
4
from contextlib import contextmanager
5
- from typing import Any , Generator , List , Optional , Sequence , Union
5
+ from typing import Any , Callable , Generator , List , Optional , Sequence , Union
6
6
7
7
8
8
class BaseSegment (abc .ABC ):
@@ -72,11 +72,30 @@ def add_exception(self, exception: BaseException, stack: List[traceback.StackSum
72
72
Whether it's a client error (False) or downstream service error (True), by default False
73
73
"""
74
74
75
+ # new function below
76
+ @abc .abstractmethod
77
+ def ignore_endpoint (self , hostname : Optional [str ] = None , urls : Optional [List [str ]] = None ):
78
+ """To ignore the endpoints you don't want requests to be traced,
79
+ perhaps due to the volume of calls or sensitive URLs."""
80
+
81
+ @abc .abstractmethod
82
+ def inject_context (self , context ):
83
+ """To inject missing context/information like service name"""
84
+
85
+ @abc .abstractmethod
86
+ def capture_method_async (
87
+ self ,
88
+ method : Callable ,
89
+ capture_response : Optional [Union [bool , str ]] = None ,
90
+ capture_error : Optional [Union [bool , str ]] = None ,
91
+ ):
92
+ """To capture async method"""
93
+
75
94
76
95
class BaseProvider (abc .ABC ):
77
96
@abc .abstractmethod
78
97
@contextmanager
79
- def in_subsegment (self , name = None , ** kwargs ) -> Generator [BaseSegment , None , None ]:
98
+ def trace (self , name = None , ** kwargs ) -> Generator [BaseSegment , None , None ]:
80
99
"""Return a subsegment context manger.
81
100
82
101
Parameters
@@ -89,7 +108,7 @@ def in_subsegment(self, name=None, **kwargs) -> Generator[BaseSegment, None, Non
89
108
90
109
@abc .abstractmethod
91
110
@contextmanager
92
- def in_subsegment_async (self , name = None , ** kwargs ) -> Generator [BaseSegment , None , None ]:
111
+ def trace_async (self , name = None , ** kwargs ) -> Generator [BaseSegment , None , None ]:
93
112
"""Return a subsegment async context manger.
94
113
95
114
Parameters
@@ -100,6 +119,18 @@ def in_subsegment_async(self, name=None, **kwargs) -> Generator[BaseSegment, Non
100
119
Optional parameters to be propagated to segment
101
120
"""
102
121
122
+ @abc .abstractmethod
123
+ def start_span (self , name = None ) -> Generator [BaseSegment , None , None ]:
124
+ """This method is proposed as a solution as it exists for other providers
125
+ This method is responsible for starting the trace. This might involve initializing some data structures,
126
+ connecting to an external service, or performing some other setup work"""
127
+
128
+ @abc .abstractmethod
129
+ def end_span (self , span : BaseSegment ):
130
+ """This method is proposed as a solution as it exists for other providers.
131
+ This method is responsible for ending the tracing of a span. This might involve finalizing data structures,
132
+ sending data to an external service, or performing some other cleanup work"""
133
+
103
134
@abc .abstractmethod
104
135
def put_annotation (self , key : str , value : Union [str , numbers .Number , bool ]) -> None :
105
136
"""Annotate current active trace entity with a key-value pair.
@@ -130,6 +161,10 @@ def put_metadata(self, key: str, value: Any, namespace: str = "default") -> None
130
161
Metadata namespace, by default 'default'
131
162
"""
132
163
164
+ @abc .abstractmethod
165
+ def put_exception (self , * args , ** kwargs ) -> None :
166
+ """Add exception to the current active trace entity."""
167
+
133
168
@abc .abstractmethod
134
169
def patch (self , modules : Sequence [str ]) -> None :
135
170
"""Instrument a set of supported libraries
0 commit comments