@borderless/worker-sentry
v2.0.0
Published
Sentry client for Cloudflare Workers using `fetch` and V8 stack traces
Downloads
26
Maintainers
Readme
Worker Sentry
Sentry client for Cloudflare Workers using
fetch
and native V8 stack traces.
Installation
npm install @borderless/worker-sentry --save
Usage
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 });
})
);
});
License
MIT