-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Self-hosted/on-premise
Which SDK are you using?
@sentry/nextjs
SDK Version
10.20.0
Framework Version
15.5.6
Link to Sentry event
No response
Reproduction Example/SDK Setup
No response
Steps to Reproduce
- Create blank Next.js app:
pnpm create next-app@latest my-app --yes - Add sentry integration:
npx @sentry/wizard@latest -i nextjs --saas --org {redacted} --project {redacted}- "Do you want to route Sentry requests ... avoid ad blockers?" - NO (intentionally not using built-in integration since final intent is to use a self-hosted Sentry instance, which is not compatible with
tunnelRouteoption according to the documentation) - "Do you want to create an example page..." - YES
- all other options - NO
- "Do you want to route Sentry requests ... avoid ad blockers?" - NO (intentionally not using built-in integration since final intent is to use a self-hosted Sentry instance, which is not compatible with
- update
instrumentation-client.ts: addtunnel: "/monitor"option - install zod
pnpm add zod(not necessary, but needed for route implementation) - implement monitoring route handler under
/monitor - start the server
pnpm devand navigate to sample page: http://localhost:3000/sentry-example-page
/src/app/monitor/route.ts implementation:
import z from 'zod'
import {NextRequest} from 'next/server';
const SentryHeaderSchema = z.object({
dsn: z.url(),
});
type SentryInfo = {
host: string;
projectId: string;
};
export async function POST(req: NextRequest) {
let envelope: string;
try {
envelope = await req.text();
if (!envelope) return new Response('Empty envelope', {status: 400});
} catch {
return new Response('Invalid body', {status: 400});
}
const info = parseSentryEnvelope(envelope);
if (!info) return new Response('Invalid envelope', {status: 400});
const upstreamSentryUrl = `https://${info.host}/api/${info.projectId}/envelope/`;
await fetch(upstreamSentryUrl, {
method: 'POST',
body: envelope,
});
return Response.json({}, {status: 200});
}
export function parseSentryEnvelope(envelope: string): SentryInfo | undefined {
const [headerRaw] = envelope.split('\n');
if (!headerRaw) return undefined;
try {
const dsnText = SentryHeaderSchema.parse(JSON.parse(headerRaw)).dsn;
const dsnUrl = new URL(dsnText);
return {
host: dsnUrl.hostname,
projectId: dsnUrl.pathname.split('/').pop() ?? '',
};
} catch (e) {
console.error('invalid Sentry envelope header', e);
return undefined;
}
}Expected Result
In presence of an Ad Blocker, sample page displays no errors after load. Test error can be simulated by pressing "Throw Sample Error", and relevant event can be successfully delivered to Sentry via /monitor tunnel.
Actual Result
Sentry SDK fires a fetch request to https://o447951.ingest.sentry.io/api/{redacted}/envelope/?sentry_version=7&sentry_key={redacted}&sentry_client=sentry.javascript.browser%2F1.33.7 which gets blocked by the Ad Blocker. Sample page displays the error and "Throw Sample Error" button is disabled:
It looks like network requests to Sentry are being blocked, which will prevent errors from being captured. Try disabling your ad-blocker to complete the test.
Additional Context
Removing useEffect which calls Sentry.diagnoseSdkConnectivity() in /src/app/sentry-example-page/page.tsx resolves the issue. Sample page does not show any errors, and test error can be successfully delivered to Sentry as expected via /monitor tunnel.
Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.
Metadata
Metadata
Assignees
Projects
Status