Skip to content

Commit 44ed341

Browse files
fix: coninous recording and patch conifgs
1 parent 1c5719f commit 44ed341

File tree

20 files changed

+95
-151
lines changed

20 files changed

+95
-151
lines changed

packages/session-recorder-browser/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@multiplayer-app/session-recorder-browser",
3-
"version": "1.2.11",
3+
"version": "1.2.12",
44
"description": "Multiplayer Fullstack Session Recorder for Browser",
55
"author": {
66
"name": "Multiplayer Software, Inc.",
@@ -55,7 +55,7 @@
5555
"webpack-cli": "5.1.4"
5656
},
5757
"dependencies": {
58-
"@multiplayer-app/session-recorder-common": "1.2.11",
58+
"@multiplayer-app/session-recorder-common": "1.2.12",
5959
"@opentelemetry/auto-instrumentations-web": "0.49.0",
6060
"@opentelemetry/context-zone": "2.0.1",
6161
"@opentelemetry/core": "2.0.1",
@@ -79,4 +79,4 @@
7979
"peerDependencies": {
8080
"@opentelemetry/api": "^1.9.0"
8181
}
82-
}
82+
}

packages/session-recorder-browser/src/config/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ export const SESSION_ID_PROP_NAME = 'multiplayer-session-id'
55

66
export const SESSION_SHORT_ID_PROP_NAME = 'multiplayer-session-short-id'
77

8-
export const SESSION_CONTINUOUS_DEBUGGING_PROP_NAME = 'multiplayer-session-continuous-debugging'
9-
108
export const SESSION_STATE_PROP_NAME = 'multiplayer-session-state'
119

1210
export const SESSION_TYPE_PROP_NAME = 'multiplayer-session-type'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { DEFAULT_MAX_HTTP_CAPTURING_PAYLOAD_SIZE } from '../config'
2+
3+
export const configs = {
4+
recordRequestHeaders: true,
5+
recordResponseHeaders: true,
6+
shouldRecordBody: true,
7+
maxCapturingHttpPayloadSize: DEFAULT_MAX_HTTP_CAPTURING_PAYLOAD_SIZE,
8+
}
9+
10+
export const setMaxCapturingHttpPayloadSize = (_maxCapturingHttpPayloadSize: number) => {
11+
configs.maxCapturingHttpPayloadSize = _maxCapturingHttpPayloadSize
12+
}
13+
14+
export const setShouldRecordHttpData = (shouldRecordBody: boolean, shouldRecordHeaders: boolean) => {
15+
configs.recordRequestHeaders = shouldRecordHeaders
16+
configs.recordResponseHeaders = shouldRecordHeaders
17+
configs.shouldRecordBody = shouldRecordBody
18+
}

packages/session-recorder-browser/src/patch/fetch.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,9 @@ import {
66
isString,
77
} from '../utils/type-utils'
88
import { formDataToQuery } from '../utils/request-utils'
9-
import { DEFAULT_MAX_HTTP_CAPTURING_PAYLOAD_SIZE } from '../config'
9+
import { configs } from './configs'
1010

11-
let recordRequestHeaders = true
12-
let recordResponseHeaders = true
13-
const shouldRecordBody = true
14-
let maxCapturingHttpPayloadSize = DEFAULT_MAX_HTTP_CAPTURING_PAYLOAD_SIZE
1511

16-
export const setMaxCapturingHttpPayloadSize = (_maxCapturingHttpPayloadSize: number) => {
17-
maxCapturingHttpPayloadSize = _maxCapturingHttpPayloadSize
18-
}
19-
20-
export const setShouldRecordHttpData = (shouldRecordBody: boolean, shouldRecordHeaders: boolean) => {
21-
recordRequestHeaders = shouldRecordHeaders
22-
recordResponseHeaders = shouldRecordHeaders
23-
// eslint-disable-next-line
24-
shouldRecordBody = shouldRecordBody
25-
}
2612

