Skip to content

Commit

Permalink
feat: improve Sentry logging (fix #1389)
Browse files Browse the repository at this point in the history
  • Loading branch information
bolinocroustibat authored Jul 30, 2024
2 parents a749969 + 8a7c66d commit 9065619
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:

- repo: https://github.com/jazzband/pip-tools
rev: 6.2.0
rev: 7.4.1
hooks:
- id: pip-compile
name: pip-compile install.in
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Current (in progress)

- Nothing yet
- Adds latest `sentry-sdk[flask]` as an install dependency, and update Sentry logic to be able to send environment, app version and profiling/performance info [#3086](https://github.com/opendatateam/udata/pull/3086)

## 9.1.2 (2024-07-29)

Expand Down
1 change: 1 addition & 0 deletions requirements/install.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pytz==2024.1
redis==4.5.2
rdflib==6.0.0
requests==2.24.0
sentry-sdk[flask]==2.9.0
speaklater==1.3
StringDist==1.0.9
tlds
Expand Down
6 changes: 4 additions & 2 deletions requirements/install.pip
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,16 @@ referencing==0.35.1
# jsonschema-specifications
regex==2024.5.15
# via awesome-slugify
requests==2.24.0
requests==2.32.3
# via -r requirements/install.in
rpds-py==0.19.0
# via
# jsonschema
# referencing
s3transfer==0.6.2
# via boto3
sentry-sdk==2.9.0
# via -r requirements/install.in
six==1.16.0
# via
# bcrypt
Expand All @@ -279,7 +281,7 @@ uritools==4.0.3
# via urlextract
urlextract==0.14.0
# via -r requirements/install.in
urllib3==1.25.11
urllib3==1.26.19
# via
# botocore
# requests
Expand Down
2 changes: 1 addition & 1 deletion udata/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


@hook.app_template_global()
def package_version(name):
def package_version(name: str) -> str:
return pkg_resources.get_distribution(name).version


Expand Down
13 changes: 11 additions & 2 deletions udata/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from udata import entrypoints
from udata.core.storages.api import UploadProgress

from .app import UDataApp
from .auth import PermissionDenied
from .frontend import package_version

log = logging.getLogger(__name__)

Expand All @@ -24,7 +26,7 @@
IGNORED_EXCEPTIONS = HTTPException, PermissionDenied, UploadProgress


def public_dsn(dsn):
def public_dsn(dsn: str) -> str | None:
"""Check if DSN is public or raise a warning and turn it into a public one"""
m = RE_DSN.match(dsn)
if not m:
Expand All @@ -41,7 +43,7 @@ def public_dsn(dsn):
return public


def init_app(app):
def init_app(app: UDataApp):
if app.config["SENTRY_DSN"]:
try:
import sentry_sdk
Expand All @@ -62,6 +64,13 @@ def init_app(app):
dsn=app.config["SENTRY_PUBLIC_DSN"],
integrations=[FlaskIntegration(), CeleryIntegration()],
ignore_errors=list(exceptions),
release=f"udata@{package_version('udata')}",
environment=app.config.get("SITE_ID", None),
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# Sentry recommends adjusting this value in production.
traces_sample_rate=app.config.get("SENTRY_SAMPLE_RATE", None),
profiles_sample_rate=app.config.get("SENTRY_SAMPLE_RATE", None),
)

# Set log level
Expand Down
1 change: 1 addition & 0 deletions udata/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class Defaults(object):
SENTRY_USER_ATTRS = ["slug", "email", "fullname"]
SENTRY_LOGGING = "WARNING"
SENTRY_IGNORE_EXCEPTIONS = []
SENTRY_SAMPLE_RATE: float = 1.0

# Flask WTF settings
CSRF_SESSION_KEY = "Default uData csrf key"
Expand Down

0 comments on commit 9065619

Please sign in to comment.