1717
1818
1919if False :
20+ from contextlib import ContextManager
21+
2022 from typing import Union
2123 from typing import Any
2224 from typing import Optional
23- from typing import Dict
2425 from typing import Tuple
2526 from typing import List
2627 from typing import Callable
28+ from typing import Generator
2729 from typing import overload
28- from contextlib import ContextManager
30+
2931 from sentry_sdk .integrations import Integration
32+ from sentry_sdk .utils import Event , Hint , Breadcrumb , BreadcrumbHint
3033else :
3134
3235 def overload (x ):
@@ -251,7 +254,7 @@ def bind_client(self, new):
251254 self ._stack [- 1 ] = (new , top [1 ])
252255
253256 def capture_event (self , event , hint = None ):
254- # type: (Dict[str, Any], Dict[str, Any] ) -> Optional[str]
257+ # type: (Event, Hint ) -> Optional[str]
255258 """Captures an event. The return value is the ID of the event.
256259
257260 The event is a dictionary following the Sentry v7/v8 protocol
@@ -268,7 +271,7 @@ def capture_event(self, event, hint=None):
268271 return None
269272
270273 def capture_message (self , message , level = None ):
271- # type: (str, Optional[Any ]) -> Optional[str]
274+ # type: (str, Optional[str ]) -> Optional[str]
272275 """Captures a message. The message is just a string. If no level
273276 is provided the default level is `info`.
274277 """
@@ -308,7 +311,7 @@ def _capture_internal_exception(self, exc_info):
308311 logger .error ("Internal error in sentry_sdk" , exc_info = exc_info )
309312
310313 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
312315 """Adds a breadcrumb. The breadcrumbs are a dictionary with the
313316 data as the sentry v7/v8 protocol expects. `hint` is an optional
314317 value that can be used by `before_breadcrumb` to customize the
@@ -319,26 +322,27 @@ def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
319322 logger .info ("Dropped breadcrumb because no client bound" )
320323 return
321324
322- crumb = dict (crumb or ()) # type: Dict[str, Any]
325+ crumb = dict (crumb or ()) # type: Breadcrumb
323326 crumb .update (kwargs )
324327 if not crumb :
325328 return
326329
327- hint = dict (hint or ())
330+ hint = dict (hint or ()) # type: Hint
328331
329332 if crumb .get ("timestamp" ) is None :
330333 crumb ["timestamp" ] = datetime .utcnow ()
331334 if crumb .get ("type" ) is None :
332335 crumb ["type" ] = "default"
333336
334- original_crumb = crumb
335337 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
337341
338- if crumb is not None :
339- scope ._breadcrumbs .append (crumb )
342+ if new_crumb is not None :
343+ scope ._breadcrumbs .append (new_crumb )
340344 else :
341- logger .info ("before breadcrumb dropped breadcrumb (%s)" , original_crumb )
345+ logger .info ("before breadcrumb dropped breadcrumb (%s)" , crumb )
342346
343347 max_breadcrumbs = client .options ["max_breadcrumbs" ] # type: int
344348 while len (scope ._breadcrumbs ) > max_breadcrumbs :
@@ -410,12 +414,14 @@ def inner():
410414 return inner ()
411415
412416 def flush (self , timeout = None , callback = None ):
417+ # type: (Optional[float], Optional[Callable[[int, float], None]]) -> None
413418 """Alias for self.client.flush"""
414419 client , scope = self ._stack [- 1 ]
415420 if client is not None :
416421 return client .flush (timeout = timeout , callback = callback )
417422
418423 def iter_trace_propagation_headers (self ):
424+ # type: () -> Generator[Tuple[str, str], None, None]
419425 client , scope = self ._stack [- 1 ]
420426 if scope ._span is None :
421427 return
0 commit comments