nuxt-posthog
nuxt-posthog copied to clipboard
Feature request: Add posthog error tracking features
Hello, is it possible to implement all error tracking features as listed here?: https://posthog.com/docs/error-tracking/installation?tab=Nuxt
- Capture vue errors via hook
- Source maps uploading
Thanks!
@mitjans Im not certain, but maybe adding :
module.ts
/**
* If set to true, the module will catch server-side errors and log them to PostHog.
* @default true
* @type boolean
*/
captureServerErrors?: boolean;
/**
* If set to true, the module will catch client-side errors and log them to PostHog.
* @default true
* @type boolean
*/
captureClientErrors?: boolean;
...
captureServerErrors: true,
captureClientErrors: true,
posthog.server.ts
if (config.captureServerErrors) {
nuxtApp.hook('app:error', (error) => {
posthog.captureException(error);
});
}
posthog.client.ts
if (config.captureClientErrors) {
nuxtApp.hook('vue:error', (error) => {
posthog.captureException(error);
});
}
would be enough?
@mitjans please look at the suggestion from @rafazafar . Looks really easy to implement. I solved the source maps myself, but would also be nice...
Sourcemap example via nuxt.config.ts:
'nitro:build:public-assets': async (nitro) => {
// Upload sourcemaps to posthog in production
if (process.env.ENV === 'production') {
console.log('Running PostHog sourcemap injection...');
try {
execSync(
'posthog-cli --host https://eu.posthog.com sourcemap inject --directory ' + nitro.options.output.publicDir,
{
stdio: 'inherit',
},
);
console.log('PostHog sourcemap injection completed successfully');
}
catch (error) {
console.error('PostHog sourcemap injection failed:', error);
}
console.log('Running PostHog sourcemap upload...');
try {
execSync(
'posthog-cli --host https://eu.posthog.com sourcemap upload --directory ' + nitro.options.output.publicDir,
{
stdio: 'inherit',
},
);
console.log('PostHog sourcemap upload completed successfully');
}
catch (error) {
console.error('PostHog sourcemap upload failed:', error);
}
}
},
```