From 3a4dbc7c317f71dadaa6d546205c986dd75adaa9 Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Sun, 3 Nov 2019 21:07:14 -0500 Subject: [PATCH] Add sentry with integrations --- config.py | 7 +++++++ proxstar/__init__.py | 11 ++++++++++- requirements.txt | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 7bead6d..58b679a 100644 --- a/config.py +++ b/config.py @@ -60,3 +60,10 @@ WEBSOCKIFY_PATH = environ.get('PROXSTAR_WEBSOCKIFY_PATH', '/opt/app-root/bin/websockify') WEBSOCKIFY_TARGET_FILE = environ.get('PROXSTAR_WEBSOCKIFY_TARGET_FILE', '/opt/app-root/src/targets') + +# SENTRY +# Do not set the DSN for local development +SENTRY_DSN = environ.get("CONDITIONAL_SENTRY_DSN", "") +SENTRY_CONFIG = { + 'dsn': environ.get("CONDITIONAL_SENTRY_DSN", "") +} \ No newline at end of file diff --git a/proxstar/__init__.py b/proxstar/__init__.py index a08da08..4ea245f 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -13,6 +13,10 @@ from rq_scheduler import Scheduler from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from flask import Flask, render_template, request, redirect, session, abort, url_for +from raven.contrib.flask import Sentry +import sentry_sdk +from sentry_sdk.integrations.flask import FlaskIntegration +from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration from proxstar.db import (Base, datetime, get_pool_cache, renew_vm_expire, set_user_usage_limits, get_template, get_templates, get_allowed_users, add_ignored_pool, delete_ignored_pool, add_allowed_user, delete_allowed_user, @@ -39,7 +43,12 @@ else: app.config.from_pyfile(config) app.config['GIT_REVISION'] = subprocess.check_output( ['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').rstrip() - +# Sentry setup +sentry = Sentry(app) +sentry_sdk.init( + dsn=app.config['SENTRY_DSN'], + integrations=[FlaskIntegration(), SqlalchemyIntegration()] +) with open('proxmox_ssh_key', 'w') as ssh_key_file: ssh_key_file.write(app.config['PROXMOX_SSH_KEY']) diff --git a/requirements.txt b/requirements.txt index 677962f..6bf3af7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,4 @@ tenacity==5.0.2 websockify==0.8.0 pylint==2.3.1 pylint-quotes==0.2.1 +sentry-sdk~=0.13.1