Skip to content

Commit fba6dd5

Browse files
committed
Add Sentry SDK config
Adds imports for - `os` for access to the system environment - `sentry_sdk` for Sentry goodness Adds a default Sentry config that is useful and verbose for development - This will only be enabled if a Sentry DSN is supplied, otherwise it is ignored - These defaults can/will be turned down a bit for production via our config repo
1 parent b334f3a commit fba6dd5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/server/main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import os
12
import pathlib
23
import logging
4+
import sentry_sdk
35
from typing import Dict, Callable
46

57
from flask import request, send_file, Response, send_from_directory, jsonify
@@ -13,6 +15,18 @@
1315
from .endpoints.admin import bp as admin_bp, enable_admin
1416
from ._limiter import limiter, apply_limit
1517

18+
SENTRY_DSN = os.environ.get('SENTRY_DSN')
19+
if SENTRY_DSN:
20+
sentry_sdk.init(
21+
dsn=SENTRY_DSN,
22+
traces_sample_rate=float(os.environ.get('SENTRY_TRACES_SAMPLE_RATE', 1.0)),
23+
profiles_sample_rate=float(os.environ.get('SENTRY_PROFILES_SAMPLE_RATE', 1.0)),
24+
environment=str(os.environ.get('SENTRY_ENVIRONMENT', 'development')),
25+
debug=str(os.environ.get('SENTRY_DEBUG', 'True')),
26+
attach_stacktrace=str(os.environ.get('SENTRY_ATTACH_STACKTRACE', 'True'))
27+
)
28+
29+
1630
__all__ = ["app"]
1731

1832
logger = get_structured_logger("webapp_main")

0 commit comments

Comments
 (0)