From 12d5c022039efa6d98e99b15896102ede25a385f Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Thu, 3 Apr 2025 18:46:49 +0200 Subject: [PATCH] Sentry support --- README.md | 28 ++++++++++++++++++++++++++++ pyproject.toml | 3 ++- src/anonchat/__init__.py | 7 +++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 23fb0eb..86e0d60 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ An anonymous chat application built with Flask. - Admin dashboard to manage inquiries - Customizable site title - Redis-based session storage for improved scalability +- Integrated error tracking with Sentry ## Development Approach @@ -34,6 +35,7 @@ AnonChat can be configured using environment variables: - `RATELIMIT_STORAGE_URL`: Storage backend for rate limiting (defaults to memory storage) - `REDIS_URL`: Redis connection URL for session storage (defaults to "redis://localhost:6379/0") - `AUTO_DELETE_HOURS`: Number of hours after which closed inquiries are automatically deleted (defaults to 48) +- `SENTRY_DSN`: Sentry Data Source Name for error tracking and monitoring (optional) You can set these variables in a `.env` file: @@ -45,6 +47,7 @@ SITE_TITLE=My Custom Chat BEHIND_PROXY=true REDIS_URL=redis://redis:6379/0 AUTO_DELETE_HOURS=72 +SENTRY_DSN=https://your-sentry-dsn ``` ## Reverse Proxy Configuration @@ -70,6 +73,31 @@ server { } ``` +## Error Tracking with Sentry + +AnonChat includes integration with Sentry for error tracking and performance monitoring. This helps identify and diagnose issues in production environments. + +### Features + +- Automatic error capturing and reporting +- Performance monitoring +- Contextual information for better debugging +- Real-time alerts for critical issues + +### Configuration + +To enable Sentry integration: + +1. Sign up for a free Sentry account at [sentry.io](https://sentry.io) +2. Create a new project and get your DSN (Data Source Name) +3. Set the `SENTRY_DSN` environment variable in your `.env` file or deployment environment: + +``` +SENTRY_DSN=https://your-sentry-project-key@sentry.io/your-project-id +``` + +When the `SENTRY_DSN` variable is set, error tracking will be automatically enabled when the application starts. + ## Installation 1. Clone the repository diff --git a/pyproject.toml b/pyproject.toml index 0efe0d0..29126d9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,8 @@ dependencies = [ "redis (>=5.0.0,<6.0.0)", "flask-session (>=0.5.0,<1.0.0)", "argon2-cffi (>=23.0.0,<24.0.0)", - "flask-apscheduler (>=1.13.1,<2.0.0)" + "flask-apscheduler (>=1.13.1,<2.0.0)", + "sentry-sdk (>=2.25.1,<3.0.0)" ] [tool.poetry] diff --git a/src/anonchat/__init__.py b/src/anonchat/__init__.py index eced8f7..90d77a7 100644 --- a/src/anonchat/__init__.py +++ b/src/anonchat/__init__.py @@ -56,6 +56,13 @@ app.config['SCHEDULER_TIMEZONE'] = 'UTC' if app.config['BEHIND_PROXY']: app.wsgi_app = ProxyFix(app.wsgi_app, x_for=2) +if os.environ.get('SENTRY_DSN'): + import sentry_sdk + + sentry_sdk.init( + dsn=os.environ.get('SENTRY_DSN') + ) + # Initialize password hasher # Parameters source: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#argon2id password_hasher = PasswordHasher(