Installation
Get started with ObserverKit in a few minutes.
Using an AI coding agent? Have it fetch the install prompt at observerkit.com/docs/web-install-prompt.md.
Install the package
terminal
pnpm add @observerkit/jsInitialize
Call init as early as possible in your application entry point. Uncaught errors and unhandled promise rejections are captured automatically.
main.tsx
import { StrictMode } from "react"
import { createRoot } from "react-dom/client"
import { init } from "@observerkit/js"
import { App } from "./App"
init({
projectKey: "ok_proj_...",
environment: "production",
})
createRoot(document.getElementById("root")!).render(
<StrictMode>
<App />
</StrictMode>
)Options
projectKeystringRequired. Your project key.autoCapturebooleanCapture uncaught errors automatically. Defaults to true.environmentstringEnvironment name, e.g. "production" or "staging".endpointURLCustom ingest API URL.servicestringOptional. Distinguishes services within one project, e.g. multiple apps in a monorepo. Auto-created on first event, up to 20 per project.Capture errors manually
Errors are captured automatically by default. You can also report them manually with additional metadata.
file.ts
import { captureException } from "@observerkit/js"
try {
await fetchUserData()
} catch (error) {
captureException(error, {
metadata: { userId: "usr_123" },
})
}Verify
Trigger a test error in your application. If everything is set up correctly, it will appear in your dashboard within a few seconds.
<button
onClick={() => {
throw new Error("test error")
}}
>
Throw test error
</button>