Skip to content

Commit

Permalink
Merge pull request #271 from SpongePowered/feature/sentry-sdk
Browse files Browse the repository at this point in the history
Switched from raven to sentry sdk
  • Loading branch information
lukegb authored Jan 1, 2019
2 parents 225578d + 2600595 commit 59d5528
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ media/
.DS_Store
.pytest_cache
venv/
Pipfile*
2 changes: 1 addition & 1 deletion requirements/prod.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-r base.txt

raven==6.9.0
sentry-sdk==0.6.5
gunicorn==19.9.0
21 changes: 10 additions & 11 deletions spongeauth/spongeauth/settings/prod.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import os.path
import raven
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

from .utils import fetch_git_sha
from .base import *

GIT_REPO_ROOT = os.path.dirname(BASE_DIR)
Expand Down Expand Up @@ -50,10 +50,6 @@
},
]

INSTALLED_APPS += [
'raven.contrib.django.raven_compat',
]

SSO_ENDPOINTS = {}
for k, v in os.environ.items():
if not k.startswith('SSO_ENDPOINT_'):
Expand All @@ -63,10 +59,12 @@
d = SSO_ENDPOINTS.setdefault(name, {})
d[key.lower()] = v

RAVEN_CONFIG = {
'dsn': os.environ['RAVEN_DSN'],
'release': raven.fetch_git_sha(GIT_REPO_ROOT),
}
sentry_sdk.init(
dsn=os.environ.get('RAVEN_DSN'),
integrations=[DjangoIntegration()],
release=fetch_git_sha(GIT_REPO_ROOT),
send_default_pii=True,
)

DATABASES = {
'default': {
Expand All @@ -88,3 +86,4 @@
from .local_settings import *
except ImportError:
pass

73 changes: 73 additions & 0 deletions spongeauth/spongeauth/settings/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Copyright (c) 2015 Functional Software, Inc and individual contributors.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the Raven nor the names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

import os.path


def fetch_git_sha(path, head=None):
if not head:
head_path = os.path.join(path, '.git', 'HEAD')
if not os.path.exists(head_path):
raise Exception(
'Cannot identify HEAD for git repository at %s' % (path,))

with open(head_path, 'r') as fp:
head = str(fp.read()).strip()

if head.startswith('ref: '):
head = head[5:]
revision_file = os.path.join(
path, '.git', *head.split('/')
)
else:
return head
else:
revision_file = os.path.join(path, '.git', 'refs', 'heads', head)

if not os.path.exists(revision_file):
if not os.path.exists(os.path.join(path, '.git')):
raise Exception(
'%s does not seem to be the root of a git repository' % (path,))

# Check for our .git/packed-refs' file since a `git gc` may have run
# https://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery
packed_file = os.path.join(path, '.git', 'packed-refs')
if os.path.exists(packed_file):
with open(packed_file) as fh:
for line in fh:
line = line.rstrip()
if line and line[:1] not in ('#', '^'):
try:
revision, ref = line.split(' ', 1)
except ValueError:
continue
if ref == head:
return str(revision)

raise Exception(
'Unable to find ref to head "%s" in repository' % (head,))

with open(revision_file) as fh:
return str(fh.read()).strip()

0 comments on commit 59d5528

Please sign in to comment.