Skip to content

Commit

Permalink
fix: Improve Session Replay abort metric reliability (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
metal-messiah authored Oct 4, 2023
1 parent 35586ab commit 14f08ac
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/features/session_replay/aggregate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { obj as encodeObj } from '../../../common/url/encode'
import { warn } from '../../../common/util/console'
import { globalScope } from '../../../common/constants/runtime'
import { SUPPORTABILITY_METRIC_CHANNEL } from '../../metrics/constants'
import { handle } from '../../../common/event-emitter/handle'
import { FEATURE_NAMES } from '../../../loaders/features/features'

// would be better to get this dynamically in some way
export const RRWEB_VERSION = '2.0.0-alpha.8'
Expand Down Expand Up @@ -53,6 +55,10 @@ const ABORT_REASONS = {
TOO_BIG: {
message: 'Payload was too large',
sm: 'Too-Big'
},
CROSS_TAB: {
message: 'Session Entity was set to OFF on another tab',
sm: 'Cross-Tab'
}
}

Expand Down Expand Up @@ -134,7 +140,7 @@ export class Aggregate extends AggregateBase {

this.ee.on(SESSION_EVENTS.UPDATE, (type, data) => {
if (!this.initialized || this.blocked || type !== SESSION_EVENT_TYPES.CROSS_TAB) return
if (this.mode !== MODE.OFF && data.sessionReplay === MODE.OFF) this.abort('Session Entity was set to OFF on another tab')
if (this.mode !== MODE.OFF && data.sessionReplay === MODE.OFF) this.abort(ABORT_REASONS.CROSS_TAB)
this.mode = data.sessionReplay
})

Expand Down Expand Up @@ -421,7 +427,7 @@ export class Aggregate extends AggregateBase {
/** Abort the feature, once aborted it will not resume */
abort (reason = {}) {
warn(`SR aborted -- ${reason.message}`)
this.ee.emit(SUPPORTABILITY_METRIC_CHANNEL, [`SessionReplay/Abort/${ABORT_REASONS[reason.sm]}`])
handle(SUPPORTABILITY_METRIC_CHANNEL, [`SessionReplay/Abort/${reason.sm}`], undefined, FEATURE_NAMES.metrics, this.ee)
this.blocked = true
this.mode = MODE.OFF
this.stopRecording()
Expand Down

0 comments on commit 14f08ac

Please sign in to comment.