@servicetitan/datadog-rum 40.2.2 → 40.4.0

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 (64) hide show
  1. package/dist/create-impl.d.ts.map +1 -1
  2. package/dist/create-impl.js +3 -0
  3. package/dist/create-impl.js.map +1 -1
  4. package/dist/datadog-provider.d.ts +3 -1
  5. package/dist/datadog-provider.d.ts.map +1 -1
  6. package/dist/datadog-provider.js +3 -1
  7. package/dist/datadog-provider.js.map +1 -1
  8. package/dist/get-env.d.ts +7 -0
  9. package/dist/get-env.d.ts.map +1 -0
  10. package/dist/get-env.js +26 -0
  11. package/dist/get-env.js.map +1 -0
  12. package/dist/hash-routing.d.ts +5 -1
  13. package/dist/hash-routing.d.ts.map +1 -1
  14. package/dist/hash-routing.js +59 -15
  15. package/dist/hash-routing.js.map +1 -1
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/sanitize-view-name.d.ts.map +1 -1
  21. package/dist/sanitize-view-name.js +10 -0
  22. package/dist/sanitize-view-name.js.map +1 -1
  23. package/dist/shared-impl.d.ts +1 -1
  24. package/dist/shared-impl.d.ts.map +1 -1
  25. package/dist/shared-impl.js.map +1 -1
  26. package/dist/types.d.ts +1 -2
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/types.js.map +1 -1
  29. package/package.json +8 -3
  30. package/src/create-impl.ts +2 -0
  31. package/src/datadog-provider.tsx +7 -3
  32. package/src/get-env.ts +27 -0
  33. package/src/hash-routing.tsx +68 -14
  34. package/src/index.ts +1 -0
  35. package/src/sanitize-view-name.tsx +17 -0
  36. package/src/shared-impl.ts +1 -1
  37. package/src/types.ts +6 -2
  38. package/src/__mocks__/before-send-data.ts +0 -538
  39. package/src/__mocks__/index.ts +0 -7
  40. package/src/__mocks__/init-config.ts +0 -6
  41. package/src/__mocks__/mfe-host.ts +0 -7
  42. package/src/__mocks__/process-event.ts +0 -20
  43. package/src/__mocks__/reset-shared-impl.ts +0 -8
  44. package/src/__mocks__/tracing-urls.ts +0 -30
  45. package/src/__mocks__/types.ts +0 -1
  46. package/src/__tests__/before-send.test.ts +0 -76
  47. package/src/__tests__/build-allowed-tracing-urls.test.ts +0 -120
  48. package/src/__tests__/build-before-send.test.ts +0 -193
  49. package/src/__tests__/create-impl.test.ts +0 -427
  50. package/src/__tests__/datadog-provider.test.tsx +0 -145
  51. package/src/__tests__/dd-rum-guard.test.ts +0 -73
  52. package/src/__tests__/element-service-recorder.test.ts +0 -127
  53. package/src/__tests__/enrich-event.test.ts +0 -139
  54. package/src/__tests__/get-shared.test.ts +0 -56
  55. package/src/__tests__/handle-resource.test.ts +0 -76
  56. package/src/__tests__/hash-routing.test.tsx +0 -70
  57. package/src/__tests__/init.test.ts +0 -69
  58. package/src/__tests__/integration.test.ts +0 -147
  59. package/src/__tests__/resolve-path-service.test.ts +0 -130
  60. package/src/__tests__/sanitize-view-name.test.tsx +0 -92
  61. package/src/__tests__/set-user.test.ts +0 -61
  62. package/src/__tests__/use-rum-service.test.tsx +0 -82
  63. package/src/runtime-override/__tests__/dev-console.test.ts +0 -158
  64. package/src/runtime-override/__tests__/override.test.ts +0 -109
