Vue
To use Sentry with your Vue application, you will need to use Sentry’s browser JavaScript SDK: @sentry/browser.
npm install --save @sentry/browser @sentry/integrationsOn its own, @sentry/browser will report any uncaught exceptions triggered by your application.
Additionally, the Vue integration will capture the name and props state of the active component where the error was thrown. This is reported via Vue’s config.errorHandler hook.
Then add this to your app.js:
import Vue from "vue";
import * as Sentry from "@sentry/browser";
import { Vue as VueIntegration } from "@sentry/integrations";
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
integrations: [new VueIntegration({ Vue, attachProps: true })],
});Additionally, Integrations.Vue accepts a few different configuration options that let you change its behavior:
- Passing in
Vueis optional, if you do not pass itwindow.Vuemust be present. - Passing in
attachPropsis optional and istrueif it is not provided. If you set it tofalse, Sentry will suppress sending all Vue components' props for logging. - Passing in
logErrorsis optional and isfalseif it is not provided. If you set it totrue, Sentry will call original Vue'slogErrorfunction as well.
Vue Error Handling
Please note that if you enable this integration, Vue will not call its logError internally. This means that errors occurring in the Vue renderer will not show up in the developer console.
If you want to preserve this functionality, make sure to pass the logErrors: true option.
In case you are using the CDN version or the Loader, we provide a standalone file for every integration, you can use it like this:
<!-- Note that we now also provide a es6 build only -->
<!-- <script src="https://browser.sentry-cdn.com/5.25.0/bundle.es6.min.js" integrity="sha384-hkwF8uNuWxp222vkQQyQsLKwSz/v/SRtfePmH0clVFwqLuxWcaKlWnQtJXegxQaR" crossorigin="anonymous"></script> -->
<script
src="https://browser.sentry-cdn.com/5.25.0/bundle.min.js"
integrity="sha384-2p7fXoWSRPG49ZgmmJlTEI/01BY1LgxCNFQFiWpImAERmS/bROOQm+cJMdq/kmWS"
crossorigin="anonymous"
></script>
<!-- If you include the integration it will be available under Sentry.Integrations.Vue -->
<script
src="https://browser.sentry-cdn.com/5.25.0/vue.min.js"
integrity="sha384-2N7Ym5Xq2tbEGuDRYVYY1fmAj2zZgR38wcPnX8nFwtOqL7Cjk0avM2R0GJ/ywIxq"
crossorigin="anonymous"
></script>
<script>
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
integrations: [new Sentry.Integrations.Vue({ Vue, attachProps: true })],
});
</script>Monitor Performance
npm install --save @sentry/browser @sentry/integrations @sentry/tracingThe most basic configuration for tracing your Vue app, which would track only the top-level component, looks like this:
import * as Sentry from "@sentry/browser";
import { Vue as VueIntegration } from "@sentry/integrations";
import { Integrations } from "@sentry/tracing";
import Vue from "vue";
Sentry.init({
// ...
integrations: [
new Integrations.BrowserTracing(),
new VueIntegration({
Vue,
tracing: true,
}),
],
// We recommend adjusting this value in production, or using tracesSampler
// for finer control
tracesSampleRate: 1.0,
});If you want to track child components, and see more details about the rendering process, configure the integration to track them all:
new VueIntegration({
Vue,
tracing: true,
tracingOptions: {
trackComponents: true,
},
});- Package:
- npm:@sentry/browser
- Version:
- 5.25.0
- Repository:
- https://github.com/getsentry/sentry-javascript