Connect Vue to Bugsink
When a Vue component fails in a user’s browser, Bugsink can show you the
exception, the component involved, and the original .vue line behind the
production bundle.
This guide adds error reporting to a Vue application, prepares its source maps, and triggers a deliberate component error. To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.
Install the Vue SDK
Install the open-source Sentry SDK for Vue. Bugsink accepts the Sentry event protocol, so the SDK can send errors directly to your Bugsink project:
npm install @sentry/vuenpm install @sentry/vue
Initialize the SDK with your Vue application
Create the Vue application first, then pass that application instance to
Sentry.init before mounting it. The Vue integration can then receive errors
from the component lifecycle and attach the component name and props that Vue
makes available.
Vite exposes variables prefixed with VITE_ to browser code, so this example
reads the project DSN from VITE_SENTRY_DSN. A DSN identifies the destination
project; it is not an administrative or source-map upload token:
import * as Sentry from "@sentry/vue"; import { createApp } from "vue"; import App from "./App.vue"; import "./styles.css"; const app = createApp(App); Sentry.init({ app, dsn: import.meta.env.VITE_SENTRY_DSN, }); app.mount("#app");import * as Sentry from "@sentry/vue"; import { createApp } from "vue"; import App from "./App.vue"; import "./styles.css"; const app = createApp(App); Sentry.init({ app, dsn: import.meta.env.VITE_SENTRY_DSN, }); app.mount("#app");
Prepare production source maps
Production Vite builds bundle and minify your Vue components. Source maps let Bugsink translate a generated browser frame back to the single-file component and line you edit. Tell Vite to retain a source map when it builds:
import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; export default defineConfig({ build: { sourcemap: true, }, plugins: [vue()], });import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; export default defineConfig({ build: { sourcemap: true, }, plugins: [vue()], });
Supply your Bugsink DSN when Vite creates the browser bundle:
VITE_SENTRY_DSN=https://key@bugsink.example/1 npm run buildVITE_SENTRY_DSN=https://key@bugsink.example/1 npm run build
Upload source maps to Bugsink
sentry-cli adds the same debug ID to a bundle and its source map, then
uploads both to Bugsink. Create a project-bound Bugsink token with the
debug-files:upload capability and keep it in your build environment rather
than in browser code.
Inject the debug IDs after the build:
npx --yes @sentry/cli sourcemaps inject ./distnpx --yes @sentry/cli sourcemaps inject ./dist
Then upload the result. Bugsink has no organization object, so --org is only
a compatibility value. Replace the URL and project slug with your own:
SENTRY_AUTH_TOKEN=your-project-token \ npx --yes @sentry/cli \ --url https://bugsink.example \ sourcemaps --org bugsink --project your-project-slug upload ./distSENTRY_AUTH_TOKEN=your-project-token \ npx --yes @sentry/cli \ --url https://bugsink.example \ sourcemaps --org bugsink --project your-project-slug upload ./dist
Upload source maps for every production build before it can report errors.
You may remove the .map files from dist after a successful upload if you do
not want the web server to publish them.
Trigger a component error
Errors from Vue event handlers pass through the application’s error handler, so you do not need a capture call in each component. This inventory action throws an application exception through the normal click lifecycle:
reserve() { const requested = 1; if (requested > this.available) { throw new ProductUnavailableError( `Cannot reserve ${requested} unit of ${this.sku}: only ${this.available} remain [vue-browser]`, ); } },reserve() { const requested = 1; if (requested > this.available) { throw new ProductUnavailableError( `Cannot reserve ${requested} unit of ${this.sku}: only ${this.available} remain [vue-browser]`, ); } },
Serve the production build, open the page, and click Reserve item:
npm run previewnpm run preview
The component remains ordinary Vue code. The SDK reports the uncaught error
in the background and includes <InventoryItem> plus its available, name,
and sku props as Vue context.
See the original Vue component in Bugsink
Open the new issue in Bugsink. The source map translates the optimized browser bundle back to the single-file component and shows the exact line that threw.
ProductUnavailableError
That’s it: Vue component failures now reach Bugsink with the component context and original source behind the production bundle. Remove the deliberate error and keep the same initialization and source-map steps in your application.
Limitations
The automatic uploader in @sentry/vite-plugin 11.15.0 currently rejects the
relative chunk-upload URL returned by Bugsink with SentryError: Invalid URL.
The plugin does generate the map and inject a runtime debug ID, but it does not
send the bundle. Use the verified explicit sentry-cli steps above until the
exchange tracked in Bugsink issue
#157 is fixed.
For SDK-wide capture options and other browser frameworks, return to the JavaScript guide.
