Skip to content
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

Enable Sentry integration for Error Reporting #175

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

rtau
Copy link

@rtau rtau commented Apr 14, 2024

When errors occur in the app/web, we rely on user feedback to provide more details. This would be a challenging situation for less technical users.

By enabling Sentry integration, uncaught errors are sent to Sentry which would allow us to know the error occurred, stacktrace at that time, the version which trigger the error, how much users are affected, etc.

Summary by CodeRabbit

  • New Features

    • Integrated Sentry for error tracking and performance monitoring in the application.
    • Added Sentry support to the deployment workflow for enhanced error reporting.
  • Documentation

    • Updated README with a section on how to enable Sentry integration for error reporting.
  • Dependencies

    • Added @sentry/react and @sentry/vite-plugin to the project dependencies.
  • Improvements

    • Enhanced error tracking within the routing setup using SentryRoutes in App.tsx.
    • Configured Sentry for error monitoring in Vite build process in vite.config.ts.

@chunlaw
Copy link
Member

chunlaw commented Apr 14, 2024

It will not be approved unless you illustrate why it is necessary.

Copy link

coderabbitai bot commented Jun 24, 2024

Walkthrough

The recent changes introduce Sentry for error monitoring and performance tracking across the project. Integration includes setting up environment variables, modifying workflow files, updating dependency management, and incorporating Sentry within the React application using @sentry/react. Additionally, Sentry is configured in the Vite build process to enable detailed error tracking and analysis.

Changes

Files Change Summary
.github/workflows/deploy.yml Added environment variables for Sentry configuration.
.github/workflows/node.js.yml Added environment variable VITE_SENTRY_DSN with value from secrets for Sentry DSN.
README.md Added a section detailing error reporting using Sentry and how to set it up.
package.json Added dependencies for @sentry/react and @sentry/vite-plugin.
src/App.tsx Replaced React Router's Routes with Sentry's SentryRoutes to enable error tracking within the routing setup.
src/main.tsx Initialized Sentry with configuration options, set up React Router integration, and changed component loading to lazy loading.
vite.config.ts Added sentryVitePlugin for Sentry error monitoring and updated build configuration to generate source maps.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant Sentry
    participant React Router
    
    User->>App: Initialize Application
    App->>Sentry: Sentry.init()
    App->>React Router: Load Routes
    React Router->>Sentry: Use SentryRoutes for tracking
    User->>React Router: Navigate through App
    React Router->>Sentry: Capture routes and errors
    Sentry->>Sentry: Send error tracking data
Loading

Poem

🐇✨
In lines of code, we swiftly weave,
With Sentry's watch, our app won't leave.
Errors caught in every stride,
With graceful routes, we now confide.
A build so safe, through Vite we glide,
Our journey steadfast, side by side.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@rtau
Copy link
Author

rtau commented Jun 24, 2024

@chunlaw Updated the PR description, please see if that explains why this PR is necessary.

@rtau rtau marked this pull request as ready for review June 25, 2024 05:52
@rtau
Copy link
Author

rtau commented Jun 25, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Jun 25, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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: 1

Outside diff range and nitpick comments (1)
src/main.tsx (1)

Line range hint 38-56: Review and potentially refactor the human detection function.

The isHuman function checks the user agent against a list of bots, which is a useful feature for analytics and performance optimizations. Consider adding more comments to explain why this check is necessary, especially in the context of rendering the application.

+ // Check if the user agent belongs to a human to optimize rendering and analytics
const isHuman = () => {
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9fdf4a5 and 239f653.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (7)
  • .github/workflows/deploy.yml (1 hunks)
  • .github/workflows/node.js.yml (1 hunks)
  • README.md (1 hunks)
  • package.json (2 hunks)
  • src/App.tsx (4 hunks)
  • src/main.tsx (1 hunks)
  • vite.config.ts (3 hunks)
Files skipped from review due to trivial changes (2)
  • .github/workflows/deploy.yml
  • .github/workflows/node.js.yml
Additional context used
LanguageTool
README.md

[grammar] ~11-~11: This phrase is duplicated. You should probably use “常見問題 FAQ” only once. (PHRASE_REPETITION)
Context: ...t lets you get what you need, fast. ## 常見問題 FAQ [常見問題 FAQ](https://github.com/hkbus/hk-independen...


[uncategorized] ~47-~47: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short). (COMMA_COMPOUND_SENTENCE_2)
Context: ...best performance. The build is minified and the filenames include the hashes.\ Your...


[style] ~66-~66: To form a complete sentence, be sure to include a subject. (MISSING_IT_THERE)
Context: ...SENTRY_DSN` when you build the project. Can be injected in GitHub Actions by secret...


[style] ~78-~78: To form a complete sentence, be sure to include a subject. (MISSING_IT_THERE)
Context: ...cs.sentry.io/account/auth-tokens/> ``` Can be injected in GitHub Actions by Variab...

Markdownlint
README.md

3-3: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


6-6: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines


