Skip to content
Merged
17 changes: 10 additions & 7 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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" --level $log_level
SENTRY_DSN=${SENTRY_DEVENV_DSN} \
sentry-cli send-event -m "$error_message" --logfile "$_SENTRY_LOG_FILE" --level $log_level
rm "$_SENTRY_LOG_FILE"
}

Expand Down Expand Up @@ -125,12 +126,19 @@ export NODE_OPTIONS=--max-old-space-size=4096
# Enable this by default for development envs (CI/deploys do not use envrc)
export SENTRY_UI_HOT_RELOAD=1

### You can override the exported variables with a .env file
# All exports should happen before here unless they're safeguarded (see devenv error reporting below)
if [ -f '.env' ]; then
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this up here works better when I want to load "SENTRY_DEVENV_NO_REPORT" through the .env file.

info ".env found. Reading it..."
dotenv .env
fi

## Notify of reporting to Sentry
if [ -n "${SENTRY_DEVENV_NO_REPORT+x}" ]; 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."$'\n'" If you wish to opt-out, set SENTRY_DEVENV_NO_REPORT as an env variable."
export SENTRY_DSN=https://[email protected]/1492057
export SENTRY_DEVENV_DSN=https://[email protected]/1492057
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm renaming this variable since SENTRY_DSN since that is the default variable and I would not want it to conflict with what some engineer would have defined by hand or in their own start-up scripts.

fi

### System ###
Expand Down Expand Up @@ -217,11 +225,6 @@ PATH_add node_modules/.bin

### Overrides ###

if [ -f '.env' ]; then
info ".env found. Reading it..."
dotenv .env
fi

cat <<EOF
${green}${bold}direnv: SUCCESS!
${reset}
Expand Down
31 changes: 30 additions & 1 deletion src/sentry/runner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import logging
import os
import click
import sys
import sentry
import datetime
import sentry_sdk
from sentry.utils.imports import import_string
from sentry.utils.compat import map

Expand Down Expand Up @@ -161,4 +163,31 @@ def call_command(name, obj=None, **kwargs):


def main():
cli(prog_name=get_prog(), obj={}, max_content_width=100)
func = cli
kwargs = {
"prog_name": get_prog(),
"obj": {},
"max_content_width": 100,
}
# This variable is *only* set as part of direnv/.envrc, thus, we cannot affect production
if os.environ.get("SENTRY_DEVENV_DSN"):
# We do this here because `configure_structlog` executes later
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.INFO)
logger = logging.getLogger(__name__)

logger.info(
"The Sentry runner will report development issues to Sentry.io. "
"Use SENTRY_DEVENV_NO_REPORT to avoid reporting issues."
)
try:
func(**kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cli(**kwargs) is probably sufficient

except Exception as e:
# This reports to the project sentry-dev-env
with sentry_sdk.init(dsn=os.environ["SENTRY_DEVENV_DSN"]):
if os.environ.get("USER"):
sentry_sdk.set_user({"username": os.environ.get("USER")})
sentry_sdk.capture_exception(e)
logger.info("We have reported the error below to Sentry")
raise e
else:
func(**kwargs)