17
17
18
18
19
19
if False :
20
+ from contextlib import ContextManager
21
+
20
22
from typing import Union
21
23
from typing import Any
22
24
from typing import Optional
23
- from typing import Dict
24
25
from typing import Tuple
25
26
from typing import List
26
27
from typing import Callable
28
+ from typing import Generator
27
29
from typing import overload
28
- from contextlib import ContextManager
30
+
29
31
from sentry_sdk .integrations import Integration
32
+ from sentry_sdk .utils import Event , Hint , Breadcrumb , BreadcrumbHint
30
33
else :
31
34
32
35
def overload (x ):
@@ -251,7 +254,7 @@ def bind_client(self, new):
251
254
self ._stack [- 1 ] = (new , top [1 ])
252
255
253
256
def capture_event (self , event , hint = None ):
254
- # type: (Dict[str, Any], Dict[str, Any] ) -> Optional[str]
257
+ # type: (Event, Hint ) -> Optional[str]
255
258
"""Captures an event. The return value is the ID of the event.
256
259
257
260
The event is a dictionary following the Sentry v7/v8 protocol
@@ -268,7 +271,7 @@ def capture_event(self, event, hint=None):
268
271
return None
269
272
270
273
def capture_message (self , message , level = None ):
271
- # type: (str, Optional[Any ]) -> Optional[str]
274
+ # type: (str, Optional[str ]) -> Optional[str]
272
275
"""Captures a message. The message is just a string. If no level
273
276
is provided the default level is `info`.
274
277
"""
@@ -308,7 +311,7 @@ def _capture_internal_exception(self, exc_info):
308
311
logger .error ("Internal error in sentry_sdk" , exc_info = exc_info )
309
312
310
313
def add_breadcrumb (self , crumb = None , hint = None , ** kwargs ):
311
- # type: (Dict[str, Any ], Dict[str, Any ], **Any) -> None
314
+ # type: (Optional[Breadcrumb ], Optional[BreadcrumbHint ], **Any) -> None
312
315
"""Adds a breadcrumb. The breadcrumbs are a dictionary with the
313
316
data as the sentry v7/v8 protocol expects. `hint` is an optional
314
317
value that can be used by `before_breadcrumb` to customize the
@@ -319,26 +322,27 @@ def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
319
322
logger .info ("Dropped breadcrumb because no client bound" )
320
323
return
321
324
322
- crumb = dict (crumb or ()) # type: Dict[str, Any]
325
+ crumb = dict (crumb or ()) # type: Breadcrumb
323
326
crumb .update (kwargs )
324
327
if not crumb :
325
328
return
326
329
327
- hint = dict (hint or ())
330
+ hint = dict (hint or ()) # type: Hint
328
331
329
332
if crumb .get ("timestamp" ) is None :
330
333
crumb ["timestamp" ] = datetime .utcnow ()
331
334
if crumb .get ("type" ) is None :
332
335
crumb ["type" ] = "default"
333
336
334
- original_crumb = crumb
335
337
if client .options ["before_breadcrumb" ] is not None :
336
- crumb = client .options ["before_breadcrumb" ](crumb , hint )
338
+ new_crumb = client .options ["before_breadcrumb" ](crumb , hint )
339
+ else :
340
+ new_crumb = crumb
337
341
338
- if crumb is not None :
339
- scope ._breadcrumbs .append (crumb )
342
+ if new_crumb is not None :
343
+ scope ._breadcrumbs .append (new_crumb )
340
344
else :
341
- logger .info ("before breadcrumb dropped breadcrumb (%s)" , original_crumb )
345
+ logger .info ("before breadcrumb dropped breadcrumb (%s)" , crumb )
342
346
343
347
max_breadcrumbs = client .options ["max_breadcrumbs" ] # type: int
344
348
while len (scope ._breadcrumbs ) > max_breadcrumbs :
@@ -410,12 +414,14 @@ def inner():
410
414
return inner ()
411
415
412
416
def flush (self , timeout = None , callback = None ):
417
+ # type: (Optional[float], Optional[Callable[[int, float], None]]) -> None
413
418
"""Alias for self.client.flush"""
414
419
client , scope = self ._stack [- 1 ]
415
420
if client is not None :
416
421
return client .flush (timeout = timeout , callback = callback )
417
422
418
423
def iter_trace_propagation_headers (self ):
424
+ # type: () -> Generator[Tuple[str, str], None, None]
419
425
client , scope = self ._stack [- 1 ]
420
426
if scope ._span is None :
421
427
return
0 commit comments