@openobserve/browser-core 0.3.2 → 0.3.3

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 (83) hide show
  1. package/cjs/boot/init.js +1 -1
  2. package/cjs/domain/configuration/endpointBuilder.js +1 -1
  3. package/cjs/domain/tags.js +1 -1
  4. package/cjs/domain/telemetry/telemetry.js +1 -1
  5. package/cjs/domain/telemetry/telemetryEvent.types.d.ts +1 -1
  6. package/esm/boot/init.js +1 -1
  7. package/esm/domain/configuration/endpointBuilder.js +1 -1
  8. package/esm/domain/tags.js +1 -1
  9. package/esm/domain/telemetry/telemetry.js +1 -1
  10. package/esm/domain/telemetry/telemetryEvent.types.d.ts +1 -1
  11. package/package.json +2 -2
  12. package/src/domain/telemetry/telemetryEvent.types.ts +1 -1
  13. package/src/boot/displayAlreadyInitializedError.spec.ts +0 -18
  14. package/src/boot/init.spec.ts +0 -50
  15. package/src/browser/addEventListener.spec.ts +0 -141
  16. package/src/browser/cookie.spec.ts +0 -53
  17. package/src/browser/fetchObservable.spec.ts +0 -334
  18. package/src/browser/pageMayExitObservable.spec.ts +0 -56
  19. package/src/browser/xhrObservable.spec.ts +0 -405
  20. package/src/domain/allowedTrackingOrigins.spec.ts +0 -210
  21. package/src/domain/bufferedData.spec.ts +0 -34
  22. package/src/domain/configuration/configuration.spec.ts +0 -236
  23. package/src/domain/configuration/endpointBuilder.spec.ts +0 -173
  24. package/src/domain/configuration/transportConfiguration.spec.ts +0 -130
  25. package/src/domain/connectivity/connectivity.spec.ts +0 -50
  26. package/src/domain/console/consoleObservable.spec.ts +0 -151
  27. package/src/domain/context/contextManager.spec.ts +0 -152
  28. package/src/domain/context/contextUtils.spec.ts +0 -26
  29. package/src/domain/context/storeContextManager.spec.ts +0 -103
  30. package/src/domain/contexts/accountContext.spec.ts +0 -99
  31. package/src/domain/contexts/globalContext.spec.ts +0 -88
  32. package/src/domain/contexts/userContext.spec.ts +0 -156
  33. package/src/domain/error/error.spec.ts +0 -294
  34. package/src/domain/error/trackRuntimeError.spec.ts +0 -343
  35. package/src/domain/eventRateLimiter/createEventRateLimiter.spec.ts +0 -119
  36. package/src/domain/extension/extensionUtils.spec.ts +0 -47
  37. package/src/domain/report/reportObservable.spec.ts +0 -71
  38. package/src/domain/session/oldCookiesMigration.spec.ts +0 -76
  39. package/src/domain/session/sessionManager.spec.ts +0 -684
  40. package/src/domain/session/sessionState.spec.ts +0 -88
  41. package/src/domain/session/sessionStore.spec.ts +0 -647
  42. package/src/domain/session/sessionStoreOperations.spec.ts +0 -234
  43. package/src/domain/session/storeStrategies/sessionInCookie.spec.ts +0 -228
  44. package/src/domain/session/storeStrategies/sessionInLocalStorage.spec.ts +0 -75
  45. package/src/domain/synthetics/syntheticsWorkerValues.spec.ts +0 -82
  46. package/src/domain/tags.spec.ts +0 -74
  47. package/src/domain/telemetry/telemetry.spec.ts +0 -494
  48. package/src/domain/trackingConsent.spec.ts +0 -44
  49. package/src/tools/abstractHooks.spec.ts +0 -76
  50. package/src/tools/abstractLifeCycle.spec.ts +0 -46
  51. package/src/tools/boundedBuffer.spec.ts +0 -40
  52. package/src/tools/catchUserErrors.spec.ts +0 -20
  53. package/src/tools/encoder.spec.ts +0 -112
  54. package/src/tools/experimentalFeatures.spec.ts +0 -60
  55. package/src/tools/getZoneJsOriginalValue.spec.ts +0 -36
  56. package/src/tools/instrumentMethod.spec.ts +0 -381
  57. package/src/tools/matchOption.spec.ts +0 -41
  58. package/src/tools/mergeInto.spec.ts +0 -198
  59. package/src/tools/monitor.spec.ts +0 -172
  60. package/src/tools/observable.spec.ts +0 -259
  61. package/src/tools/queueMicrotask.spec.ts +0 -24
  62. package/src/tools/readBytesFromStream.spec.ts +0 -62
  63. package/src/tools/requestIdleCallback.spec.ts +0 -65
  64. package/src/tools/serialisation/jsonStringify.spec.ts +0 -76
  65. package/src/tools/serialisation/sanitize.spec.ts +0 -284
  66. package/src/tools/stackTrace/capturedExceptions.specHelper.ts +0 -316
  67. package/src/tools/stackTrace/computeStackTrace.spec.ts +0 -1007
  68. package/src/tools/stackTrace/handlingStack.spec.ts +0 -20
  69. package/src/tools/taskQueue.spec.ts +0 -60
  70. package/src/tools/timer.spec.ts +0 -76
  71. package/src/tools/utils/browserDetection.spec.ts +0 -120
  72. package/src/tools/utils/byteUtils.spec.ts +0 -29
  73. package/src/tools/utils/functionUtils.spec.ts +0 -229
  74. package/src/tools/utils/numberUtils.spec.ts +0 -27
  75. package/src/tools/utils/stringUtils.spec.ts +0 -74
  76. package/src/tools/utils/typeUtils.spec.ts +0 -25
  77. package/src/tools/utils/urlPolyfill.spec.ts +0 -55
  78. package/src/tools/valueHistory.spec.ts +0 -180
  79. package/src/transport/batch.spec.ts +0 -261
  80. package/src/transport/eventBridge.spec.ts +0 -90
  81. package/src/transport/flushController.spec.ts +0 -267
  82. package/src/transport/httpRequest.spec.ts +0 -400
  83. package/src/transport/sendWithRetryStrategy.spec.ts +0 -393
