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

feat: add sentry integration #1486

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

feat: add sentry integration #1486

wants to merge 7 commits into from

Conversation

danielroe
Copy link
Owner

@danielroe danielroe commented Nov 23, 2024

Summary by CodeRabbit

  • New Features

    • Integrated Sentry for enhanced error tracking.
    • Added configuration for client-side source maps.
    • Introduced new environment variables for Sentry configuration.
  • Improvements

    • Updated source map handling to improve debugging capabilities.
  • Tests

    • Adjusted expected bundle sizes in the test suite to reflect recent changes.

@danielroe danielroe self-assigned this Nov 23, 2024
Copy link

coderabbitai bot commented Nov 23, 2024

Walkthrough

The pull request introduces several changes to the Nuxt configuration and error tracking setup. Key modifications include the addition of the @sentry/nuxt/module for Sentry integration in nuxt.config.ts, alongside new configuration options for Sentry's Data Source Name (DSN) and source map handling. Two new configuration files, sentry.client.config.ts and sentry.server.config.ts, are created to initialise Sentry for client and server environments, respectively. Additionally, the test suite for bundle sizes is updated to reflect changes in expected sizes due to new dependencies.

Changes

File Change Summary
nuxt.config.ts - Added module: @sentry/nuxt/module
- New public.sentry configuration with dsn: ''
- Updated sourcemap from false to { client: true }
- New sentry.sourceMapsUploadOptions with org: 'poetryco' and project: 'roe-dev'
sentry.client.config.ts - Added Sentry.init({...}) to initialise Sentry with DSN from runtime config and set tracesSampleRate to 1.0
sentry.server.config.ts - Added Sentry.init({...}) to initialise Sentry with DSN from environment variable and set tracesSampleRate to 1.0
test/unit/bundle.spec.ts - Updated expected client bundle size from "269k" to "397k"
- Updated expected server bundle size from "430k" to "456k"
- Increased expected total bytes for server modules from "7489k" to "23172k"
- Added new expected packages in the output
.env.example - Added variables: NUXT_PUBLIC_SENTRY_DSN= and SENTRY_AUTH_TOKEN=

Possibly related PRs

  • chore: enable sourcemaps in production #1487: The changes in this PR also involve updating the sourcemap property in nuxt.config.ts, specifically changing it from a boolean to an object, which directly relates to the modifications made in the main PR regarding source map handling.

🐇 In the garden, we hop and play,
With Sentry's help, we track the way.
Errors caught, like leaves in the breeze,
Our bundles grow, but we work with ease.
So here’s to changes, both big and small,
A joyful leap, we celebrate them all! 🌼✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 12013c7 and f225c86.

