Sentry client for Cloudflare Workers using
fetch
and native V8 stack traces.
npm install @borderless/worker-sentry --save
import { Sentry } from "@borderless/worker-sentry";
const sentry = new Sentry({ dsn: "https://[email protected]/789" });
addEventListener("fetch", (event) => {
event.respondWith(
handler(event.request).catch((err) => {
// Extend the event lifetime until the response from Sentry has resolved.
// Docs: https://developers.cloudflare.com/workers/runtime-apis/fetch-event#methods
event.waitUntil(
// Sends a request to Sentry and returns the response promise.
sentry.captureException(err, {
tags: {},
user: {
ip_address: event.request.headers.get("cf-connecting-ip"),
},
})
);
// Respond to the original request while the error is being logged (above).
return new Response(err.message || "Internal Error", { status: 500 });
})
);
});
MIT