> ## Documentation Index
> Fetch the complete documentation index at: https://docs.appsignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Cloudflare Workers

export const VersionRequirements = ({versions = []}) => {
  if (!Array.isArray(versions) || versions.length === 0) {
    return null;
  }
  const boundaries = {
    upper: " or lower",
    exact: "",
    lower: " or higher"
  };
  const containerStyle = {
    marginTop: "0.5rem",
    marginBottom: "1.5rem"
  };
  const lineStyle = {
    display: "block",
    margin: "0 0 0.35rem 0",
    fontSize: "0.875rem",
    lineHeight: "1.4"
  };
  const pillBaseStyle = {
    display: "inline-block",
    padding: "0.1em 0.4em",
    borderRadius: "0.25rem",
    border: "1px solid",
    fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
    fontSize: "0.85em",
    fontWeight: 500
  };
  const pillColors = {
    "AppSignal for Elixir": {
      background: "#f3e8ff",
      borderColor: "#e9d5ff",
      color: "#9333ea"
    },
    "AppSignal for Front-end": {
      background: "#fef9c3",
      borderColor: "#fde68a",
      color: "#ca8a04"
    },
    "AppSignal for Go": {
      background: "#ccfbf1",
      borderColor: "#99f6e4",
      color: "#0d9488"
    },
    "AppSignal for JavaScript": {
      background: "#fef9c3",
      borderColor: "#fde68a",
      color: "#ca8a04"
    },
    "AppSignal for Node.js": {
      background: "#dcfce7",
      borderColor: "#bbf7d0",
      color: "#16a34a"
    },
    "AppSignal for Python": {
      background: "#dbeafe",
      borderColor: "#bfdbfe",
      color: "#2563eb"
    },
    "AppSignal for Ruby": {
      background: "#fee2e2",
      borderColor: "#fecaca",
      color: "#dc2626"
    },
    "AppSignal for Rust": {
      background: "#ffedd5",
      borderColor: "#fed7aa",
      color: "#ea580c"
    }
  };
  const defaultPillColor = {
    background: "#f4f4f5",
    borderColor: "#e4e4e7",
    color: "#52525b"
  };
  const getPillStyle = name => ({
    ...pillBaseStyle,
    ...pillColors[name] || defaultPillColor
  });
  const getBoundText = bound => {
    return boundaries[bound] || boundaries.lower;
  };
  return <div style={containerStyle}>
      {versions.map((v, i) => <p key={`${v.name}-${v.version}-${v.bound || "lower"}-${i}`} style={lineStyle}>
          This feature requires{" "}
          <code style={getPillStyle(v.name)}>{v.name}</code> version {v.version}
          {getBoundText(v.bound)}.
        </p>)}
    </div>;
};

<VersionRequirements
  versions={[
{ name: "AppSignal for JavaScript", version: "1.3.26" }
]}
/>

A Cloudflare Workers application can report errors to AppSignal using the [AppSignal for JavaScript](/front-end) integration. It reports errors only, with no performance data, traces, or metrics.

<h2 id="module-workers">
  Module workers
</h2>

A module worker receives its secrets and environment variables on the `env` argument of the `fetch` handler. Create the `Appsignal` instance inside the handler, where `env` is available.

<h2 id="set-up">
  Set up
</h2>

Add the package to your worker project:

<CodeGroup>
  ```bash Bash theme={null}
  npm install @appsignal/javascript
  ```
</CodeGroup>

Store the Front-end API key for the app you want to report to, listed under the ["Push & deploy" section](https://appsignal.com/redirect-to/app?to=info) of that app's settings, as a worker secret:

<CodeGroup>
  ```bash Bash theme={null}
  wrangler secret put APPSIGNAL_API_KEY
  ```
</CodeGroup>

<Warning>
  A wrong key fails silently: the Push API responds with a `401`, `sendError` discards it, and you get no log line and no incident. Trigger an error after your first deploy and confirm it appears in AppSignal.
</Warning>

Create the instance in the `fetch` handler, and pass caught errors to `sendError`:

<CodeGroup>
  ```javascript JavaScript theme={null}
  import Appsignal from "@appsignal/javascript";

  let appsignal;

  export default {
    async fetch(request, env) {
      if (!appsignal) {
        appsignal = new Appsignal({ key: env.APPSIGNAL_API_KEY });
      }

      try {
        // Your worker logic
        return await handleRequest(request);
      } catch (error) {
        await appsignal.sendError(error);
        return new Response("Internal server error", { status: 500 });
      }
    },
  };
  ```
</CodeGroup>

Uncaught exceptions are [not reported automatically](/front-end/error-handling#uncaught-exceptions), so catch errors in your worker and pass them to `sendError` yourself. For the options you can set on the instance, see the [configuration section](/front-end/configuration). For the metadata you can add to an error, see the [error handling guide](/front-end/error-handling).

<h2 id="further-reading">
  Further reading
</h2>

Our blog post ["How to debug Cloudflare Workers with AppSignal"](https://blog.appsignal.com/2021/09/15/how-to-debug-cloudflare-workers-with-appsignal.html) walks through a worker project from scratch.
