Skip to content

Commit fbac7e4

Browse files
committed
add trigger back
1 parent 322935a commit fbac7e4

File tree

5 files changed

+13
-29
lines changed

5 files changed

+13
-29
lines changed

src/features/session_replay/aggregate/index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export class Aggregate extends AggregateBase {
2828

2929
// pass the recorder into the aggregator
3030
constructor (agentRef, args) {
31-
console.log('SR AGG constructor!')
3231
super(agentRef, FEATURE_NAME)
3332
/** Set once the recorder has fully initialized after flag checks and sampling */
3433
this.initialized = false
@@ -84,9 +83,7 @@ export class Aggregate extends AggregateBase {
8483

8584
const { error_sampling_rate, sampling_rate, autoStart, block_selector, mask_text_selector, mask_all_inputs, inline_images, collect_fonts } = agentRef.init.session_replay
8685

87-
console.log('wait for flags...')
8886
this.waitForFlags(['srs', 'sr']).then(([srMode, entitled]) => {
89-
console.log('got flags!', srMode, entitled)
9087
this.entitled = !!entitled
9188
if (!this.entitled) {
9289
this.deregisterDrain()
@@ -96,11 +93,7 @@ export class Aggregate extends AggregateBase {
9693
}
9794
return
9895
}
99-
this.ee.on('drain-' + this.featureName, () => {
100-
console.log('GOT DRAIN EVENT')
101-
})
102-
console.log('CALL initializeRecording... has drained?', this.drained)
103-
this.initializeRecording(srMode).then(() => { console.log('start draining'); this.drain(); console.log('drained') })
96+
this.initializeRecording(srMode).then(() => { this.drain() })
10497
}).then(() => {
10598
if (this.mode === MODE.OFF) {
10699
this.recorder?.stopRecording() // stop any conservative preload recording launched by instrument
@@ -141,7 +134,6 @@ export class Aggregate extends AggregateBase {
141134
if (!this.agentRef.runtime.isRecording) this.recorder.startRecording()
142135
this.syncWithSessionManager({ sessionReplayMode: this.mode })
143136
} else {
144-
console.log('switching to full by calling initializeRecording')
145137
this.initializeRecording(MODE.FULL, true)
146138
}
147139
}
@@ -153,7 +145,6 @@ export class Aggregate extends AggregateBase {
153145
* @returns {void}
154146
*/
155147
async initializeRecording (srMode, ignoreSession) {
156-
console.log('initialize recording!', this.initialized, this.entitled)
157148
this.initialized = true
158149
if (!this.entitled) return
159150

src/features/session_replay/instrument/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { handle } from '../../../common/event-emitter/handle'
1010
import { DEFAULT_KEY, MODE, PREFIX } from '../../../common/session/constants'
1111
import { InstrumentBase } from '../../utils/instrument-base'
1212
import { hasReplayPrerequisite, isPreloadAllowed } from '../shared/utils'
13-
import { FEATURE_NAME, SR_EVENT_EMITTER_TYPES } from '../constants'
13+
import { FEATURE_NAME, SR_EVENT_EMITTER_TYPES, TRIGGERS } from '../constants'
1414
import { setupRecordReplayAPI } from '../../../loaders/api/recordReplay'
1515
import { setupPauseReplayAPI } from '../../../loaders/api/pauseReplay'
1616

@@ -71,7 +71,7 @@ export class Instrument extends InstrumentBase {
7171
/**
7272
* This func is use for early pre-load recording prior to replay feature (agg) being loaded onto the page. It should only setup once, including if already called and in-progress.
7373
*/
74-
async #preloadStartRecording () {
74+
async #preloadStartRecording (trigger) {
7575
if (this.#alreadyStarted) return
7676
this.#alreadyStarted = true
7777

@@ -80,7 +80,7 @@ export class Instrument extends InstrumentBase {
8080

8181
// If startReplay() has been used by this point, we must record in full mode regardless of session preload:
8282
// Note: recorder starts here with w/e the mode is at this time, but this may be changed later (see #apiStartOrRestartReplay else-case)
83-
this.recorder ??= new Recorder({ ...this, mode: this.#mode, agentRef: this.#agentRef, timeKeeper: this.#agentRef.runtime.timeKeeper }) // if TK exists due to deferred state, pass it
83+
this.recorder ??= new Recorder({ ...this, mode: this.#mode, agentRef: this.#agentRef, trigger, timeKeeper: this.#agentRef.runtime.timeKeeper }) // if TK exists due to deferred state, pass it
8484
this.recorder.startRecording()
8585
this.abortHandler = this.recorder.stopRecording
8686
} catch (err) {
@@ -99,7 +99,7 @@ export class Instrument extends InstrumentBase {
9999
if (this.featAggregate.mode !== MODE.FULL) this.featAggregate.initializeRecording(MODE.FULL, true)
100100
} else { // pre-load
101101
this.#mode = MODE.FULL
102-
this.#preloadStartRecording()
102+
this.#preloadStartRecording(TRIGGERS.API)
103103
// There's a race here wherein either:
104104
// a. Recorder has not been initialized, and we've set the enforced mode, so we're good, or;
105105
// b. Record has been initialized, possibly with the "wrong" mode, so we have to correct that + restart.

src/features/session_replay/shared/recorder.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ export class Recorder {
4242
/** The method to stop recording. This defaults to a noop, but is overwritten once the recording library is imported and initialized */
4343
this.stopRecording = () => { this.parent.agentRef.runtime.isRecording = false }
4444

45-
console.log('setting up register handler for', this.parent.featureName)
46-
registerHandler(RRWEB_DATA_CHANNEL, (event, isCheckout) => {
47-
console.log('got data from rrweb register handler...', this.parent)
48-
this.audit(event, isCheckout)
49-
}, this.parent.featureName, this.parent.ee)
45+
registerHandler(RRWEB_DATA_CHANNEL, (event, isCheckout) => { this.audit(event, isCheckout) }, this.parent.featureName, this.parent.ee)
5046
}
5147

5248
getEvents () {
@@ -78,10 +74,7 @@ export class Recorder {
7874
let stop
7975
try {
8076
stop = recorder({
81-
emit: (event, isCheckout) => {
82-
console.log('EMIT! --- goes to handle for', this.parent.featureName)
83-
handle(RRWEB_DATA_CHANNEL, [event, isCheckout], undefined, this.parent.featureName, this.parent.ee)
84-
},
77+
emit: (event, isCheckout) => { handle(RRWEB_DATA_CHANNEL, [event, isCheckout], undefined, this.parent.featureName, this.parent.ee) },
8578
blockClass: block_class,
8679
ignoreClass: ignore_class,
8780
maskTextClass: mask_text_class,

tests/unit/features/session_replay/shared/recorder.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ describe('recorder', () => {
1111
stylesheets: true
1212
}
1313
},
14-
runtime: {}
15-
},
16-
timeKeeper: {
17-
correctAbsoluteTimestamp: jest.fn(x => x)
14+
runtime: {
15+
timeKeeper: {
16+
correctAbsoluteTimestamp: jest.fn(x => x)
17+
}
18+
}
1819
},
1920
ee: {
2021
emit: () => {}

tools/testing-server/constants.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ const defaultFlagValue = (flag) => {
3535
return 1
3636
}
3737
module.exports.rumFlags = (flags = {}, app = {}) => ({
38-
test: 1,
3938
loaded: defaultFlagValue(flags.loaded), // Used internally to signal the tests that the agent has loaded
4039
st: defaultFlagValue(flags.st), // session trace entitlements 0|1
4140
err: defaultFlagValue(flags.err), // err entitlements 0|1
4241
ins: defaultFlagValue(flags.ins), // ins entitlements 0|1
4342
spa: defaultFlagValue(flags.spa), // spa entitlements 0|1
4443
sr: defaultFlagValue(flags.sr), // session replay entitlements 0|1
4544
sts: defaultFlagValue(flags.sts), // session trace sampling 0|1|2 - off full error
46-
srs: 0, // session replay sampling 0|1|2 - off full error
45+
srs: defaultFlagValue(flags.srs), // session replay sampling 0|1|2 - off full error
4746
log: flags.log ?? 3, // logging sampling 0|1|2|3|4|5 - off error warn info debug trace
4847
app: {
4948
agents: app.agents || [

0 commit comments

Comments
 (0)