@multiplayer-app/session-recorder-common 2.0.17-alpha.7 → 2.0.17-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/package.json +1 -1
  2. package/dist/esm/tsconfig.esm.tsbuildinfo +0 -1
  3. package/dist/esnext/tsconfig.esnext.tsbuildinfo +0 -1
  4. package/docs/img/header-js.png +0 -0
  5. package/eslint.config.js +0 -226
  6. package/src/SessionRecorderIdGenerator.ts +0 -70
  7. package/src/SessionRecorderTraceIdRatioBasedSampler.ts +0 -89
  8. package/src/constants/constants.base.ts +0 -111
  9. package/src/constants/constants.browser.ts +0 -1
  10. package/src/constants/constants.node.ts +0 -5
  11. package/src/exporters/SessionRecorderBrowserTraceExporter.ts +0 -196
  12. package/src/exporters/SessionRecorderGrpcLogsExporter.ts +0 -52
  13. package/src/exporters/SessionRecorderGrpcTraceExporter.ts +0 -50
  14. package/src/exporters/SessionRecorderHttpLogsExporter.ts +0 -58
  15. package/src/exporters/SessionRecorderHttpTraceExporter.ts +0 -68
  16. package/src/exporters/SessionRecorderLogsExporterWrapper.ts +0 -36
  17. package/src/exporters/SessionRecorderTraceExporterWrapper.ts +0 -36
  18. package/src/exporters/index-browser.ts +0 -1
  19. package/src/exporters/index-node.ts +0 -6
  20. package/src/exporters/index.ts +0 -7
  21. package/src/index-browser.ts +0 -6
  22. package/src/index-node.ts +0 -7
  23. package/src/index.ts +0 -7
  24. package/src/instrumentations/SessionRecorderHttpInstrumentationHooksNode.ts +0 -356
  25. package/src/instrumentations/index-node.ts +0 -1
  26. package/src/sdk/capture-exception.ts +0 -102
  27. package/src/sdk/id-generator.ts +0 -17
  28. package/src/sdk/index.ts +0 -8
  29. package/src/sdk/is-gzip.ts +0 -7
  30. package/src/sdk/mask.ts +0 -161
  31. package/src/sdk/save-continuous-deb-session.ts +0 -28
  32. package/src/sdk/schemify.ts +0 -57
  33. package/src/sdk/set-attribute.ts +0 -210
  34. package/src/sdk/set-resource-attributes.ts +0 -9
  35. package/src/type/crash-buffer.ts +0 -64
  36. package/src/type/index.ts +0 -4
  37. package/src/type/session-type.enum.ts +0 -20
  38. package/src/type/session.ts +0 -84
  39. package/src/type/user-type.enum.ts +0 -5
  40. package/tsconfig.base.es5.json +0 -8
  41. package/tsconfig.base.esm.json +0 -7
  42. package/tsconfig.base.esnext.json +0 -10
  43. package/tsconfig.base.json +0 -38
  44. package/tsconfig.esm.json +0 -12
  45. package/tsconfig.esnext.json +0 -12
  46. package/tsconfig.json +0 -25
