React — Lescopr SDK

Integrate the Lescopr SDK into your React application for automatic error capture and real-time monitoring, from installation to configuration.

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_KEY and LESCOPR_API_KEY
  • A bundler: Vite, Webpack, CRA, or Parcel

Installation

Install via your package manager:

Terminal
bash
npm install lescopr

Configuration

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) or production
src/main.tsx
typescript
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>
);
.env
dotenv
VITE_LESCOPR_SDK_KEY=lsk_xxxx
VITE_LESCOPR_API_KEY=lak_xxxx

Usage

Once initialised, uncaughtException and unhandledRejection are captured automatically at the window level.

You can also capture errors and log events manually:

src/components/Checkout.tsx
typescript
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 key
  • LESCOPR_API_KEY — API key
  • LESCOPR_ENVIRONMENT — development or production
  • LESCOPR_DEBUG=true — Verbose output to .lescopr.log
Terminal
bash
npx lescopr init --sdk-key YOUR_SDK_KEY