Skip to content

Commit 0cd487c

Browse files
committed
Add classes.sentry to manage sentry_sdk
1 parent d014ca4 commit 0cd487c

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

src/classes/sentry.py

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""
2+
@file
3+
@brief This file manages the optional Sentry SDK
4+
@author Jonathan Thomas <[email protected]>
5+
@author FeRD (Frank Dana) <[email protected]>
6+
7+
@section LICENSE
8+
9+
Copyright (c) 2008-2021 OpenShot Studios, LLC
10+
(http://www.openshotstudios.com). This file is part of
11+
OpenShot Video Editor (http://www.openshot.org), an open-source project
12+
dedicated to delivering high quality video editing and animation solutions
13+
to the world.
14+
15+
OpenShot Video Editor is free software: you can redistribute it and/or modify
16+
it under the terms of the GNU General Public License as published by
17+
the Free Software Foundation, either version 3 of the License, or
18+
(at your option) any later version.
19+
20+
OpenShot Video Editor is distributed in the hope that it will be useful,
21+
but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+
GNU General Public License for more details.
24+
25+
You should have received a copy of the GNU General Public License
26+
along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
27+
"""
28+
29+
import platform
30+
31+
from classes import info
32+
33+
try:
34+
import distro
35+
except ModuleNotFoundError:
36+
distro = None
37+
38+
try:
39+
import sentry_sdk as sdk
40+
except ModuleNotFoundError:
41+
sdk = None
42+
43+
44+
def init_tracing():
45+
"""Init all Sentry tracing"""
46+
if not sdk:
47+
return
48+
49+
# Determine sample rate for exceptions
50+
traces_sample_rate = 0.1
51+
environment = "production"
52+
if "-dev" in info.VERSION:
53+
# Dev mode, trace all exceptions
54+
traces_sample_rate = 1.0
55+
environment = "development"
56+
57+
# Initialize sentry exception tracing
58+
sdk.init(
59+
"https://[email protected]/5795985",
60+
traces_sample_rate=traces_sample_rate,
61+
release=f"openshot@{info.VERSION}",
62+
environment=environment
63+
)
64+
sdk.set_tag("system", platform.system())
65+
sdk.set_tag("machine", platform.machine())
66+
sdk.set_tag("processor", platform.processor())
67+
sdk.set_tag("platform", platform.platform())
68+
if distro:
69+
sdk.set_tag("distro", " ".join(distro.linux_distribution()))
70+
sdk.set_tag("locale", info.CURRENT_LANGUAGE)
71+
72+
73+
def disable_tracing():
74+
"""Disable all Sentry tracing requests"""
75+
if sdk:
76+
sdk.init()
77+
78+
79+
def set_tag(*args):
80+
if sdk:
81+
sdk.set_tag(*args)
82+
83+
84+
def set_user(*args):
85+
if sdk:
86+
sdk.set_user(*args)
87+
88+
89+
def set_context(*args):
90+
if sdk:
91+
sdk.set_context(*args)

0 commit comments

Comments
 (0)