|
1 | 1 | import abc |
2 | | -import numbers |
3 | 2 | from contextlib import asynccontextmanager, contextmanager |
4 | | -from typing import AsyncGenerator, Generator, Sequence, Union |
| 3 | +from typing import Any, AsyncGenerator, Generator, Sequence |
5 | 4 |
|
6 | 5 |
|
7 | 6 | class BaseSpan(abc.ABC): |
8 | | - """Holds common properties and methods on span.""" |
| 7 | + """A span represents a unit of work or operation within a trace. |
| 8 | + Spans are the building blocks of Traces.""" |
9 | 9 |
|
10 | 10 | @abc.abstractmethod |
11 | | - def set_attribute(self, key: str, value: Union[str, numbers.Number, bool], **kwargs) -> None: |
12 | | - """set attribute for span with a key-value pair. |
| 11 | + def set_attribute(self, key: str, value: Any, **kwargs) -> None: |
| 12 | + """Set an attribute for a span with a key-value pair. |
13 | 13 |
|
14 | 14 | Parameters |
15 | 15 | ---------- |
16 | 16 | key: str |
17 | 17 | Attribute key |
18 | | - value: Union[str, numbers.Number, bool] |
| 18 | + value: Any |
19 | 19 | Attribute value |
| 20 | + kwargs: Optional[dict] |
| 21 | + Optional parameters |
20 | 22 | """ |
21 | 23 |
|
22 | 24 | @abc.abstractmethod |
23 | 25 | def record_exception(self, exception: BaseException, **kwargs): |
24 | | - """Add an exception to trace entities. |
| 26 | + """Records an exception to this Span. |
25 | 27 |
|
26 | 28 | Parameters |
27 | 29 | ---------- |
28 | 30 | exception: Exception |
29 | | - Caught exception |
30 | | - Output from `traceback.extract_stack()`. |
| 31 | + Caught exception during the exectution of this Span |
| 32 | + kwargs: Optional[dict] |
| 33 | + Optional parameters |
31 | 34 | """ |
32 | 35 |
|
33 | 36 |
|
34 | 37 | class BaseProvider(abc.ABC): |
| 38 | + """BaseProvider is an abstract base class that defines the expected behavior for tracing providers |
| 39 | + used by Tracer. Inheriting classes must implement this interface to be compatible with Tracer. |
| 40 | + """ |
| 41 | + |
35 | 42 | @abc.abstractmethod |
36 | 43 | @contextmanager |
37 | 44 | def trace(self, name: str, **kwargs) -> Generator[BaseSpan, None, None]: |
38 | | - """Return a span context manger. |
| 45 | + """Context manager for creating a new span and set it |
| 46 | + as the current span in this tracer's context. |
| 47 | +
|
| 48 | + Exiting the context manager will call the span's end method, |
| 49 | + as well as return the current span to its previous value by |
| 50 | + returning to the previous context. |
39 | 51 |
|
40 | 52 | Parameters |
41 | 53 | ---------- |
42 | 54 | name: str |
43 | 55 | Span name |
44 | 56 | kwargs: Optional[dict] |
45 | | - Optional parameters to be propagated to span |
| 57 | + Optional parameters to be propagated to the span |
46 | 58 | """ |
47 | 59 |
|
48 | 60 | @abc.abstractmethod |
49 | 61 | @asynccontextmanager |
50 | 62 | def trace_async(self, name: str, **kwargs) -> AsyncGenerator[BaseSpan, None]: |
51 | | - """Return a async span context manger. |
| 63 | + """Async Context manager for creating a new span and set it |
| 64 | + as the current span in this tracer's context. |
| 65 | +
|
| 66 | + Exiting the context manager will call the span's end method, |
| 67 | + as well as return the current span to its previous value by |
| 68 | + returning to the previous context. |
52 | 69 |
|
53 | 70 | Parameters |
54 | 71 | ---------- |
55 | 72 | name: str |
56 | 73 | Span name |
57 | 74 | kwargs: Optional[dict] |
58 | | - Optional parameters to be propagated to span |
| 75 | + Optional parameters to be propagated to the span |
59 | 76 | """ |
60 | 77 |
|
61 | 78 | @abc.abstractmethod |
62 | | - def set_attribute(self, key: str, value: Union[str, numbers.Number, bool], **kwargs) -> None: |
63 | | - """set attribute on current active trace entity with a key-value pair. |
| 79 | + def set_attribute(self, key: str, value: Any, **kwargs) -> None: |
| 80 | + """set attribute on current active span with a key-value pair. |
64 | 81 |
|
65 | 82 | Parameters |
66 | 83 | ---------- |
67 | 84 | key: str |
68 | 85 | attribute key |
69 | | - value: Union[str, numbers.Number, bool] |
| 86 | + value: Any |
70 | 87 | attribute value |
| 88 | + kwargs: Optional[dict] |
| 89 | + Optional parameters to be propagated to the span |
71 | 90 | """ |
72 | 91 |
|
73 | 92 | @abc.abstractmethod |
74 | 93 | def patch(self, modules: Sequence[str]) -> None: |
75 | | - """Instrument a set of supported libraries |
| 94 | + """Instrument a set of given libraries if supported by provider |
| 95 | + See specific provider for more detail |
| 96 | +
|
| 97 | + Exmaple |
| 98 | + ------- |
| 99 | + tracer = Tracer(service="payment") |
| 100 | + libraries = (['aioboto3',mysql]) |
| 101 | + # provider.patch will be called by tracer.patch |
| 102 | + tracer.patch(libraries) |
76 | 103 |
|
77 | 104 | Parameters |
78 | 105 | ---------- |
|
0 commit comments