Skip to content

feat: add Sentry observability#31

Open
thamam wants to merge 1 commit intomainfrom
feature/add-sentry-observability
Open

feat: add Sentry observability#31
thamam wants to merge 1 commit intomainfrom
feature/add-sentry-observability

Conversation

@thamam
Copy link
Copy Markdown
Owner

@thamam thamam commented Nov 25, 2025

Integrates Sentry for error tracking. Includes configuration files, next.config.ts update, and a test page.

Summary by CodeRabbit

  • New Features

    • Added a new test page with a centered card interface and button for validation testing
  • Chores

    • Integrated service configuration across client-side, server-side, and edge environments
    • Added new runtime dependency to support service integration

✏️ Tip: You can customize this high-level summary in your review settings.

- Install @sentry/nextjs
- Configure Sentry with placeholder DSN
- Update next.config.ts
- Add test page at /sentry-test
@netlify
Copy link
Copy Markdown

netlify Bot commented Nov 25, 2025

Deploy Preview for lrningisfun ready!

Name Link
🔨 Latest commit dbd60ed
🔍 Latest deploy log https://app.netlify.com/projects/lrningisfun/deploys/69261f7b4d0fc200098d5905
😎 Deploy Preview https://deploy-preview-31--lrningisfun.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99
Accessibility: 100
Best Practices: 100
SEO: 90
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 25, 2025

Walkthrough

Sentry error tracking is integrated into the Next.js application through separate configuration files for client, server, and edge environments. The Next.js configuration is wrapped with Sentry settings. The @sentry/nextjs package is added as a dependency. A test page is created to validate error reporting.

Changes

Cohort / File(s) Summary
Sentry Configuration
sentry.client.config.ts, sentry.server.config.ts, sentry.edge.config.ts
New environment-specific Sentry initialization files for client-side, server-side, and edge runtime with DSN and debug configuration
Next.js Configuration
next.config.ts
Updated to wrap nextConfig with withSentryConfig and import Sentry integration
Package Dependencies
package.json
Added @sentry/nextjs (^10.27.0) as runtime dependency
Error Reporting Test Page
app/sentry-test/page.tsx
New client-side test page that renders a card UI with button to throw test error for Sentry validation

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

  • Three near-identical configuration files with minimal logic (mostly initialization calls)
  • Straightforward dependency addition
  • Simple test page component with standard React/Next.js patterns
  • No complex business logic or intricate state management

Poem

🐇 A hop through config files so neat,
Sentry's now keeping watch complete,
Client, server, edge—all prepared,
Errors caught and logged with care! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add Sentry observability' clearly and concisely describes the main change: adding Sentry error tracking to the project. It is specific, follows conventional commit format, and accurately reflects the changeset which includes Sentry configuration files, next.config.ts integration, and a test page.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/add-sentry-observability

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @thamam, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces Sentry observability into the application, providing robust error tracking capabilities. By integrating Sentry, the project gains the ability to monitor and report errors from client-side, edge, and server-side code, significantly enhancing debugging and operational insights. The changes include necessary configuration updates and a dedicated page to facilitate testing of the new error reporting system.

Highlights

  • Sentry Integration: Integrated Sentry for comprehensive error tracking across the application, covering client, edge, and server environments.
  • Configuration Files: Added dedicated Sentry configuration files (sentry.client.config.ts, sentry.edge.config.ts, sentry.server.config.ts) to initialize Sentry for different environments.
  • Next.js Configuration Update: Modified next.config.ts to wrap the Next.js configuration with withSentryConfig, enabling Sentry's Next.js SDK and configuring various options like tunnelRoute, sourcemaps, and automaticVercelMonitors.
  • Test Page: Introduced a new test page (app/sentry-test/page.tsx) with a button to deliberately throw an error, allowing for easy verification of the Sentry integration.
  • Dependency Update: Added the @sentry/nextjs package as a dependency in package.json to support the Sentry integration.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request integrates Sentry for error tracking by adding the necessary dependency, configuration files, and a test page. My review identifies several critical issues related to hardcoded placeholder values in the Sentry configuration. These values for org, project, and dsn must be externalized into environment variables for the integration to function correctly and securely. Additionally, I've provided a suggestion to prevent the test page from being accessible in production environments, which is a recommended practice.

