@borderless/worker-sentry
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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://123@456.ingest.sentry.io/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

Package Sidebar

Install

npm i @borderless/worker-sentry

Weekly Downloads

9

Version

2.0.0

License

MIT

Unpacked Size

23.8 kB

Total Files

6

Last publish

Collaborators

  • blakeembrey