Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry integration #1846

Merged
merged 8 commits into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def insert_settings(request):
'github_handle': request.user.username if user_is_authenticated else False,
'email': request.user.email if user_is_authenticated else False,
'name': request.user.get_full_name() if user_is_authenticated else False,
'rollbar_client_token': settings.ROLLBAR_CLIENT_TOKEN,
'sentry_address': settings.SENTRY_ADDRESS,
'env': settings.ENV,
'email_key': email_key,
'profile_id': profile.id if profile else '',
Expand Down
95 changes: 49 additions & 46 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.

"""
import os
import socket

from django.http import Http404
from django.utils.translation import gettext_noop

import environ
import rollbar
import raven
from easy_thumbnails.conf import Settings as easy_thumbnails_defaults

root = environ.Path(__file__) - 2 # Set the base directory to two levels.
Expand Down Expand Up @@ -70,6 +71,7 @@
'autotranslate',
'django_extensions',
'easy_thumbnails',
'raven.contrib.django.raven_compat',
'app',
'avatar',
'retail',
Expand Down Expand Up @@ -189,26 +191,46 @@
if ENV not in ['local', 'test']:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_is_false': {
'()': 'django.utils.log.RequireDebugFalse'
'disable_existing_loggers': True,
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s '
'%(process)d %(thread)d %(message)s'
},
},
'handlers': {
'rotatingfilehandler': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': '/var/log/django/debug.log',
'maxBytes': 1024 * 1024 * 10, # 10 MB
'backupCount': 100, # max 100 logs
'sentry': {
'level': 'ERROR', # To capture more than ERROR, change to WARNING, INFO, etc.
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
'tags': {
'custom-tag': 'x'
},
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'loggers': {
'django': {
'handlers': ['rotatingfilehandler', ],
'propagate': True,
'filters': ['require_debug_is_false'],
'django.db.backends': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
'raven': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
'sentry.errors': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
},
}
Expand Down Expand Up @@ -370,38 +392,19 @@
}
HOTJAR_CONFIG = {'hjid': env.int('HOTJAR_ID', default=0), 'hjsv': env.int('HOTJAR_SV', default=0), }

# Rollbar - https://rollbar.com/docs/notifier/pyrollbar/#django
ROLLBAR_CLIENT_TOKEN = env('ROLLBAR_CLIENT_TOKEN', default='') # post_client_item
ROLLBAR_SERVER_TOKEN = env('ROLLBAR_SERVER_TOKEN', default='') # post_server_item
if ROLLBAR_SERVER_TOKEN and ENV not in ['local', 'test']:
# Handle rollbar initialization.
ROLLBAR = {
'access_token': ROLLBAR_SERVER_TOKEN,
'environment': ENV,
'root': BASE_DIR,
'patch_debugview': False, # Disable debug view patching.
'branch': 'master',
'exception_level_filters': [(Http404, 'ignored')],
'capture_ip': 'anonymize',
'capture_username': True,
'scrub_fields': [
'pw', 'passwd', 'password', 'secret', 'confirm_password', 'confirmPassword', 'password_confirmation',
'passwordConfirmation', 'access_token', 'accessToken', 'auth', 'authentication', 'github_access_token',
'github_client_secret', 'secret_key', 'twitter_access_token', 'twitter_access_secret',
'twitter_consumer_secret', 'mixpanel_token', 'slack_verification_token', 'redirect_state', 'slack_token',
'priv_key',
],
# Sentry
SENTRY_USER = env('SENTRY_USER', default='')
SENTRY_PASSWORD = env('SENTRY_PASSWORD', default='')
SENTRY_ADDRESS = env('SENTRY_ADDRESS', default='')
SENTRY_PROJECT = env('SENTRY_PROJECT', default='')
SENTRY_RELEASE = raven.fetch_git_sha(os.path.abspath(os.pardir)) if SENTRY_USER else ''
if SENTRY_ADDRESS and SENTRY_PROJECT:
RAVEN_CONFIG = {
'dsn': f'https://{SENTRY_USER}:{SENTRY_PASSWORD}@{SENTRY_ADDRESS}/{SENTRY_PROJECT}',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcode {SENTRY_ADDRESS} -> sentry.io ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We aren't using the hosted solution. This gives whoever is running the app the choice of URI. We're self-hosting, since it's a fairly small footprint and we can retain data as long as necessary.

# If you are using git, you can also automatically configure the
# release based on the git info.
'release': SENTRY_RELEASE,
}
MIDDLEWARE.append('rollbar.contrib.django.middleware.RollbarNotifierMiddleware')
REST_FRAMEWORK['EXCEPTION_HANDLER'] = 'rollbar.contrib.django_rest_framework.post_exception_handler'
# LOGGING['handlers']['rollbar'] = {
# 'filters': ['require_debug_false'],
# 'access_token': ROLLBAR_SERVER_TOKEN,
# 'environment': ENV,
# 'class': 'rollbar.logger.RollbarHandler',
# }
# LOGGING['loggers']['django']['handlers'].append('rollbar')
rollbar.init(**ROLLBAR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥


# List of github usernames to not count as comments on an issue
IGNORE_COMMENTS_FROM = ['gitcoinbot', ]
Expand Down
50 changes: 0 additions & 50 deletions app/app/templates/shared/rollbar.html

This file was deleted.

22 changes: 22 additions & 0 deletions app/app/templates/shared/sentry.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% comment %}
Copyright (C) 2018 Gitcoin Core

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
{% endcomment %}
{% if sentry_address %}
{% load raven %}
<script>
Raven.config("{% sentry_public_dsn 'https' %}").install()
</script>
{% endif %}
3 changes: 1 addition & 2 deletions app/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import geoip2.database
import requests
import rollbar
from dashboard.models import Profile
from geoip2.errors import AddressNotFoundError
from git.utils import _AUTH, HEADERS, get_user
Expand Down Expand Up @@ -119,7 +118,7 @@ def sync_profile(handle, user=None, hide_profile=True):
is_error = 'name' not in data.keys()
if is_error:
print("- error main")
rollbar.report_message('Failed to fetch github username', 'warning', extra_data=data)
logger.warning('Failed to fetch github username', exc_info=True, extra={'handle': handle})
return None

defaults = {'last_sync_date': timezone.now(), 'data': data, 'hide_profile': hide_profile, }
Expand Down
3 changes: 1 addition & 2 deletions app/dashboard/management/commands/sync_geth.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from django.conf import settings
from django.core.management.base import BaseCommand

import rollbar
from dashboard.helpers import UnsupportedSchemaException
from dashboard.utils import BountyNotFoundException, get_bounty, web3_process_bounty

Expand Down Expand Up @@ -73,7 +72,7 @@ def handle(self, *args, **options):
'more_bounties': more_bounties,
'network': network
}
rollbar.report_exc_info(sys.exc_info(), extra_data=extra_data)
logger.error('Failed to fetch github username', exc_info=True, extra=extra_data)
logger.error(f"* Exception in sync_geth => {e}")
finally:
# prepare for next loop
Expand Down
7 changes: 4 additions & 3 deletions app/dashboard/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import logging
import random
import re
import sys
from urllib.parse import urlparse as parse

from django.conf import settings
from django.contrib.humanize.templatetags.humanize import naturaltime

import requests
import rollbar
import twitter
from economy.utils import convert_token_to_usdt
from git.utils import delete_issue_comment, org_name, patch_issue_comment, post_issue_comment, repo_name
Expand All @@ -36,6 +34,8 @@
from pyshorteners import Shortener
from slackclient import SlackClient

logger = logging.getLogger(__name__)


def github_org_to_twitter_tags(github_org):
"""Build a string of github organization twitter tags.
Expand Down Expand Up @@ -308,6 +308,7 @@ def maybe_market_to_user_discord(bounty, event_name):

return sent


def maybe_market_tip_to_email(tip, emails):
"""Send an email for the specified Tip.

Expand Down Expand Up @@ -580,7 +581,7 @@ def maybe_market_to_github(bounty, event_name, profile_pairs=None):
return False
except Exception as e:
extra_data = {'github_url': url, 'bounty_id': bounty.pk, 'event_name': event_name}
rollbar.report_exc_info(sys.exc_info(), extra_data=extra_data)
logger.error('Failure in marketing to github', exc_info=True, extra=extra_data)
print(e)
return False
return True
Expand Down
Loading