File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 2
2
from unittest import mock
3
3
4
4
from sentry_sdk import (
5
+ capture_exception ,
5
6
continue_trace ,
6
7
get_baggage ,
7
8
get_client ,
8
9
get_current_span ,
9
10
get_traceparent ,
10
11
is_initialized ,
11
12
start_transaction ,
13
+ set_tags ,
12
14
)
13
15
14
16
from sentry_sdk .client import Client , NonRecordingClient
@@ -135,3 +137,45 @@ def test_get_client():
135
137
assert client is not None
136
138
assert client .__class__ == NonRecordingClient
137
139
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