-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (53 loc) · 2.36 KB
/
Copy pathmain.py
File metadata and controls
66 lines (53 loc) · 2.36 KB
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
import signal
import sentry_sdk_wrapper
import sentry_sdk
import os
import argparse
def main(other_dsn, isolated_dsn, other_is_first=True):
def handle_sigterm(signum, frame):
print("Received SIGTERM, closing Sentry clients...")
isolated_sdk.close(timeout=2)
sentry_sdk.get_client().close(2)
signal.signal(signal.SIGTERM, handle_sigterm)
def other_init():
sentry_sdk.init(other_dsn, max_breadcrumbs=5, debug=False, environment="sandbox")
if other_is_first:
other_init()
isolated_sdk = sentry_sdk_wrapper.SentrySDKWrapper(isolated_dsn, sentry_sdk_wrapper.IsInOurPathsChecker([os.path.dirname(__file__)]), max_breadcrumbs=50, environment="sandbox")
if not other_is_first:
other_init()
for i in range(10):
sentry_sdk.add_breadcrumb(message=f"external global breadcrumb_{i}")
isolated_sdk.add_breadcrumb(message=f"isolated global breadcrumb_{i}")
sentry_sdk.set_context("external_context", {"data": "external_data"})
sentry_sdk.set_tag("common_tag", "external_value")
isolated_sdk.set_context("isolated_context", {"data": f"isolated_{i}"})
isolated_sdk.set_tag("isolated_tag", f"value_{i}")
try:
{}["external capture_exception"]
except Exception as e:
sentry_sdk.capture_exception(e)
with isolated_sdk.new_scope() as isolated_scope:
for i in range(5):
isolated_scope.add_breadcrumb(message=f"isolated temp breadcrumb_{i}")
try:
{}["temp isolated capture_exception"]
except Exception as e:
isolated_scope.capture_exception(e)
with isolated_sdk.new_scope() as isolated_scope:
try:
{}["isolated capture_exception"]
except Exception as e:
isolated_scope.capture_exception(e)
def is_in_our_code_crash():
import json
data = '{"cle": is in our code not catched}'
json.loads(data)
is_in_our_code_crash()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--other-dsn", required=True, help="DSN for other Sentry SDK")
parser.add_argument("--isolated-dsn", required=True, help="DSN for isolated Sentry SDK")
parser.add_argument("--other-is-first", action="store_true", help="Init other SDK first")
args = parser.parse_args()
main(args.other_dsn, args.isolated_dsn, args.other_is_first)