@grafana/agent-integration-react
DEPRECATED Project has been moved to @grafana/faro-react
Grafana JavaScript Agent package that enables easier integration in projects built with React.
Warning: currently pre-release and subject to frequent breaking changes. Use at your own risk.
Out of the box, the package provides you the following features:
- Error Boundary - Provides additional stacktrace for errors
- Component Profiler - Capture every re-render of a component, the un/mounting time etc.
- Router (v4-v6) integration - Send events for all route changes
- SSR support
Installation
import { createRoutesFromChildren, matchRoutes, Routes, useLocation, useNavigationType } from 'react-router-dom';
import {
getWebInstrumentations,
initializeGrafanaAgent,
ReactIntegration,
ReactRouterVersion,
} from '@grafana/agent-integration-react';
import { TracingInstrumentation } from '@grafana/agent-tracing-web';
initializeGrafanaAgent({
instrumentations: [
...getWebInstrumentations(),
new TracingInstrumentation(),
new ReactIntegration({
router: {
version: ReactRouterVersion.V6,
dependencies: {
createRoutesFromChildren,
matchRoutes,
Routes,
useLocation,
useNavigationType,
},
},
router2: {
version: ReactRouterVersion.V5,
dependencies: {
history,
Route,
},
},
}),
],
});
Usage
Error Boundary
import { GrafanaAgentErrorBoundary } from '@grafana/agent-integration-react';
<GrafanaAgentErrorBoundary>
<App />
</GrafanaAgentErrorBoundary>;
or
import { withErrorBoundary } from '@grafana/agent-integration-react';
export default withErrorBoundary(App);
Router
V6
import { GrafanaAgentRoutes } from '@grafana/agent-integration-react';
<GrafanaAgentRoutes>
<Route path="/" element={<Home />} />
{/* ... */}
</GrafanaAgentRoutes>;
V4/v5
import { GrafanaAgentRoute } from '@grafana/agent-integration-react';
<Switch>
<GrafanaAgentRoute path="/">
<Home />
</GrafanaAgentRoute>
{/* ... */}
</Switch>;
Profiler
import { withGrafanaAgentProfiler } from '@grafana/agent-integration-react';
export default withGrafanaAgentProfiler(App);