@@ -1,127 +0,0 @@
1
- import { mfeHost } from '../__mocks__';
2
- import { createElementServiceRecorder } from '../element-service-recorder';
3
-
4
- describe('[datadog-rum] createElementServiceRecorder', () => {
5
- const version = '1.2.3';
6
-
7
- const dispatchPointerUp = (target: HTMLElement) => {
8
- const event = new MouseEvent('pointerup', { bubbles: true, composed: true });
9
- target.dispatchEvent(event);
10
- return event;
11
- };
12
-
13
- let recorder: ReturnType<typeof createElementServiceRecorder>;
14
- let host: HTMLElement;
15
- let button: HTMLElement;
16
-
17
- beforeEach(() => {
18
- jest.clearAllMocks();
19
- recorder = createElementServiceRecorder();
20
- host = document.body.appendChild(mfeHost('servicetitan-task-hub', version));
21
- button = host.shadowRoot!.appendChild(document.createElement('button'));
22
- });
23
-
24
- afterEach(() => {
25
- jest.restoreAllMocks();
26
- document.body.innerHTML = '';
27
- });
28
-
29
- describe('serviceFor', () => {
30
- let event: Event;
31
-
32
- beforeEach(() => (event = dispatchPointerUp(button)));
33
-
34
- const subject = () => recorder.serviceFor(event);
35
-
36
- test('returns the service of the retargeted target', () => {
37
- expect(subject()).toEqual({ service: 'task-hub', version });
38
- });
39
-
40
- describe('with a target that is not an element', () => {
41
- beforeEach(() => (event = { target: window } as unknown as Event));
42
-
43
- test('returns undefined', () => {
44
- expect(subject()).toBeUndefined();
45
- });
46
- });
47
-
48
- describe('when the recorder is installed', () => {
49
- beforeEach(() => {
50
- jest.spyOn(window, 'addEventListener');
51
- recorder.install();
52
- event = dispatchPointerUp(button);
53
- });
54
-
55
- afterEach(() => {
56
- for (const args of jest.mocked(window.addEventListener).mock.calls) {
57
- window.removeEventListener(...args);
58
- }
59
- });
60
-
61
- test('returns the service resolved at dispatch', () => {
62
- expect(subject()).toEqual({ service: 'task-hub', version });
63
- });
64
-
65
- describe('when the MFE unmounts before enrichment', () => {
66
- beforeEach(() => host.remove());
67
-
68
- test('returns the service resolved at dispatch', () => {
69
- expect(subject()).toEqual({ service: 'task-hub', version });
70
- });
71
- });
72
-
73
- describe('with a target outside any MFE', () => {
74
- let outside: HTMLElement;
75
-
76
- beforeEach(() => {
77
- outside = document.body.appendChild(document.createElement('div'));
78
- event = dispatchPointerUp(outside);
79
- });
80
-
81
- test('returns undefined', () => {
82
- expect(subject()).toBeUndefined();
83
- });
84
-
85
- describe('when the target later moves into an MFE', () => {
86
- beforeEach(() => host.appendChild(outside));
87
-
88
- test('returns undefined', () => {
89
- expect(subject()).toBeUndefined();
90
- });
91
- });
92
- });
93
- });
94
- });
95
-
96
- describe('install', () => {
97
- beforeEach(() => jest.spyOn(window, 'addEventListener').mockImplementation(() => {}));
98
-
99
- const subject = () => recorder.install();
100
-
101
- test('adds a pointerup capture listener', () => {
102
- subject();
103
-
104
- expect(window.addEventListener).toHaveBeenCalledWith(
105
- 'pointerup',
106
- expect.any(Function),
107
- {
108
- capture: true,
109
- passive: true,
110
- }
111
- );
112
- });
113
-
114
- describe('when already installed', () => {
115
- beforeEach(() => {
116
- subject();
117
- jest.mocked(window.addEventListener).mockClear();
118
- });
119
-
120
- test('adds no listener', () => {
121
- subject();
122
-
123
- expect(window.addEventListener).not.toHaveBeenCalled();
124
- });
125
- });
126
- });
127
- });
@@ -1,139 +0,0 @@
1
- /* eslint-disable @typescript-eslint/naming-convention -- RUM event fields are snake_case */
2
- import type { RumEvent, RumEventDomainContext } from '@datadog/browser-rum';
3
- import { type Mutable, rumEvents, type RumEventType } from '../__mocks__';
4
- import { type ElementService, elementServiceRecorder } from '../element-service-recorder';
5
- import { enrichEvent } from '../enrich-event';
6
-
7
- jest.mock('../element-service-recorder');
8
-
9
- describe(`[datadog-rum] ${enrichEvent.name}`, () => {
10
- let event: Mutable<RumEventType>;
11
- let context: RumEventDomainContext;
12
- let elementService: ElementService | undefined;
13
-
14
- beforeEach(() => {
15
- jest.clearAllMocks();
16
- elementService = undefined;
17
- jest.mocked(elementServiceRecorder.serviceFor).mockImplementation(() => elementService);
18
- event = { type: 'action' };
19
- context = {};
20
- });
21
-
22
- const subject = () => enrichEvent(event as RumEvent, context);
23
-
24
- describe.each(rumEvents)('when event.type=$event.type and $title', rumEvent => {
25
- beforeEach(() => {
26
- event = { ...rumEvent.event };
27
- context = rumEvent.context ?? {};
28
- });
29
-
30
- test('attributes the expected service and version', () => {
31
- subject();
32
-
33
- expect({ service: event.service, version: event.version }).toEqual({
34
- service: rumEvent.service,
35
- version: rumEvent.version,
36
- });
37
- });
38
- });
39
-
40
- describe('with a long animation frame', () => {
41
- const unpkgUrl = (name: string) =>
42
- `https://unpkg.servicetitan.com/@servicetitan/${name}@1.0.0/dist/main.js`;
43
- const hostUrl = 'https://go.servicetitan.com/scripts/build/desktop/main.js';
44
-
45
- const loafEvent = (scripts: { duration: number; source_url: string }[]) =>
46
- ({
47
- type: 'long_task',
48
- long_task: { entry_type: 'long-animation-frame', scripts },
49
- }) as Mutable<RumEventType>;
50
-
51
- beforeEach(() => {
52
- event = loafEvent([
53
- { duration: 10, source_url: unpkgUrl('task-hub') },
54
- { duration: 30, source_url: hostUrl },
55
- { duration: 20, source_url: unpkgUrl('other-mfe') },
56
- { duration: 5, source_url: unpkgUrl('task-hub') },
57
- ]);
58
- });
59
-
60
- test('lists every MFE that ran a script, in run order', () => {
61
- subject();
62
-
63
- expect(event.context?.loafServices).toEqual(['task-hub', 'other-mfe']);
64
- });
65
-
66
- describe('with only host scripts', () => {
67
- beforeEach(() => (event = loafEvent([{ duration: 60, source_url: hostUrl }])));
68
-
69
- test('adds no list', () => {
70
- subject();
71
-
72
- expect(event.context?.loafServices).toBeUndefined();
73
- });
74
- });
75
- });
76
-
77
- describe('with a click action', () => {
78
- const pointerUpEvent = new MouseEvent('pointerup');
79
- const taskHubService = { service: 'task-hub', version: '1.4.0' };
80
- const hostService = { service: 'desktop', version: '1.0.0' };
81
-
82
- beforeEach(() => {
83
- event = { type: 'action', action: { type: 'click' }, ...hostService };
84
- context = { events: [pointerUpEvent] };
85
- elementService = taskHubService;
86
- });
87
-
88
- test('reads the service from the DOM event', () => {
89
- subject();
90
-
91
- expect(elementServiceRecorder.serviceFor).toHaveBeenCalledWith(pointerUpEvent);
92
- });
93
-
94
- test('assigns the element service and version', () => {
95
- subject();
96
-
97
- expect({ service: event.service, version: event.version }).toEqual(taskHubService);
98
- });
99
-
100
- describe('with an MFE handling stack', () => {
101
- beforeEach(() => {
102
- context = {
103
- events: [pointerUpEvent],
104
- handlingStack:
105
- 'at f @ https://unpkg.servicetitan.com/@servicetitan/other-mfe@2.0.0/dist/main.js:1:1',
106
- };
107
- });
108
-
109
- test('assigns the service and version from the handling stack', () => {
110
- subject();
111
-
112
- expect({ service: event.service, version: event.version }).toEqual({
113
- service: 'other-mfe',
114
- version: '2.0.0',
115
- });
116
- });
117
- });
118
-
119
- describe('without an MFE element on the path', () => {
120
- beforeEach(() => (elementService = undefined));
121
-
122
- test('keeps the application service', () => {
123
- subject();
124
-
125
- expect({ service: event.service, version: event.version }).toEqual(hostService);
126
- });
127
- });
128
-
129
- describe('without DOM events', () => {
130
- beforeEach(() => (context = {}));
131
-
132
- test('keeps the application service', () => {
133
- subject();
134
-
135
- expect({ service: event.service, version: event.version }).toEqual(hostService);
136
- });
137
- });
138
- });
139
- });
@@ -1,56 +0,0 @@
1
- import { resetSharedImpl } from '../__mocks__/reset-shared-impl';
2
- import { getOrCreateSharedImpl, getSharedImpl, STATE_KEY } from '../get-shared';
3
-
4
- describe(`[datadog-rum] ${getOrCreateSharedImpl.name}`, () => {
5
- beforeEach(() => {
6
- resetSharedImpl();
7
- });
8
-
9
- const subject = () => getOrCreateSharedImpl();
10
-
11
- test('stores the instance under the well-known Symbol on globalThis', () => {
12
- const impl = subject();
13
-
14
- expect((globalThis as any)[STATE_KEY]).toBe(impl);
15
- });
16
-
17
- test('resolves the well-known Symbol from the package key', () => {
18
- expect(Symbol.for('@servicetitan/datadog-rum')).toBe(STATE_KEY);
19
- });
20
-
21
- describe('when an instance already exists', () => {
22
- let first: ReturnType<typeof getOrCreateSharedImpl>;
23
-
24
- beforeEach(() => {
25
- first = subject();
26
- });
27
-
28
- test('returns the same instance', () => {
29
- expect(subject()).toBe(first);
30
- });
31
- });
32
- });
33
-
34
- describe(`[datadog-rum] ${getSharedImpl.name}`, () => {
35
- beforeEach(() => {
36
- resetSharedImpl();
37
- });
38
-
39
- const subject = () => getSharedImpl();
40
-
41
- test('returns undefined', () => {
42
- expect(subject()).toBeUndefined();
43
- });
44
-
45
- describe('when an instance exists', () => {
46
- let impl: ReturnType<typeof getOrCreateSharedImpl>;
47
-
48
- beforeEach(() => {
49
- impl = getOrCreateSharedImpl();
50
- });
51
-
52
- test('returns existing instance', () => {
53
- expect(subject()).toBe(impl);
54
- });
55
- });
56
- });
@@ -1,76 +0,0 @@
1
- import type { RumResourceEvent } from '@datadog/browser-rum';
2
- import { type Mutable } from '../__mocks__';
3
- import { handleResource } from '../handle-resource';
4
-
5
- describe(`[datadog-rum] ${handleResource.name}`, () => {
6
- const cfRay = 'ray-1';
7
- const headers = new Map([['cf-ray', cfRay]]);
8
-
9
- let event: Mutable<RumResourceEvent>;
10
- let context: any;
11
-
12
- function makeResourceEvent(type: 'fetch' | 'xhr', url: string) {
13
- return {
14
- type: 'resource',
15
- resource: { type, url },
16
- } as unknown as Mutable<RumResourceEvent>;
17
- }
18
-
19
- const subject = () => handleResource(event, context);
20
-
21
- function itAddsCfRayToContext() {
22
- test('adds the cf-ray value to event context', () => {
23
- subject();
24
-
25
- expect(event.context?.cfRay).toBe(cfRay);
26
- });
27
- }
28
-
29
- function itDoesNotAddCfRay() {
30
- test('does not add a cf-ray value', () => {
31
- subject();
32
-
33
- expect(event.context?.cfRay).toBeUndefined();
34
- });
35
- }
36
-
37
- describe('with a "fetch" resource', () => {
38
- beforeEach(() => {
39
- event = makeResourceEvent('fetch', window.location.toString());
40
- context = { response: { headers } };
41
- });
42
-
43
- itAddsCfRayToContext();
44
-
45
- describe('when the request targets a different domain', () => {
46
- beforeEach(() => (event = makeResourceEvent('fetch', 'https://example.com/')));
47
-
48
- itDoesNotAddCfRay();
49
- });
50
-
51
- describe('without a cf-ray response header', () => {
52
- beforeEach(() => (context = { response: { headers: new Map() } }));
53
-
54
- itDoesNotAddCfRay();
55
- });
56
-
57
- describe('with pre-existing event context', () => {
58
- beforeEach(() => (event.context = { existing: 'keep' }));
59
-
60
- test('merges the cf-ray value without dropping existing keys', () => {
61
- subject();
62
-
63
- expect(event.context).toEqual({ existing: 'keep', cfRay });
64
- });
65
- });
66
- });
67
-
68
- describe('with an "xhr" resource', () => {
69
- beforeEach(() => {
70
- event = makeResourceEvent('xhr', window.location.toString());
71
- context = { xhr: { getResponseHeader: (key: string) => headers.get(key) } };
72
- });
73
-
74
- itAddsCfRayToContext();
75
- });
76
- });
@@ -1,70 +0,0 @@
1
- import { datadogRum } from '@datadog/browser-rum';
2
- import { act, render } from '@testing-library/react';
3
- import { FC } from 'react';
4
- import { BrowserRouter, useHistory } from 'react-router-dom';
5
- import { HashRouting } from '../hash-routing';
6
-
7
- jest.mock('@datadog/browser-rum');
8
-
9
- function mockLocation(newLocation: { origin?: string; pathname?: string } | string) {
10
- const { origin = window.location.origin, pathname = window.location.pathname } =
11
- typeof newLocation === 'string' ? { pathname: newLocation } : newLocation;
12
- (window.location as any) = Object.assign(new URL(`${origin}${pathname}`), {
13
- assign: jest.fn(),
14
- reload: jest.fn(),
15
- });
16
- }
17
-
18
- describe(`[datadog-rum] ${HashRouting.name}`, () => {
19
- let history: ReturnType<typeof useHistory>;
20
- const subject = () => {
21
- const History: FC = () => {
22
- history = useHistory();
23
- return null;
24
- };
25
- return render(
26
- <BrowserRouter>
27
- <History />
28
- <HashRouting />
29
- </BrowserRouter>
30
- );
31
- };
32
-
33
- beforeEach(() => {
34
- jest.clearAllMocks();
35
- mockLocation({ origin: 'https://go.servicetitan.com' });
36
- });
37
-
38
- describe('when location changes', () => {
39
- const location = '/billing/1';
40
- const setup = (locations: string[] = []) => {
41
- const subjectResult = subject();
42
- jest.mocked(datadogRum.startView).mockClear();
43
- locations.forEach(currentLocation => act(() => history.push(currentLocation)));
44
- return subjectResult;
45
- };
46
-
47
- test('notifies DataDog', () => {
48
- setup([location]);
49
- expect(datadogRum.startView).toHaveBeenCalledTimes(1);
50
- expect(datadogRum.startView).toHaveBeenCalledWith('/billing/{id}');
51
- });
52
-
53
- test('sends single notification for duplicate locations', () => {
54
- setup([location, location]);
55
- expect(datadogRum.startView).toHaveBeenCalledTimes(1);
56
- });
57
-
58
- test('sends single notification for similar locations', () => {
59
- setup([location, '/billing/2']);
60
- expect(datadogRum.startView).toHaveBeenCalledTimes(1);
61
- });
62
-
63
- test('sends no notification after unmount', () => {
64
- const { unmount } = setup();
65
- unmount();
66
- history.push(location);
67
- expect(datadogRum.startView).not.toHaveBeenCalled();
68
- });
69
- });
70
- });
@@ -1,69 +0,0 @@
1
- import { minimalApplication } from '../__mocks__/init-config';
2
- import { bundleState } from '../bundle-state';
3
- import { getOrCreateSharedImpl } from '../get-shared';
4
- import { init } from '../init';
5
- import type { InitRumOptions } from '../types';
6
-
7
- jest.mock('../get-shared');
8
-
9
- describe(`[datadog-rum] ${init.name}`, () => {
10
- const cleanup = jest.fn();
11
- const setServiceContext = jest.fn();
12
- let initializedSdk: boolean;
13
- let options: InitRumOptions;
14
-
15
- beforeEach(() => {
16
- jest.clearAllMocks();
17
- bundleState.isSdkInitializer = false;
18
- initializedSdk = false;
19
- jest.mocked(getOrCreateSharedImpl).mockReturnValue({
20
- init: jest.fn(() => ({ cleanup, initializedSdk })),
21
- setServiceContext,
22
- });
23
- options = { service: { name: 'desktop' }, application: minimalApplication };
24
- });
25
-
26
- const subject = () => init(options);
27
-
28
- test('forwards to the shared implementation', () => {
29
- subject();
30
-
31
- expect(getOrCreateSharedImpl().init).toHaveBeenCalledWith(options);
32
- });
33
-
34
- test('returns the cleanup from the implementation', () => {
35
- expect(subject().cleanup).toBe(cleanup);
36
- });
37
-
38
- test('returns a setServiceContext bound to the service name', () => {
39
- const context = { orgId: '42' };
40
-
41
- subject().setServiceContext(context);
42
-
43
- expect(setServiceContext).toHaveBeenCalledWith(options.service.name, context);
44
- });
45
-
46
- describe('when the implementation initialized the SDK', () => {
47
- beforeEach(() => {
48
- initializedSdk = true;
49
- });
50
-
51
- test('marks this bundle as the SDK initializer', () => {
52
- subject();
53
-
54
- expect(bundleState.isSdkInitializer).toBe(true);
55
- });
56
- });
57
-
58
- describe('when the implementation did not initialize the SDK', () => {
59
- beforeEach(() => {
60
- initializedSdk = false;
61
- });
62
-
63
- test('does not mark this bundle as the SDK initializer', () => {
64
- subject();
65
-
66
- expect(bundleState.isSdkInitializer).toBe(false);
67
- });
68
- });
69
- });
@@ -1,147 +0,0 @@
1
- import type { RumEvent } from '@datadog/browser-rum';
2
- import {
3
- getInitAllowedTracingUrls,
4
- isAllowedTracingUrl,
5
- minimalApplication,
6
- processEvent,
7
- resetSharedImpl,
8
- } from '../__mocks__';
9
- import { init, RumServiceRegistration } from '../init';
10
-
11
- jest.mock('@datadog/browser-rum');
12
-
13
- describe('[datadog-rum] integration', () => {
14
- const serviceContext = { logicalEnv: 'go5', orgId: '42' };
15
- const applicationBeforeSendHandler = jest.fn();
16
- let event: Partial<RumEvent>;
17
-
18
- beforeEach(() => {
19
- jest.clearAllMocks();
20
- resetSharedImpl();
21
-
22
- applicationBeforeSendHandler.mockReturnValue(true);
23
-
24
- init({
25
- service: { name: 'desktop' },
26
- application: { ...minimalApplication, beforeSend: applicationBeforeSendHandler },
27
- });
28
-
29
- event = {
30
- type: 'error',
31
- error: {
32
- message: 'boom',
33
- stack: 'at https://unpkg.servicetitan.com/@servicetitan/task-hub@1.2.3/main.js',
34
- } as any,
35
- };
36
- });
37
-
38
- const subject = () => processEvent(event);
39
-
40
- test('passes event through the pipeline', () => {
41
- expect(subject()).toBe(true);
42
- });
43
-
44
- test('sets event service and version', () => {
45
- subject();
46
-
47
- expect(event.service).toBe('task-hub');
48
- expect(event.version).toBe('1.2.3');
49
- });
50
-
51
- describe('when application handler returns false', () => {
52
- beforeEach(() => applicationBeforeSendHandler.mockReturnValue(false));
53
-
54
- test('drops the event', () => {
55
- expect(subject()).toBe(false);
56
- });
57
- });
58
-
59
- describe('with service handler', () => {
60
- let serviceBeforeSendHandler: jest.Mock;
61
- let serviceRegistration: RumServiceRegistration;
62
-
63
- beforeEach(() => {
64
- serviceBeforeSendHandler = jest.fn(e => {
65
- e.context = { ...e.context, kibanaUrl: 'https://kibana/example' };
66
- });
67
-
68
- serviceRegistration = init({
69
- service: {
70
- name: 'task-hub',
71
- allowedTracingUrls: { tracecontext: [/\/api\/task-hub\//] },
72
- beforeSend: serviceBeforeSendHandler,
73
- },
74
- });
75
- serviceRegistration.setServiceContext(serviceContext);
76
- });
77
-
78
- test('traces registered URLs', () => {
79
- expect(
80
- isAllowedTracingUrl(
81
- getInitAllowedTracingUrls(),
82
- 'https://go.example.com/api/task-hub/list'
83
- )
84
- ).toBe(true);
85
- });
86
-
87
- test('does not trace unregistered URLs', () => {
88
- expect(
89
- isAllowedTracingUrl(getInitAllowedTracingUrls(), 'https://go.example.com/api/other')
90
- ).toBe(false);
91
- });
92
-
93
- test('runs service handlers', () => {
94
- subject();
95
-
96
- expect(serviceBeforeSendHandler).toHaveBeenCalled();
97
- });
98
-
99
- test('enriches event.context', () => {
100
- subject();
101
-
102
- expect(event.context).toEqual({
103
- kibanaUrl: 'https://kibana/example',
104
- ...serviceContext,
105
- });
106
- });
107
-
108
- describe('when application handler returns false', () => {
109
- beforeEach(() => applicationBeforeSendHandler.mockReturnValue(false));
110
-
111
- test('does not run service handlers', () => {
112
- subject();
113
-
114
- expect(serviceBeforeSendHandler).not.toHaveBeenCalled();
115
- });
116
- });
117
-
118
- describe('when service handler returns false', () => {
119
- beforeEach(() => serviceBeforeSendHandler.mockReturnValue(false));
120
-
121
- test('passes event through the pipeline', () => {
122
- expect(subject()).toBe(true);
123
- });
124
- });
125
-
126
- describe('when service is unregistered', () => {
127
- beforeEach(() => serviceRegistration.cleanup());
128
-
129
- test('stops tracing URLs', () => {
130
- subject();
131
-
132
- expect(
133
- isAllowedTracingUrl(
134
- getInitAllowedTracingUrls(),
135
- 'https://go.example.com/api/task-hub/list'
136
- )
137
- ).toBe(false);
138
- });
139
-
140
- test('stops enriching event.context', () => {
141
- subject();
142
-
143
- expect(event.context).toBeUndefined();
144
- });
145
- });
146
- });
147
- });