Skip to content

@sentry/nextjs: captureException generates Event ID, but no Network Request visible & event not received by Sentry #15885

@yoooyo24

Description

@yoooyo24

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

9.9.0

Framework Version

14.0.4

Link to Sentry event

No response

Reproduction Example/SDK Setup

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

console.log('Initializing Sentry Client Config for Next.js');

Sentry.init({
  // Use the actual DSN for the project experiencing the issue
  dsn: "(Note: Actual DSN redacted for public issue),


  // Enable debug logging to see SDK internal messages
  debug: true,


  // Ensure performance monitoring is enabled if comparing with traces
  tracesSampleRate: 1.0,


  // Specify environment (optional but good practice)
  environment: 'development',

  // Optional: Specify release
  // release: 'my-test-release@1.0.0',

  // Other integrations like Replay might be active, but start minimal for repro
  // integrations: [],
});

console.log('Sentry client config init completed.');
// File: src/app/sentry-test/page.js (or similar route in App Router)
'use client'; // Required for button interaction

import React from 'react';
import * as Sentry from '@sentry/nextjs';

export default function SentryTestPage() {

  const triggerError = () => {
    try {
      // Create a unique error instance
      const testError = new Error("Manual captureException Test Error - " + new Date().toISOString());
      console.log("[Test Page] Reporting error to Sentry:", testError);

      // Capture the exception using the SDK
      const eventId = Sentry.captureException(testError);
      console.log("[Test Page] Sentry.captureException called. Event ID:", eventId); // Critical log

      // Attempt to flush events (also completes successfully in tests)
      Sentry.flush(2000).then(() => {
        console.log('[Test Page] Sentry.flush completed.'); // Critical log
      }).catch(err => {
        console.error('[Test Page] Sentry.flush failed:', err);
      });

    } catch (error) {
      console.error("[Test Page] Failed to call Sentry.captureException:", error);
    }
  };

  return (
    <div style={{ padding: '20px' }}>
      <h1>Sentry Test Page (Next.js App Router)</h1>
      <button
        onClick={triggerError}
        style={{ padding: '10px', backgroundColor: 'red', color: 'white', border: 'none' }}
      >
        Trigger Test Error via captureException
      </button>
      <p style={{ marginTop: '1em' }}>Check browser console and network tab after clicking.</p>
    </div>
  );
}

Steps to Reproduce

  1. Set up a basic Next.js project using the App Router (e.g., npx create-next-app@latest).
  2. Install @sentry/nextjs: npm install @sentry/nextjs (or yarn/pnpm).
  3. Run the Sentry Wizard: npx @sentry/wizard@latest -i nextjs. Follow prompts to create config files.
  4. Ensure sentry.client.config.js includes debug: true and your correct DSN (similar to setup example above).
  5. Create a client component page route (e.g., src/app/sentry-test/page.js) containing a button that calls Sentry.captureException (similar to setup example above).
  6. Start the Next.js development server: npm run dev.
  7. Open the test page (e.g., http://localhost:3000/sentry-test) in a browser (tested on Windows 10/11 with Edge/Chrome).
  8. Open the browser's Developer Tools. Go to the Console tab and clear it. Go to the Network tab, clear it, ensure "Preserve log" is checked, and optionally filter for your Sentry ingest domain (e.g., ingest.us.sentry.io).
  9. Click the "Trigger Test Error" button.
  10. Observe the Console log for the Event ID and Flush completion messages.
  11. Observe the Network tab for outgoing requests to Sentry.
  12. Copy the Event ID from the console and search for it in the Sentry Issues UI for the corresponding project.

Expected Result

  1. A valid Sentry Event ID is logged in the browser console after clicking the button.
  2. The Sentry.flush() promise resolves and logs its completion message.
  3. An HTTP POST request to the Sentry ingest endpoint (.../envelope/...) appears in the browser's Network tab, ideally with a 200 OK status.
  4. The captured error event appears in the Sentry Issues UI shortly after and is searchable by the generated Event ID.

Actual Result

  1. A valid Sentry Event ID is correctly logged in the browser console after clicking the button.
  2. The Sentry.flush() promise resolves successfully and logs its completion message.
  3. NO HTTP request to the Sentry ingest endpoint appears in the browser's Network tab, even with filters disabled or specifically filtering for the ingest domain.
  4. The captured error event cannot be found in the Sentry Issues UI, even when searching directly by the exact Event ID logged in the console.

Additional Context / Key Findings from Troubleshooting:

  • Performance Monitoring Traces are successfully sent from the same application and appear correctly in the Sentry Traces UI.

  • Testing connectivity via curl from the command line on the same machine to the project's Sentry ingest endpoint succeeds (curl ... https://@/api//envelope/... returns 200 OK or 4xx).

  • System-level interference (browser extensions, hosts file, Windows Firewall, proxy settings) have been investigated and seem unlikely to be the cause.

  • A Barebones HTML Test using the Sentry CDN bundle (@sentry/browser) directly in an HTML file (loaded via file:///) works correctly: it generates an Event ID, the network request appears in DevTools with a 200 OK status, and the event appears in the Sentry Issues UI. This suggests the issue is specific to the @sentry/nextjs integration or its interaction within the Next.js environment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPackage: nextjsIssues related to the Sentry Nextjs SDK

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions