Posthog (frontend app tracking)
Exception Tracking
We've enabled automatic exception capturing in PostHog to help monitor and debug errors in the application.
PostHog automatically captures $exception events when errors are thrown by wrapping the window.onerror and window.onunhandledrejection listeners.
Additionally; our ErrorBoundary is configured to capture and log any unhandled exceptions.
Viewing Exceptions
All captured exceptions can be viewed in the PostHog Error Tracking dashboard.
Manual Exception Logging
For cases where you need to manually log exceptions, use the usePosthogExceptions hook:
import { usePosthogExceptions } from "src/utils/hooks/usePosthogExceptions";
const ExampleComponent = () => {
const logException = usePosthogExceptions();
const handleError = () => {
try {
// We want to know if the code here fails
} catch (error) {
logException(error, {
context: "Additional error info",
component: "ExampleComponent",
});
}
};
// ...
};
Exception Parameters
error: TheErrorobject to loginfo(optional): Additional context as key-value pairs
Fallback Behaviour
If PostHog isn't initialised, errors are logged to the console as a fallback.
Best Practices
- Use for unexpected errors and exceptions
- Include relevant context in the info parameter
- Don't log secure information
- Don't log expected errors