-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Add basic router instrumentation for @sentry/ember #2784
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 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d80ee32
feat: Add router instrumentation for @sentry/ember
k-fish 02ec96c
Fix integrations overriding integrations specified by the user
k-fish 18736aa
Merge remote-tracking branch 'origin/master' into feat/sentry-ember-perf
k-fish d896ff5
Add example of slow loading route due to `model`
k-fish d958bbf
Fix error tests after adding performance
k-fish fed373d
Fix some other issues with existing error tests and change how the pe…
k-fish 2fd13f8
Run ember tests in github actions
k-fish 26c4d46
Merge remote-tracking branch 'origin/master' into feat/sentry-ember-perf
k-fish 4b8d2de
Re-introduce ember into scripts/test
k-fish 3c578ab
Merge remote-tracking branch 'origin/master' into feat/sentry-ember-perf
k-fish 2e4109c
Add render runloop post transition as a child span
k-fish db396fa
Add basic transaction tests to ensure router instrumentation works pr…
k-fish afc6a8c
Add route instrumentation
k-fish 7b6c42a
Merge remote-tracking branch 'origin/master' into feat/sentry-ember-perf
k-fish 161c364
Fix description
k-fish 56bf8d2
Update readme and cleanup
k-fish 7048f96
Update changelog
k-fish bc9b41d
Fix bad sed replacement
k-fish e0b31cc
Clean up tests and lint
k-fish 2b72278
Remove default import of Sentry
k-fish 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
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
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
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
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,14 @@ | ||
declare module 'ember-get-config' { | ||
import { BrowserOptions } from '@sentry/browser'; | ||
type EmberSentryConfig = { | ||
sentry: BrowserOptions; | ||
transitionTimeout: number; | ||
ignoreEmberOnErrorWarning: boolean; | ||
disablePerformance: boolean; | ||
disablePostTransitionRender: boolean; | ||
}; | ||
const config: { | ||
'@sentry/ember': EmberSentryConfig; | ||
}; | ||
export default config; | ||
} |
This file was deleted.
Oops, something went wrong.
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
125 changes: 125 additions & 0 deletions
125
packages/ember/addon/instance-initializers/sentry-performance.ts
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,125 @@ | ||
import ApplicationInstance from '@ember/application/instance'; | ||
import Ember from 'ember'; | ||
import { scheduleOnce } from '@ember/runloop'; | ||
import environmentConfig from 'ember-get-config'; | ||
import Sentry from '@sentry/ember'; | ||
import { Integration } from '@sentry/types'; | ||
|
||
export function initialize(appInstance: ApplicationInstance): void { | ||
const config = environmentConfig['@sentry/ember']; | ||
if (config['disablePerformance']) { | ||
return; | ||
} | ||
const performancePromise = instrumentForPerformance(appInstance); | ||
if (Ember.testing) { | ||
(<any>window)._sentryPerformanceLoad = performancePromise; | ||
} | ||
} | ||
|
||
function getTransitionInformation(transition: any, router: any) { | ||
const fromRoute = transition?.from?.name; | ||
const toRoute = transition ? transition.to.name : router.currentRouteName; | ||
return { | ||
fromRoute, | ||
toRoute, | ||
}; | ||
} | ||
|
||
export function _instrumentEmberRouter(routerService: any, routerMain: any, config: typeof environmentConfig['@sentry/ember'], startTransaction: Function, startTransactionOnPageLoad?: boolean) { | ||
const { disablePostTransitionRender } = config; | ||
const location = routerMain.location; | ||
let activeTransaction: any; | ||
let transitionSpan: any; | ||
|
||
const url = location && location.getURL && location.getURL(); | ||
|
||
if (Ember.testing) { | ||
routerService._sentryInstrumented = true; | ||
} | ||
|
||
if (startTransactionOnPageLoad && url) { | ||
const routeInfo = routerService.recognize(url); | ||
activeTransaction = startTransaction({ | ||
name: `route:${routeInfo.name}`, | ||
op: 'pageload', | ||
tags: { | ||
url, | ||
toRoute: routeInfo.name, | ||
'routing.instrumentation': '@sentry/ember', | ||
}, | ||
}); | ||
} | ||
|
||
routerService.on('routeWillChange', (transition: any) => { | ||
const { fromRoute, toRoute } = getTransitionInformation(transition, routerService); | ||
activeTransaction = startTransaction({ | ||
name: `route:${toRoute}`, | ||
op: 'navigation', | ||
tags: { | ||
fromRoute, | ||
toRoute, | ||
'routing.instrumentation': '@sentry/ember', | ||
}, | ||
}); | ||
transitionSpan = activeTransaction.startChild({ | ||
op: 'ember.transition', | ||
description: `route:${fromRoute} -> route:${toRoute}`, | ||
}); | ||
}); | ||
|
||
routerService.on('routeDidChange', (transition: any) => { | ||
const { toRoute } = getTransitionInformation(transition, routerService); | ||
let renderSpan: any; | ||
if (!transitionSpan || !activeTransaction) { | ||
return; | ||
} | ||
transitionSpan.finish(); | ||
|
||
if (disablePostTransitionRender) { | ||
activeTransaction.finish(); | ||
} | ||
|
||
function startRenderSpan() { | ||
renderSpan = activeTransaction.startChild({ | ||
op: 'ember.runloop.render', | ||
description: `post-transition render route:${toRoute}`, | ||
}); | ||
} | ||
|
||
function finishRenderSpan() { | ||
renderSpan.finish(); | ||
activeTransaction.finish(); | ||
} | ||
|
||
scheduleOnce('routerTransitions', null, startRenderSpan); | ||
scheduleOnce('afterRender', null, finishRenderSpan); | ||
}); | ||
} | ||
|
||
export async function instrumentForPerformance(appInstance: ApplicationInstance) { | ||
const config = environmentConfig['@sentry/ember']; | ||
const sentryConfig = config.sentry; | ||
const tracing = await import('@sentry/tracing'); | ||
|
||
const idleTimeout = config.transitionTimeout || 5000; | ||
|
||
const existingIntegrations = (sentryConfig['integrations'] || []) as Integration[]; | ||
|
||
sentryConfig['integrations'] = [ | ||
k-fish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
...existingIntegrations, | ||
new tracing.Integrations.BrowserTracing({ | ||
routingInstrumentation: (startTransaction, startTransactionOnPageLoad) => { | ||
const routerMain = appInstance.lookup('router:main'); | ||
const routerService = appInstance.lookup('service:router'); | ||
_instrumentEmberRouter(routerService, routerMain, config, startTransaction, startTransactionOnPageLoad) | ||
}, | ||
idleTimeout, | ||
}), | ||
]; | ||
|
||
Sentry.init(sentryConfig); // Call init again to rebind client with new integration list in addition to the defaults | ||
} | ||
|
||
export default { | ||
initialize, | ||
}; |
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 @@ | ||
export { default, initialize } from '@sentry/ember/instance-initializers/sentry-performance'; |
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
name: require('./package').name | ||
name: require('./package').name, | ||
options: { | ||
babel: { | ||
plugins: [ require.resolve('ember-auto-import/babel-plugin') ] | ||
} | ||
} | ||
}; |
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
Oops, something went wrong.
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.