Cloudflare Docs
Pages
Visit Pages on GitHub
Set theme to dark (⇧+D)

Honeycomb Pages Plugin

The Honeycomb Pages Plugin automatically sends traces to Honeycomb for analysis and observability.

Installation

$ npm install @cloudflare/pages-plugin-honeycomb

Usage

functions/_middleware.ts
import honeycombPlugin from "@cloudflare/pages-plugin-honeycomb";
export const onRequest = honeycombPlugin({
apiKey: "YOUR_HONEYCOMB_API_KEY",
dataset: "YOUR_HONEYCOMB_DATASET_NAME",
});

This Plugin is based on the @cloudflare/workers-honeycomb-logger and accepts the same configuration options.

Ensure that you enable the option to Automatically unpack nested JSON and set the Maximum unpacking depth to 5 in your Honeycomb dataset settings.

Follow the instructions above to toggle on Automatically unpack nested JSON and set the Maximum unpacking depth option to 5 in the Honeycomb dashboard

Additional context

data.honeycomb.tracer has two methods for attaching additional information about a given trace:

  • data.honeycomb.tracer.log which takes a single argument, a String.
  • data.honeycomb.tracer.addData which takes a single argument, an object of arbitrary data.

More information about these methods can be seen on @cloudflare/workers-honeycomb-logger’s documentation.

For example, if you wanted to use the addData method to attach user information:

functions/admin/_middleware.ts
import type { PluginData } from "@cloudflare/pages-plugin-honeycomb";
export const onRequest: PagesFunction<unknown, any, PluginData> = async ({
data,
next,
}) => {
// Authenticate the user from the request and extract user's email address
const email = await getEmailFromRequest(request);
data.honeycomb.tracer.addData({ email });
return next();
};