-
Notifications
You must be signed in to change notification settings - Fork 4
session-replay: add session replay package #239
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
59ade6a
sdk-core: add useModule to builder, export dataStructures
perf2711 5269b18
session-replay: add initial workspace
perf2711 0b37da4
session-replay: add session recorder module
perf2711 47e369b
session-replay: re-emit events to advancedOptions emit
perf2711 6a5c0d3
session-replay: add options and docs
perf2711 dcbf497
browser example: add example usage of session-replay
perf2711 f768fff
chore: update package-lock.json
perf2711 9d4b34f
session-replay: extract options to separate file, add inspect callback
perf2711 e4123b1
session-replay: update description
perf2711 93d0a8c
session-replay: remove test script
perf2711 b796461
session-replay: remove unnecessary check from BacktraceSessionRecorde…
perf2711 984a380
session-replay: add separate options for disabling limits
perf2711 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './OverwritingArray'; | ||
| export * from './OverwritingArrayIterator'; |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2023 Backtrace Labs | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| "name": "@backtrace/session-replay", | ||
| "version": "0.0.1", | ||
| "description": "Backtrace-JavaScript Session Replay module", | ||
| "main": "lib/index.js", | ||
| "types": "lib/index.d.ts", | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "clean": "tsc -b --clean && rimraf \"lib\"", | ||
| "format": "prettier --write '**/*.ts'", | ||
| "lint": "eslint . --ext .ts", | ||
| "watch": "tsc -w" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/backtrace-labs/backtrace-javascript.git" | ||
| }, | ||
| "author": "Backtrace <team@backtrace.io>", | ||
| "license": "MIT", | ||
| "bugs": { | ||
| "url": "https://github.com/backtrace-labs/backtrace-javascript/issues" | ||
| }, | ||
| "files": [ | ||
| "/lib" | ||
| ], | ||
| "homepage": "https://github.com/backtrace-labs/backtrace-javascript#readme", | ||
| "peerDependencies": { | ||
| "@backtrace/sdk-core": "^0.2.0" | ||
| }, | ||
| "dependencies": { | ||
| "rrweb": "^2.0.0-alpha.4" | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { BacktraceAttachment } from '@backtrace/sdk-core'; | ||
| import { eventWithTime } from '@rrweb/types'; | ||
| import { record } from 'rrweb'; | ||
| import { BacktraceSessionRecorderOptions } from './options'; | ||
|
|
||
| export class BacktraceSessionRecorder implements BacktraceAttachment { | ||
| public readonly name = 'bt-session-replay-0'; | ||
| public readonly type = 'dynamic'; | ||
|
|
||
| private readonly _maxEventCount?: number; | ||
| private readonly _maxTime?: number; | ||
|
|
||
| private _previousEvents?: eventWithTime[] = []; | ||
| private _events?: eventWithTime[] = []; | ||
|
|
||
| private _stop?: () => void; | ||
|
|
||
| constructor(private readonly _options: BacktraceSessionRecorderOptions) { | ||
| this._events = []; | ||
| this._maxEventCount = !_options.disableMaxEventCount ? _options.maxEventCount ?? 100 : undefined; | ||
| this._maxTime = !_options.disableMaxTime ? _options.maxTime : undefined; | ||
| } | ||
|
|
||
| public start() { | ||
| this._stop = record({ | ||
| ...this._options.advancedOptions, | ||
| sampling: { | ||
| mousemove: this._options.sampling?.mousemove, | ||
| mouseInteraction: this._options.sampling?.mouseInteraction, | ||
| input: this._options.sampling?.input, | ||
| media: this._options.sampling?.media, | ||
| scroll: this._options.sampling?.scroll, | ||
| ...this._options.advancedOptions, | ||
| }, | ||
| emit: (event, isCheckout) => this.onEmit(event, isCheckout), | ||
| checkoutEveryNth: this._maxEventCount && Math.ceil(this._maxEventCount / 2), | ||
| checkoutEveryNms: this._maxTime && Math.ceil(this._maxTime / 2), | ||
| }); | ||
| } | ||
|
|
||
| public stop() { | ||
| if (this._stop) { | ||
| this._stop(); | ||
| } | ||
| } | ||
|
|
||
| public get(): string { | ||
| const events = [...(this._events ?? []), ...(this._previousEvents ?? [])]; | ||
| return JSON.stringify(events); | ||
| } | ||
|
|
||
| private onEmit(event: eventWithTime, isCheckout?: boolean) { | ||
| if (isCheckout || !this._events) { | ||
| this._previousEvents = this._events; | ||
| this._events = []; | ||
| } | ||
|
|
||
| if (this._options.privacy?.inspect) { | ||
| const inspected = this._options.privacy.inspect(event); | ||
| if (!inspected) { | ||
| return; | ||
| } | ||
| event = inspected; | ||
| } | ||
|
|
||
| this._events.push(event); | ||
konraddysput marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (this._options.advancedOptions?.emit) { | ||
| this._options.advancedOptions.emit(event as never, isCheckout); | ||
| } | ||
| } | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
packages/session-replay/src/BacktraceSessionReplayModule.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { BacktraceModule, BacktraceModuleBindData } from '@backtrace/sdk-core'; | ||
| import { BacktraceSessionRecorder } from './BacktraceSessionRecorder'; | ||
| import { BacktraceSessionRecorderOptions } from './options'; | ||
|
|
||
| /** | ||
| * Adds session recorder module to `BacktraceClient`. | ||
| * | ||
| * Add using `useModule` on `BacktraceClient` builder. | ||
| * @example | ||
| const client = BacktraceClient.builder({ | ||
| ... | ||
| }).useModule(new BacktraceSessionReplayModule({ | ||
| // options here | ||
| })).build(); | ||
| */ | ||
| export class BacktraceSessionReplayModule implements BacktraceModule { | ||
| private readonly _recorder: BacktraceSessionRecorder; | ||
|
|
||
| constructor(options?: BacktraceSessionRecorderOptions) { | ||
| this._recorder = new BacktraceSessionRecorder(options ?? {}); | ||
| } | ||
|
|
||
| public bind({ client }: BacktraceModuleBindData): void { | ||
| client.addAttachment(this._recorder); | ||
| } | ||
|
|
||
| public initialize(): void { | ||
| this._recorder.start(); | ||
| } | ||
|
|
||
| public dispose(): void { | ||
| this._recorder.stop(); | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './BacktraceSessionRecorder'; | ||
| export * from './BacktraceSessionReplayModule'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.