-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ [RUMF-804] add support for session replay in E2E tests
and add a recorder test
- Loading branch information
1 parent
46e5c58
commit d09a1b6
Showing
14 changed files
with
255 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
export * from '@datadog/browser-rum' | ||
export { datadogRum } from './boot/recorder.entry' | ||
export { | ||
Segment as internal_Segment, | ||
CreationReason as internal_CreationReason, | ||
RecordType as internal_RecordType, | ||
IncrementalSource as internal_IncrementalSource, | ||
MouseMoveRecord as internal_MouseMoveRecord, | ||
} from './types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,30 +2,37 @@ | |
# yarn lockfile v1 | ||
|
||
|
||
"@datadog/browser-core@1.26.2", "@datadog/browser-core@file:../../packages/core": | ||
version "1.26.2" | ||
"@datadog/browser-core@2.1.1", "@datadog/browser-core@file:../../packages/core": | ||
version "2.1.1" | ||
dependencies: | ||
tslib "^1.10.0" | ||
|
||
"@datadog/browser-logs@file:../../packages/logs": | ||
version "1.26.2" | ||
version "2.1.1" | ||
dependencies: | ||
"@datadog/browser-core" "1.26.2" | ||
"@datadog/browser-core" "2.1.1" | ||
tslib "^1.10.0" | ||
|
||
"@datadog/browser-rum-recorder@file:../../packages/rum-recorder": | ||
version "1.26.2" | ||
version "2.1.1" | ||
dependencies: | ||
"@datadog/browser-core" "1.26.2" | ||
"@datadog/browser-rum" "1.26.2" | ||
"@datadog/browser-core" "2.1.1" | ||
"@datadog/browser-rum" "2.1.1" | ||
"@types/css-font-loading-module" "0.0.4" | ||
rrweb-snapshot "1.0.1" | ||
tslib "^1.10.0" | ||
|
||
"@datadog/browser-rum@1.26.2", "@datadog/browser-rum@file:../../packages/rum": | ||
version "1.26.2" | ||
"@datadog/browser-rum@2.1.1", "@datadog/browser-rum@file:../../packages/rum": | ||
version "2.1.1" | ||
dependencies: | ||
"@datadog/browser-core" "1.26.2" | ||
"@datadog/browser-core" "2.1.1" | ||
tslib "^1.10.0" | ||
|
||
"@types/[email protected]": | ||
version "0.0.4" | ||
resolved "https://registry.yarnpkg.com/@types/css-font-loading-module/-/css-font-loading-module-0.0.4.tgz#94a835e27d1af444c65cba88523533c174463d64" | ||
integrity sha512-ENdXf7MW4m9HeDojB2Ukbi7lYMIuQNBHVf98dbzaiG4EEJREBd6oleVAjrLRCrp7dm6CK1mmdmU9tcgF61acbw== | ||
|
||
"@webassemblyjs/[email protected]": | ||
version "1.8.5" | ||
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.8.5.tgz#51b1c5fe6576a34953bf4b253df9f0d490d9e359" | ||
|
@@ -1845,6 +1852,11 @@ ripemd160@^2.0.0, ripemd160@^2.0.1: | |
hash-base "^3.0.0" | ||
inherits "^2.0.1" | ||
|
||
[email protected]: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/rrweb-snapshot/-/rrweb-snapshot-1.0.1.tgz#f3800f4deb434da02b6086533c5c38e23e7e796b" | ||
integrity sha512-HKbfbTTDSTy4T0h/w9SubI1E5kL/qLiK08pJZRLA0MmGtqJ5nCTMtpEZXgCKMUncH3lb1rbiu+sDIoxKD+Anng== | ||
|
||
run-queue@^1.0.0, run-queue@^1.0.3: | ||
version "1.0.3" | ||
resolved "https://registry.yarnpkg.com/run-queue/-/run-queue-1.0.3.tgz#e848396f057d223f24386924618e25694161ec47" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,76 @@ | ||
import connectBusboy from 'connect-busboy' | ||
import express from 'express' | ||
import { createInflate } from 'zlib' | ||
|
||
import { SegmentFile, SerssionReplayCall } from '../../types/serverEvents' | ||
import { EventRegistry } from '../eventsRegistry' | ||
|
||
export function createIntakeServerApp(events: EventRegistry) { | ||
const app = express() | ||
|
||
app.use(express.text()) | ||
app.use(connectBusboy({ immediate: true })) | ||
|
||
app.post('/v1/input/:endpoint', (req, res) => { | ||
app.post('/v1/input/:endpoint', async (req, res) => { | ||
const endpoint = req.params.endpoint | ||
if (endpoint === 'rum' || endpoint === 'logs' || endpoint === 'internalMonitoring') { | ||
;(req.body as string).split('\n').map((rawEvent) => events.push(endpoint, JSON.parse(rawEvent) as any)) | ||
} | ||
|
||
if (endpoint === 'sessionReplay' && req.busboy) { | ||
events.push('sessionReplay', await readSessionReplay(req)) | ||
} | ||
|
||
res.end() | ||
}) | ||
|
||
return app | ||
} | ||
|
||
async function readSessionReplay(req: express.Request): Promise<SerssionReplayCall> { | ||
return new Promise((resolve, reject) => { | ||
const meta: { | ||
[field: string]: string | ||
} = {} | ||
let segmentPromise: Promise<SegmentFile> | ||
|
||
req.busboy.on('file', (fieldname, file, filename, encoding, mimetype) => { | ||
if (fieldname === 'segment') { | ||
segmentPromise = readStream(file.pipe(createInflate())).then((data) => ({ | ||
encoding, | ||
filename, | ||
mimetype, | ||
data: JSON.parse(data.toString()), | ||
})) | ||
} | ||
}) | ||
|
||
req.busboy.on('field', (key: string, value: string) => { | ||
meta[key] = value | ||
}) | ||
|
||
req.busboy.on('finish', async () => { | ||
try { | ||
const segment = await segmentPromise | ||
resolve({ meta, segment }) | ||
} catch (e) { | ||
reject(e) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
async function readStream(stream: NodeJS.ReadableStream): Promise<Buffer> { | ||
return new Promise((resolve, reject) => { | ||
const buffers: Buffer[] = [] | ||
stream.on('data', (data: Buffer) => { | ||
buffers.push(data) | ||
}) | ||
stream.on('error', (error) => { | ||
reject(error) | ||
}) | ||
stream.on('end', () => { | ||
resolve(Buffer.concat(buffers)) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.