Skip to content

ref(replay): Extract worker into @sentry-internal/replay-worker #6665

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

Closed
wants to merge 2 commits into from
Closed
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"packages/react",
"packages/remix",
"packages/replay",
"packages/replay-worker",
"packages/serverless",
"packages/svelte",
"packages/tracing",
Expand Down
8 changes: 8 additions & 0 deletions packages/replay-worker/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Note: All paths are relative to the directory in which eslint is being run, rather than the directory where this file
// lives

// ESLint config docs: https://eslint.org/docs/user-guide/configuring/

module.exports = {
extends: ['../../.eslintrc.js'],
};
5 changes: 5 additions & 0 deletions packages/replay-worker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
/*.tgz
.eslintcache
build
!types/*.d.ts
14 changes: 14 additions & 0 deletions packages/replay-worker/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright (c) 2022 Sentry (https://sentry.io) and individual contributors. All rights reserved.

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.
12 changes: 12 additions & 0 deletions packages/replay-worker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<p align="center">
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
</a>
</p>

# Sentry Session Replay Worker

This is an internal package that is used by @sentry/replay.
It generates a web worker and converts it to a string, so that we can process it easier in replay.

By extracting this into a dedicated (private, internal) package, we can streamline the build of replay.
1 change: 1 addition & 0 deletions packages/replay-worker/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../jest/jest.config.js');
51 changes: 51 additions & 0 deletions packages/replay-worker/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@sentry-internal/replay-worker",
"version": "7.29.0",
"description": "Worker for @sentry/replay",
"main": "build/index.js",
"module": "build/index.js",
"sideEffects": false,
"private": true,
"scripts": {
"build": "run-s build:rollup",
"build:rollup": "rollup -c rollup.worker.config.js",
"build:dev": "yarn build",
"build:watch": "run-p build:rollup:watch",
"build:dev:watch": "run-p build:watch",
"build:rollup:watch": "yarn build:rollup --watch",
"circularDepCheck": "madge --circular src/index.ts",
"clean": "rimraf build",
"fix": "run-s fix:eslint fix:prettier",
"fix:eslint": "eslint . --format stylish --fix",
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
"lint": "run-s lint:prettier lint:eslint",
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
"test": "jest",
"test:watch": "jest --watch"
},
"repository": {
"type": "git",
"url": "git+https://github.com/getsentry/sentry-javascript.git"
},
"author": "Sentry",
"license": "MIT",
"bugs": {
"url": "https://github.com/getsentry/sentry-javascript/issues"
},
"homepage": "https://docs.sentry.io/platforms/javascript/session-replay/",
"devDependencies": {
"@types/pako": "^2.0.0",
"rollup-plugin-copy": "~3.4.0",
"tslib": "^1.9.3"
},
"dependencies": {
"pako": "^2.0.4"
},
"engines": {
"node": ">=12"
},
"volta": {
"extends": "../../package.json"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import { defineConfig } from 'rollup';
import { terser } from 'rollup-plugin-terser';
import copy from 'rollup-plugin-copy';

const config = defineConfig({
input: ['./worker/src/worker.ts'],
input: ['./src/index.ts'],
output: {
dir: './src/worker/',
dir: './build/',
format: 'esm',
},
plugins: [
typescript({ tsconfig: './tsconfig.worker.json' }),
typescript({ tsconfig: './tsconfig.json', inlineSourceMap: false, sourceMap: false, inlineSources: false }),
resolve(),
terser({
mangle: {
Expand All @@ -25,6 +26,9 @@ const config = defineConfig({
return `export default \`${code}\`;`;
},
},
copy({
targets: [{ src: 'types/*', dest: 'build' }],
}),
],
});

Expand Down
7 changes: 7 additions & 0 deletions packages/replay-worker/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// TODO Once https://github.com/microsoft/TypeScript/issues/33094 is done (if it ever is), this file can disappear, as
// it's purely a placeholder to satisfy VSCode.
{
"extends": "../tsconfig.test.json",

"include": ["./**/*"]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pako from 'pako';

import { Compressor } from '../../../worker/src/Compressor';
import { Compressor } from '../../src/Compressor';