⛔ Files ignored due to path filters (2)
  • package.json is excluded by !package.json, !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (1)
  • .env.example (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .env.example

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

socket-security bot commented Nov 23, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@sentry/nuxt@8.40.0 Transitive: environment, filesystem, network, shell, unsafe +90 50.7 MB sentry-bot

View full report↗︎

Copy link

cloudflare-workers-and-pages bot commented Nov 23, 2024

Deploying danielroe with  Cloudflare Pages  Cloudflare Pages

Latest commit: f225c86
Status:🚫  Build failed.

View logs

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: 4

🧹 Outside diff range and nitpick comments (6)
sentry.server.config.ts (1)

6-8: Consider environment-specific trace sampling configuration.

The current 100% sampling rate could impact performance and costs in production.

Consider implementing environment-specific sampling:

+const isProd = process.env.NODE_ENV === 'production'
+
 Sentry.init({
   dsn: process.env.NUXT_PUBLIC_SENTRY_DSN,
-  tracesSampleRate: 1.0,
+  tracesSampleRate: isProd ? 0.1 : 1.0, // 10% sampling in production, 100% in development

Alternatively, implement a more granular sampling strategy:

tracesSampler: (samplingContext) => {
  if (samplingContext.transactionContext.name.includes('/api/')) {
    return 0.5; // 50% sampling for API routes
  }
  return 0.1; // 10% sampling for other transactions
}
sentry.client.config.ts (1)

6-9: Consider environment-specific sampling rates.

A 100% sampling rate (1.0) in production can significantly impact both performance and costs. Consider implementing a more selective sampling strategy:

 Sentry.init({
   dsn: useRuntimeConfig().public.sentry.dsn,
-  tracesSampleRate: 1.0,
+  tracesSampler: context => {
+    if (process.dev) return 1.0
+    // Sample error events more frequently than performance events
+    if (context.transactionContext?.name?.includes('/api/')) {
+      return 0.5  // 50% sampling for API routes
+    }
+    return 0.1    // 10% sampling for other routes
+  },
 })
nuxt.config.ts (3)

10-10: Consider pinning the Sentry module version

To ensure consistent builds and avoid unexpected breaking changes, it would be prudent to specify the exact version of @sentry/nuxt.

-    '@sentry/nuxt/module',
+    '@sentry/nuxt/module@x.y.z', // Replace with specific version

146-146: Review sourcemap security implications

Whilst client-side sourcemaps are necessary for Sentry error reporting, they could expose source code in production. Ensure that:

  1. Sourcemaps are only uploaded to Sentry and not publicly accessible
  2. Production builds strip sourcemaps from the public output

323-328: Consider additional Sentry configuration options

The current configuration could be enhanced with:

  1. Environment-specific organisation and project names
  2. Performance monitoring settings
  3. Release version tracking
  4. Error sampling rate configuration
   sentry: {
+    environment: process.env.NODE_ENV,
+    release: process.env.NUXT_PUBLIC_APP_VERSION,
+    tracesSampleRate: 0.1,
     sourceMapsUploadOptions: {
-      org: 'poetryco',
-      project: 'roe-dev',
+      org: process.env.SENTRY_ORG || 'poetryco',
+      project: process.env.SENTRY_PROJECT || 'roe-dev',
     },
   },
test/unit/bundle.spec.ts (1)

74-74: Verify Sentry chunk loading strategy

The addition of _nuxt/sentry.js suggests Sentry might be loaded eagerly. Consider implementing lazy loading for non-critical monitoring code.

Consider implementing dynamic imports for Sentry to load it after the initial page load:

- import * as Sentry from '@sentry/nuxt'
+ const Sentry = await import('@sentry/nuxt')
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b69ca53 and 12013c7.

⛔ Files ignored due to path filters (2)
  • package.json is excluded by !package.json, !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (4)
  • nuxt.config.ts (4 hunks)
  • sentry.client.config.ts (1 hunks)
  • sentry.server.config.ts (1 hunks)
  • test/unit/bundle.spec.ts (11 hunks)
🔇 Additional comments (4)
sentry.server.config.ts (1)

1-1: LGTM! Import statement follows Sentry's recommended practice.

sentry.client.config.ts (1)

1-1: LGTM! Import statement follows best practices.

test/unit/bundle.spec.ts (2)

39-39: Bundle size increases require attention

The integration has led to significant size increases:

  • Client bundle: +128KB (269KB → 397KB)
  • Server bundle: +26KB (430KB → 456KB)
  • Server modules: +15.3MB (7.4MB → 23.1MB)

These increases could impact load times and performance.

Consider implementing the following optimisations:

  1. Use Sentry's webpack plugin to upload source maps instead of bundling them
  2. Leverage code splitting to load Sentry only when needed
  3. Configure Sentry's instrumentations selectively rather than including all

Also applies to: 84-84, 89-89

✅ Verification successful

Bundle size increases are being managed appropriately

The Nuxt configuration shows that bundle size optimisations are already in place:

  • Source maps are properly configured with Sentry upload options
  • Production mode has security optimisations enabled
  • Vite is configured with minimal Vue features (Options API disabled)
  • The increase in bundle size is justified by the added observability features

The size increases are an acceptable trade-off for the added monitoring capabilities, and the configuration demonstrates awareness of performance considerations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any size optimisation configurations in Nuxt config
rg -A 5 "optimization|minimize|splitChunks" "nuxt.config.ts"

# Look for any existing bundle size optimisation strategies
fd -t f "webpack" -x rg -l "optimization|minimize|splitChunks" {}

Length of output: 128


Script:

#!/bin/bash
# Let's check the Nuxt configuration file directly to understand the build setup
fd -t f "nuxt.config" -x cat {}

# Check for any Webpack configuration files
fd -t f -e js -e ts "webpack.config" -x cat {}

# Look for any build configuration in package.json
fd "package.json" -x cat {}

# Search for any build-related configuration files
fd -t f -e js -e ts -e json "build|vite|rollup" -x cat {}

Length of output: 13258


103-255: 🛠️ Refactor suggestion

Review OpenTelemetry instrumentation scope

The extensive list of OpenTelemetry instrumentations suggests comprehensive monitoring coverage, but may be excessive. Not all instrumentations may be necessary for your use case.

Consider selectively enabling only the instrumentations that match your stack:

  • HTTP/API: @opentelemetry/instrumentation-http, @opentelemetry/instrumentation-fetch
  • Framework: @opentelemetry/instrumentation-express (if using Express)
  • Database: Choose based on your database (e.g., @opentelemetry/instrumentation-mongodb for MongoDB)

sentry.server.config.ts Show resolved Hide resolved
sentry.server.config.ts Show resolved Hide resolved
sentry.client.config.ts Show resolved Hide resolved
nuxt.config.ts Show resolved Hide resolved
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