Skip to content

Commit cc319c9

Browse files
committed
ref: Cleanup
1 parent 72c5d12 commit cc319c9

File tree

2 files changed

+59
-46
lines changed

2 files changed

+59
-46
lines changed

src/sentry/static/sentry/app/bootstrap.jsx

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import ConfigStore from 'app/stores/configStore';
2121
import Main from 'app/main';
2222
import ajaxCsrfSetup from 'app/utils/ajaxCsrfSetup';
2323
import plugins from 'app/plugins';
24+
import {startApm} from 'app/utils/apm';
2425

2526
// SDK INIT --------------------------------------------------------
2627
Sentry.init({
@@ -43,8 +44,6 @@ Sentry.configureScope(scope => {
4344
if (window.__SENTRY__VERSION) {
4445
scope.setTag('sentry_version', window.__SENTRY__VERSION);
4546
}
46-
// TODO(daniel): Maybe we need to follows from
47-
// This is the inital pageload span
4847
scope.setSpan(
4948
Sentry.getCurrentHub().startSpan({
5049
op: 'pageload',
@@ -53,50 +52,6 @@ Sentry.configureScope(scope => {
5352
);
5453
});
5554

56-
// APM --------------------------------------------------------------
57-
let flushTransactionTimeout = undefined;
58-
let firstPageLoad = true;
59-
60-
function trackTrace() {
61-
// We do set the transaction name in the router but we want to start it here
62-
// since in the App component where we set the transaction name, it's called multiple
63-
// times. This would result in losing the start of the transaction.
64-
let transactionSpan;
65-
const hub = Sentry.getCurrentHub();
66-
hub.configureScope(scope => {
67-
if (firstPageLoad) {
68-
transactionSpan = scope.getSpan();
69-
firstPageLoad = false;
70-
} else {
71-
const prevTransactionSpan = scope.getSpan();
72-
// If there is a transaction we set the name to the route
73-
if (prevTransactionSpan && prevTransactionSpan.timestamp === undefined) {
74-
hub.finishSpan(prevTransactionSpan);
75-
}
76-
transactionSpan = hub.startSpan({
77-
op: 'navigation',
78-
sampled: true,
79-
});
80-
}
81-
scope.setSpan(transactionSpan);
82-
});
83-
84-
if (flushTransactionTimeout) {
85-
clearTimeout(flushTransactionTimeout);
86-
}
87-
88-
flushTransactionTimeout = setTimeout(() => {
89-
hub.finishSpan(transactionSpan);
90-
}, 5000);
91-
}
92-
93-
trackTrace();
94-
Router.browserHistory.listen(() => {
95-
trackTrace();
96-
});
97-
98-
// -----------------------------------------------------------------
99-
10055
// Used for operational metrics to determine that the application js
10156
// bundle was loaded by browser.
10257
metric.mark('sentry-app-init');
@@ -112,6 +67,19 @@ if (window.__initialData) {
11267
ConfigStore.loadInitialData(window.__initialData);
11368
}
11469

70+
// APM -------------------------------------------------------------
71+
const config = ConfigStore.getConfig();
72+
// This is just a simple gatekeeper to not enable apm for whole sentry.io at first
73+
if (
74+
config &&
75+
config.userIdentity &&
76+
config.userIdentity.email &&
77+
config.userIdentity.email.includes('sentry')
78+
) {
79+
startApm();
80+
}
81+
// -----------------------------------------------------------------
82+
11583
// these get exported to a global variable, which is important as its the only
11684
// way we can call into scoped objects
11785

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as Router from 'react-router';
2+
import * as Sentry from '@sentry/browser';
3+
4+
let flushTransactionTimeout = undefined;
5+
let firstPageLoad = true;
6+
7+
function startTransaction() {
8+
// We do set the transaction name in the router but we want to start it here
9+
// since in the App component where we set the transaction name, it's called multiple
10+
// times. This would result in losing the start of the transaction.
11+
let transactionSpan;
12+
const hub = Sentry.getCurrentHub();
13+
hub.configureScope(scope => {
14+
if (firstPageLoad) {
15+
transactionSpan = scope.getSpan();
16+
firstPageLoad = false;
17+
} else {
18+
const prevTransactionSpan = scope.getSpan();
19+
// If there is a transaction we set the name to the route
20+
if (prevTransactionSpan && prevTransactionSpan.timestamp === undefined) {
21+
hub.finishSpan(prevTransactionSpan);
22+
}
23+
transactionSpan = hub.startSpan({
24+
op: 'navigation',
25+
sampled: true,
26+
});
27+
}
28+
scope.setSpan(transactionSpan);
29+
});
30+
31+
if (flushTransactionTimeout) {
32+
clearTimeout(flushTransactionTimeout);
33+
}
34+
35+
flushTransactionTimeout = setTimeout(() => {
36+
hub.finishSpan(transactionSpan);
37+
}, 5000);
38+
}
39+
40+
export function startApm() {
41+
startTransaction();
42+
Router.browserHistory.listen(() => {
43+
startTransaction();
44+
});
45+
}

0 commit comments

Comments
 (0)