@dynatrace/rum-javascript-sdk 1.331.17 → 1.333.2
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/README.md +8 -390
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.js +3 -0
- package/dist/testing/snapshot.d.ts +129 -0
- package/dist/testing/snapshot.js +385 -0
- package/dist/testing/test.d.ts +9 -0
- package/dist/testing/test.js +237 -160
- package/dist/types/index-typedoc.d.ts +3 -0
- package/dist/types/index-typedoc.js +4 -1
- package/dist/types/rum-events/rum-event-keys.d.ts +9 -0
- package/dist/types/rum-events/rum-event-keys.js +11 -1
- package/dist/types/rum-events/rum-internal-selfmonitoring-event.d.ts +5 -1
- package/dist/types/rum-events/rum-internal-selfmonitoring-event.js +5 -1
- package/dist/types/rum-events/rum-web-request-event.d.ts +2 -1
- package/dist/types/rum-events/rum-web-request-event.js +2 -1
- package/dist/types/rum-events/shared-namespaces-and-fields/general-rum-event-fields.d.ts +1 -0
- package/dist/types/rum-events/shared-namespaces-and-fields/general-rum-event-fields.js +1 -1
- package/docs/1-overview.md +405 -0
- package/docs/2-testing.md +424 -0
- package/docs/{types.md → 3-types.md} +8 -2
- package/docs/{USERACTIONS.md → 4-useractions.md} +10 -8
- package/package.json +46 -9
- package/docs/testing.md +0 -215
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @dynatrace/rum-javascript-sdk
|
|
2
2
|
|
|
3
|
-
A JavaScript API for interacting with the Dynatrace Real User Monitoring (RUM) JavaScript. This package provides both synchronous and asynchronous wrappers for the Dynatrace RUM API, along with TypeScript support and testing utilities.
|
|
3
|
+
A JavaScript API for interacting with the Dynatrace Real User Monitoring (RUM) JavaScript. This package provides both synchronous and asynchronous wrappers for the Dynatrace RUM JavaScript API, along with TypeScript support and testing utilities.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,395 +8,13 @@ A JavaScript API for interacting with the Dynatrace Real User Monitoring (RUM) J
|
|
|
8
8
|
npm install @dynatrace/rum-javascript-sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Documentation
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Due to rendering restrictions on npmjs.org, the full documentation for this package can be found in the [dynatrace documentation](https://www.dynatrace.com/support/doc/javascriptapi/doc-latest).
|
|
14
|
+
Alternatively you can find the *.md files in the [docs](docs) directory.
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- **Testing Framework**: Playwright-based utilities for testing RUM integration
|
|
16
|
+
:::warn
|
|
17
|
+
The dynatrace documentation only contains the documentation for the newest version of the `@dynatrace/rum-javascript-sdk` package.
|
|
18
|
+
For older versions of the documentation, check the [docs](docs) directory.
|
|
19
|
+
:::
|
|
20
20
|
|
|
21
|
-
## Quick Start
|
|
22
|
-
|
|
23
|
-
### Synchronous API (Recommended for most use cases)
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
import { sendEvent, identifyUser } from '@dynatrace/rum-javascript-sdk/api';
|
|
27
|
-
|
|
28
|
-
// Send a custom event - safely handles cases where RUM JavaScript is not loaded
|
|
29
|
-
sendEvent({
|
|
30
|
-
'event_properties.component_name': 'UserProfile',
|
|
31
|
-
'event_properties.action': 'view'
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Identify the current user
|
|
35
|
-
identifyUser('user@example.com');
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### Asynchronous API (When you need to ensure RUM JavaScript is available)
|
|
39
|
-
|
|
40
|
-
```typescript
|
|
41
|
-
import { sendEvent, identifyUser } from '@dynatrace/rum-javascript-sdk/api/promises';
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
// Wait for RUM JavaScript to be available (with 10s timeout by default)
|
|
45
|
-
await sendEvent({
|
|
46
|
-
'event_properties.component_name': 'UserProfile',
|
|
47
|
-
'event_properties.action': 'view'
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
await identifyUser('user@example.com');
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.error('RUM JavaScript not available:', error);
|
|
53
|
-
}
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## API Reference
|
|
57
|
-
|
|
58
|
-
### Synchronous API (`@dynatrace/rum-javascript-sdk/api`)
|
|
59
|
-
|
|
60
|
-
The synchronous API provides safe wrapper functions that gracefully handle cases where the Dynatrace RUM JavaScript is not available. These functions will execute as no-ops if the JavaScript is not loaded, making them safe to use in any environment.
|
|
61
|
-
|
|
62
|
-
#### `sendEvent(fields, eventContext?): void`
|
|
63
|
-
|
|
64
|
-
Sends a custom event to Dynatrace RUM.
|
|
65
|
-
|
|
66
|
-
**Parameters:**
|
|
67
|
-
- `fields: ApiCreatedEventPropertiesEvent` - Event properties object. Must be serializable JSON with properties prefixed with `event_properties.`, plus optional `duration` and `start_time` properties.
|
|
68
|
-
- `eventContext?: unknown` - Optional context for event modification callbacks.
|
|
69
|
-
|
|
70
|
-
**Example:**
|
|
71
|
-
```typescript
|
|
72
|
-
import { sendEvent } from '@dynatrace/rum-javascript-sdk/api';
|
|
73
|
-
|
|
74
|
-
sendEvent({
|
|
75
|
-
'event_properties.page_name': 'checkout',
|
|
76
|
-
'event_properties.step': 'payment',
|
|
77
|
-
'event_properties.amount': 99.99,
|
|
78
|
-
'duration': 1500,
|
|
79
|
-
'start_time': Date.now()
|
|
80
|
-
});
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
#### `addEventModifier(eventModifier): Unsubscriber | undefined`
|
|
84
|
-
|
|
85
|
-
Registers a function to modify events before they are sent to Dynatrace.
|
|
86
|
-
|
|
87
|
-
**Parameters:**
|
|
88
|
-
- `eventModifier: (jsonEvent: Readonly<JSONEvent>, eventContext?: EventContext) => JSONEvent | null` - Function that receives an event and returns a modified version or null to cancel the event.
|
|
89
|
-
|
|
90
|
-
**Returns:**
|
|
91
|
-
- `Unsubscriber | undefined` - Function to remove the modifier, or undefined if the RUM JavaScript is not available.
|
|
92
|
-
|
|
93
|
-
**Example:**
|
|
94
|
-
```typescript
|
|
95
|
-
import { addEventModifier } from '@dynatrace/rum-javascript-sdk/api';
|
|
96
|
-
|
|
97
|
-
const unsubscribe = addEventModifier((event, context) => {
|
|
98
|
-
// Add user context to all events
|
|
99
|
-
return {
|
|
100
|
-
...event,
|
|
101
|
-
'event_properties.user_tier': 'premium'
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Later, remove the modifier
|
|
106
|
-
unsubscribe?.();
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
#### `runHealthCheck(config?): Promise<unknown[] | undefined> | undefined`
|
|
110
|
-
|
|
111
|
-
Runs a health check on the RUM JavaScript to diagnose potential issues.
|
|
112
|
-
|
|
113
|
-
**Parameters:**
|
|
114
|
-
- `config?: HealthCheckConfig` - Optional configuration object:
|
|
115
|
-
- `logVerbose?: boolean` - Include verbose information in the health check
|
|
116
|
-
- `returnDiagnosticData?: boolean` - Return diagnostic data as array instead of just logging
|
|
117
|
-
- `runDetailedOverrideCheck?: boolean` - Log additional information about overridden native APIs
|
|
118
|
-
|
|
119
|
-
**Returns:**
|
|
120
|
-
- `Promise<unknown[] | undefined> | undefined` - Promise resolving to diagnostic data (if requested), or undefined if the RUM JavaScript is not available.
|
|
121
|
-
|
|
122
|
-
**Example:**
|
|
123
|
-
```typescript
|
|
124
|
-
import { runHealthCheck } from '@dynatrace/rum-javascript-sdk/api';
|
|
125
|
-
|
|
126
|
-
const diagnostics = await runHealthCheck({
|
|
127
|
-
logVerbose: true,
|
|
128
|
-
returnDiagnosticData: true
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
if (diagnostics) {
|
|
132
|
-
console.log('RUM Health Check Results:', diagnostics);
|
|
133
|
-
}
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
#### `identifyUser(value): void`
|
|
137
|
-
|
|
138
|
-
Associates the current session with a specific user identifier.
|
|
139
|
-
|
|
140
|
-
**Parameters:**
|
|
141
|
-
- `value: string` - User identifier (name, email, user ID, etc.)
|
|
142
|
-
|
|
143
|
-
**Example:**
|
|
144
|
-
```typescript
|
|
145
|
-
import { identifyUser } from '@dynatrace/rum-javascript-sdk/api';
|
|
146
|
-
|
|
147
|
-
// Identify user after login
|
|
148
|
-
identifyUser('john.doe@example.com');
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
#### `sendSessionPropertyEvent(fields): void`
|
|
152
|
-
|
|
153
|
-
Sends session-level properties that will be attached to all subsequent events in the session.
|
|
154
|
-
|
|
155
|
-
**Parameters:**
|
|
156
|
-
- `fields: ApiCreatedSessionPropertiesEvent` - Session properties object. All keys must be prefixed with `session_properties.` and follow naming conventions (lowercase, numbers, underscores, dots).
|
|
157
|
-
|
|
158
|
-
**Example:**
|
|
159
|
-
```typescript
|
|
160
|
-
import { sendSessionPropertyEvent } from '@dynatrace/rum-javascript-sdk/api';
|
|
161
|
-
|
|
162
|
-
sendSessionPropertyEvent({
|
|
163
|
-
'session_properties.user_type': 'premium',
|
|
164
|
-
'session_properties.subscription_tier': 'gold',
|
|
165
|
-
'session_properties.region': 'us_east'
|
|
166
|
-
});
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
#### `sendExceptionEvent(error, fields?): void`
|
|
170
|
-
|
|
171
|
-
Sends an exception event. Marks the exception event with `characteristics.is_api_reported` and `error.source` = `api` to make it clear on DQL side where errors are coming from.
|
|
172
|
-
Only available if the Errors module is enabled.
|
|
173
|
-
|
|
174
|
-
**Parameters:**
|
|
175
|
-
|
|
176
|
-
- `error: Error` - The error object to report. Must be an instance of the standard JavaScript `Error` class.
|
|
177
|
-
- `fields: ApiCreatedEventPropertiesEvent` - Optional Event properties object. Must be serializable JSON with properties prefixed with `event_properties.`, plus optional `duration` and `start_time` properties.
|
|
178
|
-
|
|
179
|
-
**Example:**
|
|
180
|
-
```typescript
|
|
181
|
-
import { sendExceptionEvent } from '@dynatrace/rum-javascript-sdk/api';
|
|
182
|
-
|
|
183
|
-
const yourError = new Error("Your Error Message");
|
|
184
|
-
|
|
185
|
-
sendExceptionEvent(yourError);
|
|
186
|
-
```
|
|
187
|
-
```typescript
|
|
188
|
-
import { sendExceptionEvent } from '@dynatrace/rum-javascript-sdk/api';
|
|
189
|
-
|
|
190
|
-
const yourError = new Error("Your Error Message");
|
|
191
|
-
|
|
192
|
-
sendExceptionEvent(yourError, { "event_properties.component": "myExampleComponent" });
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### Asynchronous API (`@dynatrace/rum-javascript-sdk/promises`)
|
|
196
|
-
|
|
197
|
-
The asynchronous API provides Promise-based functions that wait for the Dynatrace RUM JavaScript to become available. These functions will throw a `DynatraceError` if the RUM JavaScript is not available within the specified timeout. This is useful for scenarios where you don't want to
|
|
198
|
-
enable the RUM JavaScript before the user gives their consent.
|
|
199
|
-
|
|
200
|
-
#### `sendEvent(fields, eventContext?, timeout?): Promise<void>`
|
|
201
|
-
|
|
202
|
-
Async wrapper for sending custom events, with automatic waiting for RUM JavaScript availability.
|
|
203
|
-
|
|
204
|
-
**Parameters:**
|
|
205
|
-
- `fields: ApiCreatedEventPropertiesEvent` - Event properties object
|
|
206
|
-
- `eventContext?: unknown` - Optional context for event modification callbacks
|
|
207
|
-
- `timeout?: number` - Timeout in milliseconds to wait for RUM JavaScript (default: 10,000)
|
|
208
|
-
|
|
209
|
-
**Throws:**
|
|
210
|
-
- `DynatraceError` - If RUM JavaScript is not available within timeout
|
|
211
|
-
|
|
212
|
-
**Example:**
|
|
213
|
-
```typescript
|
|
214
|
-
import { sendEvent } from '@dynatrace/rum-javascript-sdk/api/promises';
|
|
215
|
-
|
|
216
|
-
try {
|
|
217
|
-
await sendEvent({
|
|
218
|
-
'event_properties.conversion': 'purchase',
|
|
219
|
-
'event_properties.value': 149.99
|
|
220
|
-
}, undefined, 15000); // 15 second timeout
|
|
221
|
-
} catch (error) {
|
|
222
|
-
console.error('Failed to send event:', error.message);
|
|
223
|
-
}
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
#### `addEventModifier(eventModifier, timeout?): Promise<Unsubscriber>`
|
|
227
|
-
|
|
228
|
-
Async wrapper for registering event modifiers, with automatic waiting for RUM JavaScript availability.
|
|
229
|
-
|
|
230
|
-
**Parameters:**
|
|
231
|
-
- `eventModifier: (jsonEvent: Readonly<JSONEvent>, eventContext?: EventContext) => JSONEvent | null` - Event modifier function
|
|
232
|
-
- `timeout?: number` - Timeout in milliseconds to wait for RUM JavaScript (default: 10,000)
|
|
233
|
-
|
|
234
|
-
**Returns:**
|
|
235
|
-
- `Promise<Unsubscriber>` - Promise resolving to unsubscriber function
|
|
236
|
-
|
|
237
|
-
**Example:**
|
|
238
|
-
```typescript
|
|
239
|
-
import { addEventModifier } from '@dynatrace/rum-javascript-sdk/api/promises';
|
|
240
|
-
|
|
241
|
-
const unsubscribe = await addEventModifier((event) => ({
|
|
242
|
-
...event,
|
|
243
|
-
'event_properties.environment': 'production'
|
|
244
|
-
}));
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
#### `runHealthCheck(config?, timeout?): Promise<unknown[] | undefined>`
|
|
248
|
-
|
|
249
|
-
Async wrapper for running health checks, with automatic waiting for RUM JavaScript availability.
|
|
250
|
-
|
|
251
|
-
**Parameters:**
|
|
252
|
-
- `config?: HealthCheckConfig` - Optional health check configuration
|
|
253
|
-
- `timeout?: number` - Timeout in milliseconds to wait for RUM JavaScript (default: 10,000)
|
|
254
|
-
|
|
255
|
-
**Returns:**
|
|
256
|
-
- `Promise<unknown[] | undefined>` - Promise resolving to diagnostic data
|
|
257
|
-
|
|
258
|
-
#### `identifyUser(value, timeout?): Promise<void>`
|
|
259
|
-
|
|
260
|
-
Async wrapper for user identification, with automatic waiting for RUM JavaScript availability.
|
|
261
|
-
|
|
262
|
-
**Parameters:**
|
|
263
|
-
- `value: string` - User identifier
|
|
264
|
-
- `timeout?: number` - Timeout in milliseconds to wait for RUM JavaScript (default: 10,000)
|
|
265
|
-
|
|
266
|
-
#### `sendSessionPropertyEvent(fields, timeout?): Promise<void>`
|
|
267
|
-
|
|
268
|
-
Async wrapper for sending session properties, with automatic waiting for RUM JavaScript availability.
|
|
269
|
-
|
|
270
|
-
**Parameters:**
|
|
271
|
-
- `fields: ApiCreatedSessionPropertiesEvent` - Session properties object
|
|
272
|
-
- `timeout?: number` - Timeout in milliseconds to wait for RUM JavaScript (default: 10,000)
|
|
273
|
-
|
|
274
|
-
#### `sendExceptionEvent(error, fields?): void`
|
|
275
|
-
|
|
276
|
-
Async wrapper for sending an exception event, with automatic waiting for RUM JavaScript availability.
|
|
277
|
-
Marks the exception event with `characteristics.is_api_reported` and `error.source` = `api` to make it clear on DQL side where errors are coming from.
|
|
278
|
-
Only available if the Errors module is enabled.
|
|
279
|
-
|
|
280
|
-
**Parameters:**
|
|
281
|
-
|
|
282
|
-
- `error: Error` - The error object to report. Must be an instance of the standard JavaScript `Error` class.
|
|
283
|
-
- `fields: ApiCreatedEventPropertiesEvent` - Optional Event properties object. Must be serializable JSON with properties prefixed with `event_properties.`, plus optional `duration` and `start_time` properties.
|
|
284
|
-
|
|
285
|
-
### User Actions API
|
|
286
|
-
|
|
287
|
-
Both synchronous and asynchronous wrappers are available for the User Actions API. For detailed documentation and examples, see [USERACTIONS.md](./docs/USERACTIONS.md).
|
|
288
|
-
|
|
289
|
-
**Synchronous API:**
|
|
290
|
-
```typescript
|
|
291
|
-
import {
|
|
292
|
-
createUserAction,
|
|
293
|
-
subscribeToUserActions,
|
|
294
|
-
setAutomaticUserActionDetection,
|
|
295
|
-
getCurrentUserAction
|
|
296
|
-
} from '@dynatrace/rum-javascript-sdk/api';
|
|
297
|
-
|
|
298
|
-
// Create a manual user action
|
|
299
|
-
const userAction = createUserAction({ autoClose: false });
|
|
300
|
-
// perform work
|
|
301
|
-
userAction?.finish();
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
**Asynchronous API:**
|
|
305
|
-
```typescript
|
|
306
|
-
import { createUserAction } from '@dynatrace/rum-javascript-sdk/api/promises';
|
|
307
|
-
|
|
308
|
-
const userAction = await createUserAction({ autoClose: false });
|
|
309
|
-
// perform work
|
|
310
|
-
userAction.finish();
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
## Error Handling
|
|
314
|
-
|
|
315
|
-
### DynatraceError
|
|
316
|
-
|
|
317
|
-
Both APIs export a `DynatraceError` class for handling RUM-specific errors:
|
|
318
|
-
|
|
319
|
-
```typescript
|
|
320
|
-
import { sendEvent, DynatraceError } from '@dynatrace/rum-javascript-sdk/promises';
|
|
321
|
-
|
|
322
|
-
try {
|
|
323
|
-
await sendEvent({ 'event_properties.test': 'value' });
|
|
324
|
-
} catch (error) {
|
|
325
|
-
if (error instanceof DynatraceError) {
|
|
326
|
-
console.error('RUM API Error:', error.message);
|
|
327
|
-
// Handle RUM-specific error
|
|
328
|
-
} else {
|
|
329
|
-
console.error('Unexpected error:', error);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
## TypeScript Support
|
|
335
|
-
|
|
336
|
-
For detailed type information and usage examples, see [types.md](./docs/types.md).
|
|
337
|
-
|
|
338
|
-
```typescript
|
|
339
|
-
import type {
|
|
340
|
-
ApiCreatedEventPropertiesEvent,
|
|
341
|
-
ApiCreatedSessionPropertiesEvent,
|
|
342
|
-
HealthCheckConfig,
|
|
343
|
-
JSONEvent,
|
|
344
|
-
EventContext
|
|
345
|
-
} from '@dynatrace/rum-javascript-sdk/types';
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
## Testing
|
|
349
|
-
|
|
350
|
-
This package includes a Playwright testing framework for validating RUM integration. See **[testing.md](./docs/testing.md)** for complete documentation including:
|
|
351
|
-
|
|
352
|
-
- Setup and configuration
|
|
353
|
-
- Fixture usage and ordering
|
|
354
|
-
- Event assertion methods
|
|
355
|
-
- Troubleshooting guide
|
|
356
|
-
|
|
357
|
-
## Best Practices
|
|
358
|
-
|
|
359
|
-
### When to Use Synchronous vs Asynchronous API
|
|
360
|
-
|
|
361
|
-
**Use Synchronous API when:**
|
|
362
|
-
- You want graceful degradation when the RUM JavaScript is not available
|
|
363
|
-
- You're instrumenting existing code and don't want to change control flow
|
|
364
|
-
- You're okay with events being dropped if the RUM JavaScript isn't loaded
|
|
365
|
-
|
|
366
|
-
**Use Asynchronous API when:**
|
|
367
|
-
- You need to ensure events are actually sent
|
|
368
|
-
- You want to handle RUM JavaScript availability errors explicitly
|
|
369
|
-
- You're building critical instrumentation that must not fail silently
|
|
370
|
-
|
|
371
|
-
### Event Property Naming
|
|
372
|
-
|
|
373
|
-
Follow prefix custom event properties with `event_properties.`:
|
|
374
|
-
|
|
375
|
-
```typescript
|
|
376
|
-
// ✅ Good - properties with prefix are accepted
|
|
377
|
-
sendEvent({
|
|
378
|
-
'event_properties.action': 'login',
|
|
379
|
-
'event_properties.method': 'oauth',
|
|
380
|
-
'event_properties.page_name': 'dashboard',
|
|
381
|
-
'event_properties.load_time': 1234
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
// ❌ Avoid - properties without prefix are ignored
|
|
385
|
-
sendEvent({
|
|
386
|
-
'action': 'click',
|
|
387
|
-
'data': 'some_value'
|
|
388
|
-
});
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
### Session Properties
|
|
392
|
-
|
|
393
|
-
Use session properties for data that applies to the entire user session:
|
|
394
|
-
|
|
395
|
-
```typescript
|
|
396
|
-
// Set once per session
|
|
397
|
-
sendSessionPropertyEvent({
|
|
398
|
-
'session_properties.subscription_type': 'premium',
|
|
399
|
-
'session_properties.region': 'europe',
|
|
400
|
-
'session_properties.app_version': '2.1.0'
|
|
401
|
-
});
|
|
402
|
-
```
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { SnapshotOptions, EventIgnorePattern } from "./snapshot.js";
|
|
2
|
+
export { DEFAULT_IGNORED_EVENTS, DEFAULT_IGNORED_FIELDS, DEFAULT_REMOVED_FIELDS, IGNORED_PLACEHOLDER } from "./snapshot.js";
|
|
3
|
+
export type { BeaconRequest, DynatraceConfig, DynatraceTesting, DynatraceTestingFixture, DynatraceTestingWorkerFixture, ExpectOptions, WaitForBeaconsOptions } from "./test.js";
|
|
4
|
+
export { test } from "./test.js";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { DEFAULT_IGNORED_EVENTS, DEFAULT_IGNORED_FIELDS, DEFAULT_REMOVED_FIELDS, IGNORED_PLACEHOLDER } from "./snapshot.js";
|
|
2
|
+
export { test } from "./test.js";
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zb3VyY2UvdGVzdGluZy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQ0gsc0JBQXNCLEVBQ3RCLHNCQUFzQixFQUN0QixzQkFBc0IsRUFDdEIsbUJBQW1CLEVBQ3RCLE1BQU0sZUFBZSxDQUFDO0FBVXZCLE9BQU8sRUFBRSxJQUFJLEVBQUUsTUFBTSxXQUFXLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgdHlwZSB7IFNuYXBzaG90T3B0aW9ucywgRXZlbnRJZ25vcmVQYXR0ZXJuIH0gZnJvbSBcIi4vc25hcHNob3QuanNcIjtcbmV4cG9ydCB7XG4gICAgREVGQVVMVF9JR05PUkVEX0VWRU5UUyxcbiAgICBERUZBVUxUX0lHTk9SRURfRklFTERTLFxuICAgIERFRkFVTFRfUkVNT1ZFRF9GSUVMRFMsXG4gICAgSUdOT1JFRF9QTEFDRUhPTERFUlxufSBmcm9tIFwiLi9zbmFwc2hvdC5qc1wiO1xuZXhwb3J0IHR5cGUge1xuICAgIEJlYWNvblJlcXVlc3QsXG4gICAgRHluYXRyYWNlQ29uZmlnLFxuICAgIER5bmF0cmFjZVRlc3RpbmcsXG4gICAgRHluYXRyYWNlVGVzdGluZ0ZpeHR1cmUsXG4gICAgRHluYXRyYWNlVGVzdGluZ1dvcmtlckZpeHR1cmUsXG4gICAgRXhwZWN0T3B0aW9ucyxcbiAgICBXYWl0Rm9yQmVhY29uc09wdGlvbnNcbn0gZnJvbSBcIi4vdGVzdC5qc1wiO1xuZXhwb3J0IHsgdGVzdCB9IGZyb20gXCIuL3Rlc3QuanNcIjtcbiJdfQ==
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapshot testing utilities for Dynatrace RUM event verification.
|
|
3
|
+
* Provides mechanisms to compare captured events against stored snapshots
|
|
4
|
+
* with support for masking volatile fields.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Result of reading a snapshot file.
|
|
8
|
+
*/
|
|
9
|
+
interface SnapshotReadResult {
|
|
10
|
+
/**
|
|
11
|
+
* Whether the snapshot file exists.
|
|
12
|
+
*/
|
|
13
|
+
exists: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The parsed snapshot data, or undefined if the file doesn't exist.
|
|
16
|
+
*/
|
|
17
|
+
data?: Record<string, unknown>[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Pattern to match events that should be completely ignored during snapshot comparison.
|
|
21
|
+
* Events matching any of these patterns will be filtered out before comparison.
|
|
22
|
+
*/
|
|
23
|
+
export type EventIgnorePattern = Record<string, unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Options for configuring snapshot comparison behavior.
|
|
26
|
+
*/
|
|
27
|
+
export interface SnapshotOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Properties to ignore before comparison. Values are replaced with "[IGNORED]" placeholder.
|
|
30
|
+
* Supports exact field names and wildcard patterns (`prefix.*`).
|
|
31
|
+
*
|
|
32
|
+
* Examples:
|
|
33
|
+
* - `"start_time"` → value replaced with "[IGNORED]"
|
|
34
|
+
* - `"inp.*"` → all fields starting with `inp.` have values replaced with "[IGNORED]"
|
|
35
|
+
*
|
|
36
|
+
* Default: DEFAULT_IGNORED_FIELDS
|
|
37
|
+
*/
|
|
38
|
+
ignoredFields?: string[];
|
|
39
|
+
/**
|
|
40
|
+
* Properties to remove entirely before comparison.
|
|
41
|
+
* Supports exact field names and wildcard patterns (`prefix.*`).
|
|
42
|
+
*
|
|
43
|
+
* Examples:
|
|
44
|
+
* - `"start_time"` → field is removed from the event
|
|
45
|
+
* - `"inp.*"` → all fields starting with `inp.` are removed
|
|
46
|
+
*
|
|
47
|
+
* Default: DEFAULT_REMOVED_FIELDS
|
|
48
|
+
*/
|
|
49
|
+
removedFields?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Event patterns to completely ignore during snapshot comparison.
|
|
52
|
+
* Events matching any of these patterns will be filtered out.
|
|
53
|
+
* Default: DEFAULT_IGNORED_EVENTS
|
|
54
|
+
*/
|
|
55
|
+
ignoreEvents?: EventIgnorePattern[];
|
|
56
|
+
/**
|
|
57
|
+
* Custom snapshot name. If not provided, auto-generated from test name.
|
|
58
|
+
*/
|
|
59
|
+
name?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Default properties that are ignored (replaced with "[IGNORED]") in snapshots to prevent flaky tests.
|
|
63
|
+
* These fields typically contain volatile values like timestamps, IDs, and durations
|
|
64
|
+
* that change between test runs.
|
|
65
|
+
*/
|
|
66
|
+
export declare const DEFAULT_IGNORED_FIELDS: readonly string[];
|
|
67
|
+
/**
|
|
68
|
+
* Default properties that are removed entirely from snapshots to prevent flaky tests.
|
|
69
|
+
* These fields vary in count or presence between test runs.
|
|
70
|
+
*/
|
|
71
|
+
export declare const DEFAULT_REMOVED_FIELDS: readonly string[];
|
|
72
|
+
/**
|
|
73
|
+
* Default event patterns that are ignored during snapshot comparison.
|
|
74
|
+
* These events are volatile and may or may not be recorded depending on browser performance.
|
|
75
|
+
*/
|
|
76
|
+
export declare const DEFAULT_IGNORED_EVENTS: readonly EventIgnorePattern[];
|
|
77
|
+
/**
|
|
78
|
+
* Placeholder value used to replace ignored property values.
|
|
79
|
+
*/
|
|
80
|
+
export declare const IGNORED_PLACEHOLDER = "[IGNORED]";
|
|
81
|
+
/**
|
|
82
|
+
* Processes events by ignoring and removing specified properties.
|
|
83
|
+
* - Ignored properties have their values replaced with "[IGNORED]" placeholder
|
|
84
|
+
* - Removed properties are deleted entirely from the event
|
|
85
|
+
*
|
|
86
|
+
* @param events Array of event objects to process
|
|
87
|
+
* @param ignoredFields Array of field paths to ignore (values replaced with placeholder)
|
|
88
|
+
* @param removedFields Array of field paths to remove entirely
|
|
89
|
+
* @returns Deep copy of events with specified fields processed
|
|
90
|
+
*/
|
|
91
|
+
export declare function processEventProperties(events: Record<string, unknown>[], ignoredFields?: readonly string[], removedFields?: readonly string[]): Record<string, unknown>[];
|
|
92
|
+
/**
|
|
93
|
+
* Filters out events that match any of the ignore patterns.
|
|
94
|
+
* An event matches a pattern if all properties in the pattern exist in the event with the same values.
|
|
95
|
+
*
|
|
96
|
+
* @param events Array of events to filter
|
|
97
|
+
* @param ignorePatterns Array of patterns to match against
|
|
98
|
+
* @returns Filtered array excluding events that match any pattern
|
|
99
|
+
*/
|
|
100
|
+
export declare function filterIgnoredEvents(events: Record<string, unknown>[], ignorePatterns?: readonly EventIgnorePattern[]): Record<string, unknown>[];
|
|
101
|
+
/**
|
|
102
|
+
* Reads a snapshot file from disk.
|
|
103
|
+
* Returns an object indicating whether the file exists and its parsed contents.
|
|
104
|
+
*
|
|
105
|
+
* @param snapshotPath Absolute path to the snapshot file
|
|
106
|
+
* @returns Object with exists flag and parsed data
|
|
107
|
+
* @throws Error if the file contains invalid JSON or is not an array of records
|
|
108
|
+
*/
|
|
109
|
+
export declare function readSnapshot(snapshotPath: string): SnapshotReadResult;
|
|
110
|
+
/**
|
|
111
|
+
* Writes snapshot data to disk.
|
|
112
|
+
* Creates parent directories if they don't exist.
|
|
113
|
+
* Events are sorted by characteristics for consistent ordering.
|
|
114
|
+
* Uses deterministic JSON serialization with sorted keys for consistent diffs.
|
|
115
|
+
*
|
|
116
|
+
* @param snapshotPath Absolute path to the snapshot file
|
|
117
|
+
* @param data Array of events to write
|
|
118
|
+
*/
|
|
119
|
+
export declare function writeSnapshot(snapshotPath: string, data: Record<string, unknown>[]): void;
|
|
120
|
+
/**
|
|
121
|
+
* Sorts events by their characteristics signature for order-independent comparison.
|
|
122
|
+
* Events with the same characteristics are further sorted by other stable properties.
|
|
123
|
+
* This ensures consistent ordering regardless of event arrival order.
|
|
124
|
+
*
|
|
125
|
+
* @param events Array of events to sort
|
|
126
|
+
* @returns New array with events sorted by characteristics
|
|
127
|
+
*/
|
|
128
|
+
export declare function sortEventsByCharacteristics(events: Record<string, unknown>[]): Record<string, unknown>[];
|
|
129
|
+
export {};
|