Skip to content

Commit

Permalink
Test errors from the browser console (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-GG authored Oct 31, 2024
1 parent e25e9a2 commit 139568e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ SENTRY_VUE_INTEGRATION_REPLAY=true

Check out the [sentry/sentry-laravel readme](https://github.com/getsentry/sentry-laravel) for configuration of the laravel package.

## Testing

Errors thrown directly from the browser console don't get caught by Sentry, so you can test whether or not the frontend error reporting works by sending a test error in the browser console with:

```js
document.dispatchEvent(new Event('sentry-test-error'))
```

This functionality can be disabled in your `.env`:

```
SENTRY_VUE_ALLOW_TEST_ERRORS=false
```

## License

GNU General Public License v3. Please see [License File](LICENSE) for more information.
1 change: 1 addition & 0 deletions config/rapidez/sentry-vue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Configuration as defined in the docs: https://docs.sentry.io/platforms/javascript/guides/vue/configuration/
'configuration' => [
'enabled' => env('SENTRY_VUE_ENABLED', true),
'allow_test_errors' => env('SENTRY_VUE_ALLOW_TEST_ERRORS', true),

// Amount of errors to be logged to sentry (1.00 = 100%)
'sampleRate' => env('SENTRY_VUE_SAMPLE_RATE', 100) / 100,
Expand Down
7 changes: 7 additions & 0 deletions resources/js/sentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ document.addEventListener('turbo:load', async () => {
window.app.$on(['logged-in', 'logout'], () => setUser(window.app.user))
setUser(window.app.user)
})

// Allow test errors to be sent from the browser console with `document.dispatchEvent(new Event('sentry-test-error'))`
if(window.config.sentry.configuration.allow_test_errors) {
document.addEventListener('sentry-test-error', () => {
throw new Error('Sentry test error')
})
}

0 comments on commit 139568e

Please sign in to comment.