Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/browser/replay/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ export default class Recorder {

this.options = options;
this._recordFn = recordFn;
this._isReady = false;
}

get isRecording() {
return this._stopFn !== null;
}

get isReady() {
return this._isReady;
}

get options() {
return this._options;
}
Expand Down Expand Up @@ -127,6 +132,9 @@ export default class Recorder {

this._stopFn = this._recordFn({
emit: (event, isCheckout) => {
if (!this._ready && event.type === EventType.FullSnapshot) {
this._isReady = true;
}
if (this.options.debug?.logEmits) {
this._logEvent(event, isCheckout);
}
Expand Down Expand Up @@ -158,6 +166,7 @@ export default class Recorder {

this._stopFn();
this._stopFn = null;
this._isReady = false;

return this;
}
Expand All @@ -167,6 +176,7 @@ export default class Recorder {
previous: [],
current: [],
};
this._isReady = false;
}

_collectEvents() {
Expand Down
4 changes: 4 additions & 0 deletions src/browser/replay/replayManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export default class ReplayManager {
* @returns {string} A unique identifier for this replay
*/
add(replayId, occurrenceUuid) {
if (!this._recorder.isReady) {
logger.warn('ReplayManager.add: Recorder is not ready, cannot export replay');
return null;
}
replayId = replayId || id.gen(8);

// Start processing the replay in the background
Expand Down
16 changes: 16 additions & 0 deletions test/browser.replay.recorder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('Recorder', function () {
const recorder = new Recorder({}, recordFnStub);

expect(recorder.isRecording).to.be.false;
expect(recorder.isReady).to.be.false;
expect(recorder.options).to.deep.equal({
enabled: undefined,
autoStart: undefined,
Expand Down Expand Up @@ -162,6 +163,21 @@ describe('Recorder', function () {
});
});

it('should be ready after first full snapshot', function () {
const recorder = new Recorder({}, recordFnStub);
recorder.start();

// First checkout
emitCallback({ timestamp: 0, type: EventType.Meta, data: {} }, false);
expect(recorder.isReady).to.be.false;

emitCallback(
{ timestamp: 10, type: EventType.FullSnapshot, data: {} },
false,
);
expect(recorder.isReady).to.be.true;
});

it('should handle checkout events correctly', function () {
const recorder = new Recorder({}, recordFnStub);
recorder.start();
Expand Down
15 changes: 15 additions & 0 deletions test/replay/unit/replayManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import id from '../../../src/tracing/id.js';
class MockRecorder {
constructor() {
this.exportRecordingSpan = sinon.stub();
this.isReady = true;
}
}

Expand Down Expand Up @@ -220,6 +221,20 @@ describe('ReplayManager', function () {
expect(id.gen.calledWith(8)).to.be.true;
expect(processStub.calledWith('1234567890abcdef', uuid)).to.be.true;
});

it('should return without replayId when recorder is not ready', function () {
const uuid = '12345678-1234-5678-1234-1234567890ab';
const processStub = sinon
.stub(replayManager, '_exportSpansAndAddTracingPayload')
.resolves();
mockRecorder.isReady = false;

const replayId = replayManager.add(null, uuid);

expect(replayId).to.be.null;
expect(id.gen.called).to.be.false;
expect(processStub.called).to.be.false;
});
});

describe('send', function () {
Expand Down
Loading