Sentry 是一個開發者優先的錯誤追蹤和效能監控平臺。Sentry 為 Bun 提供了一流的 SDK,@sentry/bun,可以檢測您的 Bun 應用程式以自動收集錯誤和效能資料。
還沒有 Sentry 賬戶和專案?請前往 sentry.io,然後返回此頁面。
要開始將 Sentry 與 Bun 配合使用,首先安裝 Sentry Bun SDK。
bun add @sentry/bun然後,在您的應用程式入口檔案中使用 Sentry DSN 初始化 Sentry SDK。您可以在 Sentry 專案設定中找到您的 DSN。
import * as Sentry from "@sentry/bun";
// Ensure to call this before importing any other modules!
Sentry.init({
dsn: "__SENTRY_DSN__",
// Add Performance Monitoring by setting tracesSampleRate
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
});
您可以透過捕獲測試錯誤來驗證 Sentry 是否正常工作
setTimeout(() => {
try {
foo();
} catch (e) {
Sentry.captureException(e);
}
}, 99);
要檢視和解決記錄的錯誤,請登入 sentry.io 並開啟您的專案。單擊錯誤的標題將開啟一個頁面,您可以在其中檢視詳細資訊並將其標記為已解決。
要了解有關 Sentry 和使用 Sentry Bun SDK 的更多資訊,請檢視 Sentry 文件。