Skip to content

Commit 5fdea14

Browse files
ellisongcwli24
andauthored
feat: Move deregisterDrain method to feature-base (#1220)
Co-authored-by: Chunwai Li <[email protected]>
1 parent 789df5a commit 5fdea14

File tree

11 files changed

+17
-21
lines changed

11 files changed

+17
-21
lines changed

src/features/generic_events/aggregate/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { AggregateBase } from '../../utils/aggregate-base'
1111
import { warn } from '../../../common/util/console'
1212
import { now } from '../../../common/timing/now'
1313
import { registerHandler } from '../../../common/event-emitter/register-handler'
14-
import { deregisterDrain } from '../../../common/drain/drain'
1514
import { SUPPORTABILITY_METRIC_CHANNEL } from '../../metrics/constants'
1615
import { EventBuffer } from '../../utils/event-buffer'
1716
import { applyFnToProps } from '../../../common/util/traverse'
@@ -33,7 +32,7 @@ export class Aggregate extends AggregateBase {
3332
this.waitForFlags(['ins']).then(([ins]) => {
3433
if (!ins) {
3534
this.blocked = true
36-
deregisterDrain(this.agentIdentifier, this.featureName)
35+
this.deregisterDrain()
3736
return
3837
}
3938

src/features/generic_events/instrument/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
import { isBrowserScope } from '../../../common/constants/runtime'
6-
import { deregisterDrain } from '../../../common/drain/drain'
76
import { handle } from '../../../common/event-emitter/handle'
87
import { windowAddEventListener } from '../../../common/event-listener/event-listener-opts'
98
import { InstrumentBase } from '../../utils/instrument-base'
@@ -31,7 +30,7 @@ export class Instrument extends InstrumentBase {
3130

3231
/** If any of the sources are active, import the aggregator. otherwise deregister */
3332
if (genericEventSourceConfigs.some(x => x)) this.importAggregator(agentRef)
34-
else deregisterDrain(agentRef.agentIdentifier, this.featureName)
33+
else this.deregisterDrain()
3534
}
3635
}
3736

src/features/jserrors/aggregate/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { FEATURE_NAME } from '../constants'
1818
import { FEATURE_NAMES } from '../../../loaders/features/features'
1919
import { AggregateBase } from '../../utils/aggregate-base'
2020
import { getNREUMInitializedAgent } from '../../../common/window/nreum'
21-
import { deregisterDrain } from '../../../common/drain/drain'
2221
import { now } from '../../../common/timing/now'
2322
import { applyFnToProps } from '../../../common/util/traverse'
2423
import { evaluateInternalError } from './internal-errors'
@@ -59,7 +58,7 @@ export class Aggregate extends AggregateBase {
5958
this.drain()
6059
} else {
6160
this.blocked = true // if rum response determines that customer lacks entitlements for spa endpoint, this feature shouldn't harvest
62-
deregisterDrain(this.agentIdentifier, this.featureName)
61+
this.deregisterDrain()
6362
}
6463
})
6564
}

src/features/metrics/aggregate/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { onDOMContentLoaded } from '../../../common/window/load'
77
import { windowAddEventListener } from '../../../common/event-listener/event-listener-opts'
88
import { isBrowserScope, isWorkerScope } from '../../../common/constants/runtime'
99
import { AggregateBase } from '../../utils/aggregate-base'
10-
import { deregisterDrain } from '../../../common/drain/drain'
1110
import { isIFrameWindow } from '../../../common/dom/iframe'
1211
// import { WEBSOCKET_TAG } from '../../../common/wrap/wrap-websocket'
1312
// import { handleWebsocketEvents } from './websocket-detection'
@@ -26,7 +25,7 @@ export class Aggregate extends AggregateBase {
2625
this.drain()
2726
} else {
2827
this.blocked = true // if rum response determines that customer lacks entitlements for spa endpoint, this feature shouldn't harvest
29-
deregisterDrain(this.agentIdentifier, this.featureName)
28+
this.deregisterDrain()
3029
}
3130
})
3231

src/features/session_replay/aggregate/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { RRWEB_VERSION } from '../../../common/constants/env'
2121
import { MODE, SESSION_EVENTS, SESSION_EVENT_TYPES } from '../../../common/session/constants'
2222
import { stringify } from '../../../common/util/stringify'
2323
import { stylesheetEvaluator } from '../shared/stylesheet-evaluator'
24-
import { deregisterDrain } from '../../../common/drain/drain'
2524
import { now } from '../../../common/timing/now'
2625
import { buildNRMetaNode } from '../shared/utils'
2726
import { MAX_PAYLOAD_SIZE } from '../../../common/constants/agent-constants'
@@ -106,7 +105,7 @@ export class Aggregate extends AggregateBase {
106105
this.waitForFlags(['srs', 'sr']).then(([srMode, entitled]) => {
107106
this.entitled = !!entitled
108107
if (!this.entitled) {
109-
deregisterDrain(this.agentIdentifier, this.featureName)
108+
this.deregisterDrain()
110109
if (this.recorder?.recording) {
111110
this.abort(ABORT_REASONS.ENTITLEMENTS)
112111
handle(SUPPORTABILITY_METRIC_CHANNEL, ['SessionReplay/EnabledNotEntitled/Detected'], undefined, FEATURE_NAMES.metrics, this.ee)

src/features/session_trace/aggregate/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { FEATURE_NAME } from '../constants'
44
import { AggregateBase } from '../../utils/aggregate-base'
55
import { TraceStorage } from './trace/storage'
66
import { obj as encodeObj } from '../../../common/url/encode'
7-
import { deregisterDrain } from '../../../common/drain/drain'
87
import { globalScope } from '../../../common/constants/runtime'
98
import { MODE, SESSION_EVENTS } from '../../../common/session/constants'
109
import { applyFnToProps } from '../../../common/util/traverse'
@@ -38,7 +37,7 @@ export class Aggregate extends AggregateBase {
3837
/** Sets up event listeners, and initializes this module to run in the correct "mode". Can be triggered from a few places, but makes an effort to only set up listeners once */
3938
initialize (stMode, stEntitled, ignoreSession) {
4039
this.entitled ??= stEntitled
41-
if (this.blocked || !this.entitled) return deregisterDrain(this.agentIdentifier, this.featureName)
40+
if (this.blocked || !this.entitled) return this.deregisterDrain()
4241

4342
if (!this.initialized) {
4443
this.initialized = true
@@ -74,7 +73,7 @@ export class Aggregate extends AggregateBase {
7473

7574
/** If the mode is off, we do not want to hold up draining for other features, so we deregister the feature for now.
7675
* If it drains later (due to a mode change), data and handlers will instantly drain instead of waiting for the registry. */
77-
if (this.mode === MODE.OFF) return deregisterDrain(this.agentIdentifier, this.featureName)
76+
if (this.mode === MODE.OFF) return this.deregisterDrain()
7877

7978
this.timeKeeper ??= this.agentRef.runtime.timeKeeper
8079

src/features/session_trace/instrument/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { wrapEvents } from '../../../common/wrap/wrap-events'
88
import { InstrumentBase } from '../../utils/instrument-base'
99
import * as CONSTANTS from '../constants'
1010
import { FEATURE_NAMES } from '../../../loaders/features/features'
11-
import { deregisterDrain } from '../../../common/drain/drain'
1211
import { canEnableSessionTracking } from '../../utils/feature-gates'
1312
import { now } from '../../../common/timing/now'
1413

@@ -22,7 +21,7 @@ export class Instrument extends InstrumentBase {
2221
super(agentRef, FEATURE_NAME, auto)
2322
const canTrackSession = canEnableSessionTracking(this.agentIdentifier)
2423
if (!canTrackSession) {
25-
deregisterDrain(this.agentIdentifier, this.featureName)
24+
this.deregisterDrain()
2625
return
2726
}
2827

src/features/soft_navigations/aggregate/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { deregisterDrain } from '../../../common/drain/drain'
21
import { handle } from '../../../common/event-emitter/handle'
32
import { registerHandler } from '../../../common/event-emitter/register-handler'
43
import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
@@ -49,7 +48,7 @@ export class Aggregate extends AggregateBase {
4948
scheduler.startTimer(harvestTimeSeconds, 0)
5049
} else {
5150
this.blocked = true // if rum response determines that customer lacks entitlements for spa endpoint, this feature shouldn't harvest
52-
deregisterDrain(this.agentIdentifier, this.featureName)
51+
this.deregisterDrain()
5352
}
5453
})
5554

src/features/spa/aggregate/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { bundleId } from '../../../common/ids/bundle-id'
2222
import { loadedAsDeferredBrowserScript } from '../../../common/constants/runtime'
2323
import { handle } from '../../../common/event-emitter/handle'
2424
import { SUPPORTABILITY_METRIC_CHANNEL } from '../../metrics/constants'
25-
import { deregisterDrain } from '../../../common/drain/drain'
2625
import { warn } from '../../../common/util/console'
2726
import { EventBuffer } from '../../utils/event-buffer'
2827

@@ -112,7 +111,7 @@ export class Aggregate extends AggregateBase {
112111
this.drain()
113112
} else {
114113
this.blocked = true
115-
deregisterDrain(agentRef.agentIdentifier, this.featureName)
114+
this.deregisterDrain()
116115
}
117116
})
118117

src/features/utils/aggregate-base.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FeatureBase } from './feature-base'
22
import { isValid } from '../../common/config/info'
33
import { configure } from '../../loaders/configure/configure'
44
import { gosCDN } from '../../common/window/nreum'
5-
import { deregisterDrain, drain } from '../../common/drain/drain'
5+
import { drain } from '../../common/drain/drain'
66
import { activatedFeatures } from '../../common/util/feature-flags'
77
import { Obfuscator } from '../../common/util/obfuscate'
88

@@ -38,7 +38,7 @@ export class AggregateBase extends FeatureBase {
3838
return flagsPromise.catch(err => {
3939
this.ee.emit('internal-error', [err])
4040
this.blocked = true
41-
deregisterDrain(this.agentIdentifier, this.featureName)
41+
this.deregisterDrain()
4242
})
4343
}
4444

src/features/utils/feature-base.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ee } from '../../common/event-emitter/contextual-ee'
2+
import { deregisterDrain } from '../../common/drain/drain'
23

34
export class FeatureBase {
45
constructor (agentIdentifier, featureName) {
@@ -15,4 +16,8 @@ export class FeatureBase {
1516
*/
1617
this.blocked = false
1718
}
19+
20+
deregisterDrain () {
21+
deregisterDrain(this.agentIdentifier, this.featureName)
22+
}
1823
}

0 commit comments

Comments
 (0)