-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: Add performance docs for react #1792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
src/collections/_documentation/performance-monitoring/configuration/react.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
|
||
**React** | ||
|
||
To get started with performance monitoring using Sentry's React SDK, first install the `@sentry/react` and `@sentry/apm` packages: | ||
|
||
```bash | ||
# Using yarn | ||
$ yarn add @sentry/react @sentry/apm | ||
|
||
# Using npm | ||
$ npm install @sentry/react @sentry/apm | ||
``` | ||
|
||
Next, initialize the integration in your call to `Sentry.init`. Make sure this happens before you mount your React component on the page. | ||
|
||
```jsx | ||
import * as Sentry from '@sentry/react'; | ||
import { Integrations } from "@sentry/apm"; | ||
Sentry.init({ | ||
dsn: '"___PUBLIC_DSN___"', | ||
release: 'my-project-name@' + process.env.npm_package_version, | ||
integrations: [ | ||
new Integrations.Tracing(), | ||
], | ||
tracesSampleRate: 0.25, // must be present and non-zero | ||
}); | ||
|
||
// ... | ||
|
||
ReactDOM.render(<App />, rootNode); | ||
|
||
// Can also use with React Concurrent Mode | ||
// ReactDOM.createRoot(rootNode).render(<App />); | ||
``` | ||
|
||
**`withProfiler` Higher-Order Component** | ||
|
||
`@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. | ||
|
||
In the example below, the `withProfiler` higher-order component is used to instrument an App component. | ||
|
||
```jsx | ||
import React from 'react'; | ||
import * as Sentry from '@sentry/react'; | ||
|
||
class App extends React.Component { | ||
render() { | ||
return ( | ||
<FancyComponent> | ||
<NestedComponent someProp={2} /> | ||
<AnotherComponent /> | ||
</FancyComponent> | ||
) | ||
} | ||
} | ||
|
||
export default Sentry.withProfiler(App); | ||
``` | ||
|
||
The React Profiler currently generates spans with three different kinds of op-codes: `react.mount`, `react.render`, and `react.update`. | ||
|
||
`react.mount` | ||
|
||
: The span that represents how long it took for the profiled component to mount. | ||
|
||
`react.render` | ||
|
||
: 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. | ||
|
||
`react.update` | ||
|
||
: The span that represents when the profiled component updated. This span is only generated if the profiled component has mounted. | ||
|
||
{% capture __alert_content -%} | ||
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. | ||
{%- endcapture -%} | ||
{%- include components/alert.html | ||
title="Note" | ||
content=__alert_content | ||
level="warning" | ||
%} | ||
|
||
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. | ||
|
||
```jsx | ||
export default Sentry.withProfiler(App, { name: "CustomAppName" }) | ||
``` | ||
|
||
`name` (string) | ||
|
||
: The name of the component being profiled. By default, the name is taken from the component `displayName` property or the component `name` property. | ||
|
||
`includeRender` (boolean) | ||
|
||
: If a `react.render` span should be created by the Profiler. Set as true by default. | ||
|
||
`includeUpdates` (boolean) | ||
|
||
: 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.