Skip to content

Commit f69761e

Browse files
committed
Switched from raven to sentry sdk
1 parent 225578d commit f69761e

4 files changed

Lines changed: 58 additions & 12 deletions

File tree

.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: 9 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 spongeauth.spongeauth.settings.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,11 @@
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['RAVEN_DSN'],
64+
integrations=[DjangoIntegration()],
65+
release=fetch_git_sha(GIT_REPO_ROOT)
66+
)
7067

7168
DATABASES = {
7269
'default': {
@@ -88,3 +85,4 @@
8885
from .local_settings import *
8986
except ImportError:
9087
pass
88+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os.path
2+
3+
def fetch_git_sha(path, head=None):
4+
if not head:
5+
head_path = os.path.join(path, '.git', 'HEAD')
6+
if not os.path.exists(head_path):
7+
raise Exception(
8+
'Cannot identify HEAD for git repository at %s' % (path,))
9+
10+
with open(head_path, 'r') as fp:
11+
head = str(fp.read()).strip()
12+
13+
if head.startswith('ref: '):
14+
head = head[5:]
15+
revision_file = os.path.join(
16+
path, '.git', *head.split('/')
17+
)
18+
else:
19+
return head
20+
else:
21+
revision_file = os.path.join(path, '.git', 'refs', 'heads', head)
22+
23+
if not os.path.exists(revision_file):
24+
if not os.path.exists(os.path.join(path, '.git')):
25+
raise Exception(
26+
'%s does not seem to be the root of a git repository' % (path,))
27+
28+
# Check for our .git/packed-refs' file since a `git gc` may have run
29+
# https://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery
30+
packed_file = os.path.join(path, '.git', 'packed-refs')
31+
if os.path.exists(packed_file):
32+
with open(packed_file) as fh:
33+
for line in fh:
34+
line = line.rstrip()
35+
if line and line[:1] not in ('#', '^'):
36+
try:
37+
revision, ref = line.split(' ', 1)
38+
except ValueError:
39+
continue
40+
if ref == head:
41+
return str(revision)
42+
43+
raise Exception(
44+
'Unable to find ref to head "%s" in repository' % (head,))
45+
46+
with open(revision_file) as fh:
47+
return str(fh.read()).strip()

0 commit comments

Comments
 (0)