Sending Events
The sentry-cli
tool can also be used for sending events. If you want to use it, you need to export the SENTRY_DSN
environment variable and point it to the DSN of a project of yours:
export SENTRY_DSN='https://examplePublicKey@o0.ingest.sentry.io/0'
Once that is done, you can start using the sentry-cli send-event
command.
For basic message events, you just need to provide the --message
or -m
parameter to send a message:
sentry-cli send-event -m "Hello from Sentry"
This will send a single message to Sentry and record it as an event. Along with that event, it sends basic information about the machine you are running sentry-cli
on. You can provide -m
multiple times to send multiple lines:
sentry-cli send-event -m "Hello from Sentry" -m "This is more text"
In addition you can use %s
as placeholder in a message and fill it in with the -a
parameter. This helps reviewing them, as all messages will be grouped together automatically:
sentry-cli send-event -m "Hello %s!" -a "Joe"
sentry-cli send-event -m "Hello %s!" -a "Peter"
You can also pass a logfile to the send-event
command which will be parsed and sent along as breadcrumbs. The last 100 items will be sent:
sentry-cli send-event -m “task failed” –-logfile error.log
The logfile can be in various formats. If you want to create one yourself you can do something along those lines:
echo "$(date +%c) This is a log record" >> output.log
echo "$(date +%c) This is another record" >> output.log
sentry-cli send-event -m "Demo Event" --logfile output.log
rm output.log
Extra data can be attached with the -e
parameter as KEY:VALUE
. For instance, you can send some key value pairs like this:
sentry-cli send-event -m "a failure" -e task:create-user -e object:42
Likewise, tags can be sent with -t
using the same format:
sentry-cli send-event -m "a failure" -t task:create-user
As of version 1.71
, the send-event
command can accept an optional argument that specifies a path to the stored JSON representation of an event. When used, it will load the file, validate the event and send it to Sentry.
sentry-cli send-event ./events/20211029150006.json
This argument can be also provided in the form of a glob, which will cause it to process all matched events.
sentry-cli send-event "./events/*.json"
If send-event
is called with the --raw
flag, the event will not be validated before being sent.
sentry-cli send-event --raw ./events/20211029150006.json
Releases can be sent with the --release
parameter. A default release is picked up automatically if you are using sentry-cli from within a git repository.
For bash scripts you can also enable automatic error sending by using the sentry-cli bash hook. That enables set -e
and will send a Sentry event for unhandled errors.
The limitations for this are:
- sentry-cli really only works if
set -e
is enabled (which it will by default enable for you). - sentry-cli registers an
EXIT
andERR
trap.
Usage:
#!/bin/bash
export SENTRY_DSN='https://examplePublicKey@o0.ingest.sentry.io/0'
eval "$(sentry-cli bash-hook)"
# rest of the script goes here
Alternatively you can use other mechanisms like a .sentryclirc
file to configure the DSN.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").