Browse Source

dev_env(feat): Report direnv issues (#24182)

Report issues to Sentry.io when there are `direnv` issues.
Developers can opt-out by setting `SENTRY_DEVENV_NO_REPORT` which is shown in the output.
Armen Zambrano G 4 years ago
parent
commit
03676e43e2
1 changed files with 25 additions and 0 deletions
  1. 25 0
      .envrc

+ 25 - 0
.envrc

@@ -6,6 +6,10 @@
 
 set -e
 
+_SENTRY_LOG_FILE=$(mktemp -t sentry-direnv-envrc.out)
+exec > >(tee "$_SENTRY_LOG_FILE")
+exec 2>&1
+
 bold="$(tput bold)"
 red="$(tput setaf 1)"
 green="$(tput setaf 2)"
@@ -16,6 +20,8 @@ reset="$(tput sgr0)"
 #      consequently, using "exit" anywhere will skip this notice from showing.
 #      so need to use set -e, and return 1.
 trap notice ERR
+# If no message is given then we will use this as a default
+error_message="Error without message"
 
 notice() {
     [ $? -eq 0 ] && return
@@ -26,6 +32,15 @@ Follow them, and then you'll need to redo direnv by running "direnv allow".${res
 
 If you're stuck or have questions, ask in #discuss-dev-tooling.
 EOF
+    report_to_sentry
+}
+
+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"
+    rm "$_SENTRY_LOG_FILE"
 }
 
 require() {
@@ -49,6 +64,8 @@ die() {
 ${red}${bold}direnv FATAL: ${@}
 ${reset}
 EOF
+    # When reporting to Sentry, this will allow grouping the errors differently
+    error_message=( "${@}" )
     return 1
 }
 
@@ -99,6 +116,14 @@ 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
 
+## Notify of reporting to Sentry
+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
+fi
+
 ### System ###
 
 for pkg in \