Skip to content

Sentry client for Cloudflare Workers using `fetch` and native V8 stack traces

License

Notifications You must be signed in to change notification settings

borderless/worker-sentry

Repository files navigation

Worker Sentry

NPM version NPM downloads Build status Build coverage

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

About

Sentry client for Cloudflare Workers using `fetch` and native V8 stack traces

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published