Skill 76 · Instrument Error Tracking
Subchapter 76.13
references/hono.mdMarkdown3 KBView on GitHub
AI agents: this is one page from PostHog’s docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt (opens in a new tab)
1
Required
Install the PostHog Node.js library using your package manager:
npm install posthog-nodeyarn add posthog-nodepnpm add posthog-nodebun add posthog-node2
Required
Initialize the PostHog client with your project token:
Node.js
import { PostHog } from 'posthog-node'
const client = new PostHog(
'<ph_project_token>',
{
host: 'https://us.i.posthog.com'
}
)3
Recommended
Once installed, you can manually send events to test your integration:
Node.js
client.capture({
distinctId: 'distinct_id_of_the_user',
event: 'event_name',
properties: {
property1: 'value',
property2: 'value',
},
})4
Required
Hono uses app.onError (opens in a new tab) to handle uncaught exceptions. You can take advantage of this for error tracking.
Remember to export your project token (opens in a new tab) as an environment variable.
index.ts
import
Recommended
Confirm events are being sent to PostHog
Before proceeding, let’s make sure exception events are being captured and sent to PostHog. You should see events appear in the activity feed.

5
Required
Great, you’re capturing exceptions! If you serve minified bundles, the next step is to upload source maps to generate accurate stack traces.
Let’s continue to the next section.
Ask PostHog AI
HelpfulCould be better