-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat: APM Sentry Frontend #14027
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
feat: APM Sentry Frontend #14027
Changes from all commits
cd2ae45
9f51235
c8ecbb4
0aba508
a9df2ab
6342a1e
55c437c
72c5d12
cc319c9
679803a
5781c05
5c203d7
81a9522
3a68e29
8d62f17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ConfigStore from 'app/stores/configStore'; | |
import Main from 'app/main'; | ||
import ajaxCsrfSetup from 'app/utils/ajaxCsrfSetup'; | ||
import plugins from 'app/plugins'; | ||
import {startApm} from 'app/utils/apm'; | ||
|
||
// SDK INIT -------------------------------------------------------- | ||
Sentry.init({ | ||
|
@@ -32,7 +33,6 @@ Sentry.init({ | |
}), | ||
new Tracing({ | ||
tracingOrigins: ['localhost', 'sentry.io', /^\//], | ||
autoStartOnDomReady: false, | ||
}), | ||
], | ||
}); | ||
|
@@ -44,10 +44,14 @@ Sentry.configureScope(scope => { | |
if (window.__SENTRY__VERSION) { | ||
scope.setTag('sentry_version', window.__SENTRY__VERSION); | ||
} | ||
scope.setSpan( | ||
Sentry.getCurrentHub().startSpan({ | ||
op: 'pageload', | ||
sampled: true, | ||
}) | ||
); | ||
}); | ||
|
||
// ----------------------------------------------------------------- | ||
|
||
// Used for operational metrics to determine that the application js | ||
// bundle was loaded by browser. | ||
metric.mark('sentry-app-init'); | ||
|
@@ -63,6 +67,21 @@ if (window.__initialData) { | |
ConfigStore.loadInitialData(window.__initialData); | ||
} | ||
|
||
// APM ------------------------------------------------------------- | ||
const config = ConfigStore.getConfig(); | ||
// This is just a simple gatekeeper to not enable apm for whole sentry.io at first | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we feature flag this instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, but this anyway would just report transaction events to our account. |
||
if ( | ||
config && | ||
((config.userIdentity && | ||
config.userIdentity.email && | ||
config.userIdentity.email.includes('sentry')) || | ||
(config.urlPrefix && | ||
(config.urlPrefix.includes('localhost') || config.urlPrefix.includes('127.0.0.1')))) | ||
) { | ||
startApm(); | ||
} | ||
// ----------------------------------------------------------------- | ||
|
||
// these get exported to a global variable, which is important as its the only | ||
// way we can call into scoped objects | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import * as Router from 'react-router'; | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
let flushTransactionTimeout = undefined; | ||
let firstPageLoad = true; | ||
|
||
function startTransaction() { | ||
// We do set the transaction name in the router but we want to start it here | ||
// since in the App component where we set the transaction name, it's called multiple | ||
// times. This would result in losing the start of the transaction. | ||
let transactionSpan; | ||
const hub = Sentry.getCurrentHub(); | ||
hub.configureScope(scope => { | ||
if (firstPageLoad) { | ||
transactionSpan = scope.getSpan(); | ||
firstPageLoad = false; | ||
} else { | ||
const prevTransactionSpan = scope.getSpan(); | ||
// If there is a transaction we set the name to the route | ||
if (prevTransactionSpan && prevTransactionSpan.timestamp === undefined) { | ||
hub.finishSpan(prevTransactionSpan); | ||
} | ||
transactionSpan = hub.startSpan({ | ||
op: 'navigation', | ||
sampled: true, | ||
}); | ||
} | ||
scope.setSpan(transactionSpan); | ||
}); | ||
|
||
if (flushTransactionTimeout) { | ||
clearTimeout(flushTransactionTimeout); | ||
} | ||
|
||
flushTransactionTimeout = setTimeout(() => { | ||
hub.finishSpan(transactionSpan); | ||
}, 5000); | ||
} | ||
|
||
export function startApm() { | ||
startTransaction(); | ||
Router.browserHistory.listen(() => { | ||
startTransaction(); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import $ from 'jquery'; | ||
import {ThemeProvider} from 'emotion-theming'; | ||
import {Tracing} from '@sentry/integrations'; | ||
import {browserHistory} from 'react-router'; | ||
import {get, isEqual} from 'lodash'; | ||
import {getCurrentHub} from '@sentry/browser'; | ||
|
@@ -158,7 +157,6 @@ class App extends React.Component { | |
} | ||
|
||
componentDidMount() { | ||
this.updateTracing(); | ||
fetchGuides(); | ||
} | ||
|
||
|
@@ -167,7 +165,6 @@ class App extends React.Component { | |
if (!isEqual(config, prevProps.config)) { | ||
this.handleConfigStoreChange(config); | ||
} | ||
|
||
this.updateTracing(); | ||
} | ||
|
||
|
@@ -177,7 +174,14 @@ class App extends React.Component { | |
|
||
updateTracing() { | ||
const route = getRouteStringFromRoutes(this.props.routes); | ||
Tracing.startTrace(getCurrentHub(), route); | ||
const scope = getCurrentHub().getScope(); | ||
if (scope) { | ||
const transactionSpan = scope.getSpan(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this potentially get a span inside the transaction span? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Theoretically yes but, |
||
// If there is a transaction we set the name to the route | ||
if (transactionSpan) { | ||
transactionSpan.transaction = route; | ||
} | ||
} | ||
} | ||
|
||
handleConfigStoreChange(config) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.