Overview
Automatically send errors and source maps to your Sentry project from your Trigger.dev tasks. Sending source maps to Sentry allows for more detailed stack traces when errors occur, as Sentry can map the minified code back to the original source code.Prerequisites
- A Sentry account and project
- A Trigger.dev account and project
Setup
This setup involves two files:trigger.config.ts- Configures the build to upload source maps to Sentry during deploymenttrigger/init.ts- Initializes Sentry and registers the error tracking hook at runtime
You will need to set the
SENTRY_AUTH_TOKEN and SENTRY_DSN environment variables. You can find
the SENTRY_AUTH_TOKEN in your Sentry dashboard, in settings -> developer settings -> auth tokens
and the SENTRY_DSN in your Sentry dashboard, in settings -> projects -> your project -> client
keys (DSN). Add these to your .env file, and in your Trigger.dev
dashboard, under environment variables in your project’s sidebar.Build configuration
Add this build configuration to yourtrigger.config.ts file. This uses the Sentry esbuild plugin to upload source maps every time you deploy your project.
trigger.config.ts
Build extensions allow you to hook into the build system and
customize the build process or the resulting bundle and container image (in the case of
deploying). You can use pre-built extensions or create your own.
Runtime initialization
Create atrigger/init.ts file to initialize Sentry and register the global onFailure hook. This file is automatically loaded when your tasks execute.
trigger/init.ts
Learn more about global lifecycle hooks and the
init.ts file.Testing that errors are being sent to Sentry
To test that errors are being sent to Sentry, you need to create a task that will fail. This task takes no payload, and will throw an error.trigger/sentry-error-test.ts
test page in the sidebar of your Trigger.dev dashboard, click on your prod environment, and select the sentryErrorTest task.
Run a test task with an empty payload by clicking the Run test button.
Your run should then fail, and if everything is set up correctly, you will see an error in the Sentry project dashboard shortly after.
