Skip to content

Added Sentry example #1435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 28, 2024
Merged

Added Sentry example #1435

merged 5 commits into from
Oct 28, 2024

Conversation

D-K-P
Copy link
Member

@D-K-P D-K-P commented Oct 28, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a comprehensive guide on integrating Sentry error tracking with Trigger.dev.
    • Added a new example task for Sentry error tracking in the documentation.
  • Documentation

    • Created a new documentation file titled "Track errors with Sentry."
    • Updated the "Example tasks" section to include Sentry error tracking.
    • Enhanced documentation structure with new entries in the navigation.

Copy link

changeset-bot bot commented Oct 28, 2024

⚠️ No Changeset found

Latest commit: 96229f0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Oct 28, 2024

Warning

Rate limit exceeded

@D-K-P has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between 28caad3 and 96229f0.

Walkthrough

This pull request introduces a new documentation file titled "Track errors with Sentry," which guides users on integrating Sentry error tracking with Trigger.dev. It includes prerequisites, configuration examples, and testing instructions. Additionally, a new task for testing Sentry integration is added. The introduction document is updated to reference this new guide, and the documentation structure in docs/mint.json is enhanced to include the new task in the navigation.

Changes

File Path Change Summary
docs/guides/examples/sentry-error-tracking.mdx New documentation file created to guide Sentry error tracking integration with Trigger.dev.
trigger/sentry-error-test.ts New task sentryErrorTest added for testing Sentry integration.
docs/guides/introduction.mdx New entry added in "Example tasks" section linking to the Sentry error tracking guide.
docs/mint.json New entry added for the Sentry error tracking example task in the navigation structure.

Possibly related PRs

Suggested reviewers

  • matt-aitken

🐰 In the meadow, I hop with glee,
New Sentry docs, oh what a spree!
Track those errors, let them not hide,
With Trigger.dev, take it in stride.
A task to test, a guide so bright,
Hop along now, errors take flight! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (5)
docs/guides/examples/sentry-error-tracking.mdx (5)

7-10: Enhance the overview section with more context.

Consider expanding the overview to include:

  • A brief explanation of what Sentry is
  • The benefits of error tracking
  • Why someone would want to integrate Sentry with Trigger.dev

Example enhancement:

 ## Overview

-Automatically send errors to your Sentry project from your Trigger.dev tasks.
+[Sentry](https://sentry.io) is an error monitoring and performance tracking platform that helps developers identify and fix issues in real-time. By integrating Sentry with your Trigger.dev tasks, you can:
+
+- Automatically capture and track errors in your tasks
+- Get detailed error reports with stack traces and context
+- Monitor task performance and reliability
+- Receive instant notifications when issues occur

11-15: Add additional prerequisites for clarity.

Consider adding these important prerequisites:

  • Required Sentry permissions/roles for creating auth tokens
  • Node.js/runtime environment requirements
  • Basic familiarity with Trigger.dev tasks

40-42: Explain the project ref placeholder.

The <project ref> placeholder needs explanation on where to find this value.

Add a note explaining that the project ref can be found in the Trigger.dev dashboard project settings.


128-132: Add troubleshooting guide and expected results.

The testing instructions should include:

  1. Screenshots of the expected Sentry dashboard view
  2. Common troubleshooting steps
  3. Verification steps to ensure the integration is working

16-19: Add security considerations section.

Consider adding a section about security best practices:

  • Proper handling of Sentry DSN and auth tokens
  • Data privacy considerations
  • Rate limiting and quotas
  • Environment-specific configurations
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3d7a6d8 and 28caad3.

📒 Files selected for processing (3)
  • docs/guides/examples/sentry-error-tracking.mdx (1 hunks)
  • docs/guides/introduction.mdx (1 hunks)
  • docs/mint.json (1 hunks)
🔇 Additional comments (2)
docs/guides/introduction.mdx (1)

50-50: LGTM! Well-structured documentation addition.

The new Sentry example task entry is well-integrated into the documentation:

  • Follows consistent formatting
  • Maintains alphabetical ordering
  • Provides clear and concise description
  • Uses correct link structure
docs/mint.json (1)

314-314: LGTM! Documentation navigation entry is properly structured.

The new Sentry error tracking guide is correctly added to the "Example tasks" section, maintaining alphabetical order and consistent formatting with other entries.

Comment on lines 61 to 69
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",
});
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling to the init function.

The initialization could fail silently if environment variables are missing.

 init: async () => {
+  if (!process.env.SENTRY_DSN) {
+    throw new Error("SENTRY_DSN environment variable is required");
+  }
   Sentry.init({
     dsn: process.env.SENTRY_DSN,
     environment: process.env.NODE_ENV === "production" ? "production" : "development",
   });
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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",
});
},
init: async () => {
if (!process.env.SENTRY_DSN) {
throw new Error("SENTRY_DSN environment variable is required");
}
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",
});
},

Comment on lines +70 to +78
onFailure: async (payload, error, { ctx }) => {
Sentry.captureException(error, {
extra: {
payload,
ctx,
},
});
},
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve error handling in the onFailure handler.

The current implementation might swallow errors. Consider:

  1. Adding error logging
  2. Implementing proper error propagation
 onFailure: async (payload, error, { ctx }) => {
+  console.error("Task failed:", error);
   Sentry.captureException(error, {
     extra: {
       payload,
       ctx,
     },
   });
+  // Re-throw the error to ensure it's properly propagated
+  throw error;
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onFailure: async (payload, error, { ctx }) => {
Sentry.captureException(error, {
extra: {
payload,
ctx,
},
});
},
});
onFailure: async (payload, error, { ctx }) => {
console.error("Task failed:", error);
Sentry.captureException(error, {
extra: {
payload,
ctx,
},
});
// Re-throw the error to ensure it's properly propagated
throw error;
},
});

Comment on lines +93 to +108
```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;
},
});
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make the test task more realistic and informative.

The current test task is overly simplistic. Consider:

  1. Adding more realistic error scenarios
  2. Including structured metadata
  3. Using Sentry's breadcrumbs feature
 export const sentryErrorTest = task({
   id: "sentry-error-test",
   retry: {
     maxAttempts: 1,
   },
   run: async () => {
+    // Add breadcrumb for better error context
+    Sentry.addBreadcrumb({
+      category: 'task',
+      message: 'Starting sentry test task',
+      level: 'info',
+    });
+
+    // Simulate a more realistic error scenario
+    try {
+      const result = await simulateApiCall();
+      // Process result...
+    } catch (e) {
       const error = new Error("This is a custom error that Sentry will capture");
-      error.cause = { additionalContext: "This is additional context" };
+      error.cause = {
+        originalError: e,
+        context: {
+          taskId: "sentry-error-test",
+          timestamp: new Date().toISOString(),
+          environment: process.env.NODE_ENV,
+        }
+      };
       throw error;
+    }
   },
 });

Committable suggestion was skipped due to low confidence.

@D-K-P D-K-P merged commit cbe5170 into main Oct 28, 2024
2 checks passed
@D-K-P D-K-P deleted the docs/sentry-example branch October 28, 2024 15:57
This was referenced Oct 30, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant