Skip to content

Commit b7a9a6c

Browse files
committed
feat: Add performance docs for react
1 parent c91050d commit b7a9a6c

File tree

1 file changed

+90
-0
lines changed
  • src/collections/_documentation/performance-monitoring/configuration

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
To get started with performance monitoring using Sentry's React SDK, first install the `@sentry/react` and `@sentry/apm` packages:
2+
3+
```bash
4+
# Using yarn
5+
$ yarn add @sentry/react @sentry/apm
6+
7+
# Using npm
8+
$ npm install @sentry/react @sentry/apm
9+
```
10+
11+
Next, initialize the integration in your call to `Sentry.init`. Make sure this happens before you mount your React component on the page.
12+
13+
```jsx
14+
import * as Sentry from '@sentry/react';
15+
import { Integrations } from "@sentry/apm";
16+
Sentry.init({
17+
dsn: '"___PUBLIC_DSN___"',
18+
release: 'my-project-name@' + process.env.npm_package_version,
19+
integrations: [
20+
new Integrations.Tracing(),
21+
],
22+
tracesSampleRate: 0.25, // must be present and non-zero
23+
});
24+
25+
// ...
26+
27+
ReactDOM.render(<App />, rootNode);
28+
29+
// Can also use with React Concurrent Mode
30+
// ReactDOM.createRoot(rootNode).render(<App />);
31+
```
32+
33+
### `withProfiler` Higher-Order Component
34+
35+
`@sentry/react` exports a `withProfiler` Higher-Order Component that leverages the `@sentry/apm` Tracing integration to add React related spans to transactions. If the Tracing integration is not enabled, the Profiler will not work.
36+
37+
In the example below, the `withProfiler` Higher-Order Component is used to instrument an App component.
38+
39+
```jsx
40+
import React from 'react';
41+
import * as Sentry from '@sentry/react';
42+
43+
class App extends React.Component {
44+
render() {
45+
return (
46+
<FancyComponent>
47+
<NestedComponent someProp={2} />
48+
<AnotherComponent />
49+
</FancyComponent>
50+
)
51+
}
52+
}
53+
54+
export default Sentry.withProfiler(App);
55+
```
56+
57+
The React Profiler current generates spans with three different kinds of op codes: `react.mount`, `react.render`, and `react.update`.
58+
59+
1. `react.mount` is the span that represents how long it took for the profiled component to mount.
60+
61+
2. `react.render` is the span that represents how long the profiled component was on a page. This span is only generated if the profiled component unmounts.
62+
63+
2. `react.update` is the span that represents when the profiled component updated.
64+
65+
{% capture __alert_content -%}
66+
In [React Strict Mode](https://reactjs.org/docs/strict-mode.html), certain component methods will be [invoked twice](https://reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects). This may lead to duplicate `react.mount` spans appearing in a transaction. React Strict Mode only runs in development mode, so this should have no impact on your production traces.
67+
{%- endcapture -%}
68+
{%- include components/alert.html
69+
title="Note"
70+
content=__alert_content
71+
level="warning"
72+
%}
73+
74+
The `withProfiler` higher order component has a variety options for further customization. They can be passed in as the second argument to the `withProfiler` function.
75+
76+
```jsx
77+
export default Sentry.withProfiler(App, { name: "CustomAppName" })
78+
```
79+
80+
#### `name` (string)
81+
82+
The name of the component being profiled. By default, the name is taken from the component `displayName` property or the component `name` property.
83+
84+
#### `includeRender` (boolean)
85+
86+
If a `react.render` span should be created by the Profiler. Set as true by default.
87+
88+
#### `includeUpdates` (boolean)
89+
90+
If `react.update` spans should be created by the Profiler. Set as true by default. You should set this prop as false for that components experience that will many rerenders, as text input components, as the resulting spans can become very noisy.

0 commit comments

Comments
 (0)