ref: Move instrumentation handlers into main plugin class #82
Conversation
This moves the core SDK instrumentation handlers into the main plugin class as the typings are more accurate and allows better testing of the handler data transforms as well.
| const hub = Sentry.getCurrentHub(); | ||
| const scope = hub.getScope(); | ||
|
|
||
| addInstrumentationListeners(scope, this); | ||
|
|
There was a problem hiding this comment.
@JoshFerge was there a specific reason to have addInstrumentationListeners so early in this setup fn?
| scope.addScopeListener(this.handleCoreListener('scope')); | ||
| addInstrumentationHandler('dom', this.handleCoreListener('dom')); |
There was a problem hiding this comment.
I removed observing fetch/xhr because there was a bug where we actually weren't using it -- let's keep it simple and continue to not use it. Although a case where we may want to reduce some duplicated logic is that the SDK ignores capturing requests that get sent to our ingestion endpoint.
| /** | ||
| * Keep a list of performance entries that will be sent with a replay | ||
| */ | ||
| handlePerformanceObserver = ( | ||
| list: PerformanceObserverEntryList | ||
| // observer: PerformanceObserver | ||
| ) => { | ||
| this.performanceEvents = [...this.performanceEvents, ...list.getEntries()]; | ||
| }; |
| handlerData.xhr.__sentry_xhr__.startTimestamp = handlerData.startTimestamp; | ||
| } | ||
| if (handlerData.endTimestamp) { | ||
| this.spans.push({ |
There was a problem hiding this comment.
Refactoring this caught a bug where spans is not a member of the replay plugin class. We were using the requests from window.PerformanceObserver.
JoshFerge
left a comment
There was a problem hiding this comment.
good improvement 👍🏼 .what would you think about renaming the getXXX functions to XXXhandler // XXXlistener? (getScope e.g. confused me for a second).
…sentry-replay#82) This moves the core SDK instrumentation handlers into the main plugin class as the typings are more accurate and allows better testing of the handler data transforms as well.
This moves the core SDK instrumentation handlers into the main plugin class as the typings are more accurate and allows better testing of the handler data transforms as well.