Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: merge server permissions for payload capture #892

Merged
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
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const AUTOCAPTURE_DISABLED_SERVER_SIDE = '$autocapture_disabled_server_si
export const SESSION_RECORDING_ENABLED_SERVER_SIDE = '$session_recording_enabled_server_side'
export const CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE = '$console_log_recording_enabled_server_side'
export const SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE = '$session_recording_recorder_version_server_side' // follows rrweb versioning
export const SESSION_RECORDING_NETWORK_PAYLOAD_CAPTURE = '$session_recording_network_payload_capture'
export const SESSION_ID = '$sesid'
export const SESSION_RECORDING_IS_SAMPLED = '$session_is_sampled'
export const ENABLED_FEATURE_FLAGS = '$enabled_feature_flags'
Expand Down
30 changes: 20 additions & 10 deletions src/extensions/replay/sessionrecording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE,
SESSION_RECORDING_ENABLED_SERVER_SIDE,
SESSION_RECORDING_IS_SAMPLED,
SESSION_RECORDING_NETWORK_PAYLOAD_CAPTURE,
SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE,
} from '../../constants'
import {
Expand Down Expand Up @@ -92,7 +93,6 @@ export class SessionRecording {
private receivedDecide: boolean
private rrwebRecord: rrwebRecord | undefined
private isIdle = false
private _networkPayloadCapture: Pick<NetworkRecordOptions, 'recordHeaders' | 'recordBody'> | undefined = undefined

private _linkedFlagSeen: boolean = false
private _lastActivityTimestamp: number = Date.now()
Expand Down Expand Up @@ -148,6 +148,19 @@ export class SessionRecording {
return recordingVersion_client_side || recordingVersion_server_side || 'v1'
}

private get networkPayloadCapture(): Pick<NetworkRecordOptions, 'recordHeaders' | 'recordBody'> | undefined {
const networkPayloadCapture_server_side = this.instance.get_property(SESSION_RECORDING_NETWORK_PAYLOAD_CAPTURE)
const networkPayloadCapture_client_side = {
recordHeaders: this.instance.config.session_recording?.recordHeaders,
recordBody: this.instance.config.session_recording?.recordBody,
}
const headersEnabled =
networkPayloadCapture_client_side?.recordHeaders || networkPayloadCapture_server_side?.recordHeaders
const bodyEnabled =
networkPayloadCapture_client_side?.recordBody || networkPayloadCapture_server_side?.recordBody
return headersEnabled || bodyEnabled ? { recordHeaders: headersEnabled, recordBody: bodyEnabled } : undefined
}

/**
* defaults to buffering mode until a decide response is received
* once a decide response is received status can be disabled, active or sampled
Expand Down Expand Up @@ -252,11 +265,10 @@ export class SessionRecording {
[SESSION_RECORDING_ENABLED_SERVER_SIDE]: !!response['sessionRecording'],
[CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE]: response.sessionRecording?.consoleLogRecordingEnabled,
[SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE]: response.sessionRecording?.recorderVersion,
[SESSION_RECORDING_NETWORK_PAYLOAD_CAPTURE]: response.sessionRecording?.networkPayloadCapture,
})
}

this._networkPayloadCapture = response.sessionRecording?.networkPayloadCapture

const receivedSampleRate = response.sessionRecording?.sampleRate
this._sampleRate =
_isUndefined(receivedSampleRate) || _isNull(receivedSampleRate) ? null : parseFloat(receivedSampleRate)
Expand Down Expand Up @@ -472,14 +484,12 @@ export class SessionRecording {
if ((window as any).rrwebConsoleRecord && this.isConsoleLogCaptureEnabled) {
plugins.push((window as any).rrwebConsoleRecord.getRecordConsolePlugin())
}
if (this._networkPayloadCapture) {
if (_isFunction((window as any).getRecordNetworkPlugin)) {
plugins.push(
(window as any).getRecordNetworkPlugin(
buildNetworkRequestOptions(this.instance.config, this._networkPayloadCapture)
)
if (this.networkPayloadCapture && _isFunction((window as any).getRecordNetworkPlugin)) {
plugins.push(
(window as any).getRecordNetworkPlugin(
buildNetworkRequestOptions(this.instance.config, this.networkPayloadCapture)
)
}
)
}

this.stopRrweb = this.rrwebRecord({
Expand Down
Loading