Rollbar integration plugin for Cloudflare Pages
- JavaScript 100%
|
|
||
|---|---|---|
| .github | ||
| .yarn/releases | ||
| functions | ||
| lib | ||
| .gitignore | ||
| .yarnrc.yml | ||
| biome.json | ||
| index.d.ts | ||
| LICENSE | ||
| package.json | ||
| README.md | ||
| renovate.json | ||
| tsconfig.json | ||
| yarn.lock | ||
cloudflare-pages-plugin-rollbar
Rollbar integration plugin for Cloudflare Pages
Installation
yarn add @hckr_/cloudflare-pages-plugin-rollbar
npm install @hckr_/cloudflare-pages-plugin-rollbar
Usage
// functions/_middleware.js
import rollbarPlugin from "@hckr_/cloudflare-pages-plugin-rollbar";
/**
* @param {EventContext<Env>} context
* @returns {Promise<Response>}
*/
export async function rollbar(context) {
return rollbarPlugin({ token: context.env.ROLLBAR_TOKEN })(context);
}
export const onRequest = [rollbar];
The Plugin takes an object with two properties: the Rollbar Project Access token with post_server_item scope
and optional custom for adding custom properties into logged payload.
This plugin catches unhandled exceptions and logs them into Rollbar.
It gathers request data and Cloudflare metadata with exception details.
You can access Rollbar logger instance via the context.data.rollbar property.
There are debug, info, warn and error methods for corresponding levels.
First three take message and attributes as parameters. error takes
exception and descrition.
interface Rollbar {
debug(message: string, attributes: Record<string, any>): Promise;
info(message: string, attributes: Record<string, any>): Promise;
warn(message: string, attributes: Record<string, any>): Promise;
error(exception: Error, description: string): Promise;
}
Publish
yarn build
yarn npm publish --access public --tag latest