@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,236 +0,0 @@
1
- import type { RumEvent } from '../../../../rum-core/src'
2
- import { EXHAUSTIVE_INIT_CONFIGURATION, SERIALIZED_EXHAUSTIVE_INIT_CONFIGURATION } from '../../../test'
3
- import type { ExtractTelemetryConfiguration, MapInitConfigurationKey } from '../../../test'
4
- import { DOCS_ORIGIN, MORE_DETAILS, display } from '../../tools/display'
5
- import {
6
- ExperimentalFeature,
7
- isExperimentalFeatureEnabled,
8
- resetExperimentalFeatures,
9
- } from '../../tools/experimentalFeatures'
10
- import { SessionPersistence } from '../session/sessionConstants'
11
- import { TrackingConsent } from '../trackingConsent'
12
- import type { InitConfiguration } from './configuration'
13
- import { serializeConfiguration, validateAndBuildConfiguration } from './configuration'
14
-
15
- describe('validateAndBuildConfiguration', () => {
16
- const clientToken = 'some_client_token'
17
-
18
- let displaySpy: jasmine.Spy<typeof display.error>
19
-
20
- beforeEach(() => {
21
- displaySpy = spyOn(display, 'error')
22
- })
23
-
24
- afterEach(() => {
25
- resetExperimentalFeatures()
26
- })
27
-
28
- describe('experimentalFeatures', () => {
29
- const TEST_FEATURE_FLAG = 'foo' as ExperimentalFeature
30
-
31
- beforeEach(() => {
32
- ;(ExperimentalFeature as any).FOO = TEST_FEATURE_FLAG
33
- })
34
-
35
- afterEach(() => {
36
- delete (ExperimentalFeature as any).FOO
37
- })
38
-
39
- it('ignores unknown experimental features', () => {
40
- validateAndBuildConfiguration({
41
- clientToken,
42
- enableExperimentalFeatures: ['bar', undefined as any, null as any, 11 as any],
43
- })
44
- expect(isExperimentalFeatureEnabled('bar' as any)).toBeFalse()
45
- expect(isExperimentalFeatureEnabled(undefined as any)).toBeFalse()
46
- expect(isExperimentalFeatureEnabled(null as any)).toBeFalse()
47
- expect(isExperimentalFeatureEnabled(11 as any)).toBeFalse()
48
- })
49
- })
50
-
51
- describe('validate init configuration', () => {
52
- it('requires the InitConfiguration to be defined', () => {
53
- expect(validateAndBuildConfiguration(undefined as unknown as InitConfiguration)).toBeUndefined()
54
- expect(displaySpy).toHaveBeenCalledOnceWith('Client Token is not configured, we will not send any data.')
55
- })
56
-
57
- it('requires clientToken to be defined', () => {
58
- expect(validateAndBuildConfiguration({} as unknown as InitConfiguration)).toBeUndefined()
59
- expect(displaySpy).toHaveBeenCalledOnceWith('Client Token is not configured, we will not send any data.')
60
- })
61
-
62
- it("shouldn't display any error if the configuration is correct", () => {
63
- validateAndBuildConfiguration({ clientToken: 'yes' })
64
- expect(displaySpy).not.toHaveBeenCalled()
65
- })
66
-
67
- it('requires sessionSampleRate to be a percentage', () => {
68
- expect(
69
- validateAndBuildConfiguration({ clientToken, sessionSampleRate: 'foo' } as unknown as InitConfiguration)
70
- ).toBeUndefined()
71
- expect(displaySpy).toHaveBeenCalledOnceWith('Session Sample Rate should be a number between 0 and 100')
72
-
73
- displaySpy.calls.reset()
74
- expect(
75
- validateAndBuildConfiguration({ clientToken, sessionSampleRate: 200 } as unknown as InitConfiguration)
76
- ).toBeUndefined()
77
- expect(displaySpy).toHaveBeenCalledOnceWith('Session Sample Rate should be a number between 0 and 100')
78
-
79
- displaySpy.calls.reset()
80
- validateAndBuildConfiguration({ clientToken: 'yes', sessionSampleRate: 1 })
81
- expect(displaySpy).not.toHaveBeenCalled()
82
- })
83
-
84
- it('requires telemetrySampleRate to be a percentage', () => {
85
- expect(
86
- validateAndBuildConfiguration({ clientToken, telemetrySampleRate: 'foo' } as unknown as InitConfiguration)
87
- ).toBeUndefined()
88
- expect(displaySpy).toHaveBeenCalledOnceWith('Telemetry Sample Rate should be a number between 0 and 100')
89
-
90
- displaySpy.calls.reset()
91
- expect(
92
- validateAndBuildConfiguration({ clientToken, telemetrySampleRate: 200 } as unknown as InitConfiguration)
93
- ).toBeUndefined()
94
- expect(displaySpy).toHaveBeenCalledOnceWith('Telemetry Sample Rate should be a number between 0 and 100')
95
-
96
- displaySpy.calls.reset()
97
- validateAndBuildConfiguration({ clientToken: 'yes', telemetrySampleRate: 1 })
98
- expect(displaySpy).not.toHaveBeenCalled()
99
- })
100
- })
101
-
102
- describe('sessionStoreStrategyType', () => {
103
- it('is present in the returned configuration', () => {
104
- const configuration = validateAndBuildConfiguration({ clientToken })
105
- expect(configuration!.sessionStoreStrategyType).toEqual({
106
- type: SessionPersistence.COOKIE,
107
- cookieOptions: { secure: false, crossSite: false, partitioned: false },
108
- })
109
- })
110
- })
111
-
112
- describe('beforeSend', () => {
113
- it('should be undefined when beforeSend is missing on user configuration', () => {
114
- const configuration = validateAndBuildConfiguration({ clientToken })!
115
- expect(configuration.beforeSend).toBeUndefined()
116
- })
117
-
118
- it('should return the same result as the original', () => {
119
- const beforeSend = (event: RumEvent) => {
120
- if (event.view.url === '/foo') {
121
- return false
122
- }
123
- }
124
- const configuration = validateAndBuildConfiguration({ clientToken, beforeSend })!
125
- expect(configuration.beforeSend!({ view: { url: '/foo' } }, {})).toBeFalse()
126
- expect(configuration.beforeSend!({ view: { url: '/bar' } }, {})).toBeUndefined()
127
- })
128
-
129
- it('should catch errors and log them', () => {
130
- const myError = 'Ooops!'
131
- const beforeSend = () => {
132
- // eslint-disable-next-line @typescript-eslint/only-throw-error
133
- throw myError
134
- }
135
- const configuration = validateAndBuildConfiguration({ clientToken, beforeSend })!
136
- expect(configuration.beforeSend!(null, {})).toBeUndefined()
137
- expect(displaySpy).toHaveBeenCalledWith('beforeSend threw an error:', myError)
138
- })
139
- })
140
-
141
- describe('allowUntrustedEvents', () => {
142
- it('defaults to false', () => {
143
- expect(validateAndBuildConfiguration({ clientToken: 'yes' })!.allowUntrustedEvents).toBeFalse()
144
- })
145
-
146
- it('is set to provided value', () => {
147
- expect(
148
- validateAndBuildConfiguration({ clientToken: 'yes', allowUntrustedEvents: true })!.allowUntrustedEvents
149
- ).toBeTrue()
150
- expect(
151
- validateAndBuildConfiguration({ clientToken: 'yes', allowUntrustedEvents: false })!.allowUntrustedEvents
152
- ).toBeFalse()
153
- })
154
-
155
- it('the provided value is cast to boolean', () => {
156
- expect(
157
- validateAndBuildConfiguration({ clientToken: 'yes', allowUntrustedEvents: 'foo' as any })!.allowUntrustedEvents
158
- ).toBeTrue()
159
- })
160
- })
161
-
162
- describe('trackingConsent', () => {
163
- it('defaults to "granted"', () => {
164
- expect(validateAndBuildConfiguration({ clientToken: 'yes' })!.trackingConsent).toBe(TrackingConsent.GRANTED)
165
- })
166
-
167
- it('is set to provided value', () => {
168
- expect(
169
- validateAndBuildConfiguration({ clientToken: 'yes', trackingConsent: TrackingConsent.NOT_GRANTED })!
170
- .trackingConsent
171
- ).toBe(TrackingConsent.NOT_GRANTED)
172
- expect(
173
- validateAndBuildConfiguration({ clientToken: 'yes', trackingConsent: TrackingConsent.GRANTED })!.trackingConsent
174
- ).toBe(TrackingConsent.GRANTED)
175
- })
176
-
177
- it('rejects invalid values', () => {
178
- expect(validateAndBuildConfiguration({ clientToken: 'yes', trackingConsent: 'foo' as any })).toBeUndefined()
179
- expect(displaySpy).toHaveBeenCalledOnceWith('Tracking Consent should be either "granted" or "not-granted"')
180
- })
181
- })
182
-
183
- describe('site parameter validation', () => {
184
- it('should validate the site parameter', () => {
185
- validateAndBuildConfiguration({ clientToken, site: 'foo.com' as any })
186
- expect(displaySpy).toHaveBeenCalledOnceWith(
187
- `Site should be a valid Datadog site. ${MORE_DETAILS} ${DOCS_ORIGIN}/getting_started/site/.`
188
- )
189
- })
190
- })
191
-
192
- describe('env parameter validation', () => {
193
- it('should validate the env parameter', () => {
194
- validateAndBuildConfiguration({ clientToken, env: false as any })
195
- expect(displaySpy).toHaveBeenCalledOnceWith('Env must be defined as a string')
196
- })
197
- })
198
-
199
- describe('service parameter validation', () => {
200
- it('should validate the service parameter', () => {
201
- validateAndBuildConfiguration({ clientToken, service: 1 as any })
202
- expect(displaySpy).toHaveBeenCalledOnceWith('Service must be defined as a string')
203
- })
204
-
205
- it('should not reject null', () => {
206
- const configuration = validateAndBuildConfiguration({ clientToken, service: null })
207
- expect(displaySpy).not.toHaveBeenCalled()
208
- expect(configuration!.service).toBeUndefined()
209
- })
210
- })
211
-
212
- describe('version parameter validation', () => {
213
- it('should validate the version parameter', () => {
214
- validateAndBuildConfiguration({ clientToken, version: 0 as any })
215
- expect(displaySpy).toHaveBeenCalledOnceWith('Version must be defined as a string')
216
- })
217
- })
218
-
219
- describe('allowedTrackingOrigins parameter validation', () => {
220
- it('should validate the allowedTrackingOrigins parameter', () => {
221
- validateAndBuildConfiguration({ clientToken, allowedTrackingOrigins: 'foo' as any })
222
- expect(displaySpy).toHaveBeenCalledOnceWith('Allowed Tracking Origins must be an array')
223
- })
224
- })
225
-
226
- describe('serializeConfiguration', () => {
227
- it('should serialize the configuration', () => {
228
- // By specifying the type here, we can ensure that serializeConfiguration is returning an
229
- // object containing all expected properties.
230
- const serializedConfiguration: ExtractTelemetryConfiguration<MapInitConfigurationKey<keyof InitConfiguration>> =
231
- serializeConfiguration(EXHAUSTIVE_INIT_CONFIGURATION)
232
-
233
- expect(serializedConfiguration).toEqual(SERIALIZED_EXHAUSTIVE_INIT_CONFIGURATION)
234
- })
235
- })
236
- })
@@ -1,173 +0,0 @@
1
- import type { Payload } from '../../transport'
2
- import type { InitConfiguration } from './configuration'
3
- import { createEndpointBuilder } from './endpointBuilder'
4
-
5
- const DEFAULT_PAYLOAD = {} as Payload
6
-
7
- describe('endpointBuilder', () => {
8
- const clientToken = 'some_client_token'
9
- let initConfiguration: InitConfiguration
10
-
11
- beforeEach(() => {
12
- initConfiguration = { clientToken, apiVersion: 'v1', organizationIdentifier: 'xyz', insecureHTTP: false }
13
- })
14
-
15
- describe('query parameters', () => {
16
- it('should add intake query parameters', () => {
17
- expect(createEndpointBuilder(initConfiguration, 'rum').build('fetch', DEFAULT_PAYLOAD)).toMatch(
18
- `&o2-api-key=${clientToken}&o2-evp-origin-version=(.*)&o2-evp-origin=browser&o2-request-id=(.*)`
19
- )
20
- })
21
-
22
- it('should add batch_time for rum endpoint', () => {
23
- expect(createEndpointBuilder(initConfiguration, 'rum').build('fetch', DEFAULT_PAYLOAD)).toContain('&batch_time=')
24
- })
25
-
26
- it('should not add batch_time for logs and replay endpoints', () => {
27
- expect(createEndpointBuilder(initConfiguration, 'logs').build('fetch', DEFAULT_PAYLOAD)).not.toContain(
28
- '&batch_time='
29
- )
30
- expect(createEndpointBuilder(initConfiguration, 'replay').build('fetch', DEFAULT_PAYLOAD)).not.toContain(
31
- '&batch_time='
32
- )
33
- })
34
-
35
- it('should add the provided encoding', () => {
36
- expect(
37
- createEndpointBuilder(initConfiguration, 'rum').build('fetch', { ...DEFAULT_PAYLOAD, encoding: 'deflate' })
38
- ).toContain('&dd-evp-encoding=deflate')
39
- })
40
-
41
- it('should not start with o2source for internal analytics mode', () => {
42
- const url = createEndpointBuilder({ ...initConfiguration, internalAnalyticsSubdomain: 'foo' }, 'rum').build(
43
- 'fetch',
44
- DEFAULT_PAYLOAD
45
- )
46
- expect(url).not.toContain('/rum?o2source')
47
- expect(url).toContain('o2source=browser')
48
- })
49
-
50
- it('accepts extra parameters', () => {
51
- const extraParameters = ['application.id=1234', 'application.version=1.0.0']
52
- const url = createEndpointBuilder(initConfiguration, 'rum', extraParameters).build('fetch', DEFAULT_PAYLOAD)
53
- expect(url).toContain('application.id=1234')
54
- expect(url).toContain('application.version=1.0.0')
55
- })
56
- })
57
-
58
- describe('proxy configuration', () => {
59
- it('should replace the intake endpoint by the proxy and set the intake path and parameters in the attribute ooforward', () => {
60
- expect(
61
- createEndpointBuilder({ ...initConfiguration, proxy: 'https://proxy.io/path' }, 'rum').build(
62
- 'fetch',
63
- DEFAULT_PAYLOAD
64
- )
65
- ).toMatch(
66
- `https://proxy.io/path\\?ooforward=${encodeURIComponent(
67
- `/rum/v2/rum?o2source=(.*)&o2-api-key=${clientToken}` +
68
- '&o2-evp-origin-version=(.*)&o2-evp-origin=browser&o2-request-id=(.*)&batch_time=(.*)'
69
- )}`
70
- )
71
- })
72
-
73
- it('normalizes the proxy url', () => {
74
- const endpoint = createEndpointBuilder({ ...initConfiguration, proxy: '/path' }, 'rum').build(
75
- 'fetch',
76
- DEFAULT_PAYLOAD
77
- )
78
- expect(endpoint.startsWith(`${location.origin}/path?ooforward`)).toBeTrue()
79
- })
80
-
81
- it('should allow to fully control the proxy url', () => {
82
- const proxyFn = (options: { path: string; parameters: string }) =>
83
- `https://proxy.io/prefix${options.path}/suffix?${options.parameters}`
84
- expect(
85
- createEndpointBuilder({ ...initConfiguration, proxy: proxyFn }, 'rum').build('fetch', DEFAULT_PAYLOAD)
86
- ).toMatch(
87
- `https://proxy.io/prefix/api/v2/rum/suffix\\?oosource=(.*)&o2-api-key=${clientToken}&o2-evp-origin-version=(.*)&o2-evp-origin=browser&o2-request-id=(.*)&batch_time=(.*)`
88
- )
89
- })
90
- })
91
-
92
- describe('_o2 attributes', () => {
93
- it('should contain api', () => {
94
- expect(createEndpointBuilder(initConfiguration, 'rum').build('fetch', DEFAULT_PAYLOAD)).toContain('_o2.api=fetch')
95
- })
96
-
97
- it('should contain retry infos', () => {
98
- expect(
99
- createEndpointBuilder(initConfiguration, 'rum').build('fetch', {
100
- ...DEFAULT_PAYLOAD,
101
- retry: {
102
- count: 5,
103
- lastFailureStatus: 408,
104
- },
105
- })
106
- ).toContain('_oo.retry_count=5&_oo.retry_after=408')
107
- })
108
-
109
- it('should not contain any _oo attributes for non rum endpoints', () => {
110
- expect(
111
- createEndpointBuilder(initConfiguration, 'logs').build('fetch', {
112
- ...DEFAULT_PAYLOAD,
113
- retry: {
114
- count: 5,
115
- lastFailureStatus: 408,
116
- },
117
- })
118
- ).not.toContain('_o2.api=fetch&_o2.retry_count=5&_o2.retry_after=408')
119
- })
120
- })
121
-
122
- describe('PCI compliance intake with option', () => {
123
- it('should return PCI compliance intake endpoint if site is us1', () => {
124
- const config: InitConfiguration & { usePciIntake?: boolean } = {
125
- clientToken,
126
- usePciIntake: true,
127
- site: 'datadoghq.com',
128
- }
129
- expect(createEndpointBuilder(config, 'logs').build('fetch', DEFAULT_PAYLOAD)).toContain(
130
- 'https://pci.browser-intake-datadoghq.com'
131
- )
132
- })
133
- it('should not return PCI compliance intake endpoint if site is not us1', () => {
134
- const config: InitConfiguration & { usePciIntake?: boolean } = {
135
- clientToken,
136
- usePciIntake: true,
137
- site: 'ap1.datadoghq.com',
138
- }
139
- expect(createEndpointBuilder(config, 'logs').build('fetch', DEFAULT_PAYLOAD)).not.toContain(
140
- 'https://pci.browser-intake-datadoghq.com'
141
- )
142
- })
143
- it('should not return PCI compliance intake endpoint if and site is us1 and track is not logs', () => {
144
- const config: InitConfiguration & { usePciIntake?: boolean } = {
145
- clientToken,
146
- usePciIntake: true,
147
- site: 'datadoghq.com',
148
- }
149
- expect(createEndpointBuilder(config, 'rum').build('fetch', DEFAULT_PAYLOAD)).not.toContain(
150
- 'https://pci.browser-intake-datadoghq.com'
151
- )
152
- })
153
- })
154
-
155
- describe('source configuration', () => {
156
- it('should use the default source when no configuration is provided', () => {
157
- const endpoint = createEndpointBuilder(initConfiguration, 'rum').build('fetch', DEFAULT_PAYLOAD)
158
- expect(endpoint).toContain('ddsource=browser')
159
- })
160
-
161
- it('should use flutter source when provided', () => {
162
- const config = { ...initConfiguration, source: 'flutter' as const }
163
- const endpoint = createEndpointBuilder(config, 'rum').build('fetch', DEFAULT_PAYLOAD)
164
- expect(endpoint).toContain('ddsource=flutter')
165
- })
166
-
167
- it('should use unity source when provided', () => {
168
- const config = { ...initConfiguration, source: 'unity' as const }
169
- const endpoint = createEndpointBuilder(config, 'rum').build('fetch', DEFAULT_PAYLOAD)
170
- expect(endpoint).toContain('ddsource=unity')
171
- })
172
- })
173
- })
@@ -1,130 +0,0 @@
1
- import { INTAKE_SITE_FED_STAGING } from '../intakeSites'
2
- import type { Payload } from '../../transport'
3
- import { computeTransportConfiguration, isIntakeUrl } from './transportConfiguration'
4
-
5
- const DEFAULT_PAYLOAD = {} as Payload
6
-
7
- describe('transportConfiguration', () => {
8
- const clientToken = 'some_client_token'
9
- const internalAnalyticsSubdomain = 'ia-rum-intake'
10
- const intakeParameters = 'ddsource=browser&dd-api-key=xxxx&dd-request-id=1234567890'
11
-
12
- describe('site', () => {
13
- it('should use US site by default', () => {
14
- const configuration = computeTransportConfiguration({ clientToken })
15
- expect(configuration.rumEndpointBuilder.build('fetch', DEFAULT_PAYLOAD)).toContain('openobserve.ai')
16
- expect(configuration.site).toBe('openobserve.ai')
17
- })
18
-
19
- it('should use logs intake domain for fed staging', () => {
20
- const configuration = computeTransportConfiguration({ clientToken, site: INTAKE_SITE_FED_STAGING })
21
- expect(configuration.rumEndpointBuilder.build('fetch', DEFAULT_PAYLOAD)).toContain(
22
- 'http-intake.logs.dd0g-gov.com'
23
- )
24
- expect(configuration.site).toBe(INTAKE_SITE_FED_STAGING)
25
- })
26
-
27
- it('should use site value when set', () => {
28
- const configuration = computeTransportConfiguration({ clientToken, site: 'openobserve.ai' })
29
- expect(configuration.rumEndpointBuilder.build('fetch', DEFAULT_PAYLOAD)).toContain('openobserve.ai')
30
- expect(configuration.site).toBe('openobserve.ai')
31
- })
32
- })
33
-
34
- describe('internalAnalyticsSubdomain', () => {
35
- it('should use internal analytics subdomain value when set for openobserve.ai site', () => {
36
- const configuration = computeTransportConfiguration({
37
- clientToken,
38
- internalAnalyticsSubdomain,
39
- })
40
- expect(configuration.rumEndpointBuilder.build('fetch', DEFAULT_PAYLOAD)).toContain(internalAnalyticsSubdomain)
41
- })
42
-
43
- it('should not use internal analytics subdomain value when set for other sites', () => {
44
- const configuration = computeTransportConfiguration({
45
- clientToken,
46
- site: 'us3.datadoghq.com',
47
- internalAnalyticsSubdomain,
48
- })
49
- expect(configuration.rumEndpointBuilder.build('fetch', DEFAULT_PAYLOAD)).not.toContain(internalAnalyticsSubdomain)
50
- })
51
- })
52
-
53
- it('adds the replica application id to the rum replica endpoint', () => {
54
- const replicaApplicationId = 'replica-application-id'
55
- const configuration = computeTransportConfiguration({
56
- clientToken,
57
- replica: {
58
- clientToken: 'replica-client-token',
59
- applicationId: replicaApplicationId,
60
- },
61
- })
62
- expect(configuration.replica!.rumEndpointBuilder.build('fetch', DEFAULT_PAYLOAD)).toContain(
63
- `application.id=${replicaApplicationId}`
64
- )
65
- })
66
-
67
- describe('isIntakeUrl', () => {
68
- const v1IntakePath = `/v1/input/${clientToken}`
69
- ;[
70
- { expectSubdomain: true, site: 'api.openobserve.ai', intakeDomain: 'api.openobserve.ai' },
71
- ].forEach(({ site, intakeDomain, expectSubdomain }) => {
72
- it(`should detect intake request for ${site} site`, () => {
73
- const configuration = computeTransportConfiguration({ clientToken, site })
74
-
75
- expect(configuration.isIntakeUrl(`https://${intakeDomain}/rum/v2/rum?xxx`)).toBe(expectSubdomain)
76
- expect(configuration.isIntakeUrl(`https://${intakeDomain}/rum/v2/logs?xxx`)).toBe(expectSubdomain)
77
- expect(configuration.isIntakeUrl(`https://${intakeDomain}/rum/v2/replay?xxx`)).toBe(
78
- expectSubdomain
79
- )
80
-
81
- expect(configuration.isIntakeUrl(`https://${intakeDomain}/rum/v2/rum?xxx`)).toBe(!expectSubdomain)
82
- expect(configuration.isIntakeUrl(`https://${intakeDomain}/rum/v2/logs?xxx`)).toBe(!expectSubdomain)
83
- expect(configuration.isIntakeUrl(`https://${intakeDomain}/rum/v2/replay?xxx`)).toBe(!expectSubdomain)
84
- })
85
- })
86
-
87
- it('should detect internal analytics intake request for openobserve.ai site', () => {
88
- const configuration = computeTransportConfiguration({
89
- clientToken,
90
- internalAnalyticsSubdomain,
91
- })
92
- expect(configuration.isIntakeUrl(`https://api.openobserve.ai/rum/v2/rum?xxx`)).toBe(true)
93
- })
94
-
95
- it('should not detect non intake request', () => {
96
- expect(isIntakeUrl('https://www.foo.com')).toBe(false)
97
- })
98
-
99
- describe('proxy configuration', () => {
100
- it('should detect proxy intake request', () => {
101
- expect(
102
- isIntakeUrl(`https://www.proxy.com/?ooforward=${encodeURIComponent(`/api/v2/rum?${intakeParameters}`)}`)
103
- ).toBe(true)
104
- expect(
105
- isIntakeUrl(
106
- `https://www.proxy.com/custom/path?ooforward=${encodeURIComponent(`/api/v2/rum?${intakeParameters}`)}`
107
- )
108
- ).toBe(true)
109
- })
110
-
111
- it('should not detect request done on the same host as the proxy', () => {
112
- expect(isIntakeUrl('https://www.proxy.com/foo')).toBe(false)
113
- })
114
- })
115
- ;[
116
- { site: 'openobserve.ai' },
117
- ].forEach(({ site }) => {
118
- it(`should detect replica intake request for site ${site}`, () => {
119
- expect(isIntakeUrl(`https://${internalAnalyticsSubdomain}.openobserve.ai/api/v2/rum?${intakeParameters}`)).toBe(
120
- true
121
- )
122
- expect(isIntakeUrl(`https://${internalAnalyticsSubdomain}.openobserve.ai/api/v2/logs?${intakeParameters}`)).toBe(
123
- true
124
- )
125
- expect(
126
- isIntakeUrl(`https://${internalAnalyticsSubdomain}.openobserve.ai/api/v2/replay?${intakeParameters}`)
127
- ).toBe(true)
128
- })
129
- })
130
- })
@@ -1,50 +0,0 @@
1
- import { setNavigatorOnLine, setNavigatorConnection } from '../../../test'
2
- import { getConnectivity } from './connectivity'
3
-
4
- describe('connectivity', () => {
5
- describe('status', () => {
6
- it('should return `connected` when navigator.onLine is true', () => {
7
- setNavigatorOnLine(true)
8
- expect(getConnectivity().status).toEqual('connected')
9
- })
10
-
11
- it('should return `not_connected` when navigator.onLine is false', () => {
12
- setNavigatorOnLine(false)
13
- expect(getConnectivity().status).toEqual('not_connected')
14
- })
15
- })
16
-
17
- describe('interfaces', () => {
18
- it('should not be defined if navigator.connection is not available', () => {
19
- setNavigatorConnection(undefined)
20
- expect(getConnectivity().interfaces).toBeUndefined()
21
- })
22
-
23
- it('should not be defined if navigator.connection.type is not available', () => {
24
- setNavigatorConnection({})
25
- expect(getConnectivity().interfaces).toBeUndefined()
26
- })
27
-
28
- it('should return navigator.connection.type value', () => {
29
- setNavigatorConnection({ type: 'bluetooth' })
30
- expect(getConnectivity().interfaces).toEqual(['bluetooth'])
31
- })
32
- })
33
-
34
- describe('effective_type', () => {
35
- it('should not be defined if navigator.connection is not available', () => {
36
- setNavigatorConnection(undefined)
37
- expect(getConnectivity().effective_type).toBeUndefined()
38
- })
39
-
40
- it('should not be defined if navigator.connection.effective_type is not available', () => {
41
- setNavigatorConnection({})
42
- expect(getConnectivity().effective_type).toBeUndefined()
43
- })
44
-
45
- it('should return navigator.connection.effective_type value', () => {
46
- setNavigatorConnection({ effectiveType: '4g' })
47
- expect(getConnectivity().effective_type).toBe('4g')
48
- })
49
- })
50
- })