Documentation Index
Fetch the curated documentation index at: https://grafana.com/llms.txt
Fetch the complete documentation index at: https://grafana.com/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: https://grafana.com/docs/grafana-cloud/monitor-applications/frontend-observability/instrument/faro-react/error-boundary.md (append .md) or send Accept: text/markdown to https://grafana.com/docs/grafana-cloud/monitor-applications/frontend-observability/instrument/faro-react/error-boundary/. For the curated documentation index, use https://grafana.com/llms.txt. For the complete documentation index, use https://grafana.com/llms-full.txt.
React ErrorBoundary support
In React error boundaries are components that allow you to render a fallback UI in case an error occurs in the respective React component tree.
Faro provides its own error boundary component which enhances the standard React error boundary with Faro specific functionality.
In case of an error it sends a Faro error event which contains the error message, the React component stack of the component which contains the exception, and the name of name of the error boundary if configured.
import { getWebInstrumentations, initializeFaro, ReactIntegration } from '@grafana/faro-react';
initializeFaro({
// ...
instrumentations: [
// Load the default Web instrumentations
...getWebInstrumentations(),
// minimum setup to get the FaroErrorBoundary support
new ReactIntegration(),
],
});import { FaroErrorBoundary } from '@grafana/faro-react';
// during render
<FaroErrorBoundary>
<App />
</FaroErrorBoundary>;or
import { withErrorBoundary } from '@grafana/faro-react';
export default withErrorBoundary(App);FaroErrorBoundary properties
Configuration options:
fallback: The fallback UI to render instead, either:- a
ReactElement FaroErrorBoundaryFallbackRenderfunction that passes the Error object and a callback function to reset the error boundary to it’s initial state when called
- a
pushErrorOptions: Options passed to thepushErrorAPI, for example additional context to an error
Lifecycle callbacks:
beforeCapture: Executed before the FaropushErrorAPI call, with the Error object as a parameteronError: Executed when an error occurs, with the Error object as a parameteronMount: Executed when React calls thecomponentDidMountlifecycle hookonUnmount: Executed when React calls thecomponentWillUnmountlifecycle hook, with the Error object as a parameteronReset: Executed when React callsresetErrorBoundary, with the Error object as a parameter
import { FaroErrorBoundary, PushErrorOptions } from '@grafana/faro-react';
const pushErrorOptions: PushErrorOptions = {
type: "Custom Error Type"
context: {
foo: "bar",
baz: "abc"
},
};
// during render
<FaroErrorBoundary
beforeCapture={(error) => handleBeforeCapture(error)}
onError={(error) => handleError(error)}
onMount={() => handleOnMount()}
onUnmount={(error) => handleUnmount(error)}
onReset={(error) => handleReset(error)}
pushErrorOptions={pushErrorOptions}
fallback={(error, resetBoundary) => {
return errorBoundaryFallbackRenderer(error, resetBoundary) }}
>
<App />
</FaroErrorBoundary>;Was this page helpful?
Related resources from Grafana Labs


