@servicetitan/datadog-rum 40.2.1 → 40.3.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.
- package/dist/create-impl.d.ts.map +1 -1
- package/dist/create-impl.js +3 -0
- package/dist/create-impl.js.map +1 -1
- package/dist/datadog-provider.d.ts +3 -1
- package/dist/datadog-provider.d.ts.map +1 -1
- package/dist/datadog-provider.js +3 -1
- package/dist/datadog-provider.js.map +1 -1
- package/dist/get-env.d.ts +7 -0
- package/dist/get-env.d.ts.map +1 -0
- package/dist/get-env.js +26 -0
- package/dist/get-env.js.map +1 -0
- package/dist/hash-routing.d.ts +5 -1
- package/dist/hash-routing.d.ts.map +1 -1
- package/dist/hash-routing.js +23 -8
- package/dist/hash-routing.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/sanitize-view-name.d.ts.map +1 -1
- package/dist/sanitize-view-name.js +10 -0
- package/dist/sanitize-view-name.js.map +1 -1
- package/dist/shared-impl.d.ts +1 -1
- package/dist/shared-impl.d.ts.map +1 -1
- package/dist/shared-impl.js.map +1 -1
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +8 -3
- package/src/create-impl.ts +2 -0
- package/src/datadog-provider.tsx +7 -3
- package/src/get-env.ts +27 -0
- package/src/hash-routing.tsx +28 -9
- package/src/index.ts +1 -0
- package/src/sanitize-view-name.tsx +17 -0
- package/src/shared-impl.ts +1 -1
- package/src/types.ts +6 -2
- package/src/__mocks__/before-send-data.ts +0 -538
- package/src/__mocks__/index.ts +0 -7
- package/src/__mocks__/init-config.ts +0 -6
- package/src/__mocks__/mfe-host.ts +0 -7
- package/src/__mocks__/process-event.ts +0 -20
- package/src/__mocks__/reset-shared-impl.ts +0 -8
- package/src/__mocks__/tracing-urls.ts +0 -30
- package/src/__mocks__/types.ts +0 -1
- package/src/__tests__/before-send.test.ts +0 -76
- package/src/__tests__/build-allowed-tracing-urls.test.ts +0 -120
- package/src/__tests__/build-before-send.test.ts +0 -193
- package/src/__tests__/create-impl.test.ts +0 -427
- package/src/__tests__/datadog-provider.test.tsx +0 -145
- package/src/__tests__/dd-rum-guard.test.ts +0 -73
- package/src/__tests__/element-service-recorder.test.ts +0 -127
- package/src/__tests__/enrich-event.test.ts +0 -139
- package/src/__tests__/get-shared.test.ts +0 -56
- package/src/__tests__/handle-resource.test.ts +0 -76
- package/src/__tests__/hash-routing.test.tsx +0 -70
- package/src/__tests__/init.test.ts +0 -69
- package/src/__tests__/integration.test.ts +0 -147
- package/src/__tests__/resolve-path-service.test.ts +0 -130
- package/src/__tests__/sanitize-view-name.test.tsx +0 -92
- package/src/__tests__/set-user.test.ts +0 -61
- package/src/__tests__/use-rum-service.test.tsx +0 -82
- package/src/runtime-override/__tests__/dev-console.test.ts +0 -158
- package/src/runtime-override/__tests__/override.test.ts +0 -109
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { RumEvent, RumEventDomainContext } from '@datadog/browser-rum';
|
|
2
|
-
import { type Mutable, type RumEventType } from '../__mocks__';
|
|
3
|
-
import { beforeSend } from '../before-send';
|
|
4
|
-
import { enrichEvent } from '../enrich-event';
|
|
5
|
-
import { handleResource } from '../handle-resource';
|
|
6
|
-
|
|
7
|
-
jest.mock('../enrich-event');
|
|
8
|
-
jest.mock('../handle-resource');
|
|
9
|
-
|
|
10
|
-
describe(`[datadog-rum] ${beforeSend.name}`, () => {
|
|
11
|
-
let event: Mutable<RumEventType>;
|
|
12
|
-
let context: RumEventDomainContext;
|
|
13
|
-
let customHandler: (() => boolean) | undefined;
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
jest.clearAllMocks();
|
|
17
|
-
context = {};
|
|
18
|
-
event = { type: 'action' };
|
|
19
|
-
customHandler = undefined;
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const subject = () => beforeSend(customHandler)(event as RumEvent, context);
|
|
23
|
-
|
|
24
|
-
function itReturns(value: boolean) {
|
|
25
|
-
test(`returns ${value}`, () => expect(subject()).toBe(value));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
itReturns(true);
|
|
29
|
-
|
|
30
|
-
test('calls enrichEvent with the event and context', () => {
|
|
31
|
-
subject();
|
|
32
|
-
|
|
33
|
-
expect(enrichEvent).toHaveBeenCalledWith(event, context);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('with a "resource" event', () => {
|
|
37
|
-
beforeEach(() => (event.type = 'resource'));
|
|
38
|
-
|
|
39
|
-
test('calls handleResource with the event and context', () => {
|
|
40
|
-
subject();
|
|
41
|
-
|
|
42
|
-
expect(handleResource).toHaveBeenCalledWith(event, context);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('with a non-resource event', () => {
|
|
47
|
-
beforeEach(() => (event.type = 'action'));
|
|
48
|
-
|
|
49
|
-
test('does not call handleResource', () => {
|
|
50
|
-
subject();
|
|
51
|
-
|
|
52
|
-
expect(handleResource).not.toHaveBeenCalled();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('with custom handler', () => {
|
|
57
|
-
let result: boolean;
|
|
58
|
-
|
|
59
|
-
beforeEach(() => {
|
|
60
|
-
result = true;
|
|
61
|
-
customHandler = jest.fn(() => result);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('calls custom handler', () => {
|
|
65
|
-
subject();
|
|
66
|
-
|
|
67
|
-
expect(customHandler).toHaveBeenCalled();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('when the handler returns false', () => {
|
|
71
|
-
beforeEach(() => (result = false));
|
|
72
|
-
|
|
73
|
-
itReturns(false);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { isAllowedTracingUrl, type PropagatorType } from '../__mocks__';
|
|
2
|
-
import { buildAllowedTracingUrls } from '../build-allowed-tracing-urls';
|
|
3
|
-
import type { ServiceEntry, State } from '../types';
|
|
4
|
-
|
|
5
|
-
describe(`[datadog-rum] ${buildAllowedTracingUrls.name}`, () => {
|
|
6
|
-
let serviceEntry: ServiceEntry;
|
|
7
|
-
let state: State;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
serviceEntry = {};
|
|
11
|
-
state = { services: new Map() };
|
|
12
|
-
state.services.set('foo', serviceEntry);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const subject = () => buildAllowedTracingUrls(state);
|
|
16
|
-
|
|
17
|
-
test('returns matchers for propagatorTypes', () => {
|
|
18
|
-
expect(subject()).toEqual(
|
|
19
|
-
expect.arrayContaining(
|
|
20
|
-
['datadog', 'tracecontext', 'b3', 'b3multi'].map(type => ({
|
|
21
|
-
match: expect.any(Function),
|
|
22
|
-
propagatorTypes: [type],
|
|
23
|
-
}))
|
|
24
|
-
)
|
|
25
|
-
);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe.each(['datadog', 'tracecontext', 'b3', 'b3multi'] as PropagatorType[])(
|
|
29
|
-
'with %s matcher',
|
|
30
|
-
type => {
|
|
31
|
-
test('traces no URLs', () => {
|
|
32
|
-
expect(isAllowedTracingUrl(subject(), 'https://example.com', type)).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('when service entry contains string (prefix) matcher', () => {
|
|
36
|
-
const prefix = 'https://prefix.example.com';
|
|
37
|
-
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
serviceEntry.allowedTracingUrls = { [type]: [prefix] };
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('traces URLs starting with the prefix', () => {
|
|
43
|
-
expect(isAllowedTracingUrl(subject(), `${prefix}/foo`, type)).toBe(true);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('when service entry contains RegExp matcher', () => {
|
|
48
|
-
const regex = /bar/;
|
|
49
|
-
|
|
50
|
-
beforeEach(() => {
|
|
51
|
-
serviceEntry.allowedTracingUrls = { [type]: [regex] };
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('traces URLs that match the pattern', () => {
|
|
55
|
-
expect(
|
|
56
|
-
isAllowedTracingUrl(
|
|
57
|
-
subject(),
|
|
58
|
-
`https://example.com/${regex.toString()}`,
|
|
59
|
-
type
|
|
60
|
-
)
|
|
61
|
-
).toBe(true);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe('when service entry contains function matcher', () => {
|
|
66
|
-
const predicate = 'baz';
|
|
67
|
-
|
|
68
|
-
beforeEach(() => {
|
|
69
|
-
serviceEntry.allowedTracingUrls = {
|
|
70
|
-
[type]: [(url: string) => url.includes(predicate)],
|
|
71
|
-
};
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('traces URLs for which the predicate returns true', () => {
|
|
75
|
-
expect(
|
|
76
|
-
isAllowedTracingUrl(subject(), `https://example.com/${predicate}`, type)
|
|
77
|
-
).toBe(true);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
describe('with multiple matchers', () => {
|
|
84
|
-
let matcher: (url: string) => boolean;
|
|
85
|
-
|
|
86
|
-
beforeEach(() => {
|
|
87
|
-
matcher = (url: string) => url.includes('foo');
|
|
88
|
-
serviceEntry.allowedTracingUrls = {
|
|
89
|
-
tracecontext: [url => matcher(url)],
|
|
90
|
-
b3: [/\/b3\//],
|
|
91
|
-
};
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test('traces URLs matched under tracecontext', () => {
|
|
95
|
-
expect(isAllowedTracingUrl(subject(), 'https://foo.com', 'tracecontext')).toBe(true);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test('traces URLs matched under b3', () => {
|
|
99
|
-
expect(isAllowedTracingUrl(subject(), 'https://example.com/b3/x', 'b3')).toBe(true);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('when function matcher throws', () => {
|
|
103
|
-
beforeEach(() => {
|
|
104
|
-
matcher = () => {
|
|
105
|
-
throw new Error('Oops!');
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test('does not trace URLs from failing matcher', () => {
|
|
110
|
-
expect(isAllowedTracingUrl(subject(), 'https://foo.com', 'tracecontext')).toBe(
|
|
111
|
-
false
|
|
112
|
-
);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test('traces URLs from healthy matcher', () => {
|
|
116
|
-
expect(isAllowedTracingUrl(subject(), 'https://example.com/b3/x', 'b3')).toBe(true);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
});
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import type { RumEvent, RumEventDomainContext } from '@datadog/browser-rum';
|
|
2
|
-
import { type Mutable } from '../__mocks__';
|
|
3
|
-
import { buildBeforeSend } from '../build-before-send';
|
|
4
|
-
import { enrichEvent } from '../enrich-event';
|
|
5
|
-
import { handleResource } from '../handle-resource';
|
|
6
|
-
import type { State } from '../types';
|
|
7
|
-
|
|
8
|
-
jest.mock('../enrich-event');
|
|
9
|
-
jest.mock('../handle-resource');
|
|
10
|
-
|
|
11
|
-
describe(`[datadog-rum] ${buildBeforeSend.name}`, () => {
|
|
12
|
-
const service = 'task-hub';
|
|
13
|
-
|
|
14
|
-
let state: State;
|
|
15
|
-
let event: Mutable<RumEvent>;
|
|
16
|
-
let context: RumEventDomainContext;
|
|
17
|
-
let serviceHandler: jest.Mock;
|
|
18
|
-
let applicationBeforeSend: jest.Mock;
|
|
19
|
-
|
|
20
|
-
function makeEvent(overrides: Record<string, unknown> = {}) {
|
|
21
|
-
return { type: 'error', service, ...overrides } as unknown as Mutable<RumEvent>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
jest.clearAllMocks();
|
|
26
|
-
jest.mocked(enrichEvent).mockImplementation(jest.fn());
|
|
27
|
-
jest.mocked(handleResource).mockImplementation(jest.fn());
|
|
28
|
-
serviceHandler = jest.fn(() => {});
|
|
29
|
-
applicationBeforeSend = jest.fn(() => true);
|
|
30
|
-
state = { services: new Map(), applicationBeforeSend };
|
|
31
|
-
state.services.set(service, { beforeSend: serviceHandler });
|
|
32
|
-
event = makeEvent();
|
|
33
|
-
context = {};
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const subject = () => buildBeforeSend(state)(event as RumEvent, context);
|
|
37
|
-
|
|
38
|
-
function itReturns(value: boolean) {
|
|
39
|
-
test(`returns ${value}`, () => {
|
|
40
|
-
expect(subject()).toBe(value);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function itCallsServiceHandler() {
|
|
45
|
-
test('calls service handler', () => {
|
|
46
|
-
subject();
|
|
47
|
-
|
|
48
|
-
expect(serviceHandler).toHaveBeenCalledWith(event, context);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function itDoesNotCallServiceHandler() {
|
|
53
|
-
test('does not call service handler', () => {
|
|
54
|
-
subject();
|
|
55
|
-
|
|
56
|
-
expect(serviceHandler).not.toHaveBeenCalled();
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
test('enriches the event', () => {
|
|
61
|
-
subject();
|
|
62
|
-
|
|
63
|
-
expect(enrichEvent).toHaveBeenCalledWith(event, context);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('calls application handler', () => {
|
|
67
|
-
subject();
|
|
68
|
-
|
|
69
|
-
expect(applicationBeforeSend).toHaveBeenCalledWith(event, context);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
itCallsServiceHandler();
|
|
73
|
-
|
|
74
|
-
itReturns(true);
|
|
75
|
-
|
|
76
|
-
describe('when enrichment throws', () => {
|
|
77
|
-
beforeEach(() => {
|
|
78
|
-
jest.mocked(enrichEvent).mockImplementation(() => {
|
|
79
|
-
throw new Error('boom');
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
itReturns(true);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('when application handler throws', () => {
|
|
87
|
-
beforeEach(() => {
|
|
88
|
-
jest.mocked(applicationBeforeSend).mockImplementation(() => {
|
|
89
|
-
throw new Error('Nope!');
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
itCallsServiceHandler();
|
|
94
|
-
|
|
95
|
-
itReturns(true);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('when service handler throws', () => {
|
|
99
|
-
beforeEach(() => {
|
|
100
|
-
jest.mocked(serviceHandler).mockImplementation(() => {
|
|
101
|
-
throw new Error('Nope!');
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
itReturns(true);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test('does not call handleResource', () => {
|
|
109
|
-
subject();
|
|
110
|
-
|
|
111
|
-
expect(handleResource).not.toHaveBeenCalled();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe('when application handler returns false', () => {
|
|
115
|
-
beforeEach(() => jest.mocked(applicationBeforeSend).mockReturnValue(false));
|
|
116
|
-
|
|
117
|
-
itReturns(false);
|
|
118
|
-
|
|
119
|
-
itDoesNotCallServiceHandler();
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe('when service handler returns false', () => {
|
|
123
|
-
beforeEach(() => jest.mocked(serviceHandler).mockReturnValue(false));
|
|
124
|
-
|
|
125
|
-
itReturns(true);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
describe('when event.service does not match', () => {
|
|
129
|
-
beforeEach(() => (event.service = 'unknown'));
|
|
130
|
-
|
|
131
|
-
itDoesNotCallServiceHandler();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe('when event.service is undefined', () => {
|
|
135
|
-
beforeEach(() => delete event.service);
|
|
136
|
-
|
|
137
|
-
itDoesNotCallServiceHandler();
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
describe('with a service context', () => {
|
|
141
|
-
const serviceContext = { orgId: '42', env: 'prod' };
|
|
142
|
-
|
|
143
|
-
beforeEach(() => (state.services.get(service)!.context = serviceContext));
|
|
144
|
-
|
|
145
|
-
test('adds context to event', () => {
|
|
146
|
-
subject();
|
|
147
|
-
|
|
148
|
-
expect(event.context).toEqual(serviceContext);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('when event.service does not match', () => {
|
|
152
|
-
beforeEach(() => (event.service = 'unknown'));
|
|
153
|
-
|
|
154
|
-
test('does not add context', () => {
|
|
155
|
-
subject();
|
|
156
|
-
|
|
157
|
-
expect(event.context).toBeUndefined();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe('with pre-existing event.context', () => {
|
|
162
|
-
const eventContext = { foo: 'bar' };
|
|
163
|
-
|
|
164
|
-
beforeEach(() => (event.context = eventContext));
|
|
165
|
-
|
|
166
|
-
test('merges service and event contexts', () => {
|
|
167
|
-
subject();
|
|
168
|
-
|
|
169
|
-
expect(event.context).toEqual({ ...eventContext, ...serviceContext });
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
describe('with a "resource" event', () => {
|
|
175
|
-
beforeEach(() => (event = makeEvent({ type: 'resource' })));
|
|
176
|
-
|
|
177
|
-
test('calls handleResource with the event and context', () => {
|
|
178
|
-
subject();
|
|
179
|
-
|
|
180
|
-
expect(handleResource).toHaveBeenCalledWith(event, context);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
describe('when handleResource throws', () => {
|
|
184
|
-
beforeEach(() => {
|
|
185
|
-
jest.mocked(handleResource).mockImplementation(() => {
|
|
186
|
-
throw new Error('Nope!');
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
itReturns(true);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
});
|