Vue

On this page, we get you up and running with Sentry's SDK, so that it will automatically report errors and exceptions in your application.

Don't already have an account and Sentry project established? Head over to sentry.io, then return to this page.

Install

Sentry captures data by using an SDK within your application’s runtime.

Copied
npm install --save  @sentry/vue @sentry/tracing

Configure

Configuration should happen as early as possible in your application's lifecycle.

To initialize Sentry in your Vue application, add this to your app.js:

Copied
import Vue from "vue";
import * as Sentry from "@sentry/vue";
import { Integrations } from "@sentry/tracing";

Sentry.init({
  Vue: Vue,
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  integrations: [new Integrations.BrowserTracing()],

  // We recommend adjusting this value in production, or using tracesSampler
  // for finer control
  tracesSampleRate: 1.0,
});

Sentry's Vue SDK accepts a few different configuration options that let you change its behavior:

  • Passing in Vue is optional. If you do not pass it, window.Vue must be present.
  • Passing in attachProps is optional and is true if it is not provided. If set to false, Sentry will suppress sending all Vue components' props for logging.
  • Passing in logErrors is optional and is false if it is not provided. If set to true, Sentry will call original Vue's logError function as well.

Verify

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:

Add a button to your page that throws an error:

App.vue
Copied
// ...
<button :onClick="throwError" />
    Throw error
</button>
// ...

export default {
  // ...
  methods: {
    throwError: function() {
        throw new Error('Sentry Error')
    }
  }
};

To view and resolve the recorded error, log into sentry.io and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").