AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

instrument-error-tracking

Add PostHog error tracking to capture and monitor exceptions. Use after implementing features or reviewing PRs to ensure errors are tracked with stack traces and source maps. Also handles initial PostHog SDK setup if not yet installed.

Original source
posthog
License
MIT
Pinned revision
cac7c80a9e5b73484d18eda1bffb47297c938e0c

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

Ask your assistant

Use Agentic Memory skills to read posthog--instrument-error-tracking at revision cac7c80a9e5b73484d18eda1bffb47297c938e0c, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 30

references/hono.md

AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt

Hono Error Tracking installation

Canonical URL: https://posthog.com/docs/error-tracking/installation/hono

Cloud region: This page uses US Cloud hosts. For an EU Cloud project, use https://eu.i.posthog.com instead of https://us.i.posthog.com (ingestion host), and use https://eu.posthog.com instead of https://app.posthog.com (app host for links).

On this page

  1. 1

    Install the package

    Required

    Install the PostHog Node.js library using your package manager:

    npm

    npm install posthog-node
    

    yarn

    yarn add posthog-node
    

    pnpm

    pnpm add posthog-node
    

    bun

    bun add posthog-node
    
  2. 2

    Initialize PostHog

    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. 3

    Send an event

    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. 4

    Exception handling example

    Required

    Hono uses app.onError to handle uncaught exceptions. You can take advantage of this for error tracking.

    Remember to export your project token as an environment variable.

    index.ts

    import { PostHog } from 'posthog-node'
    const posthog = new PostHog(process.env.POSTHOG_TOKEN, { host: 'https://us.i.posthog.com' })
    app.onError(async (err, c) => {
      posthog.captureException(err, 'user_distinct_id_with_err_rethrow', {
        path: c.req.path,
        method: c.req.method,
        url: c.req.url,
        headers: c.req.header(),
        // ... other properties
      })
      await posthog.flush()
      // other error handling logic
      return c.text('Internal Server Error', 500)
    })
    
  5. Verify error tracking

    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.

    Activity feed with events

    Check for exceptions in PostHog

  6. 5

    Upload source maps

    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.

    Upload source maps