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 文件。