Comment on lines +12 to +13
org: "example-org",
project: "example-project",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The Sentry org and project are hardcoded with placeholder values. This will prevent Sentry from working correctly. These values should be externalized to environment variables to allow for different configurations across environments (e.g., development, staging, production).

Suggested change
org: "example-org",
project: "example-project",
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,

import * as Sentry from "@sentry/nextjs";

Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The Sentry DSN is hardcoded with a placeholder value. This will prevent errors from being reported to Sentry. The DSN should be stored in an environment variable. For client-side code, Next.js requires environment variables to be prefixed with NEXT_PUBLIC_.

Suggested change
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,

import * as Sentry from "@sentry/nextjs";

Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The Sentry DSN is hardcoded with a placeholder value. This will prevent errors from being reported to Sentry. The DSN should be stored in an environment variable. It's a good practice to use process.env.NEXT_PUBLIC_SENTRY_DSN for consistency with the client configuration, or process.env.SENTRY_DSN if it should not be exposed to the browser.

Suggested change
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,

import * as Sentry from "@sentry/nextjs";

Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The Sentry DSN is hardcoded with a placeholder value. This will prevent errors from being reported to Sentry. The DSN should be stored in an environment variable. It's a good practice to use process.env.NEXT_PUBLIC_SENTRY_DSN for consistency with the client configuration, or process.env.SENTRY_DSN if it should not be exposed to the browser.

Suggested change
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,

Comment on lines +3 to +25
import React from "react";

