csii-sentry-react
TypeScript icon, indicating that this package has built-in type declarations

5.29.0 • Public • Published


Official Sentry SDK for ReactJS

Links

General

This package is a wrapper around csii-sentry-browser, with added functionality related to React. All methods available in csii-sentry-browser can be imported from csii-sentry-react.

To use this SDK, call Sentry.init(options) before you mount your React component.

import React from 'react';
import ReactDOM from "react-dom";
import * as Sentry from 'csii-sentry-react';

Sentry.init({
  dsn: '__DSN__',
  // ...
});

// ...

ReactDOM.render(<App />, rootNode);

// Can also use with React Concurrent Mode
// ReactDOM.createRoot(rootNode).render(<App />);

ErrorBoundary

csii-sentry-react exports an ErrorBoundary component that will automatically send Javascript errors from inside a component tree to Sentry, and set a fallback UI. Requires React version >= 16.

app.js

import React from 'react';
import * as Sentry from 'csii-sentry-react';

function FallbackComponent() {
  return (
    <div>An error has occured</div>
  )
}

class App extends React.Component {
  render() {
    return (
      <Sentry.ErrorBoundary fallback={FallbackComponent} showDialog>
        <OtherComponents />
      </Sentry.ErrorBoundary>
    )
  }
}

export default App;

Profiler

csii-sentry-react exports a Profiler component that leverages the csii-sentry-tracing Tracing integration to add React related spans to transactions. If the Tracing integration is not enabled, the Profiler component will not work. The Profiler tracks component mount, render duration and updates. Requires React version >= 15.

app.js

import React from 'react';
import * as Sentry from 'csii-sentry-react';

class App extends React.Component {
  render() {
    return (
      <FancyComponent>
        <InsideComponent someProp={2} />
        <AnotherComponent />
      </FancyComponent>
    )
  }
}

export default Sentry.withProfiler(App);

Readme

Keywords

none

Package Sidebar

Install

npm i csii-sentry-react

Weekly Downloads

1

Version

5.29.0

License

BSD-3-Clause

Unpacked Size

189 kB

Total Files

59

Last publish

Collaborators

  • fqs