@@ -91,7 +91,79 @@ def test_event_id(sentry_init, capture_events):
9191 assert Hub .current .last_event_id () == event_id
9292
9393
94- def test_option_callback (sentry_init , capture_events , monkeypatch ):
94+ def test_option_before_send (sentry_init , capture_events ):
95+ def before_send (event , hint ):
96+ event ["extra" ] = {"before_send_called" : True }
97+ return event
98+
99+ def do_this ():
100+ try :
101+ raise ValueError ("aha!" )
102+ except Exception :
103+ capture_exception ()
104+
105+ sentry_init (before_send = before_send )
106+ events = capture_events ()
107+
108+ do_this ()
109+
110+ (event ,) = events
111+ assert event ["extra" ] == {"before_send_called" : True }
112+
113+
114+ def test_option_before_send_discard (sentry_init , capture_events ):
115+ def before_send_discard (event , hint ):
116+ return None
117+
118+ def do_this ():
119+ try :
120+ raise ValueError ("aha!" )
121+ except Exception :
122+ capture_exception ()
123+
124+ sentry_init (before_send = before_send_discard )
125+ events = capture_events ()
126+
127+ do_this ()
128+
129+ assert len (events ) == 0
130+
131+
132+ def test_option_before_send_transaction (sentry_init , capture_events ):
133+ def before_send_transaction (event , hint ):
134+ assert event ["type" ] == "transaction"
135+ event ["extra" ] = {"before_send_transaction_called" : True }
136+ return event
137+
138+ sentry_init (
139+ before_send_transaction = before_send_transaction ,
140+ traces_sample_rate = 1.0 ,
141+ )
142+ events = capture_events ()
143+ transaction = start_transaction (name = "foo" )
144+ transaction .finish ()
145+
146+ (event ,) = events
147+ assert event ["transaction" ] == "foo"
148+ assert event ["extra" ] == {"before_send_transaction_called" : True }
149+
150+
151+ def test_option_before_send_transaction_discard (sentry_init , capture_events ):
152+ def before_send_transaction_discard (event , hint ):
153+ return None
154+
155+ sentry_init (
156+ before_send_transaction = before_send_transaction_discard ,
157+ traces_sample_rate = 1.0 ,
158+ )
159+ events = capture_events ()
160+ transaction = start_transaction (name = "foo" )
161+ transaction .finish ()
162+
163+ assert len (events ) == 0
164+
165+
166+ def test_option_before_breadcrumb (sentry_init , capture_events , monkeypatch ):
95167 drop_events = False
96168 drop_breadcrumbs = False
97169 reports = []
0 commit comments