2929 Transaction ,
3030)
3131from sentry_sdk .utils import (
32+ AnnotatedValue ,
3233 capture_internal_exception ,
3334 capture_internal_exceptions ,
3435 ContextVar ,
@@ -181,6 +182,7 @@ class Scope:
181182 "_contexts" ,
182183 "_extras" ,
183184 "_breadcrumbs" ,
185+ "_breadcrumb_info" ,
184186 "_event_processors" ,
185187 "_error_processors" ,
186188 "_should_capture" ,
@@ -205,6 +207,7 @@ def __init__(self, ty=None, client=None):
205207
206208 self ._name = None # type: Optional[str]
207209 self ._propagation_context = None # type: Optional[PropagationContext]
210+ self ._breadcrumb_info = 0 # type: int
208211
209212 self .client = NonRecordingClient () # type: sentry_sdk.client.BaseClient
210213
@@ -238,6 +241,7 @@ def __copy__(self):
238241 rv ._extras = dict (self ._extras )
239242
240243 rv ._breadcrumbs = copy (self ._breadcrumbs )
244+ rv ._breadcrumb_info = copy (self ._breadcrumb_info )
241245 rv ._event_processors = list (self ._event_processors )
242246 rv ._error_processors = list (self ._error_processors )
243247 rv ._propagation_context = self ._propagation_context
@@ -906,6 +910,7 @@ def clear_breadcrumbs(self):
906910 # type: () -> None
907911 """Clears breadcrumb buffer."""
908912 self ._breadcrumbs = deque () # type: Deque[Breadcrumb]
913+ self ._breadcrumb_info = 0
909914
910915 def add_attachment (
911916 self ,
@@ -973,6 +978,7 @@ def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
973978
974979 while len (self ._breadcrumbs ) > max_breadcrumbs :
975980 self ._breadcrumbs .popleft ()
981+ self ._breadcrumb_info += 1
976982
977983 def start_transaction (
978984 self ,
@@ -1339,6 +1345,12 @@ def _apply_breadcrumbs_to_event(self, event, hint, options):
13391345 logger .debug ("Error when sorting breadcrumbs" , exc_info = err )
13401346 pass
13411347
1348+ # Add annotation that breadcrumbs were truncated
1349+ original_length = len (event ["breadcrumbs" ]["values" ]) + self ._breadcrumb_info
1350+ event ["breadcrumbs" ]["values" ] = AnnotatedValue .truncated_breadcrumbs (
1351+ event ["breadcrumbs" ]["values" ], original_length
1352+ )
1353+
13421354 def _apply_user_to_event (self , event , hint , options ):
13431355 # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
13441356 if event .get ("user" ) is None and self ._user is not None :
0 commit comments