@@ -1,57 +0,0 @@
1
- import * as _toJsonSchema from 'to-json-schema'
2
-
3
- // @ts-ignore
4
- const toJsonSchema = _toJsonSchema?.default || _toJsonSchema
5
-
6
- const defaultSchemifyOptions: _toJsonSchema.Options = {
7
- strings: {
8
- preProcessFnc: (value: string, defaultFnc: any) => {
9
- if (value?.length >= 30) {
10
- return defaultFnc('some_string')
11
- }
12
-
13
-
14
- return defaultFnc(value)
15
- },
16
- },
17
- arrays: {
18
- mode: 'first',
19
- },
20
- }
21
-
22
- export default (
23
- payload: string | object | undefined,
24
- stringify = true,
25
- options: _toJsonSchema.Options = defaultSchemifyOptions,
26
- ): any => {
27
- if (!payload) {
28
- return ''
29
- }
30
-
31
- let payloadJson: any
32
-
33
- if (typeof payload === 'string') {
34
- try {
35
- payloadJson = JSON.parse(payload)
36
- } catch {
37
- return payload
38
- }
39
- } else if (typeof payload === 'object') {
40
- payloadJson = payload
41
- } else {
42
- return payload
43
- }
44
-
45
- try {
46
- const schema = toJsonSchema(payloadJson, options)
47
-
48
- if (stringify) {
49
- return JSON.stringify(schema)
50
- }
51
-
52
- return schema
53
- } catch (err) {
54
- // error can happen when array has items like ['test', 'asd', '1'], type for '1' is null
55
- return ''
56
- }
57
- }
@@ -1,210 +0,0 @@
1
- import {
2
- trace,
3
- AttributeValue,
4
- context,
5
- } from '@opentelemetry/api'
6
- import {
7
- ATTR_MULTIPLAYER_HTTP_RESPONSE_BODY,
8
- ATTR_MULTIPLAYER_HTTP_RESPONSE_HEADERS,
9
- ATTR_MULTIPLAYER_HTTP_REQUEST_BODY,
10
- ATTR_MULTIPLAYER_HTTP_REQUEST_HEADERS,
11
- ATTR_MULTIPLAYER_RPC_REQUEST_MESSAGE,
12
- ATTR_MULTIPLAYER_RPC_RESPONSE_MESSAGE,
13
- ATTR_MULTIPLAYER_GRPC_REQUEST_MESSAGE,
14
- ATTR_MULTIPLAYER_GRPC_RESPONSE_MESSAGE,
15
- ATTR_MULTIPLAYER_MESSAGING_MESSAGE_BODY,
16
- } from '../constants/constants.base'
17
- import mask, { sensitiveFields, sensitiveHeaders } from './mask'
18
-
19
- /**
20
- * @description Set attribute to current span
21
- * @param {string} key
22
- * @param {AttributeValue} value
23
- * @returns {void}
24
- */
25
- export const setAttribute = (key: string, value: AttributeValue) => {
26
- const span = trace.getSpan(context.active())
27
- if (!span) return
28
-
29
- span.setAttribute(key, value)
30
- }
31
-
32
- /**
33
- * @description Set request body to current span attributes
34
- * @param body
35
- * @param {{ mask: boolean }} options
36
- * @returns {void}
37
- */
38
- export const setHttpRequestBody = (
39
- body: any,
40
- options: { mask: boolean } = { mask: true },
41
- ) => {
42
- const span = trace.getSpan(context.active())
43
- if (!span) return
44
-
45
- if (options?.mask) {
46
- body = mask(sensitiveFields)(body, span)
47
- }
48
-
49
- span.setAttribute(ATTR_MULTIPLAYER_HTTP_REQUEST_BODY, body)
50
- }
51
-
52
- /**
53
- * @description Set request headers to current span attributes
54
- * @param body
55
- * @param {{ mask: boolean }} options
56
- * @returns {void}
57
- */
58
- export const setHttpRequestHeaders = (
59
- body: any,
60
- options: { mask: boolean } = { mask: true },
61
- ) => {
62
- const span = trace.getSpan(context.active())
63
- if (!span) return
64
-
65
- if (options?.mask) {
66
- body = mask(sensitiveHeaders)(body, span)
67
- }
68
-
69
- span.setAttribute(ATTR_MULTIPLAYER_HTTP_REQUEST_HEADERS, body)
70
- }
71
-
72
- /**
73
- * @description Set response body to current span attributes
74
- * @param body
75
- * @param {{ mask: boolean }} options
76
- * @returns {void}
77
- */
78
- export const setHttpResponseBody = (
79
- body: any,
80
- options: { mask: boolean } = { mask: true },
81
- ) => {
82
- const span = trace.getSpan(context.active())
83
- if (!span) return
84
-
85
- if (options?.mask) {
86
- body = mask(sensitiveFields)(body, span)
87
- }
88
-
89
- span.setAttribute(ATTR_MULTIPLAYER_HTTP_RESPONSE_BODY, body)
90
- }
91
-
92
- /**
93
- * @description Set response body to current span attributes
94
- * @param body
95
- * @param {{ mask: boolean }} options
96
- * @returns {void}
97
- */
98
- export const setHttpResponseHeaders = (
99
- body: any,
100
- options: { mask: boolean } = { mask: true },
101
- ) => {
102
- const span = trace.getSpan(context.active())
103
- if (!span) return
104
-
105
- if (options?.mask) {
106
- body = mask(sensitiveFields)(body, span)
107
- }
108
-
109
- span.setAttribute(ATTR_MULTIPLAYER_HTTP_RESPONSE_HEADERS, body)
110
- }
111
-
112
- /**
113
- * @description Set message body to current span attributes
114
- * @param body
115
- * @param {{ mask: boolean }} options
116
- * @returns {void}
117
- */
118
- export const setMessageBody = (
119
- body: any,
120
- options: { mask: boolean } = { mask: true },
121
- ) => {
122
- const span = trace.getSpan(context.active())
123
- if (!span) return
124
-
125
- if (options?.mask) {
126
- body = mask(sensitiveFields)(body, span)
127
- }
128
-
129
- span.setAttribute(ATTR_MULTIPLAYER_MESSAGING_MESSAGE_BODY, body)
130
- }
131
-
132
- /**
133
- * @description Set rpc request message to current span attributes
134
- * @param body
135
- * @param {{ mask: boolean }} options
136
- * @returns {void}
137
- */
138
- export const setRpcRequestMessage = (
139
- body: any,
140
- options: { mask: boolean } = { mask: true },
141
- ) => {
142
- const span = trace.getSpan(context.active())
143
- if (!span) return
144
-
145
- if (options?.mask) {
146
- body = mask(sensitiveFields)(body, span)
147
- }
148
-
149
- span.setAttribute(ATTR_MULTIPLAYER_RPC_REQUEST_MESSAGE, body)
150
- }
151
-
152
- /**
153
- * @description Set rpc response message to current span attributes
154
- * @param body
155
- * @param {{ mask: boolean }} options
156
- * @returns {void}
157
- */
158
- export const setRpcResponseMessage = (
159
- body: any,
160
- options: { mask: boolean } = { mask: true },
161
- ) => {
162
- const span = trace.getSpan(context.active())
163
- if (!span) return
164
-
165
- if (options?.mask) {
166
- body = mask(sensitiveFields)(body, span)
167
- }
168
-
169
- span.setAttribute(ATTR_MULTIPLAYER_RPC_RESPONSE_MESSAGE, body)
170
- }
171
-
172
- /**
173
- * @description Set grpc request message to current span attributes
174
- * @param body
175
- * @param {{ mask: boolean }} options
176
- * @returns {void}
177
- */
178
- export const setGrpcRequestMessage = (
179
- body: any,
180
- options: { mask: boolean } = { mask: true },
181
- ) => {
182
- const span = trace.getSpan(context.active())
183
- if (!span) return
184
-
185
- if (options?.mask) {
186
- body = mask(sensitiveFields)(body, span)
187
- }
188
-
189
- span.setAttribute(ATTR_MULTIPLAYER_GRPC_REQUEST_MESSAGE, body)
190
- }
191
-
192
- /**
193
- * @description Set grpc response message to current span attributes
194
- * @param body
195
- * @param {{ mask: boolean }} options
196
- * @returns {void}
197
- */
198
- export const setGrpcResponseMessage = (
199
- body: any,
200
- options: { mask: boolean } = { mask: true },
201
- ) => {
202
- const span = trace.getSpan(context.active())
203
- if (!span) return
204
-
205
- if (options?.mask) {
206
- body = mask(sensitiveFields)(body, span)
207
- }
208
-
209
- span.setAttribute(ATTR_MULTIPLAYER_GRPC_RESPONSE_MESSAGE, body)
210
- }
@@ -1,9 +0,0 @@
1
- let resourceAttributes: Record<string, any> = {}
2
-
3
- export const setResourceAttributes = (attributes: Record<string, any>) => {
4
- resourceAttributes = attributes
5
- }
6
-
7
- export const getResourceAttributes = () => {
8
- return resourceAttributes
9
- }
@@ -1,64 +0,0 @@
1
- export type CrashBufferAttrs = {
2
- sessionAttributes?: Record<string, any>
3
- resourceAttributes?: Record<string, any>
4
- userAttributes?: any
5
- }
6
-
7
- export type CrashBufferRrwebEventPayload = {
8
- ts: number
9
- isFullSnapshot?: boolean
10
- event: any
11
- }
12
-
13
- export type CrashBufferOtelSpanPayload = {
14
- ts: number
15
- span: any
16
- }
17
-
18
- /**
19
- * Batch append payload for OTEL spans.
20
- * This is intentionally the same per-span shape as `CrashBufferOtelSpanPayload`,
21
- * just provided as an array to allow implementations to persist efficiently.
22
- */
23
- export type CrashBufferOtelSpanBatchPayload = CrashBufferOtelSpanPayload[]
24
-
25
- export type CrashBufferErrorSpanAppendedEvent = CrashBufferOtelSpanPayload
26
-
27
- export type CrashBufferEventName = 'error-span-appended'
28
-
29
- export type CrashBufferEventMap = {
30
- 'error-span-appended': CrashBufferErrorSpanAppendedEvent
31
- }
32
-
33
- export type CrashBufferSnapshot = {
34
- startedAt: number
35
- stoppedAt: number
36
- events: CrashBufferRrwebEventPayload[]
37
- spans: CrashBufferOtelSpanPayload[]
38
- }
39
-
40
- /**
41
- * Shared CrashBuffer contract used across browser + react-native implementations.
42
- *
43
- * Notes:
44
- * - `windowMs` is optional because browser implementations usually bake the window into the instance,
45
- * while React Native typically passes it per call.
46
- * - `pruneOlderThan` is optional because browser implementations can handle pruning internally.
47
- */
48
- export interface CrashBuffer {
49
- appendEvent(payload: CrashBufferRrwebEventPayload, windowMs?: number): Promise<void>
50
- appendSpans(payload: CrashBufferOtelSpanBatchPayload, windowMs?: number): Promise<void>
51
- snapshot(windowMs?: number, now?: number): Promise<CrashBufferSnapshot>
52
- clear(): Promise<void>
53
- pruneOlderThan?(cutoffTs: number): Promise<void>
54
- on?(event: CrashBufferEventName, listener: (payload: CrashBufferEventMap[CrashBufferEventName]) => void): () => void
55
- off?(event: CrashBufferEventName, listener: (payload: CrashBufferEventMap[CrashBufferEventName]) => void): void
56
- }
57
-
58
- /**
59
- * Optional lifecycle controls supported by some CrashBuffer implementations (e.g. browser tabs).
60
- */
61
- export interface CrashBufferLifecycle extends CrashBuffer {
62
- setActive(active: boolean): void
63
- needsFullSnapshot(): boolean
64
- }
package/src/type/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './session-type.enum'
2
- export * from './user-type.enum'
3
- export * from './session'
4
- export * from './crash-buffer'
@@ -1,20 +0,0 @@
1
- export enum SessionType {
2
- CONTINUOUS = 'CONTINUOUS',
3
- /**
4
- * @deprecated Use MANUAL instead
5
- */
6
- PLAIN = 'MANUAL',
7
- /**
8
- * @description Manually triggered session recording
9
- */
10
- MANUAL = 'MANUAL',
11
-
12
- /**
13
- * @description Just for corellation without cache
14
- */
15
- SESSION = 'SESSION',
16
- /**
17
- * @description Correlation + caching
18
- */
19
- SESSION_CACHE = 'SESSION_CACHE',
20
- }
@@ -1,84 +0,0 @@
1
- import { SessionType } from './session-type.enum'
2
- import { UserType } from './user-type.enum'
3
-
4
- export interface IResourceAttributes {
5
- browserInfo?: string;
6
- cookiesEnabled?: string;
7
- deviceInfo?: string;
8
- hardwareConcurrency?: number;
9
- osInfo?: string;
10
- pixelRatio?: number;
11
- screenSize?: string;
12
- packageVersion?: string;
13
- [key: string]: any;
14
- }
15
-
16
- export interface ISessionAttributes {
17
- [key: string]: any;
18
- }
19
-
20
- export interface IUserAttributes {
21
- type: UserType
22
- id?: string
23
- name?: string
24
- groupId?: string
25
- groupName?: string
26
- userEmail?: string
27
- userId?: string
28
- userName?: string
29
- accountId?: string
30
- accountName?: string
31
- orgId?: string
32
- orgName?: string
33
- tags?: string[]
34
- environment?: string
35
- }
36
-
37
- export interface ISession {
38
- _id: string;
39
- shortId: string;
40
- workspace: string;
41
- project: string;
42
- continuousDebugSession?: string;
43
- creationType: SessionType;
44
- name: string;
45
- startedAt: string | Date;
46
- stoppedAt: string | Date;
47
- durationInSeconds?: number;
48
- createdAt: string | Date;
49
- updatedAt: string | Date;
50
- tags: any[];
51
-
52
- resourceAttributes?: IResourceAttributes;
53
- sessionAttributes?: ISessionAttributes;
54
-
55
- userAttributes?: IUserAttributes
56
-
57
- views: ISessionView[];
58
- starred: boolean;
59
- starredItems: string[];
60
- s3Files: {
61
- _id?: string;
62
- bucket: string;
63
- key: string;
64
- dataType: DebugSessionDataType;
65
- url?: string;
66
- }[];
67
- finishedS3Transfer?: boolean;
68
- tempApiKey?: string;
69
- }
70
-
71
-
72
-
73
- export interface ISessionView {
74
- _id: string;
75
- name: string;
76
- components?: string[];
77
- }
78
-
79
-
80
- export enum DebugSessionDataType {
81
- OTLP_TRACES = 'OTLP_TRACES',
82
- OTLP_LOGS = 'OTLP_LOGS',
83
- RRWEB_EVENTS = 'RRWEB_EVENTS',
84
- }
@@ -1,5 +0,0 @@
1
- export enum UserType {
2
- USER = 'USER',
3
- VISITOR = 'VISITOR',
4
- API_CLIENT = 'API_CLIENT',
5
- }
@@ -1,8 +0,0 @@
1
-
2
- {
3
- "extends": "./tsconfig.base.json",
4
- "compilerOptions": {
5
- "target": "es5",
6
- "downlevelIteration": true
7
- }
8
- }
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.base.es5.json",
3
- "compilerOptions": {
4
- "module": "ES6",
5
- "moduleResolution": "node"
6
- }
7
- }
@@ -1,10 +0,0 @@
1
-
2
- {
3
- "extends": "./tsconfig.base.json",
4
- "compilerOptions": {
5
- "module": "esnext",
6
- // target should be aligned with tsconfig.base.json
7
- "target": "es2017",
8
- "moduleResolution": "node"
9
- },
10
- }
@@ -1,38 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowSyntheticDefaultImports": true,
4
- "allowUnreachableCode": false,
5
- "allowUnusedLabels": false,
6
- "composite": true,
7
- "declaration": true,
8
- "declarationMap": true,
9
- "forceConsistentCasingInFileNames": true,
10
- "incremental": true,
11
- "inlineSources": true,
12
- "module": "commonjs",
13
- "newLine": "LF",
14
- "noEmitOnError": true,
15
- "noFallthroughCasesInSwitch": true,
16
- "noImplicitOverride": true,
17
- "noImplicitReturns": true,
18
- "noUnusedLocals": true,
19
- "pretty": true,
20
- "skipLibCheck": true,
21
- "sourceMap": true,
22
- "strict": true,
23
- "strictNullChecks": true,
24
- "target": "es2017",
25
- "useUnknownInCatchVariables": false,
26
- "types": [
27
- "node"
28
- ],
29
- "lib": [
30
- "es2017",
31
- "dom",
32
- "dom.iterable"
33
- ]
34
- },
35
- "exclude": [
36
- "node_modules"
37
- ]
38
- }
package/tsconfig.esm.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "./tsconfig.base.esm.json",
3
- "compilerOptions": {
4
- "outDir": "dist/esm",
5
- "rootDir": "src",
6
- "tsBuildInfoFile": "dist/esm/tsconfig.esm.tsbuildinfo"
7
- },
8
- "include": [
9
- "src/**/*.ts"
10
- ],
11
- "references": []
12
- }
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "./tsconfig.base.esnext.json",
3
- "compilerOptions": {
4
- "outDir": "dist/esnext",
5
- "rootDir": "src",
6
- "tsBuildInfoFile": "dist/esnext/tsconfig.esnext.tsbuildinfo"
7
- },
8
- "include": [
9
- "src/**/*.ts"
10
- ],
11
- "references": []
12
- }
package/tsconfig.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "extends": "./tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "rootDir": "."
6
- },
7
- "composite": true,
8
- "files": [],
9
- "include": [
10
- "src/**/*.ts",
11
- "test/**/*.ts"
12
- ],
13
- "typedocOptions": {
14
- "out": "docs",
15
- "exclude": [
16
- "**/dist/**",
17
- "**/build/**",
18
- "**/node_modules/**",
19
- "**/*.spec.ts"
20
- ],
21
- "name": "OpenTelemetry SDK",
22
- "excludePrivate": true
23
- },
24
- "references": []
25
- }