File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22from unittest import mock
33
44from sentry_sdk import (
5+ capture_exception ,
56 continue_trace ,
67 get_baggage ,
78 get_client ,
89 get_current_span ,
910 get_traceparent ,
1011 is_initialized ,
1112 start_transaction ,
13+ set_tags ,
1214)
1315
1416from sentry_sdk .client import Client , NonRecordingClient
@@ -135,3 +137,45 @@ def test_get_client():
135137 assert client is not None
136138 assert client .__class__ == NonRecordingClient
137139 assert not client .is_active ()
140+
141+
142+ def raise_and_capture ():
143+ """Raise an exception and capture it.
144+
145+ This is a utility function for test_set_tags.
146+ """
147+ try :
148+ 1 / 0
149+ except ZeroDivisionError :
150+ capture_exception ()
151+
152+
153+ def test_set_tags (sentry_init , capture_events ):
154+ sentry_init ()
155+ events = capture_events ()
156+
157+ set_tags ({"tag1" : "value1" , "tag2" : "value2" })
158+ raise_and_capture ()
159+
160+ (* _ , event ) = events
161+ assert event ["tags" ] == {"tag1" : "value1" , "tag2" : "value2" }, "Setting tags failed"
162+
163+ set_tags ({"tag2" : "updated" , "tag3" : "new" })
164+ raise_and_capture ()
165+
166+ (* _ , event ) = events
167+ assert event ["tags" ] == {
168+ "tag1" : "value1" ,
169+ "tag2" : "updated" ,
170+ "tag3" : "new" ,
171+ }, "Updating tags failed"
172+
173+ set_tags ({})
174+ raise_and_capture ()
175+
176+ (* _ , event ) = events
177+ assert event ["tags" ] == {
178+ "tag1" : "value1" ,
179+ "tag2" : "updated" ,
180+ "tag3" : "new" ,
181+ }, "Upating tags with empty dict changed tags"
You can’t perform that action at this time.
0 commit comments