-
-
Notifications
You must be signed in to change notification settings - Fork 4k
/
withProfiler.tsx
54 lines (45 loc) · 1.42 KB
/
withProfiler.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React from 'react';
import {Integrations} from '@sentry/apm';
import getDisplayName from 'app/utils/getDisplayName';
type InjectedProps = {
finishProfile: () => void;
};
export default function withProfiler<P extends InjectedProps>(
WrappedComponent: React.ComponentType<P>
) {
const componentDisplayName = getDisplayName(WrappedComponent);
return class extends React.Component<Omit<P, keyof InjectedProps>> {
static displayName = `profiler(${componentDisplayName})`;
componentWillUnmount() {
this.finishProfile();
}
activity: number | null = Integrations.Tracing.pushActivity(
componentDisplayName,
{
data: {},
op: 'react',
description: `<${componentDisplayName}>`,
},
{
// After this timeout we'll pop this activity regardless
// Set to 30s because that's the length of our longest requests
autoPopAfter: 30000,
}
);
// For whatever reason it's not guaranteed that `finishProfile` will be
// called, that's why we need the previously described timeout to make
// sure our transaction will be finished.
finishProfile = () => {
if (!this.activity) {
return;
}
Integrations.Tracing.popActivity(this.activity);
this.activity = null;
};
render() {
return (
<WrappedComponent {...(this.props as P)} finishProfile={this.finishProfile} />
);
}
};
}