From 99056fdf10a98fd4eb678de9cec57142dcfd669f Mon Sep 17 00:00:00 2001 From: Andrew Carter Date: Thu, 21 Dec 2023 12:32:27 -0600 Subject: [PATCH 1/2] chore: Make Sentry config optional Since the application crashes with an invalid/incomplete Sentry DSN, and it seems somewhat unnecessary for local dev, I made it optional. Should this perhaps also detect if it's in production and still crash in case of misconfigurations? --- .env.sample | 3 ++- terraso_backend/config/settings.py | 26 +++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.env.sample b/.env.sample index 84217e804..c377a7d66 100644 --- a/.env.sample +++ b/.env.sample @@ -53,4 +53,5 @@ GOOGLE_IOS_CLIENT_ID=google-mobile-client-id MAPBOX_USERNAME=mapbox-username MAPBOX_ACCESS_TOKEN=your-mapbox-token -SENTRY_DSN=https://xyz.ingest.sentry.io/abcd +# Uncomment and populate with a DSN to enable sentry. +# SENTRY_DSN=https://xyz.ingest.sentry.io/abcd diff --git a/terraso_backend/config/settings.py b/terraso_backend/config/settings.py index e214baa13..cd29b9f62 100644 --- a/terraso_backend/config/settings.py +++ b/terraso_backend/config/settings.py @@ -418,14 +418,18 @@ class JWTProvider(TypedDict): MAPBOX_USERNAME = config("MAPBOX_USERNAME", default="") MAPBOX_ACCESS_TOKEN = config("MAPBOX_ACCESS_TOKEN", default="") -sentry_sdk.init( - dsn=config("SENTRY_DSN", default=""), - environment=config("ENV", default="development"), - # Set traces_sample_rate to 1.0 to capture 100% - # of transactions for performance monitoring. - traces_sample_rate=1.0, - # Set profiles_sample_rate to 1.0 to profile 100% - # of sampled transactions. - # We recommend adjusting this value in production. - profiles_sample_rate=1.0, -) +if config("SENTRY_DSN", default=""): + sentry_sdk.init( + dsn=config("SENTRY_DSN", default=""), + environment=config("ENV", default="development"), + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for performance monitoring. + traces_sample_rate=1.0, + # Set profiles_sample_rate to 1.0 to profile 100% + # of sampled transactions. + # We recommend adjusting this value in production. + profiles_sample_rate=1.0, + ) +else: + # structlog is already set up at this point, so we can log nicely. + structlog.get_logger().warning("SENTRY_DSN is not defined, continuing without Sentry.") From 3360d23aac5b9287e6768583558112a6c6cd6a57 Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Thu, 21 Dec 2023 14:58:06 -0500 Subject: [PATCH 2/2] Update .env.sample --- .env.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index c377a7d66..994277d63 100644 --- a/.env.sample +++ b/.env.sample @@ -53,5 +53,5 @@ GOOGLE_IOS_CLIENT_ID=google-mobile-client-id MAPBOX_USERNAME=mapbox-username MAPBOX_ACCESS_TOKEN=your-mapbox-token -# Uncomment and populate with a DSN to enable sentry. +# Uncomment and populate with a DSN to enable Sentry. # SENTRY_DSN=https://xyz.ingest.sentry.io/abcd