Skip to content

Commit 076a98b

Browse files
committed
feat: Add performance docs for react
1 parent 6b38ded commit 076a98b

File tree

1 file changed

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

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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`:
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 component will not work.
36+
37+
In the example below, uses the `withProfiler` Higher Order Component 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+
<InsideComponent someProp={2} />
48+
<AnotherComponent />
49+
</FancyComponent>
50+
)
51+
}
52+
}
53+
54+
export default Sentry.withProfiler(App);
55+
```
56+
57+
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.
58+
59+
```jsx
60+
export default Sentry.withProfiler(App, { name: "CustomAppName" })
61+
```
62+
63+
#### `name` (string)
64+
65+
The name of the component being profiled. Normally the name is taken from the component `displayName` or component `name`.
66+
67+
#### `disabled` (boolean)
68+
69+
If the Profiler should be disabled or not.
70+
71+
#### `includeRender` (boolean)
72+
73+
74+
75+
<!--
76+
// The name of the component being profiled.
77+
name: string;
78+
// If the Profiler is disabled. False by default. This is useful if you want to disable profilers
79+
// in certain environments.
80+
disabled?: boolean;
81+
// If time component is on page should be displayed as spans. True by default.
82+
includeRender?: boolean;
83+
// If component updates should be displayed as spans. True by default.
84+
includeUpdates?: boolean;
85+
// props given to component being profiled.
86+
updateProps: { [key: string]: any };
87+
-->

0 commit comments

Comments
 (0)