diff --git a/.envrc b/.envrc index 7b082b8082e662..2ef74831a5c684 100644 --- a/.envrc +++ b/.envrc @@ -39,7 +39,8 @@ report_to_sentry() { if ! require sentry-cli; then curl -sL https://sentry.io/get-cli/ | bash fi - sentry-cli send-event -m "$error_message" --logfile "$_SENTRY_LOG_FILE" + SENTRY_DSN=${SENTRY_DEVENV_DSN} \ + sentry-cli send-event -m "$error_message" --logfile "$_SENTRY_LOG_FILE" rm "$_SENTRY_LOG_FILE" } @@ -121,7 +122,7 @@ if [ "$SENTRY_DEVENV_NO_REPORT" ]; then info "No development environment errors will be reported (since you've defined SENTRY_DEVENV_NO_REPORT)." else info "Development errors will be reported to Sentry.io. If you wish to opt-out, set SENTRY_DEVENV_NO_REPORT as an env variable." - export SENTRY_DSN=https://23670f54c6254bfd9b7de106637808e9@o1.ingest.sentry.io/1492057 + export SENTRY_DEVENV_DSN=https://23670f54c6254bfd9b7de106637808e9@o1.ingest.sentry.io/1492057 fi ### System ### diff --git a/src/sentry/runner/__init__.py b/src/sentry/runner/__init__.py index 622c1f3f4dab89..bf6a68ab34f1ac 100644 --- a/src/sentry/runner/__init__.py +++ b/src/sentry/runner/__init__.py @@ -3,9 +3,20 @@ import sys import sentry import datetime +import sentry_sdk from sentry.utils.imports import import_string from sentry.utils.compat import map +# SENTRY_DEVENV_DSN gets set up automatically by direnv/.envrc +# This check prevents executing this code unintentionally (e.g. CI or production) +if os.environ.get("SENTRY_DEVENV_DSN") and not os.environ.get("SENTRY_DEVENV_NO_REPORT"): + # This reports to the project sentry-dev-env + sentry_sdk.init( + dsn=os.environ["SENTRY_DEVENV_DSN"], + ) + if os.environ.get("USER"): + sentry_sdk.set_user({"username": os.environ.get("USER")}) + # We need to run this here because of a concurrency bug in Python's locale # with the lazy initialization. datetime.datetime.strptime("", "") diff --git a/src/sentry/utils/sdk.py b/src/sentry/utils/sdk.py index 040ff7ee4fa7b2..7ed7035bf81aed 100644 --- a/src/sentry/utils/sdk.py +++ b/src/sentry/utils/sdk.py @@ -166,8 +166,6 @@ def configure_sdk(): from sentry_sdk.integrations.celery import CeleryIntegration from sentry_sdk.integrations.redis import RedisIntegration - assert sentry_sdk.Hub.main.client is None - sdk_options = dict(settings.SENTRY_SDK_CONFIG) relay_dsn = sdk_options.pop("relay_dsn", None)