@@ -560,69 +560,62 @@ def func(event, exc_info):
560
560
561
561
self ._error_processors .append (func )
562
562
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
589
565
if self ._level is not None :
590
566
event ["level" ] = self ._level
591
567
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
+ )
596
573
574
+ def _apply_user_to_event (self , event , hint , options ):
575
+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
597
576
if event .get ("user" ) is None and self ._user is not None :
598
577
event ["user" ] = self ._user
599
578
579
+ def _apply_transaction_name_to_event (self , event , hint , options ):
580
+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
600
581
if event .get ("transaction" ) is None and self ._transaction is not None :
601
582
event ["transaction" ] = self ._transaction
602
583
584
+ def _apply_transaction_info_to_event (self , event , hint , options ):
585
+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
603
586
if event .get ("transaction_info" ) is None and self ._transaction_info is not None :
604
587
event ["transaction_info" ] = self ._transaction_info
605
588
589
+ def _apply_fingerprint_to_event (self , event , hint , options ):
590
+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
606
591
if event .get ("fingerprint" ) is None and self ._fingerprint is not None :
607
592
event ["fingerprint" ] = self ._fingerprint
608
593
594
+ def _apply_extra_to_event (self , event , hint , options ):
595
+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
609
596
if self ._extras :
610
597
event .setdefault ("extra" , {}).update (self ._extras )
611
598
599
+ def _apply_tags_to_event (self , event , hint , options ):
600
+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
612
601
if self ._tags :
613
602
event .setdefault ("tags" , {}).update (self ._tags )
614
603
604
+ def _apply_contexts_to_event (self , event , hint , options ):
605
+ # type: (Event, Hint, Optional[Dict[str, Any]]) -> None
615
606
if self ._contexts :
616
607
event .setdefault ("contexts" , {}).update (self ._contexts )
617
608
618
609
contexts = event .setdefault ("contexts" , {})
619
610
611
+ # Add "trace" context
620
612
if contexts .get ("trace" ) is None :
621
613
if has_tracing_enabled (options ) and self ._span is not None :
622
614
contexts ["trace" ] = self ._span .get_trace_context ()
623
615
else :
624
616
contexts ["trace" ] = self .get_trace_context ()
625
617
618
+ # Add "reply_id" context
626
619
try :
627
620
replay_id = contexts ["trace" ]["dynamic_sampling_context" ]["replay_id" ]
628
621
except (KeyError , TypeError ):
@@ -633,14 +626,58 @@ def _drop(cause, ty):
633
626
"replay_id" : replay_id ,
634
627
}
635
628
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
636
671
exc_info = hint .get ("exc_info" )
637
672
if exc_info is not None :
638
673
for error_processor in self ._error_processors :
639
674
new_event = error_processor (event , exc_info )
640
675
if new_event is None :
641
676
return _drop (error_processor , "error processor" )
677
+
642
678
event = new_event
643
679
680
+ # run event processors
644
681
for event_processor in chain (global_event_processors , self ._event_processors ):
645
682
new_event = event
646
683
with capture_internal_exceptions ():
0 commit comments