-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvars.ts
390 lines (348 loc) · 15.2 KB
/
vars.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
import {generateUniqueId, now} from './util';
import {performance} from './performance';
import type {Meta, ReportingBackend, AutoPageDetectionType} from './types';
const defaultVars: {
// This is the global object name which the user of the EUM
// product has no influence over. This should be chosen
// wisely such that conflicts with other tools are highly
// unlikely.
nameOfLongGlobal: string;
// The version of the snippet loading/initializing Weasel.
// This value is automatically retrieved from the global
// object's `v` field.
trackingSnippetVersion: string | null | undefined;
// The trace id of the page load. You should never need to
// change this.
pageLoadTraceId: string;
// An optional trace ID to correlate the page load trace
// to a backend trace.
// Set via:
// eum('traceId', '123');
pageLoadBackendTraceId?: string | null;
// Name of the server timing entry under which the backend trace
// ID can be found. Expects a server timing entry in the following
// format.
// PerformanceServerTiming {name: "intid", duration: 0, description: "1f27caa3493aeb"}
serverTimingBackendTraceIdEntryName: string;
// All timestamps which are part of beacons will be adjusted
// using this timestamp before transmission to save some bytes.
// So what we are doing is:
// timestampToTransmit = actualTimestamp - referenceTimestamp
referenceTimestamp: number;
// High resolution reference point. Will be used to relate
// high res timestamps to a value that client and server
// understands.
highResTimestampReference: number;
// The time at which the EUM initializer was executed. Useful
// to get a load time indicator for older devices.
initializerExecutionTimestamp: number;
// Changes the URL to which beacons will be send.
// Change via
// eum('reportingUrl', '//eum.example.com');
reportingUrl: string | null | undefined;
// The number of milliseconds to potentially wait to batch beacons
// into a single request.
// Change via
// eum('beaconBatchingTime', 1000);
beaconBatchingTime: number;
// How long to wait after an XMLHttpRequest or fetch request has finished
// for the retrieval of resource timing data. Performance timeline events
// are placed on the low priority task queue and therefore high values
// might be necessary.
//
// Change via:
// eum('maxWaitForResourceTimingsMillis', 5000);
maxWaitForResourceTimingsMillis: number;
// The number of milliseconds added to endTime so that performanceEntry is
// available before endTime and backendTraceId does not become undefined for
// xhr beacons
// Change via:
// eum('maxToleranceForResourceTimingsMillis', 3000);
maxToleranceForResourceTimingsMillis: number;
// Weasel will wait up to this many milliseconds after the onLoad event
// completes for any additional metrics related to the page load, e.g.
// first input delay or cumulative layout shift. Additional waiting time
// means that:
//
// 1. Data is seen later within the monitoring system and
// 2. that data could theoretically be lost.
//
// Change via:
// eum('maxMaitForPageLoadMetricsMillis', 2000);
maxMaitForPageLoadMetricsMillis: number;
// Defines an application identification mechanism. This value
// will always be transfered with every beacon to associate
// requests with a monitored system.
// Change via:
// eum('apiKey', 'myKey');
apiKey: null;
// Defines user-configurable application payloads. These payloads
// will be transfered with the page load beacon and should be a
// Set meta data via:
// eum('meta', 'key', 'value');
meta: Meta;
// An array of URL regular expression for which no data should be
// collected. These regular expressions are evaluated against
// the document, XMLHttpRequest, fetch and resource URLs.
// Set via:
// eum('ignoreUrls', [/example.com/]);
ignoreUrls: RegExp[];
queryTrackedDomainList: RegExp[];
// Whether or not ping like requests should be ignored from AJAX
// collection. This is separate from ignoreUrls to handle cases
// where users start monitoring using weasel and generate tons
// of beacons which look like
// GET /ping
// These types of beacons are often times not really helpful and
// users typically only learn about these types of beacons after
// they have monitored using weasel for some time. At that point,
// this could have generated hundreds of thousands of beacons
// that nobody is interested in.
//
// Set via:
// eum('ignorePings', false);
ignorePings: boolean;
// An array of error message regular expressions for which no data
// should be collected.
// Set via:
// eum('ignoreErrorMessages', [/script error/i]);
ignoreErrorMessages: RegExp[];
// Timeout for the transmission of XHR beacons.
//
// Set via:
// eum('xhrTransmissionTimeout', 60000);
xhrTransmissionTimeout: number;
// Correlation headers can by default only be transmitted to the
// origin of the document. This is the case because the same-origin
// policy forbids a piece of JavaScript to send custom headers to
// request to other origins. This results in a lack of
// backend correlation which is especially bothersome when the
// document is an SPA which is always gathering data from a different
// origin.
//
// Custom headers can be enabled by leveraging CORS. With CORS,
// the server can denote that the tracing headers are to be
// allowed for cross-origin requests. The CORS specification
// has more information about the header:
//
// https://www.w3.org/TR/cors/#access-control-allow-headers-response-header
//
// Example header for the Instana tracing headers:
// Access-Control-Allow-Headers: X-INSTANA-T, X-INSTANA-S, X-INSTANA-L
//
// Next, the origin needs to be allowed via:
// eum('allowedOrigins', [/.*shop.example.com/i]);
//
// The regular expressions will be matched against URLs.
allowedOrigins: RegExp[];
// Name of the page which the user is currently viewing. May be set as
// part of the page load or later for SPA, XHR and error beacons.
// Any string can be used as the page name. Try to keep it short though
// for efficiency sake.
//
// Set via:
// eum('page', 'myPageName');
page: string | null | undefined;
// Whether or not weasel should automatically wrap DOM event handlers
// added via addEventlistener for improved uncaught error tracking.
// This results in improved uncaught error tracking for cross-origin
// errors, but may have adverse effects on website performance and
// stability.
//
// Set via:
// eum('wrapEventHandlers', true)
wrapEventHandlers: boolean;
/**
* Whether to automatically detect page transitions
*
* A boolean `true` or valid {@link AutoPageDetectionType} to enable this feature.
* the {@link AutoPageDetectionType.mappingRule} could be an array of
* pathname regular expression and each entry maps to a new page name.
* If the mapping result is empty, this transition will be ignored.
* {@link AutoPageDetectionType.ignorePopstateEvent}: whether to ignore popstate event.
* {@link AutoPageDetectionType.titleAsPageName}: whether to use document title to generate page name.
*
* @example
* eum('autoPageDetection', true)
*
* @example
* eum('autoPageDetection', {
* mappingRule: [
* [/regex-with-group-(.*)/, 'Customized Page Name with $1 group references'],
* [/regex-to-ignore/, ''],
* ],
* })
*/
autoPageDetection: boolean | AutoPageDetectionType | null;
// When wrapping event handlers (enabled only when wrapEventHandlers=true),
// we will have to wrap user provided callbacks in addEventListener. This
// wrapping is pretty straightforward in itself, but it becomes troublesome
// due to removeEventListener. Within removeEventListener, we somehow must
// map the original function to the mapped function. Otherwise, we would
// break the applications.
//
// Not configurable externally. Overwrite by forking.
wrappedEventHandlersOriginalFunctionStorageKey: string;
// Whether or not weasel should automatically wrap timers
// added via setTimeout / setInterval for improved uncaught error tracking.
// This results in improved uncaught error tracking for cross-origin
// errors, but may have adverse effects on website performance and
// stability.
//
// Set via:
// eum('wrapTimers', true)
wrapTimers: boolean;
// This key will be used by Weasel to privately store data on objects.
// Make sure to change this key when deploying Weasel in production.
secretPropertyKey: string;
// Weasel will not attempt automatic user tracking via cookies,
// fingerprinting or any other means. Instead, we give users the
// ability manually define user identifying properties. This means
// that Weasel can adapt to various data security & privacy
// settings.
//
// Set via:
// eum('user', 'userId', 'user name', 'email')
userId: string | null | undefined;
userName: string | null | undefined;
userEmail: string | null | undefined;
// Weasel by default does not collect session information as this
// has privacy policy implications. The session ID is a random
// value and does not make use of any fingerprinting mechanisms!
//
// Enable via:
// eum(
// 'trackSessions',
// sessionInactivityTimeoutMillis: ?number = 21600000, // six hours
// sessionTerminationTimeoutMillis: ?number = 21600000 // six hours
// )
sessionId: string | null | undefined;
// Information about sessions will be stored under this name in
// localStorage or cookies whenever allowed by calling trackSessions.
//
// This value cannot be changed at runtime.
sessionStorageKey: string;
// The default session inactivity timeout. Session inactivity is the maximum
// allowed time to pass between two page loads before the session is considered
// to be expired. Also think of cache time-to-idle configuration options.
//
// This value cannot be changed at runtime.
defaultSessionInactivityTimeoutMillis: number;
// The default session termination timeout. Session termination is the maximum
// allowed time to pass since session start before the session is considered
// to be expired. Also think of cache time-to-live configuration options.
//
// This value cannot be changed at runtime.
defaultSessionTerminationTimeoutMillis: number;
// The maximum allowed value for either all session timeouts. Users can overwrite
// the defaults on a per page-load basis. We want to avoid abuse by protecting
// end-user from (near-) infinite timeouts.
//
// This value cannot be changed at runtime.
maxAllowedSessionTimeoutMillis: number;
// A set of regular expressions that will be matched against user timing
// mark and measure names. When any of the regular expressions match, then
// the user timing value will not be collected.
//
// eum('ignoreUserTimings', [/^\u269B/, /^\u26D4/]);
ignoreUserTimings: RegExp[];
// A set of regular expressions that will be matched against the first parameter
// of the `fetch` API, i.e. the relative or absolute request URL. By configuring
// this, you can decide which URLs Weasel we analyze for GraphQL specifics.
//
// eum('urlsToCheckForGraphQlInsights', [/\/graphql/i]);
urlsToCheckForGraphQlInsights: RegExp[];
// A set of regular expression that will be matched against query parameters
// in any URL that collected. When matched, value of the query parameter will be
// set to <redacted>. By configuring this, data treated as secrets will not reach
// the backend for processing, thus, will not be available for analysis in the UI
// or retrieval via API. By default, 'key', 'password' and 'secret' query
// parameters are treated as secret data.
//
// eum('secrets', [/mysecret/i]);
secrets: RegExp[];
// A set of regular expressions that will be matched against fragment in URL
//When matched, the fragment containing secrets will be set to <redacted> and
//will not reach the backend for processing,thus, will not be available for
//analysis in the UI or retrieval via API.
//eum('fragment', [/url-segment/i]);
fragment: RegExp[];
// A set of regular expressions that will be matched against HTTP headers to be
// captured in `XMLHttpRequest` and `fetch` API. These headers will be transfered
// within the http request beacon.
// Set the config via:
// eum('captureHeaders', [/content-type/i]);
headersToCapture: RegExp[];
// Changes backends which beacons will be send.
// Change via
// eum('reportingBackends', [{reportingUrl: '//eum.example.com', key: 'key'}]);
reportingBackends: ReportingBackend[];
//The version of Weasel agent.
agentVersion?: string;
// Whether or not weasel should generate dedicated custom events on webvital metrics
// these custom events is more reliable than webvitals in PageLoad beacon, as we
// will not wait for so long in PageLoad beacon, with custom events, these metrics
// could be reported on demand at any time.
//
// Set via:
// eum('webvitalsInCustomEvent', false)
webvitalsInCustomEvent: boolean;
} = {
nameOfLongGlobal: 'EumObject',
trackingSnippetVersion: null,
pageLoadTraceId: generateUniqueId(),
pageLoadBackendTraceId: null,
serverTimingBackendTraceIdEntryName: 'intid',
referenceTimestamp: now(),
highResTimestampReference: performance && performance.now ? performance.now() : 0,
initializerExecutionTimestamp: now(),
reportingUrl: null,
beaconBatchingTime: 500,
maxWaitForResourceTimingsMillis: 10000,
maxToleranceForResourceTimingsMillis: 3000,
maxMaitForPageLoadMetricsMillis: 5000,
apiKey: null,
meta: {},
ignoreUrls: [],
ignorePings: true,
ignoreErrorMessages: [],
queryTrackedDomainList: [],
xhrTransmissionTimeout: 20000,
allowedOrigins: [],
page: undefined,
wrapEventHandlers: false,
autoPageDetection: false,
wrappedEventHandlersOriginalFunctionStorageKey: '__weaselOriginalFunctions__',
wrapTimers: false,
secretPropertyKey: '__weaselSecretData__',
userId: undefined,
userName: undefined,
userEmail: undefined,
sessionId: undefined,
sessionStorageKey: 'session',
defaultSessionInactivityTimeoutMillis: 1000 * 60 * 60 * 3,
defaultSessionTerminationTimeoutMillis: 1000 * 60 * 60 * 6,
maxAllowedSessionTimeoutMillis: 1000 * 60 * 60 * 24,
// The default ignore rules cover specific React and Angular patterns:
//
// React has a whole lot of user timings. Luckily all of them start with
// the emojis for easy filtering. Let's ignore them by default as most of
// them won't be valuable to many of our users (in production).
//
// Similar for Angular which uses zones with a ton of custom user
// timings. https://angular.io/guide/zone
//
// We have also seen people use 'start xyz' / 'end xyz' as a common pattern to
// name marks used to create measures. This is surely not a comprehensive
// solution to identify these cases, but should for now be sufficient.
ignoreUserTimings: [/^\u269B/, /^\u26D4/, /^Zone(:|$)/, /^start /i, /^end /i],
urlsToCheckForGraphQlInsights: [/\/graphql/i],
secrets: [/key/i, /password/i, /secret/i],
fragment: [],
headersToCapture: [],
reportingBackends: [],
agentVersion: '0.0.0',
//0.0.0 will be replaced with version from package.json
webvitalsInCustomEvent: false
};
export default defaultVars;