Skip to content

Commit 59d5528

Browse files
authored
Merge pull request #271 from SpongePowered/feature/sentry-sdk
Switched from raven to sentry sdk
2 parents 225578d + 2600595 commit 59d5528

File tree

4 files changed

+85
-12
lines changed

4 files changed

+85
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ media/
1313
.DS_Store
1414
.pytest_cache
1515
venv/
16+
Pipfile*

requirements/prod.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-r base.txt
22

3-
raven==6.9.0
3+
sentry-sdk==0.6.5
44
gunicorn==19.9.0

spongeauth/spongeauth/settings/prod.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import os
2-
import os.path
3-
import raven
1+
import sentry_sdk
2+
from sentry_sdk.integrations.django import DjangoIntegration
43

4+
from .utils import fetch_git_sha
55
from .base import *
66

77
GIT_REPO_ROOT = os.path.dirname(BASE_DIR)
@@ -50,10 +50,6 @@
5050
},
5151
]
5252

53-
INSTALLED_APPS += [
54-
'raven.contrib.django.raven_compat',
55-
]
56-
5753
SSO_ENDPOINTS = {}
5854
for k, v in os.environ.items():
5955
if not k.startswith('SSO_ENDPOINT_'):
@@ -63,10 +59,12 @@
6359
d = SSO_ENDPOINTS.setdefault(name, {})
6460
d[key.lower()] = v
6561

66-
RAVEN_CONFIG = {
67-
'dsn': os.environ['RAVEN_DSN'],
68-
'release': raven.fetch_git_sha(GIT_REPO_ROOT),
69-
}
62+
sentry_sdk.init(
63+
dsn=os.environ.get('RAVEN_DSN'),
64+
integrations=[DjangoIntegration()],
65+
release=fetch_git_sha(GIT_REPO_ROOT),
66+
send_default_pii=True,
67+
)
7068

7169
DATABASES = {
7270
'default': {
@@ -88,3 +86,4 @@
8886
from .local_settings import *
8987
except ImportError:
9088
pass
89+
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""
2+
Copyright (c) 2015 Functional Software, Inc and individual contributors.
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without modification,
6+
are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice,
9+
this list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
12+
following disclaimer in the documentation and/or other materials provided with the distribution.
13+
14+
3. Neither the name of the Raven nor the names of its contributors may be used to endorse or promote products
15+
derived from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
"""
25+
26+
import os.path
27+
28+
29+
def fetch_git_sha(path, head=None):
30+
if not head:
31+
head_path = os.path.join(path, '.git', 'HEAD')
32+
if not os.path.exists(head_path):
33+
raise Exception(
34+
'Cannot identify HEAD for git repository at %s' % (path,))
35+
36+
with open(head_path, 'r') as fp:
37+
head = str(fp.read()).strip()
38+
39+
if head.startswith('ref: '):
40+
head = head[5:]
41+
revision_file = os.path.join(
42+
path, '.git', *head.split('/')
43+
)
44+
else:
45+
return head
46+
else:
47+
revision_file = os.path.join(path, '.git', 'refs', 'heads', head)
48+
49+
if not os.path.exists(revision_file):
50+
if not os.path.exists(os.path.join(path, '.git')):
51+
raise Exception(
52+
'%s does not seem to be the root of a git repository' % (path,))
53+
54+
# Check for our .git/packed-refs' file since a `git gc` may have run
55+
# https://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery
56+
packed_file = os.path.join(path, '.git', 'packed-refs')
57+
if os.path.exists(packed_file):
58+
with open(packed_file) as fh:
59+
for line in fh:
60+
line = line.rstrip()
61+
if line and line[:1] not in ('#', '^'):
62+
try:
63+
revision, ref = line.split(' ', 1)
64+
except ValueError:
65+
continue
66+
if ref == head:
67+
return str(revision)
68+
69+
raise Exception(
70+
'Unable to find ref to head "%s" in repository' % (head,))
71+
72+
with open(revision_file) as fh:
73+
return str(fh.read()).strip()

0 commit comments

Comments
 (0)