Skip to content

Commit b01e0cd

Browse files
AbhiPrasaddashedMimiDumpling
authored
feat: Add performance docs for react (#1792)
Co-authored-by: Alberto Leal <[email protected]> Co-authored-by: Tien "Mimi" Nguyen <[email protected]>
1 parent c649c0b commit b01e0cd

File tree

2 files changed

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

2 files changed

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

src/collections/_documentation/performance-monitoring/setup.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Supported SDKs for Tracing
1212
- JavaScript Browser SDK ≥ 5.16.0
1313
- JavaScript Node SDK ≥ 5.16.0
1414
- Python SDK version ≥ 0.11.2
15+
- Javascript React SDK ≥ 5.18.1
1516

1617
{%- endcapture -%}
1718
{%- include components/alert.html

0 commit comments

Comments
 (0)