npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

toucan-js

v4.0.0

Published

Cloudflare Workers client for Sentry

Downloads

245,595

Readme

npm version npm version npm version

toucan-js

Toucan is a Sentry client for Cloudflare Workers written in TypeScript.

Features

This SDK provides all options and methods of ScopeClass and additionally:

Additional constructor options

| Option | Type | Description | | ------------------ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | context | Context | This can be any object that contains waitUntil. It can be FetchEvent, ScheduledEvent, DurableObjectState, or .mjs context. | | request | Request | If set, the SDK will send information about incoming requests to Sentry. By default, only the request method and request origin + pathname are sent. If you want to include more data, you need to use requestDataOptions option. | | requestDataOptions | RequestDataOptions | Object containing allowlist for specific parts of request. Refer to sensitive data section below. |

Constructor options overrides

Transport options

On top of base transportOptions you can pass additional configuration:

| Option | Type | Description | | ------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | headers | Record<string, string> | Custom headers passed to fetch. | | fetcher | typeof fetch | Custom fetch function. This can be useful for tests or when the global fetch used by toucan-js doesn't satisfy your use-cases. Note that custom fetcher must conform to fetch interface. |

Additional methods

  • Toucan.setEnabled(enabled: boolean): void: Can be used to disable and again enable the SDK later in your code.
  • Toucan.setRequestBody(body: unknown): void: Attaches request body to future events. body can be anything serializable.

Integrations

You can use custom integrations to enhance toucan-js as you would any other Sentry SDK. Some integrations are provided in various Sentry packages, and you can also write your own! To ensure an integration will work properly in toucan-js, it must:

  • not enhance or wrap global runtime methods (such as console.log).
  • not use runtime APIs that aren't available in Cloudflare Workers (NodeJS runtime functions, window object, etc...).

Supported integrations from @sentry/core are re-exported from toucan-js:

toucan-js also provides 2 integrations that are enabled by default, but are provided if you need to reconfigure them:

Custom integration example:

import { Toucan, rewriteFramesIntegration } from 'toucan-js';

type Env = {
  SENTRY_DSN: string;
};

export default {
  async fetch(request, env, context): Promise<Response> {
    const sentry = new Toucan({
      dsn: env.SENTRY_DSN,
      context,
      request,
      integrations: [rewriteFramesIntegration({ root: '/' })],
    });

    ...
  },
} as ExportedHandler<Env>;

Sensitive data

By default, Toucan does not send any request data that might contain PII (Personally Identifiable Information) to Sentry.

This includes:

  • request headers
  • request cookies
  • request search params
  • request body
  • user's IP address (read from CF-Connecting-Ip header)

You will need to explicitly allow these data using:

  • allowedHeaders option (array of headers or Regex or boolean)
  • allowedCookies option (array of cookies or Regex or boolean)
  • allowedSearchParams option (array of search params or Regex or boolean)
  • allowedIps option (array of search params or Regex or boolean)

These options are available on RequestData integration or requestDataOptions option (which is passed down to RequestData automatically).