export default function SentryTestPage() {
return (
<div className="flex min-h-screen flex-col items-center justify-center bg-gray-100 p-4">
<div className="w-full max-w-md rounded-lg bg-white p-8 shadow-md">
<h1 className="mb-6 text-2xl font-bold text-gray-800">Sentry Test Page</h1>
<p className="mb-6 text-gray-600">
Click the button below to throw a test error and verify Sentry integration.
</p>
<button
type="button"
className="w-full rounded-md bg-red-600 px-4 py-2 text-white transition-colors hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2"
onClick={() => {
throw new Error("Sentry Test Error");
}}
>
Throw Test Error
</button>
</div>
</div>
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This test page is useful for verifying the Sentry integration, but it shouldn't be accessible in a production environment. Exposing test pages can be unprofessional and could potentially be misused to spam your Sentry project with errors. It's better to make this page available only during development. You can achieve this by checking process.env.NODE_ENV and calling notFound() from next/navigation in production.

import React from "react";
import { notFound } from "next/navigation";

export default function SentryTestPage() {
    if (process.env.NODE_ENV === "production") {
        notFound();
    }

    return (
        <div className="flex min-h-screen flex-col items-center justify-center bg-gray-100 p-4">
            <div className="w-full max-w-md rounded-lg bg-white p-8 shadow-md">
                <h1 className="mb-6 text-2xl font-bold text-gray-800">Sentry Test Page</h1>
                <p className="mb-6 text-gray-600">
                    Click the button below to throw a test error and verify Sentry integration.
                </p>
                <button
                    type="button"
                    className="w-full rounded-md bg-red-600 px-4 py-2 text-white transition-colors hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2"
                    onClick={() => {
                        throw new Error("Sentry Test Error");
                    }}
                >
                    Throw Test Error
                </button>
            </div>
        </div>
    );
}

Copy link
Copy Markdown

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

🧹 Nitpick comments (4)
learningisfun-app/sentry.server.config.ts (1)

1-8: Use env-driven DSN and avoid hard‑coding in server config

Right now the server DSN is a static example URL. For real usage you’ll want to read this from environment (and keep real values out of the repo) and ideally share common options across client/server/edge.

Example refactor:

-import * as Sentry from "@sentry/nextjs";
-
-Sentry.init({
-    dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
-
-    // Setting this option to true will print useful information to the console while you're setting up Sentry.
-    debug: false,
-});
+import * as Sentry from "@sentry/nextjs";
+
+Sentry.init({
+    dsn: process.env.SENTRY_DSN,
+    // Consider making this env-driven too, e.g. only true in development:
+    debug: process.env.NODE_ENV === "development",
+});

You could also extract a small helper (e.g. getSentryOptions()) and reuse it in the client/edge configs to keep DSN, environment, and release settings in sync.

learningisfun-app/sentry.edge.config.ts (1)

1-8: Align edge config with server and source DSN from env

The edge config also hard‑codes the example DSN. For actual deployments, you’ll want to pull this from env (and keep the real DSN out of source) and keep options consistent with the server config.

For example:

-import * as Sentry from "@sentry/nextjs";
-
-Sentry.init({
-    dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
-
-    // Setting this option to true will print useful information to the console while you're setting up Sentry.
-    debug: false,
-});
+import * as Sentry from "@sentry/nextjs";
+
+Sentry.init({
+    dsn: process.env.SENTRY_DSN,
+    debug: process.env.NODE_ENV === "development",
+});

(Using process.env.SENTRY_DSN is fine here because Next inlines env vars at build time for edge runtimes.)

learningisfun-app/sentry.client.config.ts (1)

1-8: Use NEXT_PUBLIC_ env var for client DSN and keep options consistent

For the browser bundle, it’s better to source the DSN from a NEXT_PUBLIC_ env var instead of hard‑coding the example URL, and to keep common options (env, release, sampling) aligned with server/edge.

Example:

-import * as Sentry from "@sentry/nextjs";
-
-Sentry.init({
-    dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
-
-    // Setting this option to true will print useful information to the console while you're setting up Sentry.
-    debug: false,
-});
+import * as Sentry from "@sentry/nextjs";
+
+Sentry.init({
+    dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
+    debug: process.env.NODE_ENV === "development",
+});

You can then share a small helper between this file and the server/edge configs so DSN, environment, release, and any sampling config all live in one place.

learningisfun-app/app/sentry-test/page.tsx (1)

1-25: Test page implementation is solid; consider gating/removing in production

The page is a clean way to manually verify Sentry wiring (explicit throw new Error in the click handler, good button semantics and styling). Once you’re confident in the integration, you may want to either remove /sentry-test or guard it behind an env flag / auth check so end users can’t trivially crash a page in production.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0020919 and dbd60ed.

⛔ Files ignored due to path filters (1)
  • learningisfun-app/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • learningisfun-app/app/sentry-test/page.tsx (1 hunks)
  • learningisfun-app/next.config.ts (1 hunks)
  • learningisfun-app/package.json (1 hunks)
  • learningisfun-app/sentry.client.config.ts (1 hunks)
  • learningisfun-app/sentry.edge.config.ts (1 hunks)
  • learningisfun-app/sentry.server.config.ts (1 hunks)
🔇 Additional comments (2)
learningisfun-app/next.config.ts (1)

8-43: Sentry wrapper looks good; double‑check org/project, sourcemap upload, and tunnel route

The withSentryConfig usage and options look aligned with Sentry’s Next.js examples. Before relying on this in CI, a few things to confirm:

  • Replace org: "example-org" / project: "example-project" with your real values (or load them from env) so sourcemaps upload to the correct Sentry project.
  • Ensure your CI sets the required Sentry auth/env vars; otherwise builds may warn or fail when uploading sourcemaps.
  • Verify that /monitoring doesn’t conflict with any existing route or middleware, per your own comment, so client error reporting via the tunnel doesn’t get intercepted.
learningisfun-app/package.json (1)

12-12: @sentry/nextjs@10.27.0 is compatible with Next 16.0.3 and React 19.2.0

The peer dependency declaration (next: '^13.2.0 || ^14.0 || ^15.0.0-rc.0 || ^16.0.0-0') explicitly supports Next.js 16.0.3. Version 10.27.0 (released November 2025) includes React 19 support via updated Sentry JS packages.

⚠️ Minor caveat: Some ecosystem packages may still pin older React ranges, causing install-time peer-dependency warnings. If this occurs, use npm install --legacy-peer-deps as a workaround, and validate runtime behavior in your app.

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