- 1
Install PostHog Node.js SDK
RequiredError tracking enables you to track, investigate, and resolve exceptions your customers face. Start by installing the
posthog-node
package using your package manager:Terminalnpm install --save posthog-node - 2
Exception handling example
RequiredHono uses
app.onError
to handle uncaught exceptions. You can take advantage of this for error tracking. Remember to export your project API key as an environment variable.index.tsimport { env } from 'hono/adapter'import { PostHog } from 'posthog-node'app.onError((err, c) => {const { POSTHOG_PUBLIC_KEY } = env<{ POSTHOG_PUBLIC_KEY:string }>(c)const posthog = new PostHog(POSTHOG_PUBLIC_KEY, { host: 'https://us.i.posthog.com' })posthog.captureException(new Error(err.message, { cause: 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})posthog.shutdown()// other error handling logicreturn c.text('Internal Server Error', 500)}) - 4
Hono error tracking installation
Questions? Ask Max AI.
It's easier than reading through 698 pages of documentation
Community questions
Was this page useful?
Next article
Manual error tracking installation
Error tracking enables you to track, investigate, and resolve exceptions your customers face. If you're using a different SDK or the API, you can manually capture errors by using the capture API or calling the capture method to capture an $exception event with the following properties: Property Description $exception_list A list of exception objects with detailed information about each error $exception_fingerprint (Optional) The identifier used to group issues. If not set, a unique hash…