Everything you need to integrate Patchly into your app.
npm install patchlyAlso works with pnpm, yarn, or bun.
import { init } from "patchly";
const patchly = init({
dsn: process.env.PATCHLY_DSN!, // required — from patchly.cc → Settings
release: "1.2.0", // optional — enables source map resolution
userId: "user_123", // optional — track affected users
autoCapture: true, // default: true — captures uncaught errors
});
// manual capture
patchly.capture(new Error("something broke"));
// flush on shutdown (Node.js)
await patchly.close();Your DSN is available in the Patchly dashboard under Settings. It follows this format:
https://<API_KEY>@api.patchly.cc/<PROJECT_ID>Add it to your .env file. Never commit it to version control.
Create at your project root:
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
const { init } = await import("patchly");
init({ dsn: process.env.PATCHLY_DSN! });
}
}Enable in next.config.ts:
const nextConfig = {
experimental: { instrumentationHook: true },
};
export default nextConfig;"use client";
import { useEffect } from "react";
import { init } from "patchly";
const patchly = init({ dsn: process.env.NEXT_PUBLIC_PATCHLY_DSN! });
export default function Error({
error,
reset,
}: {
error: Error;
reset: () => void;
}) {
useEffect(() => { patchly.capture(error); }, [error]);
return (
<div>
<h2>Something went wrong</h2>
<button onClick={reset}>Try again</button>
</div>
);
}# .env.local
PATCHLY_DSN=https://<key>@api.patchly.cc/<projectId>
NEXT_PUBLIC_PATCHLY_DSN=https://<key>@api.patchly.cc/<projectId>import { init } from "patchly";
const patchly = init({ dsn: process.env.PATCHLY_DSN! });
// Uncaught exceptions are captured automatically.
// For manual capture:
try {
riskyOperation();
} catch (err) {
patchly.capture(err as Error);
}
// Graceful shutdown
process.on("SIGTERM", async () => {
await patchly.close();
process.exit(0);
});Upload source maps so Patchly can show original file names and line numbers in stack traces.
curl -X POST https://api.patchly.cc/sourcemaps \
-H "Authorization: Bearer <API_KEY>" \
-F "release=1.2.0" \
-F "filePath=_next/static/chunks/app/page.js" \
-F "sourcemap=@.next/static/chunks/app/page.js.map"Set the release option in init() to match.
When an error group reaches 3 events, Patchly automatically fetches your source code from GitHub and generates a fix suggestion using an LLM. Fix suggestions include:
View and vote on fixes in the dashboard.
Configure Slack webhook or email alerts in Settings. Alerts fire when an error group exceeds your threshold count within a time window.
| Method | Description |
|---|---|
| init(config) | Initialize the SDK. Returns { capture, close }. |
| capture(error) | Manually capture an Error instance. |
| close() | Flush pending events and remove global handlers. |
| Option | Type | Description |
|---|---|---|
| dsn | string | Required. Your project DSN. |
| release | string? | App version. Enables source map resolution. |
| userId | string? | User identifier for affected-user tracking. |
| autoCapture | boolean? | Default true. Auto-capture uncaught errors. |
Patchly ships a SKILLS.md for Claude Code. Add it to your project so Claude can help integrate and debug Patchly errors:
curl -o PATCHLY.md https://patchly.cc/SKILLS.mdOr get a project-specific version with your DSN pre-filled from /skills.