11-11: Expected: 1; Actual: 0; Below (MD022, blanks-around-headings)
Headings should be surrounded by blank lines


72-72: null (MD031, blanks-around-fences)
Fenced code blocks should be surrounded by blank lines


81-81: null (MD034, no-bare-urls)
Bare URL used


72-72: null (MD040, fenced-code-language)
Fenced code blocks should have a language specified

Additional comments not posted (6)
src/main.tsx (3)

3-3: Ensure correct import and usage of Sentry and React Router modules.

The import statements for Sentry and React Router modules are correctly placed and follow best practices for modular JavaScript applications.

Also applies to: 7-7


35-35: Good use of React.lazy for component loading.

Using React.lazy for loading the App component is a good practice for improving the performance of the application by splitting the code at a logical point.


10-34: Review Sentry Configuration for Best Practices.

The Sentry initialization is comprehensive, covering various aspects like browser tracing and session replays. However, consider adjusting the tracesSampleRate to a lower value unless you need to capture every transaction, as a rate of 1.0 might be excessive and could impact performance.

-  tracesSampleRate: 1.0,
+  tracesSampleRate: 0.1, // Adjust according to your needs

Additionally, the tracePropagationTargets only includes localhost. Ensure to add production URLs or remove this setting if it's not necessary.

vite.config.ts (1)

6-6: Review the configuration of the Sentry Vite plugin.

The integration of the Sentry Vite plugin is done correctly. The placement after other plugins is appropriate as recommended by Sentry's documentation. However, ensure that the Sentry environment variables (SENTRY_ORG, SENTRY_PROJECT, SENTRY_AUTH_TOKEN) are securely managed and not hardcoded in the configuration files.

Also, enabling source map generation is crucial for debugging production errors effectively.

Also applies to: 18-26, 35-35

package.json (1)

28-28: Review the addition of Sentry dependencies.

The addition of @sentry/react and @sentry/vite-plugin is aligned with the objectives of the PR to integrate Sentry for error tracking. Ensure that the versions used are compatible with the rest of the project's dependencies.

Also applies to: 64-64

src/App.tsx (1)

18-18: Ensure correct integration of Sentry with React Router.

The integration of Sentry with React Router using withSentryReactRouterV6Routing is implemented correctly. This setup will help in capturing route-related errors effectively. However, ensure that this integration does not interfere with the existing routing logic, especially with lazy-loaded components.

Also applies to: 45-47, 68-141

Comment on lines +56 to +82
## Error Reporting

Sentry can be used to collect errors and events from users for troubleshooting purpose. To enable the integration, the following steps are required.

### Pre-requisite

1. A project created on Sentry (either sentry.io or your own Sentry installation), [with DSN](https://docs.sentry.io/concepts/key-terms/dsn-explainer/#where-to-find-your-dsn) created.

### Enable Sentry during build time

Set the DSN to the environment variable `VITE_SENTRY_DSN` when you build the project.
Can be injected in GitHub Actions by secret `SENTRY_DSN`

### Automating Sentry-related tasks at build time

Set these environment variables in CI/CD pipeline:
```
# You can derieve the SENTRY_ORG and SENTRY_PROJECT (their slug) from your Sentry project URL. For example, "https://my-org.sentry.io/projects/my-project/", then SENTRY_ORG=my-org, SENTRY_PROJECT=my-project
SENTRY_ORG=
SENTRY_PROJECT=
SENTRY_AUTH_TOKEN=<See how to get it from https://docs.sentry.io/account/auth-tokens/>
```

Can be injected in GitHub Actions by Variables `SENTRY_ORG`, `SENTRY_PROJECT` and secret `SENTRY_AUTH_TOKEN`.

Reference: https://github.com/getsentry/sentry-javascript-bundler-plugins

Copy link

Choose a reason for hiding this comment

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

Review and enhance the documentation on Sentry integration.

The documentation provides a clear step-by-step guide on integrating Sentry. However, ensure that the environment variables and their usage are clearly explained to avoid any confusion during setup.

+ # Ensure to replace SENTRY_ORG, SENTRY_PROJECT, and SENTRY_AUTH_TOKEN with your actual Sentry credentials

Also, consider adding a link to the Sentry documentation for React to provide users with additional resources.

+ Reference: [Sentry for React](https://docs.sentry.io/platforms/javascript/guides/react/)
Tools
LanguageTool

[style] ~66-~66: To form a complete sentence, be sure to include a subject. (MISSING_IT_THERE)
Context: ...SENTRY_DSN` when you build the project. Can be injected in GitHub Actions by secret...


[style] ~78-~78: To form a complete sentence, be sure to include a subject. (MISSING_IT_THERE)
Context: ...cs.sentry.io/account/auth-tokens/> ``` Can be injected in GitHub Actions by Variab...

Markdownlint

72-72: null (MD031, blanks-around-fences)
Fenced code blocks should be surrounded by blank lines


81-81: null (MD034, no-bare-urls)
Bare URL used


72-72: null (MD040, fenced-code-language)
Fenced code blocks should have a language specified

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.

2 participants