Last active
May 4, 2024 11:25
-
-
Save barroco/1a0009500ebd963b6522 to your computer and use it in GitHub Desktop.
Send Sentry error from shell using curl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
SENTRY_KEY= | |
SENTRY_SECRET= | |
SENTRY_PROJECTID=1 | |
SENTRY_HOST=sentry.example.com | |
SCRIPT_ARGUMENTS=$@ | |
capture_error() | |
{ | |
MESSAGE=$1 | |
EVENT_ID=`openssl rand -hex 32` | |
EVENT_TIMESTAMP=`date +"%Y-%m-%dT%H:%M:%S"` | |
SENTRY_TIMESTAMP=`date +%s` | |
curl --data "{ | |
\"event_id\": \"$EVENT_ID\", | |
\"culprit\": \"$0\", | |
\"timestamp\": \"$EVENT_TIMESTAMP\", | |
\"message\": \"$MESSAGE\", | |
\"tags\": { | |
\"shell\": \"$SHELL\", | |
\"server_name\": \"`hostname`\", | |
\"path\": \"`pwd`\" | |
}, | |
\"exception\": [{ | |
\"type\": \"ScriptError\", | |
\"value\": \"$MESSAGE\", | |
\"module\": \"__builtins__\" | |
}], | |
\"extra\": { | |
\"sys.argv\": \"$SCRIPT_ARGUMENTS\" | |
} | |
}" -H "Content-Type: application/json" -H "X-Sentry-Auth: Sentry sentry_version=5, sentry_timestamp=$SENTRY_TIMESTAMP, | |
sentry_key=$SENTRY_KEY, sentry_client=raven-bash/0.1, | |
sentry_secret=$SENTRY_SECRET" http://$SENTRY_KEY:$SENTRY_SECRET@$SENTRY_HOST/api/$SENTRY_PROJECTID/store/ | |
} | |
# Example: | |
capture_error "Unable to execute the command" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a pure JS NodeJS example I build using this gist: https://gist.github.com/williamdes/1d0b02c1bf3b94ee0dbaecdbc26d12c1