Skip to content

fix(dev): Do not export SENTRY_DSN in .envrc #35440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ report_to_sentry() {
curl -sL https://sentry.io/get-cli/ | bash
fi
# Report to sentry-dev-env project
sentry-cli send-event -m "$error_message" --logfile "$_SENTRY_LOG_FILE" --level $log_level
SENTRY_DSN="https://[email protected]/5723503" \
sentry-cli send-event -m "$error_message" --logfile "$_SENTRY_LOG_FILE" --level $log_level
rm "$_SENTRY_LOG_FILE"
}

Expand Down Expand Up @@ -142,8 +143,6 @@ fi
if [ -n "${SENTRY_DEVENV_NO_REPORT+x}" ]; then
debug "No development environment errors will be reported (since you've defined SENTRY_DEVENV_NO_REPORT)."
else
# This is necessary for the bash-hook in lib.sh to work
export SENTRY_DSN="https://[email protected]/5723503"
Copy link
Member Author

Choose a reason for hiding this comment

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

When exporting via direnv, any Sentry error reporting in the code will pick up the reserved variable.

# Since direnv traps the EXIT signal we place the temp file under /tmp for the odd time
# the script will use the EXIT path
_SENTRY_LOG_FILE=$(mktemp /tmp/sentry.envrc.$$.out || mktemp /tmp/sentry.envrc.XXXXXXXX.out)
Expand Down
9 changes: 2 additions & 7 deletions config/hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ if sys.version_info.major < 3:
try:
import sentry_sdk

if os.environ.get("SENTRY_DSN"):
sentry_sdk.init(dsn=os.environ["SENTRY_DSN"])
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 guess this block was redundant since init would have loaded automatically from the reserved variable.

else:
sys.stdout.write(
"WARNING: Errors in this file will not be reported to Sentry since SENTRY_DSN is not set.\n"
"Use this command to report the issue: make direnv-help\n\n"
)
if not os.environ.get("SENTRY_DEVENV_NO_REPORT"):
sentry_sdk.init(dsn="https://[email protected]/5723503")
except ModuleNotFoundError:
sys.stdout.write(
"WARNING: Sentry SDK not installed, thus, errors will not be reported. Run: make install-py-dev\n"
Expand Down
5 changes: 4 additions & 1 deletion scripts/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ configure-sentry-cli() {
# We can remove this after it's fixed
# https://github.com/getsentry/sentry-cli/pull/1059
export SENTRY_CLI_NO_EXIT_TRAP=${SENTRY_CLI_NO_EXIT_TRAP-0}
if [ -n "${SENTRY_DSN+x}" ] && [ -z "${SENTRY_DEVENV_NO_REPORT+x}" ]; then
if [ -z "${SENTRY_DEVENV_NO_REPORT+x}" ]; 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.

Since we now don't export the variable.

if ! require sentry-cli; then
curl -sL https://sentry.io/get-cli/ | SENTRY_CLI_VERSION=2.0.4 bash
fi
# This exported variable does not persist outside of the calling script, thus, not affecting other
# parts of the system
export SENTRY_DSN="https://[email protected]/5723503"
Copy link
Member Author

Choose a reason for hiding this comment

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

Once the script that calls configure-sentry-cli ends, the variable is lost and the potential impact contained.

eval "$(sentry-cli bash-hook)"
fi
}
Expand Down