Skip to content
Snippets Groups Projects
Commit 8ad85e56 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Replace raven with sentry-sdk

JIRA INFRA-979 #action In Progress
parent 3cf58d3e
No related branches found
No related tags found
No related merge requests found
......@@ -13,10 +13,9 @@ import ldap3
import redis
import rq
import sqlalchemy as sa
import sentry_sdk
from flask import current_app
from rq.contrib.sentry import register_sentry
from raven import Client
from raven.transport.http import HTTPTransport
from sentry_sdk.integrations.rq import RqIntegration
from .extensions import db, ldap_manager
from .defaults import defaults
from .tasks import TaskWorker
......@@ -108,13 +107,11 @@ def register_cli(app):
with rq.Connection(redis_connection):
worker = TaskWorker(["high", "normal", "low"])
if current_app.config["SENTRY_DSN"]:
client = Client(
sentry_sdk.init(
current_app.config["SENTRY_DSN"],
transport=HTTPTransport,
environment=current_app.config["CSENTRY_ENVIRONMENT"],
release=current_app.config["CSENTRY_RELEASE"],
integrations=[RqIntegration()],
)
register_sentry(client, worker)
worker.work()
@app.cli.command()
......
......@@ -21,7 +21,6 @@ from flask_debugtoolbar import DebugToolbarExtension
from flask_redis import FlaskRedis
from flask_session import Session
from flask_caching import Cache
from raven.contrib.flask import Sentry
convention = {
......@@ -44,4 +43,3 @@ toolbar = DebugToolbarExtension()
session_redis_store = FlaskRedis(config_prefix="SESSION_REDIS")
fsession = Session()
cache = Cache()
sentry = Sentry()
......@@ -12,9 +12,11 @@ Create the WSGI application.
import logging
import sqlalchemy as sa
import rq_dashboard
import sentry_sdk
from flask import Flask
from whitenoise import WhiteNoise
from elasticsearch import Elasticsearch
from sentry_sdk.integrations.flask import FlaskIntegration
from . import settings, models
from .extensions import (
db,
......@@ -28,7 +30,6 @@ from .extensions import (
session_redis_store,
fsession,
cache,
sentry,
)
from .admin.views import (
AdminModelView,
......@@ -62,11 +63,11 @@ def create_app(config=None):
app.jinja_env.filters["toyaml"] = utils.pretty_yaml
if app.config["SENTRY_DSN"]:
# CSENTRY_ENVIRONMENT can be overwritten in the local settings
# We can't define SENTRY_ENVIRONMENT before loading them
app.config["SENTRY_ENVIRONMENT"] = app.config["CSENTRY_ENVIRONMENT"]
sentry.init_app(
app, dsn=app.config["SENTRY_DSN"], logging=True, level=logging.ERROR
sentry_sdk.init(
dsn=app.config["SENTRY_DSN"],
environment=app.config["CSENTRY_ENVIRONMENT"],
send_default_pii=True,
integrations=[FlaskIntegration()],
)
if not app.debug:
......
......@@ -16,7 +16,7 @@ import rq_dashboard
from flask import Blueprint, render_template, jsonify, g, current_app, abort, request
from flask_login import login_required, current_user
from rq import push_connection, pop_connection
from ..extensions import sentry
from sentry_sdk import last_event_id
from .. import utils
bp = Blueprint("main", __name__)
......@@ -50,13 +50,7 @@ def not_found_error(error):
@bp.app_errorhandler(500)
def internal_error(error):
if current_app.config["SENTRY_DSN"]:
event_id = g.sentry_event_id
public_dsn = sentry.client.get_public_dsn("https")
else:
event_id = ""
public_dsn = ""
return render_template("500.html", event_id=event_id, public_dsn=public_dsn), 500
return (render_template("500.html", sentry_event_id=last_event_id()), 500)
@bp.app_errorhandler(utils.CSEntryError)
......
......@@ -11,7 +11,6 @@ This module implements the app default settings.
"""
import base64
import os
import raven
from pathlib import Path
from datetime import timedelta
......@@ -141,11 +140,8 @@ include: 'https://gitlab.esss.lu.se/ics-infrastructure/gitlab-ci-yml/raw/master/
"""
# Sentry integration
CSENTRY_RELEASE = raven.fetch_git_sha(Path(__file__).parents[1])
# Leave to empty string to disable sentry integration
SENTRY_DSN = os.environ.get("SENTRY_DSN", "")
SENTRY_USER_ATTRS = ["username"]
SENTRY_CONFIG = {"release": CSENTRY_RELEASE}
# Static local files
CSENTRY_STATIC_DIR = Path(__file__).parent / "static"
......
This diff is collapsed.
This diff is collapsed.
......@@ -7,13 +7,11 @@
{%- endblock %}
{% block csentry_scripts %}
<script src="{{ url_for('static', filename='js/raven.min.js') }}"></script>
{% if event_id %}
<script src="{{ url_for('static', filename='js/sentry-bundle.min.js') }}"></script>
{% if config["SENTRY_DSN"] %}
<script>
Raven.showReportDialog({
eventId: '{{ event_id }}',
dsn: '{{ public_dsn }}'
});
Sentry.init({ dsn: '{{ config["SENTRY_DSN"] }}' });
Sentry.showReportDialog({ eventId: '{{ sentry_event_id }}' });
</script>
{% endif %}
{% endblock %}
......@@ -20,9 +20,9 @@ pyyaml
qrcode
whitenoise
ansible-tower-cli
raven
rq
rq-dashboard
sentry-sdk
sqlalchemy-citext
sqlalchemy-continuum
openpyxl
......@@ -37,11 +37,11 @@ python-dateutil==2.7.5
python-editor==1.0.3
PyYAML==3.13
qrcode==6.0
raven==6.9.0
redis==2.10.6
requests==2.20.1
rq==0.12.0
rq-dashboard==0.3.12
sentry-sdk==0.7.10
six==1.11.0
SQLAlchemy==1.2.14
sqlalchemy-citext==1.3.post0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment