-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
124 lines (108 loc) · 4.99 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import sentry_sdk
import globals
def main():
# noop client
client = sentry_sdk.get_client()
assert isinstance(client, sentry_sdk.NoopClient)
assert not sentry_sdk.sentry_is_initialized()
# sentry init
sentry_sdk.init()
assert sentry_sdk.sentry_is_initialized()
client = sentry_sdk.get_client()
assert isinstance(client, sentry_sdk.Client)
assert client == sentry_sdk.get_global_scope().client
global_scope = sentry_sdk.get_global_scope()
global_scope.set_tag("gtag1", "g1")
assert global_scope.get_tags() == {"gtag1": "g1"}
assert sentry_sdk.Scope.get_current_scope().get_merged_scope_data() == {
"gtag1": "g1"
} # this is what sentry_sdk.capure_event() sends.
sentry_sdk.capture_event({"name": "gevent1"})
current_scope = globals.sentry_current_scope.get()
isolation_scope = globals.sentry_isolation_scope.get()
print(f"before with Current: {current_scope}/{isolation_scope}")
print("--------")
with sentry_sdk.isolated_scope() as isolated_scope:
current_scope = globals.sentry_current_scope.get()
isolation_scope = globals.sentry_isolation_scope.get()
print(f"in with Current: {current_scope}/{isolation_scope}")
print("--------")
isolated_scope.set_tag("itag2", "i1")
assert isolated_scope.get_tags() == {"itag2": "i1"}
assert sentry_sdk.Scope.get_current_scope().get_merged_scope_data() == {
"gtag1": "g1",
"itag2": "i1",
} # this is what sentry_sdk.capure_event() sends.
sentry_sdk.capture_event({"name": "ievent1"})
scope = sentry_sdk.get_current_scope()
scope.set_tag("tag2", "1")
assert scope.get_tags() == {"tag2": "1"}
assert sentry_sdk.Scope.get_current_scope().get_merged_scope_data() == {
"gtag1": "g1",
"itag2": "i1",
"tag2": "1",
} # this is what sentry_sdk.capure_event() sends.
sentry_sdk.capture_event({"name": "event1"})
with sentry_sdk.isolated_scope() as isolated_scope:
isolated_scope.set_tag("itag2", "i2")
assert isolated_scope.get_tags() == {"itag2": "i2", "tag2": "1"}
assert sentry_sdk.Scope.get_current_scope().get_merged_scope_data() == {
"gtag1": "g1",
"itag2": "i2",
"tag2": "1",
} # this is what sentry_sdk.capure_event() sends.
sentry_sdk.capture_event({"name": "ievent2"})
with sentry_sdk.new_scope() as scope: # did not call it "withScope" this sounds more natural
scope.set_tag("tag4", "4")
assert scope.get_tags() == {"tag2": "1", "tag4": "4"}
assert sentry_sdk.Scope.get_current_scope().get_merged_scope_data() == {
"gtag1": "g1",
"itag2": "i2",
"tag2": "1",
"tag4": "4",
} # this is what sentry_sdk.capure_event() sends.
sentry_sdk.capture_event({"name": "event2"})
global_scope = sentry_sdk.get_global_scope()
global_scope.set_tag("gtag2", "g2")
assert global_scope.get_tags() == {"gtag1": "g1", "gtag2": "g2"}
assert sentry_sdk.Scope.get_current_scope().get_merged_scope_data() == {
"gtag1": "g1",
"gtag2": "g2",
"itag2": "i2",
"tag2": "1",
"tag4": "4",
} # this is what sentry_sdk.capure_event() sends.
sentry_sdk.capture_event({"name": "gevent1"})
with sentry_sdk.new_scope() as scope: # did not call it "withScope" this sounds more natural
scope.set_tag("tag2", "2")
assert scope.get_tags() == {"tag2": "1", "tag2": "2"}
assert sentry_sdk.Scope.get_current_scope().get_merged_scope_data() == {
"gtag1": "g1",
"gtag2": "g2",
"itag2": "i1",
"tag2": "1",
"tag2": "2",
} # this is what sentry_sdk.capure_event() sends.
sentry_sdk.capture_event({"name": "event2"})
scope = sentry_sdk.get_current_scope()
scope.set_tag("tag3", "3")
assert scope.get_tags() == {"tag2": "1", "tag3": "3"}
assert sentry_sdk.Scope.get_current_scope().get_merged_scope_data() == {
"gtag1": "g1",
"gtag2": "g2",
"itag2": "i1",
"tag2": "1",
"tag3": "3",
} # this is what sentry_sdk.capure_event() sends.
sentry_sdk.capture_event({"name": "event3"})
scope = sentry_sdk.get_current_scope()
scope.set_tag("tagx", "x")
assert scope.get_tags() == {"tagx": "x"}
assert sentry_sdk.Scope.get_current_scope().get_merged_scope_data() == {
"gtag1": "g1",
"gtag2": "g2",
"tagx": "x",
} # this is what sentry_sdk.capure_event() sends.
sentry_sdk.capture_event({"name": "eventx"})
if __name__ == "__main__":
main()