@@ -560,69 +560,62 @@ def func(event, exc_info):
560560
561561 self ._error_processors .append (func )
562562
563- @_disable_capture
564- def apply_to_event (
565- self ,
566- event , # type: Event
567- hint , # type: Hint
568- options = None , # type: Optional[Dict[str, Any]]
569- ):
570- # type: (...) -> Optional[Event]
571- """Applies the information contained on the scope to the given event."""
572-
573- def _drop (cause , ty ):
574- # type: (Any, str) -> Optional[Any]
575- logger .info ("%s (%s) dropped event" , ty , cause )
576- return None
577-
578- is_transaction = event .get ("type" ) == "transaction"
579-
580- # put all attachments into the hint. This lets callbacks play around
581- # with attachments. We also later pull this out of the hint when we
582- # create the envelope.
583- attachments_to_send = hint .get ("attachments" ) or []
584- for attachment in self ._attachments :
585- if not is_transaction or attachment .add_to_transactions :
586- attachments_to_send .append (attachment )
587- hint ["attachments" ] = attachments_to_send
588-
563+ def _apply_level_to_event (self , event , hint , options ):
564+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
589565 if self ._level is not None :
590566 event ["level" ] = self ._level
591567
592- if not is_transaction :
593- event .setdefault ("breadcrumbs" , {}).setdefault ("values" , []).extend (
594- self ._breadcrumbs
595- )
568+ def _apply_breadcrumbs_to_event (self , event , hint , options ):
569+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
570+ event .setdefault ("breadcrumbs" , {}).setdefault ("values" , []).extend (
571+ self ._breadcrumbs
572+ )
596573
574+ def _apply_user_to_event (self , event , hint , options ):
575+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
597576 if event .get ("user" ) is None and self ._user is not None :
598577 event ["user" ] = self ._user
599578
579+ def _apply_transaction_name_to_event (self , event , hint , options ):
580+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
600581 if event .get ("transaction" ) is None and self ._transaction is not None :
601582 event ["transaction" ] = self ._transaction
602583
584+ def _apply_transaction_info_to_event (self , event , hint , options ):
585+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
603586 if event .get ("transaction_info" ) is None and self ._transaction_info is not None :
604587 event ["transaction_info" ] = self ._transaction_info
605588
589+ def _apply_fingerprint_to_event (self , event , hint , options ):
590+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
606591 if event .get ("fingerprint" ) is None and self ._fingerprint is not None :
607592 event ["fingerprint" ] = self ._fingerprint
608593
594+ def _apply_extra_to_event (self , event , hint , options ):
595+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
609596 if self ._extras :
610597 event .setdefault ("extra" , {}).update (self ._extras )
611598
599+ def _apply_tags_to_event (self , event , hint , options ):
600+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
612601 if self ._tags :
613602 event .setdefault ("tags" , {}).update (self ._tags )
614603
604+ def _apply_contexts_to_event (self , event , hint , options ):
605+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
615606 if self ._contexts :
616607 event .setdefault ("contexts" , {}).update (self ._contexts )
617608
618609 contexts = event .setdefault ("contexts" , {})
619610
611+ # Add "trace" context
620612 if contexts .get ("trace" ) is None :
621613 if has_tracing_enabled (options ) and self ._span is not None :
622614 contexts ["trace" ] = self ._span .get_trace_context ()
623615 else :
624616 contexts ["trace" ] = self .get_trace_context ()
625617
618+ # Add "reply_id" context
626619 try :
627620 replay_id = contexts ["trace" ]["dynamic_sampling_context" ]["replay_id" ]
628621 except (KeyError , TypeError ):
@@ -633,14 +626,58 @@ def _drop(cause, ty):
633626 "replay_id" : replay_id ,
634627 }
635628
629+ @_disable_capture
630+ def apply_to_event (
631+ self ,
632+ event , # type: Event
633+ hint , # type: Hint
634+ options = None , # type: Optional[Dict[str, Any]]
635+ ):
636+ # type: (...) -> Optional[Event]
637+ """Applies the information contained on the scope to the given event."""
638+ ty = event .get ("type" )
639+ is_transaction = ty == "transaction"
640+ is_check_in = ty == "check_in"
641+
642+ # put all attachments into the hint. This lets callbacks play around
643+ # with attachments. We also later pull this out of the hint when we
644+ # create the envelope.
645+ attachments_to_send = hint .get ("attachments" ) or []
646+ for attachment in self ._attachments :
647+ if not is_transaction or attachment .add_to_transactions :
648+ attachments_to_send .append (attachment )
649+ hint ["attachments" ] = attachments_to_send
650+
651+ self ._apply_contexts_to_event (event , hint , options )
652+
653+ if not is_check_in :
654+ self ._apply_level_to_event (event , hint , options )
655+ self ._apply_fingerprint_to_event (event , hint , options )
656+ self ._apply_user_to_event (event , hint , options )
657+ self ._apply_transaction_name_to_event (event , hint , options )
658+ self ._apply_transaction_info_to_event (event , hint , options )
659+ self ._apply_tags_to_event (event , hint , options )
660+ self ._apply_extra_to_event (event , hint , options )
661+
662+ if not is_transaction and not is_check_in :
663+ self ._apply_breadcrumbs_to_event (event , hint , options )
664+
665+ def _drop (cause , ty ):
666+ # type: (Any, str) -> Optional[Any]
667+ logger .info ("%s (%s) dropped event" , ty , cause )
668+ return None
669+
670+ # run error processors
636671 exc_info = hint .get ("exc_info" )
637672 if exc_info is not None :
638673 for error_processor in self ._error_processors :
639674 new_event = error_processor (event , exc_info )
640675 if new_event is None :
641676 return _drop (error_processor , "error processor" )
677+
642678 event = new_event
643679
680+ # run event processors
644681 for event_processor in chain (global_event_processors , self ._event_processors ):
645682 new_event = event
646683 with capture_internal_exceptions ():
0 commit comments