From 28caad38adbaff0b0d9b7887620dc6b10501cc4e Mon Sep 17 00:00:00 2001
From: D-K-P <8297864+D-K-P@users.noreply.github.com>
Date: Mon, 28 Oct 2024 15:10:50 +0000
Subject: [PATCH 1/4] Added sentry docs
---
.../guides/examples/sentry-error-tracking.mdx | 132 ++++++++++++++++++
docs/guides/introduction.mdx | 1 +
docs/mint.json | 1 +
3 files changed, 134 insertions(+)
create mode 100644 docs/guides/examples/sentry-error-tracking.mdx
diff --git a/docs/guides/examples/sentry-error-tracking.mdx b/docs/guides/examples/sentry-error-tracking.mdx
new file mode 100644
index 0000000000..d4efc7a5e5
--- /dev/null
+++ b/docs/guides/examples/sentry-error-tracking.mdx
@@ -0,0 +1,132 @@
+---
+title: "Track errors with Sentry"
+sidebarTitle: "Sentry error tracking"
+description: "This example demonstrates how to track errors with Sentry using Trigger.dev."
+---
+
+## Overview
+
+Automatically send errors to your Sentry project from your Trigger.dev tasks.
+
+## Prerequisites
+
+- A [Sentry](https://sentry.io) account and project
+- A [Trigger.dev](https://trigger.dev) account and project
+
+## Build configuration
+
+To send errors to Sentry when there are errors in your tasks, you'll need to add this build configuration to your `trigger.config.ts` file. This will then run every time you deploy your project.
+
+
+ Make sure you use the correct sentry package for your runtime. For example, if you are using
+ Node.js, you should use the `@sentry/node` package. For a full list of supported packages, see the
+ [Sentry docs](https://docs.sentry.io/platforms/).
+
+
+
+ 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](https://cloud.trigger.dev), under environment variables in your project's sidebar.
+
+
+```ts trigger.config.ts
+import { defineConfig } from "@trigger.dev/sdk/v3";
+import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
+// Import the correct Sentry package for your runtime, e.g. @sentry/node for Node.js or @Sentry/nextjs for Next.js
+import * as Sentry from "@sentry/node";
+
+export default defineConfig({
+ project: "",
+ // Your other config settings...
+ build: {
+ extensions: [
+ additionalPackages({
+ // Add the correct Sentry package for your runtime, e.g. @sentry/node for Node.js or @Sentry/nextjs for Next.js
+ packages: ["@sentry/node"],
+ }),
+ esbuildPlugin(
+ sentryEsbuildPlugin({
+ org: "",
+ project: "",
+ // Find this auth token in settings -> developer settings -> auth tokens
+ authToken: process.env.SENTRY_AUTH_TOKEN,
+ }),
+ // Optional - only runs during the deploy command, and adds the plugin to the end of the list of plugins
+ { placement: "last", target: "deploy" }
+ ),
+ ],
+ },
+ init: async () => {
+ Sentry.init({
+ // The Data Source Name (DSN) is a unique identifier for your Sentry project.
+
+ dsn: process.env.SENTRY_DSN,
+ // Update this to match the environment you want to track errors for
+ environment: process.env.NODE_ENV === "production" ? "production" : "development",
+ });
+ },
+ onFailure: async (payload, error, { ctx }) => {
+ Sentry.captureException(error, {
+ extra: {
+ payload,
+ ctx,
+ },
+ });
+ },
+});
+```
+
+
+ [Build extensions](/config/config-file#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.
+
+
+## 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.
+
+```ts trigger/sentry-error-test.ts
+import { task } from "@trigger.dev/sdk/v3";
+
+export const sentryErrorTest = task({
+ id: "sentry-error-test",
+ retry: {
+ // Only retry once
+ maxAttempts: 1,
+ },
+ run: async () => {
+ const error = new Error("This is a custom error that Sentry will capture");
+ error.cause = { additionalContext: "This is additional context" };
+ throw error;
+ },
+});
+```
+
+After creating the task, deploy your project.
+
+
+
+ ```bash npm
+ npx trigger.dev@latest deploy
+ ```
+
+ ```bash pnpm
+ pnpm dlx trigger.dev@latest deploy
+ ```
+
+ ```bash yarn
+ yarn dlx trigger.dev@latest deploy
+ ```
+
+
+
+Once deployed, navigate to the `test` page in the sidebar of your [Trigger.dev dashboard](https://cloud.trigger.dev), 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.
diff --git a/docs/guides/introduction.mdx b/docs/guides/introduction.mdx
index c2808715ff..fcc46e2454 100644
--- a/docs/guides/introduction.mdx
+++ b/docs/guides/introduction.mdx
@@ -47,6 +47,7 @@ Tasks you can copy and paste to get started with Trigger.dev. They can all be ex
| [React to PDF](/guides/examples/react-pdf) | Use `react-pdf` to generate a PDF and save it to Cloudflare R2. |
| [Puppeteer](/guides/examples/puppeteer) | Use Puppeteer to generate a PDF or scrape a webpage. |
| [Resend email sequence](/guides/examples/resend-email-sequence) | Send a sequence of emails over several days using Resend with Trigger.dev. |
+| [Sentry error tracking](/guides/examples/sentry-error-tracking) | Automatically send errors to Sentry from your tasks. |
| [Sharp image processing](/guides/examples/sharp-image-processing) | Use Sharp to process an image and save it to Cloudflare R2. |
| [Supabase database operations](/guides/examples/supabase-database-operations) | Run basic CRUD operations on a table in a Supabase database using Trigger.dev. |
| [Supabase Storage upload](/guides/examples/supabase-storage-upload) | Download a video from a URL and upload it to Supabase Storage using S3. |
diff --git a/docs/mint.json b/docs/mint.json
index a04a4681ee..edb804ec66 100644
--- a/docs/mint.json
+++ b/docs/mint.json
@@ -311,6 +311,7 @@
"guides/examples/pdf-to-image",
"guides/examples/puppeteer",
"guides/examples/scrape-hacker-news",
+ "guides/examples/sentry-error-tracking",
"guides/examples/sharp-image-processing",
"guides/examples/supabase-database-operations",
"guides/examples/supabase-storage-upload",
From 77738c83fcef1503a14d55cd36b89347da559d88 Mon Sep 17 00:00:00 2001
From: D-K-P <8297864+D-K-P@users.noreply.github.com>
Date: Mon, 28 Oct 2024 15:24:46 +0000
Subject: [PATCH 2/4] Removed additionalPackages
---
docs/guides/examples/sentry-error-tracking.mdx | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/docs/guides/examples/sentry-error-tracking.mdx b/docs/guides/examples/sentry-error-tracking.mdx
index d4efc7a5e5..8485299940 100644
--- a/docs/guides/examples/sentry-error-tracking.mdx
+++ b/docs/guides/examples/sentry-error-tracking.mdx
@@ -33,6 +33,7 @@ To send errors to Sentry when there are errors in your tasks, you'll need to add
```ts trigger.config.ts
import { defineConfig } from "@trigger.dev/sdk/v3";
+import { esbuildPlugin } from "@trigger.dev/build/extensions";
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
// Import the correct Sentry package for your runtime, e.g. @sentry/node for Node.js or @Sentry/nextjs for Next.js
import * as Sentry from "@sentry/node";
@@ -42,10 +43,6 @@ export default defineConfig({
// Your other config settings...
build: {
extensions: [
- additionalPackages({
- // Add the correct Sentry package for your runtime, e.g. @sentry/node for Node.js or @Sentry/nextjs for Next.js
- packages: ["@sentry/node"],
- }),
esbuildPlugin(
sentryEsbuildPlugin({
org: "",
From 2396133f1435c2faf8454c352941f94902f51c03 Mon Sep 17 00:00:00 2001
From: D-K-P <8297864+D-K-P@users.noreply.github.com>
Date: Mon, 28 Oct 2024 15:27:25 +0000
Subject: [PATCH 3/4] Updated description
---
docs/guides/examples/sentry-error-tracking.mdx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/guides/examples/sentry-error-tracking.mdx b/docs/guides/examples/sentry-error-tracking.mdx
index 8485299940..6f0eca7f4b 100644
--- a/docs/guides/examples/sentry-error-tracking.mdx
+++ b/docs/guides/examples/sentry-error-tracking.mdx
@@ -6,7 +6,7 @@ description: "This example demonstrates how to track errors with Sentry using Tr
## Overview
-Automatically send errors to your Sentry project from your Trigger.dev tasks.
+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
From 42d83f29193a3c56dc71a7cf0b33dfbfb594aa58 Mon Sep 17 00:00:00 2001
From: D-K-P <8297864+D-K-P@users.noreply.github.com>
Date: Mon, 28 Oct 2024 15:34:49 +0000
Subject: [PATCH 4/4] Copy updates
---
docs/guides/examples/sentry-error-tracking.mdx | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/docs/guides/examples/sentry-error-tracking.mdx b/docs/guides/examples/sentry-error-tracking.mdx
index 6f0eca7f4b..f975c2a4e9 100644
--- a/docs/guides/examples/sentry-error-tracking.mdx
+++ b/docs/guides/examples/sentry-error-tracking.mdx
@@ -17,12 +17,6 @@ Automatically send errors and source maps to your Sentry project from your Trigg
To send errors to Sentry when there are errors in your tasks, you'll need to add this build configuration to your `trigger.config.ts` file. This will then run every time you deploy your project.
-
- Make sure you use the correct sentry package for your runtime. For example, if you are using
- Node.js, you should use the `@sentry/node` package. For a full list of supported packages, see the
- [Sentry docs](https://docs.sentry.io/platforms/).
-
-
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
@@ -35,7 +29,6 @@ To send errors to Sentry when there are errors in your tasks, you'll need to add
import { defineConfig } from "@trigger.dev/sdk/v3";
import { esbuildPlugin } from "@trigger.dev/build/extensions";
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
-// Import the correct Sentry package for your runtime, e.g. @sentry/node for Node.js or @Sentry/nextjs for Next.js
import * as Sentry from "@sentry/node";
export default defineConfig({
@@ -50,7 +43,6 @@ export default defineConfig({
// Find this auth token in settings -> developer settings -> auth tokens
authToken: process.env.SENTRY_AUTH_TOKEN,
}),
- // Optional - only runs during the deploy command, and adds the plugin to the end of the list of plugins
{ placement: "last", target: "deploy" }
),
],
@@ -58,7 +50,6 @@ export default defineConfig({
init: async () => {
Sentry.init({
// The Data Source Name (DSN) is a unique identifier for your Sentry project.
-
dsn: process.env.SENTRY_DSN,
// Update this to match the environment you want to track errors for
environment: process.env.NODE_ENV === "production" ? "production" : "development",