Introduction
The Lescopr SDK integrates with React applications by initialising at the app entry point and optionally wrapping your component tree in an error boundary.
All unhandled JavaScript errors and explicit lescopr.log() calls are streamed in real-time to your Lescopr dashboard.
The package is available on npm and works with React 17+ and any bundler (Vite, Webpack, Parcel).
Requirements
- Node.js >= 16.0.0
- React >= 17.0
- A valid
LESCOPR_SDK_KEYandLESCOPR_API_KEY - A bundler: Vite, Webpack, CRA, or Parcel
Installation
Install via your package manager:
npm install lescoprConfiguration
Initialise at the very top of your main.tsx / index.tsx, before rendering the React tree:
Store your keys as environment variables (prefix with VITE_ for Vite, or REACT_APP_ for CRA):
Available options:
sdkKey— Your Lescopr SDK key (required)apiKey— Your Lescopr API key (required)environment—development(default) orproduction
import lescopr from 'lescopr';
lescopr.init({
sdkKey: import.meta.env.VITE_LESCOPR_SDK_KEY,
apiKey: import.meta.env.VITE_LESCOPR_API_KEY,
environment: import.meta.env.MODE,
});
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './App';
createRoot(document.getElementById('root')!).render(
<StrictMode><App /></StrictMode>
);VITE_LESCOPR_SDK_KEY=lsk_xxxx
VITE_LESCOPR_API_KEY=lak_xxxxUsage
Once initialised, uncaughtException and unhandledRejection are captured automatically at the window level.
You can also capture errors and log events manually:
import lescopr from 'lescopr';
async function handleCheckout() {
try {
await processOrder(cart);
lescopr.log('info', 'Order placed', { items: cart.length });
} catch (err) {
lescopr.captureException(err as Error);
throw err;
}
}Advanced
CLI initialisation
Run the CLI in the project root to auto-detect the framework and generate .lescopr.json:
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