fix: 提交sentry

This commit is contained in:
speakeloudest 2025-09-02 20:10:24 -07:00
parent 135d78fc0d
commit 3c615237e7
9 changed files with 163 additions and 19 deletions

View File

@ -55,6 +55,25 @@ export function TutorialButton({ items }: { items: Item[] }) {
useOutsideClick(ref as RefObject<HTMLDivElement>, () => setActive(null));
function openPopupWindow(item) {
// features 字符串用于控制窗口的特性
const pageWidth = 600; // 弹出窗口的宽度
const pageHeight = 550; // 弹出窗口的高度
const {
availLeft, // 返回浏览器可用空间左边距离屏幕(系统桌面)左边界的距离。
availHeight, // 浏览器在显示屏上的可用高度,即当前屏幕高度
availWidth, // 浏览器在显示屏上的可用宽度,即当前屏幕宽度
} = window.screen;
const pageTop = (availHeight - pageHeight) / 2; // 窗口的垂直位置
let pageLeft = (availWidth - pageWidth) / 2; // 窗口的水平位置;
pageLeft += availLeft; // 加上屏幕偏移值
const features = `width=${pageWidth},height=${pageHeight},left=${pageLeft},top=${pageTop},toolbar=no,location=no,menubar=no`;
console.log(features);
window.open(item.download, item.title, features);
}
return (
<>
<AnimatePresence>
@ -151,18 +170,17 @@ export function TutorialButton({ items }: { items: Item[] }) {
</div>
<div>
{item.download ? (
<a
<button
className={cn(
buttonVariants({
variant: 'default',
}),
'mr-2 min-w-0 bg-[#EAEAEA] px-3 text-[#225BA9] hover:text-white sm:min-w-[80px]',
)}
href={item.download}
target='_blank'
onClick={() => openPopupWindow(item)}
>
</a>
</button>
) : null}
<motion.button
layoutId={`button-${item.title}-${id}`}

View File

@ -0,0 +1,23 @@
'use client';
import * as Sentry from '@sentry/nextjs';
import NextError from 'next/error';
import { useEffect } from 'react';
export default function GlobalError({ error }: { error: Error & { digest?: string } }) {
useEffect(() => {
Sentry.captureException(error);
}, [error]);
return (
<html>
<body>
{/* `NextError` is the default Next.js error page component. Its type
definition requires a `statusCode` prop. However, since the App Router
does not expose status codes for errors, we simply pass 0 to render a
generic error message. */}
<NextError statusCode={0} />
</body>
</html>
);
}

View File

@ -0,0 +1,30 @@
// This file configures the initialization of Sentry on the client.
// The added config here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import * as Sentry from '@sentry/nextjs';
Sentry.init({
dsn: 'https://e519096f8b71cba99d86ddc46d8e424f@o4509950153719808.ingest.us.sentry.io/4509950194679808',
// Add optional integrations for additional features
integrations: [Sentry.replayIntegration()],
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,
// Enable logs to be sent to Sentry
enableLogs: true,
// Define how likely Replay events are sampled.
// This sets the sample rate to be 10%. You may want this to be 100% while
// in development and sample at a lower rate in production
replaysSessionSampleRate: 0.1,
// Define how likely Replay events are sampled when an error occurs.
replaysOnErrorSampleRate: 1.0,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
});
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;

View File

@ -0,0 +1,13 @@
import * as Sentry from '@sentry/nextjs';
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('./sentry.server.config');
}
if (process.env.NEXT_RUNTIME === 'edge') {
await import('./sentry.edge.config');
}
}
export const onRequestError = Sentry.captureRequestError;

View File

@ -57,17 +57,38 @@ const nextConfig: NextConfig = {
},
};
const sentryWebpackPluginOptions = {
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options
org: '你的组织名称',
project: '你的项目名称',
authToken: '你的 Sentry Auth Token',
silent: true, // Suppresses all logs
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#use-sentrywebpackplugin
};
// 组合两个插件
export default withSentryConfig(withNextIntl(nextConfig), sentryWebpackPluginOptions);
export default withSentryConfig(withNextIntl(nextConfig), {
// For all available options, see:
// https://www.npmjs.com/package/@sentry/webpack-plugin#options
org: 'pa-f0',
project: 'javascript-nextjs',
// Only print logs for uploading source maps in CI
silent: true,
authToken:
'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',
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,
// Uncomment to route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
// This can increase your server load as well as your hosting bill.
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
// side errors will fail.
// tunnelRoute: "/monitoring",
// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
// See the following for more information:
// https://docs.sentry.io/product/crons/
// https://vercel.com/docs/cron-jobs
automaticVercelMonitors: true,
});

View File

@ -19,7 +19,7 @@
"dependencies": {
"@react-spring/three": "^10.0.1",
"@react-three/fiber": "^9.2.0",
"@sentry/nextjs": "^10.8.0",
"@sentry/nextjs": "^10",
"@shadergradient/react": "^2.1.2",
"@stripe/react-stripe-js": "^3.4.0",
"@stripe/stripe-js": "^6.0.0",
@ -50,6 +50,7 @@
"zustand": "^5.0.3"
},
"devDependencies": {
"@babel/plugin-transform-named-capturing-groups-regex": "^7.27.1",
"@svgr/webpack": "^8.1.0",
"@types/node": "^22.10.5",
"@types/react": "^19.0.4",

View File

@ -0,0 +1,19 @@
// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).
// The config you add here will be used whenever one of the edge features is loaded.
// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import * as Sentry from '@sentry/nextjs';
Sentry.init({
dsn: 'https://e519096f8b71cba99d86ddc46d8e424f@o4509950153719808.ingest.us.sentry.io/4509950194679808',
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,
// Enable logs to be sent to Sentry
enableLogs: true,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
});

View File

@ -0,0 +1,18 @@
// This file configures the initialization of Sentry on the server.
// The config you add here will be used whenever the server handles a request.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import * as Sentry from '@sentry/nextjs';
Sentry.init({
dsn: 'https://e519096f8b71cba99d86ddc46d8e424f@o4509950153719808.ingest.us.sentry.io/4509950194679808',
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,
// Enable logs to be sent to Sentry
enableLogs: true,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
});

View File

@ -57,7 +57,7 @@
"dependencies": {
"@react-spring/three": "^10.0.1",
"@react-three/fiber": "^9.2.0",
"@sentry/nextjs": "^10.8.0",
"@sentry/nextjs": "^10",
"@shadergradient/react": "^2.1.2",
"@stripe/react-stripe-js": "^3.4.0",
"@stripe/stripe-js": "^6.0.0",
@ -88,6 +88,7 @@
"zustand": "^5.0.3",
},
"devDependencies": {
"@babel/plugin-transform-named-capturing-groups-regex": "^7.27.1",
"@svgr/webpack": "^8.1.0",
"@types/node": "^22.10.5",
"@types/react": "^19.0.4",