@thomas-adam-leigh/elenjical-react
v0.3.0
Published
Elenjical error tracking, session replay and logs for React applications.
Maintainers
Readme
@elenjical/react
Error tracking, session replay and logs for React applications, reported to Elenjical.
Install
npm install @elenjical/react@npm:@thomas-adam-leigh/elenjical-react@^0.3.0(@elenjical/react is the name your code imports; until the package is published under it, the alias installs
@thomas-adam-leigh/elenjical-react.)
Set up
Start the SDK before anything else renders, with your service's public DSN from Elenjical (Settings > Services):
import * as Elenjical from "@elenjical/react";
Elenjical.init({
dsn: import.meta.env.VITE_ELENJICAL_DSN, // undefined turns reporting off, e.g. in local development
environment: import.meta.env.VITE_ELENJICAL_ENVIRONMENT ?? "development",
release: import.meta.env.VITE_ELENJICAL_RELEASE,
integrations: [
Elenjical.browserTracingIntegration(), // forwards the trace to your API, linking its errors to this session
Elenjical.replayIntegration({ maskAllText: true, blockAllMedia: true }),
Elenjical.consoleLoggingIntegration({ levels: ["warn", "error"] }),
],
tracePropagationTargets: [/^\/api\//],
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
});Wrap the app so render errors are reported instead of leaving a blank page:
<Elenjical.ErrorBoundary fallback={<p>Something went wrong.</p>}>
<App />
</Elenjical.ErrorBoundary>Identify people when they sign in: Elenjical.setUser({ id, email, username }), and Elenjical.setUser(null) when
they sign out.
Feature flags
Read a flag where your code branches. Flags load the first time one is read, from the Elenjical server your DSN names; until they arrive, and whenever they cannot be read, every flag is off.
import { useFeatureFlagEnabled, useFeatureFlagPayload } from "@elenjical/react";
function Checkout() {
const onePage = useFeatureFlagEnabled("new-checkout");
return onePage ? <OnePageCheckout /> : <Checkout />;
}Outside components: Elenjical.isFeatureEnabled("new-checkout"), Elenjical.getFeatureFlagPayload(...), and
Elenjical.onFeatureFlags(callback) to run once they have loaded. Flags are for the person setUser names (an
anonymous id kept in the browser before that), and their errors report the flags read before them. If a flag's rule
reads something Elenjical may not have seen yet, send it first: Elenjical.setPersonPropertiesForFlags({ email }).
To start from values you already have, pass init({ ..., flags: { bootstrap: { featureFlags: { "new-checkout": true } } } }).
Session replay privacy
Mark elements in your markup:
| Attribute (or class) | Effect |
| ----------------------------------------- | ----------------------------------- |
| data-elenjical-mask (.elenjical-mask) | its text is replaced with asterisks |
| data-elenjical-unmask | shown even with maskAllText |
| data-elenjical-block | replaced by an empty box |
| data-elenjical-unblock | shown even with blockAllMedia |
| data-elenjical-ignore | its input events are not recorded |
Linking browser and API
Allow the trace headers in your API's CORS configuration: Elenjical.TRACE_HEADERS.
Source maps
Upload them from your build with @elenjical/vite-plugin.
See NOTICE for the open-source software this package is built on.
