Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,43 @@

import {tracesSampler} from './tracesSampler';

/**
* Filter for suppressing expected runtime MDX compilation errors.
* These occur when serverless functions attempt to compile MDX at runtime
* because source files are excluded from the bundle to stay under Vercel's 250MB limit.
* This is an infrastructure edge case that's already handled gracefully by returning 404.
* See: app/[[...path]]/page.tsx for graceful error handling.
*/
function isExpectedMdxRuntimeError(event: Sentry.ErrorEvent): boolean {
const exception = event.exception?.values?.[0];
if (!exception) return false;

const errorMessage = exception.value || '';
const errorCode = (exception.mechanism?.data as Record<string, unknown>)?.code ||
(exception as Record<string, unknown>).code;

// Filter errors related to missing MDX files at runtime
const isMdxRuntimeError =
errorCode === 'MDX_RUNTIME_ERROR' ||
(errorCode === 'ENOENT' && errorMessage.includes('Failed to find a valid source file'));

// Filter errors from attempting to compile MDX when files aren't in bundle
const isMdxCompilationError = errorMessage.includes(
'Failed to find a valid source file for slug'
);

return isMdxRuntimeError || isMdxCompilationError;
}

function beforeSendEvent(event: Sentry.ErrorEvent) {
if (isExpectedMdxRuntimeError(event)) {
// Suppress this error from being reported to Sentry.
// The error is handled gracefully in page.tsx with notFound() response.
return null;
}
return event;
}

export function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
Sentry.init({
Expand All @@ -12,6 +49,7 @@
environment: process.env.NODE_ENV === 'development' ? 'development' : undefined,
spotlight: process.env.NODE_ENV === 'development',
integrations: [Sentry.consoleLoggingIntegration()],
beforeSendEvent,

Check failure on line 52 in src/instrumentation.ts

View workflow job for this annotation

GitHub Actions / Lint

Object literal may only specify known properties, but 'beforeSendEvent' does not exist in type 'CoreOptions<BaseTransportOptions> | BrowserOptions | NodeOptions | VercelEdgeOptions'. Did you mean to write 'beforeSend'?

// Filter sensitive metric attributes (no PII in metrics)
beforeSendMetric: metric => {
Expand All @@ -36,6 +74,7 @@
debug: false,
environment: process.env.NODE_ENV === 'development' ? 'development' : undefined,
integrations: [Sentry.consoleLoggingIntegration()],
beforeSendEvent,

Check failure on line 77 in src/instrumentation.ts

View workflow job for this annotation

GitHub Actions / Lint

Object literal may only specify known properties, but 'beforeSendEvent' does not exist in type 'CoreOptions<BaseTransportOptions> | BrowserOptions | NodeOptions | VercelEdgeOptions'. Did you mean to write 'beforeSend'?

// Filter sensitive metric attributes (no PII in metrics)
beforeSendMetric: metric => {
Expand Down
Loading