describe('Compressor', () => {
it('compresses multiple events', () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/replay-worker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "esnext",
"lib": ["webworker", "scripthost"],
"esModuleInterop": true,
"target": "es6",
"strictPropertyInitialization": false
},
"include": ["src/**/*.ts"]
}
7 changes: 7 additions & 0 deletions packages/replay-worker/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": ["test/**/*.ts"],
"compilerOptions": {
"types": ["node", "jest"]
}
}
16 changes: 1 addition & 15 deletions packages/replay/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,9 @@

module.exports = {
extends: ['../../.eslintrc.js'],
ignorePatterns: ['rollup.config.worker.js'],
overrides: [
{
files: ['worker/**/*.ts'],
parserOptions: {
// TODO: figure out if we need a worker-specific tsconfig
project: ['tsconfig.worker.json'],
},
},
{
files: ['src/worker/**/*.js'],
parserOptions: {
sourceType: 'module',
},
},
{
files: ['*.ts', '*.tsx', '*.d.ts'],
files: ['*.ts', '*.tsx'],
rules: {
// TODO (high-prio): Re-enable this after migration
'@typescript-eslint/explicit-member-accessibility': 'off',
Expand Down
22 changes: 9 additions & 13 deletions packages/replay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@
"types": "build/npm/types/index.d.ts",
"sideEffects": false,
"scripts": {
"build": "run-s build:worker && run-p build:core build:types build:bundle",
"build:rollup": "run-s build:worker build:core",
"build": "run-p build:rollup build:types build:bundle",
"build:rollup": "rollup -c rollup.npm.config.js",
"build:bundle": "rollup -c rollup.bundle.config.js",
"build:dev": "run-p build:worker build:rollup build:types",
"build:worker": "rollup -c rollup.config.worker.js",
"build:core": "rollup -c rollup.npm.config.js",
"build:dev": "run-p build:rollup build:types",
"build:types": "tsc -p tsconfig.types.json",
"build:watch": "run-p build:worker:watch build:core:watch build:bundle:watch build:types:watch",
"build:dev:watch": "run-p build:core:watch build:types:watch",
"build:core:watch": "yarn build:core --watch",
"build:worker:watch": "yarn build:worker --watch",
"build:watch": "run-p build:rollup:watch build:bundle:watch build:types:watch",
"build:dev:watch": "run-p build:rollup:watch build:types:watch",
"build:rollup:watch": "yarn build:core --watch",
"build:bundle:watch": "yarn build:bundle --watch",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:npm": "ts-node ../../scripts/prepack.ts --bundles && npm pack ./build/npm",
"circularDepCheck": "madge --circular src/index.ts",
"clean": "rimraf build sentry-replay-*.tgz",
"fix": "run-s fix:eslint fix:prettier",
"fix:eslint": "eslint . --format stylish --fix",
"fix:prettier": "prettier --write \"{src,test,scripts,worker}/**/*.ts\"",
"fix:prettier": "prettier --write \"{src,test,scripts}/**/*.ts\"",
"lint": "run-s lint:prettier lint:eslint",
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
"lint:prettier": "prettier --check \"{src,test,scripts,worker}/**/*.ts\"",
"lint:prettier": "prettier --check \"{src,test,scripts}/**/*.ts\"",
"test": "jest",
"test:watch": "jest --watch",
"bootstrap:demo": "cd demo && yarn",
Expand All @@ -46,9 +43,8 @@
"homepage": "https://docs.sentry.io/platforms/javascript/session-replay/",
"devDependencies": {
"@babel/core": "^7.17.5",
"@types/pako": "^2.0.0",
"@sentry-internal/replay-worker": "7.29.0",
"jsdom-worker": "^0.2.1",
"pako": "^2.0.4",
"rrweb": "1.1.3",
"tslib": "^1.9.3"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/rollup.npm.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export default makeNPMConfigVariants(
}),
],
output: {
// set exports to 'named' or 'auto' so that rollup doesn't warn about
// the default export in `worker/worker.js`
// set exports to 'named' or 'auto' so that rollup doesn't warn
exports: 'named',

// As we are inlining the rrweb dependency here, we need to ensure the nested folders are correct
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/src/eventBuffer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
// TODO: figure out member access types and remove the line above

import workerString from '@sentry-internal/replay-worker';
import { captureException } from '@sentry/core';
import { ReplayRecordingData } from '@sentry/types';
import { logger } from '@sentry/utils';

import type { EventBuffer, RecordingEvent, WorkerRequest, WorkerResponse } from './types';
import workerString from './worker/worker.js';

interface CreateEventBufferParams {
useCompression: boolean;
Expand Down
2 changes: 0 additions & 2 deletions packages/replay/src/worker/worker.js

This file was deleted.

19 changes: 0 additions & 19 deletions packages/replay/tsconfig.worker.json

This file was deleted.

39 changes: 38 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4117,6 +4117,13 @@
dependencies:
"@types/node" "*"

"@types/fs-extra@^8.0.1":
version "8.1.2"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-8.1.2.tgz#7125cc2e4bdd9bd2fc83005ffdb1d0ba00cca61f"
integrity sha512-SvSrYXfWSc7R4eqnOzbQF4TZmfpNSM9FrSWLU3EUnWBuyZqNBOrv1B1JA3byUDPUl9z4Ab3jeZG2eDdySlgNMg==
dependencies:
"@types/node" "*"

"@types/fs-extra@^8.1.0":
version "8.1.1"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-8.1.1.tgz#1e49f22d09aa46e19b51c0b013cb63d0d923a068"
Expand Down Expand Up @@ -8493,7 +8500,7 @@ color@^3.0.0:
color-convert "^1.9.1"
color-string "^1.5.4"

colorette@^1.2.1, colorette@^1.2.2:
colorette@^1.1.0, colorette@^1.2.1, colorette@^1.2.2:
version "1.4.0"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.4.0.tgz#5190fbb87276259a86ad700bff2c6d6faa3fca40"
integrity sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==
Expand Down Expand Up @@ -12857,6 +12864,20 @@ [email protected]:
merge2 "^1.2.3"
slash "^3.0.0"

[email protected]:
version "10.0.1"
resolved "https://registry.yarnpkg.com/globby/-/globby-10.0.1.tgz#4782c34cb75dd683351335c5829cc3420e606b22"
integrity sha512-sSs4inE1FB2YQiymcmTv6NWENryABjUNPeWhOvmn4SjtKybglsyPZxFB3U1/+L1bYi0rNZDqCLlHyLYDl1Pq5A==
dependencies:
"@types/glob" "^7.1.1"
array-union "^2.1.0"
dir-glob "^3.0.1"
fast-glob "^3.0.3"
glob "^7.1.3"
ignore "^5.1.1"
merge2 "^1.2.3"
slash "^3.0.0"

globby@^11.0.1, globby@^11.0.2, globby@^11.0.3, globby@^11.1.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
Expand Down Expand Up @@ -14349,6 +14370,11 @@ is-plain-object@^2.0.1, is-plain-object@^2.0.3, is-plain-object@^2.0.4:
dependencies:
isobject "^3.0.1"

is-plain-object@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-3.0.1.tgz#662d92d24c0aa4302407b0d45d21f2251c85f85b"
integrity sha512-Xnpx182SBMrr/aBik8y+GuR4U1L9FqMSojwDQwPMmxyC6bvEqly9UBCxhauBF5vNh2gwWJNX6oDV7O+OM4z34g==

is-plain-object@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-5.0.0.tgz#4427f50ab3429e9025ea7d52e9043a9ef4159344"
Expand Down Expand Up @@ -21061,6 +21087,17 @@ [email protected]:
js-cleanup "^1.2.0"
rollup-pluginutils "^2.8.2"

rollup-plugin-copy@~3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-copy/-/rollup-plugin-copy-3.4.0.tgz#f1228a3ffb66ffad8606e2f3fb7ff23141ed3286"
integrity sha512-rGUmYYsYsceRJRqLVlE9FivJMxJ7X6jDlP79fmFkL8sJs7VVMSVyA2yfyL+PGyO/vJs4A87hwhgVfz61njI+uQ==
dependencies:
"@types/fs-extra" "^8.0.1"
colorette "^1.1.0"
fs-extra "^8.1.0"
globby "10.0.1"
is-plain-object "^3.0.0"

rollup-plugin-license@^2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-license/-/rollup-plugin-license-2.6.1.tgz#20f15cc37950f362f8eefdc6e3a2e659d0cad9eb"
Expand Down