You only need to install this for Admins Only.
https://login.salesforce.com/packaging/installPackage.apexp?p0=04t1i000001SDJdAAO
<your org url>/packaging/installPackage.apexp?p0=04t1i000001SDJdAAO
Upload the code with SFDX. To be expanded upon later!
- Go to Custom Code > Custom Metadata
- Click "Manage Records" on "Sentry Config"
- Click "Edit" on "Default"
- Put in your Sentry DSN in the "DSN" field
- Save!
There is also a Custom Setting which you can use.
- Go to Custom Code > Custom Settings
- Click "Manage Records" on "Sentry Active Config"
- Click "New"
Environment Name
is the name of the environment that will show up in Sentry.Debug
turns on developer debugging for the Salesforce for Sentry internals.Is Issue Creation Disabled
turns off sending errors to Sentry.Sentry Config DeveloperName
takes the DeveloperName of aSentry Config
entry, and uses that configuration. This makes it easy to have sentry disabled by default in cloned sandboxes. Just make aSentry Config
for Production, and set theSentry Config DeveloperName
to that in your Production environment.
try {
doSomethingExceptional();
} catch (Exception e) {
Sentry.record(e);
throw e;
}
Behind the scenes, the exception is serialized, and published immediately to the EventBus, via the Sentry_Error__c
event.
After that, an Apex Trigger is listening for new Sentry_Error__e
after inserts, and hands them off to a @Future
which makes the API calls to Sentry.
This means you can record exceptions AND throw them, to prevent bad things from happening.
By default, Custom Exceptions in Apex do not get the privilege of having stack traces. See the known issue - no fix report for more details about that.
Don't give up hope, though! All is not lost!
If you use the Sentry_Exception
class included in this package, you will have stack traces exposed. It requires two steps to work correctly:
- Extend your custom exception from
Sentry_Exception
instead ofException
. - Create your exception instances using the
Sentry_ExceptionFactory
.
Here's an example from Sentry_TestingThrower.cls:
public with sharing class Sentry_TestingThrower {
class MyException extends Sentry_Exception {}
public void throwException() {
MyException ex = (MyException) Sentry_ExceptionFactory.build(MyException.class);
ex.setMessage('Something broke.');
throw ex;
}
}
There is an included Sentry_Log
class with methods for logging Error, Warn, Info, Debug, and Trace messages.
At some point this will get wired up to Sentry's breadcrumbs, to pass additional data through to your Sentry report.
Do you have everything configured and ready to go? Open up the Sentry Testing
tab and click on that Trigger an exception!
button.
You will see the sort of error you would expect with an uncaught exception being thrown.
Now check Sentry, and you should see an error present!
Help is definitely welcome! This does the basics, but it could be so much better!
Right now, it seriously needs some tests. Seriously.
The biggest tips I can give you for testing additional development work are:
- Turn on
Debug
in theActive Sentry Config
Custom Setting. It will make everything produce a lot more logs. - If you're working on something in the
Sentry_Error_Handler
, be sure to go to the Developer Console > Debug > Change Log Levels, and add the Automated Process user in theUser Tracing for All Users
section. The query to find the User Id you need isSELECT Id FROM User WHERE Name = 'Automated Process'
.