|
1 | | -from typing import TYPE_CHECKING, TypeVar, Union |
| 1 | +from datetime import datetime |
| 2 | +from collections.abc import Container, MutableMapping, Sequence |
| 3 | + |
| 4 | +from types import TracebackType |
| 5 | +from typing import ( |
| 6 | + TYPE_CHECKING, |
| 7 | + TypeVar, |
| 8 | + Union, |
| 9 | + Any, |
| 10 | + Callable, |
| 11 | + Dict, |
| 12 | + Literal, |
| 13 | + Mapping, |
| 14 | + NotRequired, |
| 15 | + Optional, |
| 16 | + Type, |
| 17 | + TypedDict, |
| 18 | +) |
2 | 19 |
|
3 | 20 |
|
4 | 21 | # Re-exported for compat, since code out there in the wild might use this variable. |
@@ -96,146 +113,131 @@ def substituted_because_contains_sensitive_data(cls): |
96 | 113 | T = TypeVar("T") |
97 | 114 | Annotated = Union[AnnotatedValue, T] |
98 | 115 |
|
| 116 | +Hint = Dict[str, Any] |
| 117 | +Log = TypedDict( |
| 118 | + "Log", |
| 119 | + { |
| 120 | + "severity_text": str, |
| 121 | + "severity_number": int, |
| 122 | + "body": str, |
| 123 | + "attributes": dict[str, str | bool | float | int], |
| 124 | + "time_unix_nano": int, |
| 125 | + "trace_id": Optional[str], |
| 126 | + }, |
| 127 | +) |
| 128 | + |
| 129 | +# "critical" is an alias of "fatal" recognized by Relay |
| 130 | +LogLevelStr = Literal["fatal", "critical", "error", "warning", "info", "debug"] |
| 131 | + |
| 132 | +DurationUnit = Literal[ |
| 133 | + "nanosecond", |
| 134 | + "microsecond", |
| 135 | + "millisecond", |
| 136 | + "second", |
| 137 | + "minute", |
| 138 | + "hour", |
| 139 | + "day", |
| 140 | + "week", |
| 141 | +] |
| 142 | + |
| 143 | +InformationUnit = Literal[ |
| 144 | + "bit", |
| 145 | + "byte", |
| 146 | + "kilobyte", |
| 147 | + "kibibyte", |
| 148 | + "megabyte", |
| 149 | + "mebibyte", |
| 150 | + "gigabyte", |
| 151 | + "gibibyte", |
| 152 | + "terabyte", |
| 153 | + "tebibyte", |
| 154 | + "petabyte", |
| 155 | + "pebibyte", |
| 156 | + "exabyte", |
| 157 | + "exbibyte", |
| 158 | +] |
| 159 | + |
| 160 | +FractionUnit = Literal["ratio", "percent"] |
| 161 | +MeasurementUnit = Union[DurationUnit, InformationUnit, FractionUnit, str] |
| 162 | + |
| 163 | +MeasurementValue = TypedDict( |
| 164 | + "MeasurementValue", |
| 165 | + { |
| 166 | + "value": float, |
| 167 | + "unit": NotRequired[Optional[MeasurementUnit]], |
| 168 | + }, |
| 169 | +) |
| 170 | + |
| 171 | +Breadcrumb = Dict[str, Any] |
| 172 | +BreadcrumbHint = Dict[str, Any] |
| 173 | + |
| 174 | +SamplingContext = Dict[str, Any] |
| 175 | + |
| 176 | +Event = TypedDict( |
| 177 | + "Event", |
| 178 | + { |
| 179 | + "breadcrumbs": Annotated[ |
| 180 | + dict[Literal["values"], list[dict[str, Any]]] |
| 181 | + ], # TODO: We can expand on this type |
| 182 | + "check_in_id": str, |
| 183 | + "contexts": dict[str, dict[str, object]], |
| 184 | + "dist": str, |
| 185 | + "duration": Optional[float], |
| 186 | + "environment": str, |
| 187 | + "errors": list[dict[str, Any]], # TODO: We can expand on this type |
| 188 | + "event_id": str, |
| 189 | + "exception": dict[ |
| 190 | + Literal["values"], list[dict[str, Any]] |
| 191 | + ], # TODO: We can expand on this type |
| 192 | + "extra": MutableMapping[str, object], |
| 193 | + "fingerprint": list[str], |
| 194 | + "level": LogLevelStr, |
| 195 | + "logentry": Mapping[str, object], |
| 196 | + "logger": str, |
| 197 | + "measurements": dict[str, MeasurementValue], |
| 198 | + "message": str, |
| 199 | + "modules": dict[str, str], |
| 200 | + "monitor_config": Mapping[str, object], |
| 201 | + "monitor_slug": Optional[str], |
| 202 | + "platform": Literal["python"], |
| 203 | + "profile": object, # Should be sentry_sdk.profiler.Profile, but we can't import that here due to circular imports |
| 204 | + "release": str, |
| 205 | + "request": dict[str, object], |
| 206 | + "sdk": Mapping[str, object], |
| 207 | + "server_name": str, |
| 208 | + "spans": Annotated[list[dict[str, object]]], |
| 209 | + "stacktrace": dict[ |
| 210 | + str, object |
| 211 | + ], # We access this key in the code, but I am unsure whether we ever set it |
| 212 | + "start_timestamp": datetime, |
| 213 | + "status": Optional[str], |
| 214 | + "tags": MutableMapping[str, str], # Tags must be less than 200 characters each |
| 215 | + "threads": dict[ |
| 216 | + Literal["values"], list[dict[str, Any]] |
| 217 | + ], # TODO: We can expand on this type |
| 218 | + "timestamp": Optional[datetime], # Must be set before sending the event |
| 219 | + "transaction": str, |
| 220 | + "transaction_info": Mapping[str, Any], # TODO: We can expand on this type |
| 221 | + "type": Literal["check_in", "transaction"], |
| 222 | + "user": dict[str, object], |
| 223 | + "_dropped_spans": int, |
| 224 | + }, |
| 225 | + total=False, |
| 226 | +) |
99 | 227 |
|
100 | | -if TYPE_CHECKING: |
101 | | - from collections.abc import Container, MutableMapping, Sequence |
102 | | - |
103 | | - from datetime import datetime |
104 | 228 |
|
105 | | - from types import TracebackType |
106 | | - from typing import Any |
107 | | - from typing import Callable |
108 | | - from typing import Dict |
109 | | - from typing import Mapping |
110 | | - from typing import NotRequired |
111 | | - from typing import Optional |
112 | | - from typing import Type |
113 | | - from typing_extensions import Literal, TypedDict |
| 229 | +if TYPE_CHECKING: |
114 | 230 |
|
115 | 231 | class SDKInfo(TypedDict): |
116 | 232 | name: str |
117 | 233 | version: str |
118 | 234 | packages: Sequence[Mapping[str, str]] |
119 | 235 |
|
120 | | - # "critical" is an alias of "fatal" recognized by Relay |
121 | | - LogLevelStr = Literal["fatal", "critical", "error", "warning", "info", "debug"] |
122 | | - |
123 | | - DurationUnit = Literal[ |
124 | | - "nanosecond", |
125 | | - "microsecond", |
126 | | - "millisecond", |
127 | | - "second", |
128 | | - "minute", |
129 | | - "hour", |
130 | | - "day", |
131 | | - "week", |
132 | | - ] |
133 | | - |
134 | | - InformationUnit = Literal[ |
135 | | - "bit", |
136 | | - "byte", |
137 | | - "kilobyte", |
138 | | - "kibibyte", |
139 | | - "megabyte", |
140 | | - "mebibyte", |
141 | | - "gigabyte", |
142 | | - "gibibyte", |
143 | | - "terabyte", |
144 | | - "tebibyte", |
145 | | - "petabyte", |
146 | | - "pebibyte", |
147 | | - "exabyte", |
148 | | - "exbibyte", |
149 | | - ] |
150 | | - |
151 | | - FractionUnit = Literal["ratio", "percent"] |
152 | | - MeasurementUnit = Union[DurationUnit, InformationUnit, FractionUnit, str] |
153 | | - |
154 | | - MeasurementValue = TypedDict( |
155 | | - "MeasurementValue", |
156 | | - { |
157 | | - "value": float, |
158 | | - "unit": NotRequired[Optional[MeasurementUnit]], |
159 | | - }, |
160 | | - ) |
161 | | - |
162 | | - Event = TypedDict( |
163 | | - "Event", |
164 | | - { |
165 | | - "breadcrumbs": Annotated[ |
166 | | - dict[Literal["values"], list[dict[str, Any]]] |
167 | | - ], # TODO: We can expand on this type |
168 | | - "check_in_id": str, |
169 | | - "contexts": dict[str, dict[str, object]], |
170 | | - "dist": str, |
171 | | - "duration": Optional[float], |
172 | | - "environment": str, |
173 | | - "errors": list[dict[str, Any]], # TODO: We can expand on this type |
174 | | - "event_id": str, |
175 | | - "exception": dict[ |
176 | | - Literal["values"], list[dict[str, Any]] |
177 | | - ], # TODO: We can expand on this type |
178 | | - "extra": MutableMapping[str, object], |
179 | | - "fingerprint": list[str], |
180 | | - "level": LogLevelStr, |
181 | | - "logentry": Mapping[str, object], |
182 | | - "logger": str, |
183 | | - "measurements": dict[str, MeasurementValue], |
184 | | - "message": str, |
185 | | - "modules": dict[str, str], |
186 | | - "monitor_config": Mapping[str, object], |
187 | | - "monitor_slug": Optional[str], |
188 | | - "platform": Literal["python"], |
189 | | - "profile": object, # Should be sentry_sdk.profiler.Profile, but we can't import that here due to circular imports |
190 | | - "release": str, |
191 | | - "request": dict[str, object], |
192 | | - "sdk": Mapping[str, object], |
193 | | - "server_name": str, |
194 | | - "spans": Annotated[list[dict[str, object]]], |
195 | | - "stacktrace": dict[ |
196 | | - str, object |
197 | | - ], # We access this key in the code, but I am unsure whether we ever set it |
198 | | - "start_timestamp": datetime, |
199 | | - "status": Optional[str], |
200 | | - "tags": MutableMapping[ |
201 | | - str, str |
202 | | - ], # Tags must be less than 200 characters each |
203 | | - "threads": dict[ |
204 | | - Literal["values"], list[dict[str, Any]] |
205 | | - ], # TODO: We can expand on this type |
206 | | - "timestamp": Optional[datetime], # Must be set before sending the event |
207 | | - "transaction": str, |
208 | | - "transaction_info": Mapping[str, Any], # TODO: We can expand on this type |
209 | | - "type": Literal["check_in", "transaction"], |
210 | | - "user": dict[str, object], |
211 | | - "_dropped_spans": int, |
212 | | - }, |
213 | | - total=False, |
214 | | - ) |
215 | | - |
216 | 236 | ExcInfo = Union[ |
217 | 237 | tuple[Type[BaseException], BaseException, Optional[TracebackType]], |
218 | 238 | tuple[None, None, None], |
219 | 239 | ] |
220 | 240 |
|
221 | | - Hint = Dict[str, Any] |
222 | | - Log = TypedDict( |
223 | | - "Log", |
224 | | - { |
225 | | - "severity_text": str, |
226 | | - "severity_number": int, |
227 | | - "body": str, |
228 | | - "attributes": dict[str, str | bool | float | int], |
229 | | - "time_unix_nano": int, |
230 | | - "trace_id": Optional[str], |
231 | | - }, |
232 | | - ) |
233 | | - |
234 | | - Breadcrumb = Dict[str, Any] |
235 | | - BreadcrumbHint = Dict[str, Any] |
236 | | - |
237 | | - SamplingContext = Dict[str, Any] |
238 | | - |
239 | 241 | EventProcessor = Callable[[Event, Hint], Optional[Event]] |
240 | 242 | ErrorProcessor = Callable[[Event, ExcInfo], Optional[Event]] |
241 | 243 | BreadcrumbProcessor = Callable[[Breadcrumb, BreadcrumbHint], Optional[Breadcrumb]] |
|
0 commit comments