2713
function _tryReadFetchBody({
2814
body,
@@ -115,19 +101,19 @@ window.fetch = async function (
115101
// Capture request data
116102
const request = new Request(input, init)
117103

118-
if (recordRequestHeaders) {
104+
if (configs.recordRequestHeaders) {
119105
networkRequest.requestHeaders = _headersToObject(request.headers)
120106
}
121107

122-
if (shouldRecordBody && request.body) {
108+
if (configs.shouldRecordBody && request.body) {
123109
const requestBody = _tryReadFetchBody({
124110
body: request.body,
125111
url: request.url,
126112
})
127113

128114
if (
129115
requestBody?.length &&
130-
new Blob([requestBody]).size <= maxCapturingHttpPayloadSize
116+
new Blob([requestBody]).size <= configs.maxCapturingHttpPayloadSize
131117
) {
132118
networkRequest.requestBody = requestBody
133119
}
@@ -138,16 +124,16 @@ window.fetch = async function (
138124
const response = await originalFetch(input, init)
139125

140126
// Capture response data
141-
if (recordResponseHeaders) {
127+
if (configs.recordResponseHeaders) {
142128
networkRequest.responseHeaders = _headersToObject(response.headers)
143129
}
144130

145-
if (shouldRecordBody) {
131+
if (configs.shouldRecordBody) {
146132
const responseBody = await _tryReadResponseBody(response)
147133

148134
if (
149135
responseBody?.length &&
150-
new Blob([responseBody]).size <= maxCapturingHttpPayloadSize
136+
new Blob([responseBody]).size <= configs.maxCapturingHttpPayloadSize
151137
) {
152138
networkRequest.responseBody = responseBody
153139
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
import './xhr'
22
import './fetch'
3+
4+
export * from './configs'

packages/session-recorder-browser/src/patch/xhr.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,8 @@ import {
66
isString,
77
} from '../utils/type-utils'
88
import { formDataToQuery } from '../utils/request-utils'
9-
import { DEFAULT_MAX_HTTP_CAPTURING_PAYLOAD_SIZE } from '../config'
9+
import { configs } from './configs'
1010

11-
let recordRequestHeaders = true
12-
let recordResponseHeaders = true
13-
const shouldRecordBody = true
14-
let maxCapturingHttpPayloadSize = DEFAULT_MAX_HTTP_CAPTURING_PAYLOAD_SIZE
15-
16-
export const setMaxCapturingHttpPayloadSize = (_maxCapturingHttpPayloadSize: number) => {
17-
maxCapturingHttpPayloadSize = _maxCapturingHttpPayloadSize
18-
}
19-
20-
export const setShouldRecordHttpData = (shouldRecordBody: boolean, shouldRecordHeaders: boolean) => {
21-
recordRequestHeaders = shouldRecordHeaders
22-
recordResponseHeaders = shouldRecordHeaders
23-
// eslint-disable-next-line
24-
shouldRecordBody = shouldRecordBody
25-
}
2611

2712
function _tryReadXHRBody({
2813
body,
@@ -84,18 +69,18 @@ function _tryReadXHRBody({
8469
requestHeaders[header] = value
8570
return originalSetRequestHeader(header, value)
8671
}
87-
if (recordRequestHeaders) {
72+
if (configs.recordRequestHeaders) {
8873
networkRequest.requestHeaders = requestHeaders
8974
}
9075

9176
const originalSend = xhr.send.bind(xhr)
9277
xhr.send = (body) => {
93-
if (shouldRecordBody) {
78+
if (configs.shouldRecordBody) {
9479
const requestBody = _tryReadXHRBody({ body, url })
9580

9681
if (
9782
requestBody?.length
98-
&& new Blob([requestBody]).size <= maxCapturingHttpPayloadSize
83+
&& new Blob([requestBody]).size <= configs.maxCapturingHttpPayloadSize
9984
) {
10085
networkRequest.requestBody = requestBody
10186
}
@@ -121,15 +106,15 @@ function _tryReadXHRBody({
121106
responseHeaders[header] = value
122107
}
123108
})
124-
if (recordResponseHeaders) {
109+
if (configs.recordResponseHeaders) {
125110
networkRequest.responseHeaders = responseHeaders
126111
}
127-
if (shouldRecordBody) {
112+
if (configs.shouldRecordBody) {
128113
const responseBody = _tryReadXHRBody({ body: xhr.response, url })
129114

130115
if (
131116
responseBody?.length
132-
&& new Blob([responseBody]).size <= maxCapturingHttpPayloadSize
117+
&& new Blob([responseBody]).size <= configs.maxCapturingHttpPayloadSize
133118
) {
134119
networkRequest.responseBody = responseBody
135120
}

packages/session-recorder-browser/src/sessionRecorder.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@ import {
2323
SESSION_ID_PROP_NAME,
2424
SESSION_TYPE_PROP_NAME,
2525
SESSION_STATE_PROP_NAME,
26-
SESSION_CONTINUOUS_DEBUGGING_PROP_NAME,
2726
DEFAULT_MAX_HTTP_CAPTURING_PAYLOAD_SIZE,
2827
getSessionRecorderConfig,
2928
SESSION_AUTO_CREATED,
3029
SESSION_STOPPED_EVENT,
31-
SESSION_STARTED_EVENT,
30+
SESSION_STARTED_EVENT
3231
} from './config'
3332

34-
import {
35-
setShouldRecordHttpData,
36-
setMaxCapturingHttpPayloadSize,
37-
} from './patch/xhr'
33+
import { setShouldRecordHttpData, setMaxCapturingHttpPayloadSize, } from './patch'
3834
import { recorderEventBus } from './eventBus'
3935
import { SessionWidget } from './sessionWidget'
4036
import messagingService from './services/messaging.service'
@@ -147,9 +143,8 @@ export class SessionRecorder extends Observable<SessionRecorderEvents> implement
147143
const sessionIdLocal = getStoredItem(SESSION_ID_PROP_NAME)
148144
const sessionStateLocal = getStoredItem(SESSION_STATE_PROP_NAME)
149145
const sessionTypeLocal = getStoredItem(SESSION_TYPE_PROP_NAME)
150-
const continuousRecordingLocal = getStoredItem(SESSION_CONTINUOUS_DEBUGGING_PROP_NAME, true)
151146

152-
if (isSessionActive(sessionLocal, continuousRecordingLocal)) {
147+
if (isSessionActive(sessionLocal, sessionTypeLocal)) {
153148
this.session = sessionLocal
154149
this.sessionId = sessionIdLocal
155150
this.sessionType = sessionTypeLocal

packages/session-recorder-browser/src/utils/session.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { eventWithTime, EventType } from 'rrweb'
22
import { DEBUG_SESSION_MAX_DURATION_SECONDS } from '../config/constants'
3+
import { SessionType } from '@multiplayer-app/session-recorder-common'
34

45
/**
56
* Session-related utility functions
67
*/
78

8-
export const isSessionActive = (session, continuousRecording: boolean) => {
9+
export const isSessionActive = (session, sessionType: SessionType) => {
910
if (!session) return false
10-
if (continuousRecording) return true
11+
if (sessionType === SessionType.CONTINUOUS) return true
1112
const startedAt = new Date(session.startedAt)
1213
const now = new Date()
1314
const diff = now.getTime() - startedAt.getTime()

packages/session-recorder-common/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@multiplayer-app/session-recorder-common",
3-
"version": "1.2.11",
3+
"version": "1.2.12",
44
"description": "Multiplayer Fullstack Session Recorder - opentelemetry",
55
"author": {
66
"name": "Multiplayer Software, Inc.",
@@ -60,4 +60,4 @@
6060
"@types/to-json-schema": "0.2.4",
6161
"typescript": "5.8.3"
6262
}
63-
}
63+
}

packages/session-recorder-node/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@multiplayer-app/session-recorder-node",
3-
"version": "1.2.11",
3+
"version": "1.2.12",
44
"description": "Multiplayer Fullstack Session Recorder for Node.js",
55
"author": {
66
"name": "Multiplayer Software, Inc.",
@@ -36,7 +36,7 @@
3636
"prepublishOnly": "npm run build"
3737
},
3838
"dependencies": {
39-
"@multiplayer-app/session-recorder-common": "1.2.11",
39+
"@multiplayer-app/session-recorder-common": "1.2.12",
4040
"@opentelemetry/api": "^1.9.0",
4141
"@opentelemetry/core": "^2.0.1",
4242
"@opentelemetry/otlp-exporter-base": "^0.203.0",
@@ -49,4 +49,4 @@
4949
"@types/node": "24.0.12",
5050
"typescript": "5.8.3"
5151
}
52-
}
52+
}

0 commit comments

Comments
 (0)