@@ -1,156 +0,0 @@
1
- import type { Hooks } from '../../../test'
2
- import { createHooks, registerCleanupTask } from '../../../test'
3
- import { mockRumConfiguration } from '../../../../rum-core/test'
4
- import type { ContextManager } from '../context/contextManager'
5
- import type { RelativeTime } from '../../tools/utils/timeUtils'
6
- import { HookNames } from '../../tools/abstractHooks'
7
- import { removeStorageListeners } from '../context/storeContextManager'
8
- import type { Configuration } from '../configuration'
9
- import type { SessionContext } from '../session/sessionManager'
10
- import { startUserContext } from './userContext'
11
-
12
- describe('user context', () => {
13
- let userContext: ContextManager
14
- let hooks: Hooks
15
- const mockSessionManager = {
16
- findTrackedSession: () =>
17
- ({
18
- anonymousId: 'device-123',
19
- }) as SessionContext<string>,
20
- }
21
-
22
- beforeEach(() => {
23
- hooks = createHooks()
24
- userContext = startUserContext(
25
- hooks,
26
- mockRumConfiguration({ trackAnonymousUser: false }),
27
- mockSessionManager,
28
- 'some_product_key'
29
- )
30
- })
31
-
32
- it('should sanitize predefined properties', () => {
33
- userContext.setContext({ id: false, name: 2, email: { bar: 'qux' } })
34
-
35
- expect(userContext.getContext()).toEqual({
36
- email: '[object Object]',
37
- id: 'false',
38
- name: '2',
39
- })
40
- })
41
-
42
- describe('assemble hook', () => {
43
- it('should set the user', () => {
44
- userContext.setContext({ id: '123', foo: 'bar' })
45
- const defaultRumEventAttributes = hooks.triggerHook(HookNames.Assemble, {
46
- eventType: 'view',
47
- startTime: 0 as RelativeTime,
48
- })
49
-
50
- expect(defaultRumEventAttributes).toEqual({
51
- type: 'view',
52
- usr: {
53
- id: '123',
54
- foo: 'bar',
55
- },
56
- })
57
- })
58
-
59
- it('should set anonymous_id when trackAnonymousUser is true', () => {
60
- userContext = startUserContext(
61
- hooks,
62
- { trackAnonymousUser: true } as Configuration,
63
- mockSessionManager,
64
- 'some_product_key'
65
- )
66
- userContext.setContext({ id: '123' })
67
- const defaultRumEventAttributes = hooks.triggerHook(HookNames.Assemble, {
68
- eventType: 'view',
69
- startTime: 0 as RelativeTime,
70
- })
71
-
72
- expect(defaultRumEventAttributes).toEqual({
73
- type: 'view',
74
- usr: {
75
- id: '123',
76
- anonymous_id: 'device-123',
77
- },
78
- })
79
- })
80
-
81
- it('should not override customer provided anonymous_id when trackAnonymousUser is true', () => {
82
- userContext = startUserContext(
83
- hooks,
84
- { trackAnonymousUser: true } as Configuration,
85
- mockSessionManager,
86
- 'some_product_key'
87
- )
88
- userContext.setContext({ id: '123', anonymous_id: 'foo' })
89
- const defaultRumEventAttributes = hooks.triggerHook(HookNames.Assemble, {
90
- eventType: 'view',
91
- startTime: 0 as RelativeTime,
92
- })
93
-
94
- expect(defaultRumEventAttributes).toEqual({
95
- type: 'view',
96
- usr: {
97
- id: '123',
98
- anonymous_id: 'foo',
99
- },
100
- })
101
- })
102
- })
103
-
104
- describe('assemble telemetry hook', () => {
105
- it('should set the anonymous_id', () => {
106
- const defaultRumEventAttributes = hooks.triggerHook(HookNames.AssembleTelemetry, {
107
- startTime: 0 as RelativeTime,
108
- })
109
-
110
- expect(defaultRumEventAttributes).toEqual({
111
- anonymous_id: 'device-123',
112
- })
113
- })
114
- })
115
- })
116
-
117
- describe('user context across pages', () => {
118
- let userContext: ContextManager
119
- let hooks: Hooks
120
- const mockSessionManager = { findTrackedSession: () => undefined }
121
-
122
- beforeEach(() => {
123
- hooks = createHooks()
124
-
125
- registerCleanupTask(() => {
126
- localStorage.clear()
127
- removeStorageListeners()
128
- })
129
- })
130
-
131
- it('when disabled, should store contexts only in memory', () => {
132
- userContext = startUserContext(
133
- hooks,
134
- { storeContextsAcrossPages: false } as Configuration,
135
- mockSessionManager,
136
- 'some_product_key'
137
- )
138
- userContext.setContext({ id: '123' })
139
-
140
- expect(userContext.getContext()).toEqual({ id: '123' })
141
- expect(localStorage.getItem('_oo_c_some_product_key_1')).toBeNull()
142
- })
143
-
144
- it('when enabled, should maintain the user in local storage', () => {
145
- userContext = startUserContext(
146
- hooks,
147
- { storeContextsAcrossPages: true } as Configuration,
148
- mockSessionManager,
149
- 'some_product_key'
150
- )
151
-
152
- userContext.setContext({ id: 'foo', qux: 'qix' })
153
- expect(userContext.getContext()).toEqual({ id: 'foo', qux: 'qix' })
154
- expect(localStorage.getItem('_oo_c_some_product_key_1')).toBe('{"id":"foo","qux":"qix"}')
155
- })
156
- })
@@ -1,294 +0,0 @@
1
- import { clocksNow } from '../../tools/utils/timeUtils'
2
- import type { StackTrace } from '../../tools/stackTrace/computeStackTrace'
3
- import { registerCleanupTask } from '../../../test'
4
- import {
5
- computeRawError,
6
- getFileFromStackTraceString,
7
- flattenErrorCauses,
8
- isError,
9
- NO_ERROR_STACK_PRESENT_MESSAGE,
10
- } from './error'
11
- import type { RawErrorCause, ErrorWithCause } from './error.types'
12
- import { ErrorHandling, ErrorSource, NonErrorPrefix } from './error.types'
13
-
14
- describe('computeRawError', () => {
15
- const DEFAULT_RAW_ERROR_PARAMS = {
16
- startClocks: clocksNow(),
17
- nonErrorPrefix: NonErrorPrefix.UNCAUGHT,
18
- source: ErrorSource.CUSTOM,
19
- }
20
-
21
- it('should format an error instance', () => {
22
- const error = new TypeError('oh snap!')
23
- // This stack was generated in Chrome.
24
- error.stack = `TypeError: Oh snap!
25
- at foo (http://path/to/file.js:52:15)
26
- at <anonymous>:3:1`
27
-
28
- const formatted = computeRawError({
29
- ...DEFAULT_RAW_ERROR_PARAMS,
30
- originalError: error,
31
- handling: ErrorHandling.HANDLED,
32
- })
33
-
34
- expect(formatted.message).toEqual('oh snap!')
35
- expect(formatted.type).toEqual('TypeError')
36
- expect(formatted.stack).toEqual(`TypeError: oh snap!
37
- at foo @ http://path/to/file.js:52:15
38
- at <anonymous> @ <anonymous>:3:1`)
39
- })
40
-
41
- it('should format an error instance with an empty message', () => {
42
- const error = new TypeError('oh snap!')
43
- error.message = ''
44
-
45
- const formatted = computeRawError({
46
- ...DEFAULT_RAW_ERROR_PARAMS,
47
- originalError: error,
48
- handling: ErrorHandling.HANDLED,
49
- })
50
-
51
- expect(formatted.message).toEqual('Empty message')
52
- })
53
-
54
- it('should format a string error', () => {
55
- const error = 'oh snap!'
56
-
57
- const formatted = computeRawError({
58
- ...DEFAULT_RAW_ERROR_PARAMS,
59
- originalError: error,
60
- handling: ErrorHandling.HANDLED,
61
- })
62
-
63
- expect(formatted.message).toEqual('Uncaught "oh snap!"')
64
- expect(formatted.stack).toEqual(NO_ERROR_STACK_PRESENT_MESSAGE)
65
- })
66
-
67
- it('should format an object error', () => {
68
- const error = { foo: 'bar' }
69
-
70
- const formatted = computeRawError({
71
- ...DEFAULT_RAW_ERROR_PARAMS,
72
- originalError: error,
73
- handling: ErrorHandling.HANDLED,
74
- })
75
-
76
- expect(formatted.message).toEqual('Uncaught {"foo":"bar"}')
77
- expect(formatted.stack).toEqual(NO_ERROR_STACK_PRESENT_MESSAGE)
78
- })
79
-
80
- it('does not define the stack if useFallbackStack is false', () => {
81
- const error = 'foo is undefined'
82
-
83
- const formatted = computeRawError({
84
- ...DEFAULT_RAW_ERROR_PARAMS,
85
- originalError: error,
86
- handling: ErrorHandling.HANDLED,
87
- useFallbackStack: false,
88
- })
89
-
90
- expect(formatted.stack).toEqual(undefined)
91
- })
92
-
93
- it('uses the provided stack trace object', () => {
94
- const stackTrace: StackTrace = {
95
- message: 'oh snap!',
96
- name: 'TypeError',
97
- stack: [
98
- {
99
- args: ['1', 'bar'],
100
- column: 15,
101
- func: 'foo',
102
- line: 52,
103
- url: 'http://path/to/file.js',
104
- },
105
- {
106
- args: [],
107
- column: undefined,
108
- func: '?',
109
- line: 12,
110
- url: 'http://path/to/file.js',
111
- },
112
- {
113
- args: ['baz'],
114
- column: undefined,
115
- func: '?',
116
- line: undefined,
117
- url: 'http://path/to/file.js',
118
- },
119
- ],
120
- }
121
-
122
- const formatted = computeRawError({
123
- ...DEFAULT_RAW_ERROR_PARAMS,
124
- originalError: 'toto',
125
- handling: ErrorHandling.HANDLED,
126
- stackTrace,
127
- })
128
-
129
- expect(formatted.message).toEqual('oh snap!')
130
- expect(formatted.stack).toEqual(`TypeError: oh snap!
131
- at foo(1, bar) @ http://path/to/file.js:52:15
132
- at <anonymous> @ http://path/to/file.js:12
133
- at <anonymous>(baz) @ http://path/to/file.js`)
134
- expect(formatted.type).toEqual('TypeError')
135
- })
136
-
137
- it('should set handling according to given parameter', () => {
138
- const error = { foo: 'bar' }
139
-
140
- expect(
141
- computeRawError({
142
- ...DEFAULT_RAW_ERROR_PARAMS,
143
- originalError: error,
144
- handling: ErrorHandling.HANDLED,
145
- }).handling
146
- ).toEqual(ErrorHandling.HANDLED)
147
-
148
- expect(
149
- computeRawError({
150
- ...DEFAULT_RAW_ERROR_PARAMS,
151
- originalError: error,
152
- handling: ErrorHandling.UNHANDLED,
153
- }).handling
154
- ).toEqual(ErrorHandling.UNHANDLED)
155
- })
156
-
157
- it('should compute an object error with causes', () => {
158
- const error = new Error('foo: bar') as ErrorWithCause
159
- error.stack = 'Error: foo: bar\n at <anonymous>:1:15'
160
-
161
- const nestedError = new Error('biz: buz') as ErrorWithCause
162
- nestedError.stack = 'NestedError: biz: buz\n at <anonymous>:2:15'
163
-
164
- const deepNestedError = new TypeError('fiz: buz') as ErrorWithCause
165
- deepNestedError.stack = 'NestedError: fiz: buz\n at <anonymous>:3:15'
166
-
167
- error.cause = nestedError
168
- nestedError.cause = deepNestedError
169
-
170
- const formatted = computeRawError({
171
- ...DEFAULT_RAW_ERROR_PARAMS,
172
- originalError: error,
173
- handling: ErrorHandling.HANDLED,
174
- source: ErrorSource.SOURCE,
175
- })
176
-
177
- expect(formatted.type).toEqual('Error')
178
- expect(formatted.message).toEqual('foo: bar')
179
- expect(formatted.causes!.length).toBe(2)
180
- expect(formatted.stack).toContain('Error: foo: bar')
181
-
182
- const causes = formatted.causes as RawErrorCause[]
183
-
184
- expect(causes[0].message).toContain(nestedError.message)
185
- expect(causes[0].source).toContain(ErrorSource.SOURCE)
186
- expect(causes[0].type).toEqual(nestedError.name)
187
- expect(causes[0].stack).toContain('Error: biz: buz')
188
-
189
- expect(causes[1].message).toContain(deepNestedError.message)
190
- expect(causes[1].source).toContain(ErrorSource.SOURCE)
191
- expect(causes[1].type).toEqual(deepNestedError.name)
192
- expect(causes[1].stack).toContain('Error: fiz: buz')
193
- })
194
-
195
- it('should propagate the original error without modifications', () => {
196
- const error = { description: 'syntax error' }
197
-
198
- const formattedWithoutStackTrace = computeRawError({
199
- ...DEFAULT_RAW_ERROR_PARAMS,
200
- originalError: error,
201
- handling: ErrorHandling.HANDLED,
202
- })
203
-
204
- const formattedWithStackTrace = computeRawError({
205
- ...DEFAULT_RAW_ERROR_PARAMS,
206
- originalError: error,
207
- handling: ErrorHandling.HANDLED,
208
- })
209
-
210
- expect(formattedWithStackTrace.originalError).toBe(error)
211
- expect(formattedWithoutStackTrace.originalError).toBe(error)
212
- })
213
- })
214
-
215
- describe('getFileFromStackTraceString', () => {
216
- it('should get the first source file of the stack', () => {
217
- expect(
218
- getFileFromStackTraceString(`TypeError: oh snap!
219
- at foo(1, bar) @ http://path/to/file.js:52:15
220
- at <anonymous> @ http://path/to/file.js:12
221
- at <anonymous>(baz) @ http://path/to/file.js`)
222
- ).toEqual('http://path/to/file.js:52:15')
223
- })
224
-
225
- it('should get undefined if no source file is in the stack', () => {
226
- expect(getFileFromStackTraceString('TypeError: oh snap!')).not.toBeDefined()
227
- })
228
- })
229
-
230
- describe('flattenErrorCauses', () => {
231
- it('should return undefined if no cause found', () => {
232
- const error = new Error('foo') as ErrorWithCause
233
- const errorCauses = flattenErrorCauses(error, ErrorSource.LOGGER)
234
- expect(errorCauses).toEqual(undefined)
235
- })
236
-
237
- it('should return undefined if cause is not of type Error', () => {
238
- const error = new Error('foo') as ErrorWithCause
239
- const nestedError = { biz: 'buz', cause: new Error('boo') } as unknown as Error
240
-
241
- error.cause = nestedError
242
-
243
- const errorCauses = flattenErrorCauses(error, ErrorSource.LOGGER)
244
- expect(errorCauses?.length).toEqual(undefined)
245
- })
246
-
247
- it('should use error to extract stack trace', () => {
248
- const error = new Error('foo') as ErrorWithCause
249
-
250
- error.cause = new Error('bar')
251
-
252
- const errorCauses = flattenErrorCauses(error, ErrorSource.LOGGER)
253
- expect(errorCauses?.[0].type).toEqual('Error')
254
- })
255
-
256
- it('should only return the first 10 errors if nested chain is longer', () => {
257
- const error = new Error('foo') as ErrorWithCause
258
- error.cause = error
259
- const errorCauses = flattenErrorCauses(error, ErrorSource.LOGGER)
260
- expect(errorCauses?.length).toEqual(10)
261
- })
262
- })
263
-
264
- describe('isError', () => {
265
- it('should correctly identify an error object from a different window context', () => {
266
- const iframe = document.createElement('iframe')
267
- document.body.appendChild(iframe)
268
- registerCleanupTask(() => document.body.removeChild(iframe))
269
-
270
- const iframeWindow = iframe.contentWindow as Window & { Error: ErrorConstructor }
271
-
272
- expect(isError(new iframeWindow.Error())).toBe(true)
273
- })
274
- })
275
-
276
- describe('tryToGetContext', () => {
277
- it('should extract dd_context from an error object', () => {
278
- const context = { key: 'value' }
279
- const error = new Error('Test error') as any
280
- error.dd_context = context
281
-
282
- const rawError = computeRawError({
283
- originalError: error,
284
- handlingStack: undefined,
285
- componentStack: undefined,
286
- startClocks: clocksNow(),
287
- nonErrorPrefix: NonErrorPrefix.UNCAUGHT,
288
- source: ErrorSource.CUSTOM,
289
- handling: ErrorHandling.HANDLED,
290
- })
291
-
292
- expect(rawError.context).toEqual(context)
293
- })
294
- })