Introduction
The Lescopr SDK integrates with Vue.js by initialising at the app entry point and hooking into Vue's global error handler.
Every uncaught component error, unhandled promise rejection and explicit log call is streamed in real-time to your Lescopr dashboard.
The package is available on npm and works with Vue 3+.
Requirements
- Node.js >= 16.0.0
- Vue >= 3.0
- A valid
LESCOPR_SDK_KEYandLESCOPR_API_KEY - Vite or any modern bundler
Installation
Install via your package manager:
npm install lescoprConfiguration
Initialise the SDK in your main.ts / main.js before mounting the app, then hook it into Vue's global error handler:
Store your keys as environment variables:
Available options:
sdkKey— Your Lescopr SDK key (required)apiKey— Your Lescopr API key (required)environment—development(default) orproduction
import lescopr from 'lescopr';
import { createApp } from 'vue';
import App from './App.vue';
lescopr.init({
sdkKey: import.meta.env.VITE_LESCOPR_SDK_KEY,
apiKey: import.meta.env.VITE_LESCOPR_API_KEY,
environment: import.meta.env.MODE,
});
const app = createApp(App);
app.config.errorHandler = (err, instance, info) => {
lescopr.captureException(err as Error, { info });
};
app.mount('#app');VITE_LESCOPR_SDK_KEY=lsk_xxxx
VITE_LESCOPR_API_KEY=lak_xxxxUsage
Once initialised, all uncaught Vue component errors and unhandled promise rejections are captured automatically.
You can also log events and capture exceptions manually:
import lescopr from 'lescopr';
async function checkout() {
try {
await submitOrder(cart.value);
lescopr.log('info', 'Order placed');
} catch (err) {
lescopr.captureException(err as Error);
throw err;
}
}Advanced
CLI initialisation
Run the CLI in the project root:
Environment variables
LESCOPR_SDK_KEY— SDK keyLESCOPR_API_KEY— API keyLESCOPR_ENVIRONMENT—developmentorproductionLESCOPR_DEBUG=true— Verbose output to.lescopr.log
npx lescopr init --sdk-key YOUR_SDK_KEY