@oodle-ai/mobile-sdk-reactnative 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/OodleMobileSdkReactNative.podspec +24 -0
- package/README.md +191 -2
- package/android/build.gradle +55 -0
- package/android/proguard-rules.pro +5 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/ai/oodle/rum/Connectivity.kt +19 -0
- package/android/src/main/java/ai/oodle/rum/CrashReporter.kt +88 -0
- package/android/src/main/java/ai/oodle/rum/DeviceInfo.kt +50 -0
- package/android/src/main/java/ai/oodle/rum/ExitReasons.kt +104 -0
- package/android/src/main/java/ai/oodle/rum/NativeEvents.kt +24 -0
- package/android/src/main/java/ai/oodle/rum/OodleRumModule.kt +96 -0
- package/android/src/main/java/ai/oodle/rum/OodleRumPackage.kt +26 -0
- package/android/src/main/java/ai/oodle/rum/Storage.kt +84 -0
- package/android/src/main/java/ai/oodle/rum/Vitals.kt +188 -0
- package/android/src/main/java/ai/oodle/rum/Watchdog.kt +81 -0
- package/android/src/main/java/ai/oodle/rum/WireframeCapture.kt +398 -0
- package/bin/oodle-rum-upload.mjs +104 -0
- package/ios/OodleCrashReporter.h +16 -0
- package/ios/OodleCrashReporter.m +202 -0
- package/ios/OodleRum.h +18 -0
- package/ios/OodleRum.mm +129 -0
- package/ios/OodleRumImpl.swift +450 -0
- package/ios/WireframeWalker.swift +279 -0
- package/lib/core/clock.d.ts +19 -0
- package/lib/core/clock.js +47 -0
- package/lib/core/clock.js.map +1 -0
- package/lib/core/config.d.ts +142 -0
- package/lib/core/config.js +178 -0
- package/lib/core/config.js.map +1 -0
- package/lib/core/consent.d.ts +5 -0
- package/lib/core/consent.js +33 -0
- package/lib/core/consent.js.map +1 -0
- package/lib/core/context.d.ts +36 -0
- package/lib/core/context.js +172 -0
- package/lib/core/context.js.map +1 -0
- package/lib/core/flags.d.ts +3 -0
- package/lib/core/flags.js +20 -0
- package/lib/core/flags.js.map +1 -0
- package/lib/core/ids.d.ts +7 -0
- package/lib/core/ids.js +40 -0
- package/lib/core/ids.js.map +1 -0
- package/lib/core/internal.d.ts +6 -0
- package/lib/core/internal.js +10 -0
- package/lib/core/internal.js.map +1 -0
- package/lib/core/logger.d.ts +8 -0
- package/lib/core/logger.js +38 -0
- package/lib/core/logger.js.map +1 -0
- package/lib/core/native.d.ts +71 -0
- package/lib/core/native.js +156 -0
- package/lib/core/native.js.map +1 -0
- package/lib/core/rate-limiter.d.ts +7 -0
- package/lib/core/rate-limiter.js +31 -0
- package/lib/core/rate-limiter.js.map +1 -0
- package/lib/core/session.d.ts +51 -0
- package/lib/core/session.js +196 -0
- package/lib/core/session.js.map +1 -0
- package/lib/core/size.d.ts +15 -0
- package/lib/core/size.js +68 -0
- package/lib/core/size.js.map +1 -0
- package/lib/core/tags.d.ts +10 -0
- package/lib/core/tags.js +33 -0
- package/lib/core/tags.js.map +1 -0
- package/lib/core/telemetry.d.ts +6 -0
- package/lib/core/telemetry.js +37 -0
- package/lib/core/telemetry.js.map +1 -0
- package/lib/core/tracing.d.ts +9 -0
- package/lib/core/tracing.js +57 -0
- package/lib/core/tracing.js.map +1 -0
- package/lib/core/transport.d.ts +76 -0
- package/lib/core/transport.js +560 -0
- package/lib/core/transport.js.map +1 -0
- package/lib/core/user.d.ts +12 -0
- package/lib/core/user.js +41 -0
- package/lib/core/user.js.map +1 -0
- package/lib/events/actions.d.ts +13 -0
- package/lib/events/actions.js +147 -0
- package/lib/events/actions.js.map +1 -0
- package/lib/events/emit.d.ts +21 -0
- package/lib/events/emit.js +144 -0
- package/lib/events/emit.js.map +1 -0
- package/lib/events/errors.d.ts +19 -0
- package/lib/events/errors.js +257 -0
- package/lib/events/errors.js.map +1 -0
- package/lib/events/lifecycle.d.ts +7 -0
- package/lib/events/lifecycle.js +101 -0
- package/lib/events/lifecycle.js.map +1 -0
- package/lib/events/longtasks.d.ts +2 -0
- package/lib/events/longtasks.js +42 -0
- package/lib/events/longtasks.js.map +1 -0
- package/lib/events/resources.d.ts +15 -0
- package/lib/events/resources.js +156 -0
- package/lib/events/resources.js.map +1 -0
- package/lib/events/tap-target.d.ts +42 -0
- package/lib/events/tap-target.js +191 -0
- package/lib/events/tap-target.js.map +1 -0
- package/lib/events/view-state.d.ts +13 -0
- package/lib/events/view-state.js +25 -0
- package/lib/events/view-state.js.map +1 -0
- package/lib/events/views.d.ts +21 -0
- package/lib/events/views.js +347 -0
- package/lib/events/views.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +24 -0
- package/lib/index.js.map +1 -0
- package/lib/navigation/react-navigation.d.ts +33 -0
- package/lib/navigation/react-navigation.js +61 -0
- package/lib/navigation/react-navigation.js.map +1 -0
- package/lib/react/OodlePrivacy.d.ts +15 -0
- package/lib/react/OodlePrivacy.js +13 -0
- package/lib/react/OodlePrivacy.js.map +1 -0
- package/lib/react/OodleProvider.d.ts +18 -0
- package/lib/react/OodleProvider.js +72 -0
- package/lib/react/OodleProvider.js.map +1 -0
- package/lib/replay/recorder.d.ts +22 -0
- package/lib/replay/recorder.js +317 -0
- package/lib/replay/recorder.js.map +1 -0
- package/lib/replay/rrweb.d.ts +105 -0
- package/lib/replay/rrweb.js +335 -0
- package/lib/replay/rrweb.js.map +1 -0
- package/lib/rum.d.ts +52 -0
- package/lib/rum.js +281 -0
- package/lib/rum.js.map +1 -0
- package/lib/specs/NativeOodleRum.d.ts +43 -0
- package/lib/specs/NativeOodleRum.js +5 -0
- package/lib/specs/NativeOodleRum.js.map +1 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +6 -0
- package/lib/version.js.map +1 -0
- package/package.json +91 -4
- package/react-native.config.js +10 -0
- package/src/core/clock.ts +43 -0
- package/src/core/config.ts +344 -0
- package/src/core/consent.ts +32 -0
- package/src/core/context.ts +189 -0
- package/src/core/flags.ts +15 -0
- package/src/core/ids.ts +35 -0
- package/src/core/internal.ts +6 -0
- package/src/core/logger.ts +37 -0
- package/src/core/native.ts +201 -0
- package/src/core/rate-limiter.ts +34 -0
- package/src/core/session.ts +209 -0
- package/src/core/size.ts +79 -0
- package/src/core/tags.ts +30 -0
- package/src/core/telemetry.ts +35 -0
- package/src/core/tracing.ts +60 -0
- package/src/core/transport.ts +590 -0
- package/src/core/user.ts +45 -0
- package/src/events/actions.ts +157 -0
- package/src/events/emit.ts +131 -0
- package/src/events/errors.ts +283 -0
- package/src/events/lifecycle.ts +102 -0
- package/src/events/longtasks.ts +40 -0
- package/src/events/resources.ts +167 -0
- package/src/events/tap-target.ts +210 -0
- package/src/events/view-state.ts +30 -0
- package/src/events/views.ts +356 -0
- package/src/index.ts +34 -0
- package/src/navigation/react-navigation.ts +72 -0
- package/src/react/OodlePrivacy.tsx +25 -0
- package/src/react/OodleProvider.tsx +88 -0
- package/src/replay/recorder.ts +310 -0
- package/src/replay/rrweb.ts +460 -0
- package/src/rum.ts +295 -0
- package/src/specs/NativeOodleRum.ts +51 -0
- package/src/version.ts +2 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token bucket per event type. A render loop that throws or logs on
|
|
3
|
+
* every frame must not flood the queue and push out the events that
|
|
4
|
+
* explain it.
|
|
5
|
+
*/
|
|
6
|
+
export declare function tryConsume(category: string): boolean;
|
|
7
|
+
export declare function resetBuckets(): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tryConsume = tryConsume;
|
|
4
|
+
exports.resetBuckets = resetBuckets;
|
|
5
|
+
const RATE_PER_SEC = 50;
|
|
6
|
+
const BURST = 200;
|
|
7
|
+
const buckets = new Map();
|
|
8
|
+
/**
|
|
9
|
+
* Token bucket per event type. A render loop that throws or logs on
|
|
10
|
+
* every frame must not flood the queue and push out the events that
|
|
11
|
+
* explain it.
|
|
12
|
+
*/
|
|
13
|
+
function tryConsume(category) {
|
|
14
|
+
const now = Date.now();
|
|
15
|
+
let b = buckets.get(category);
|
|
16
|
+
if (!b) {
|
|
17
|
+
b = { tokens: BURST, lastRefill: now };
|
|
18
|
+
buckets.set(category, b);
|
|
19
|
+
}
|
|
20
|
+
b.tokens = Math.min(BURST, b.tokens + ((now - b.lastRefill) / 1000) * RATE_PER_SEC);
|
|
21
|
+
b.lastRefill = now;
|
|
22
|
+
if (b.tokens >= 1) {
|
|
23
|
+
b.tokens--;
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
function resetBuckets() {
|
|
29
|
+
buckets.clear();
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=rate-limiter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../../src/core/rate-limiter.ts"],"names":[],"mappings":";;;;AAAA,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,KAAK,GAAG,GAAG,CAAC;AAOlB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE1C;;;;GAIG;AACH,oBAA2B,QAAgB;IACzC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,IAAI,CAAC,CAAC,EAAE,CAAC;QACP,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC3B,CAAC;IACD,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;IACpF,CAAC,CAAC,UAAU,GAAG,GAAG,CAAC;IACnB,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QAClB,CAAC,CAAC,MAAM,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;IACE,OAAO,CAAC,KAAK,EAAE,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** A session ends after this much time with no activity. */
|
|
2
|
+
export declare const SESSION_TIMEOUT_MS: number;
|
|
3
|
+
/** A session never lasts longer than this. */
|
|
4
|
+
export declare const SESSION_MAX_DURATION_MS: number;
|
|
5
|
+
export interface SessionData {
|
|
6
|
+
id: string;
|
|
7
|
+
createdAt: number;
|
|
8
|
+
lastActivity: number;
|
|
9
|
+
viewCount: number;
|
|
10
|
+
errorCount: number;
|
|
11
|
+
actionCount: number;
|
|
12
|
+
sampled: boolean;
|
|
13
|
+
replaySampled: boolean;
|
|
14
|
+
replaySegmentSeq: number;
|
|
15
|
+
/** An event of this session was marked as its first. */
|
|
16
|
+
started: boolean;
|
|
17
|
+
/** The session this one followed (`session.previous_id`), if any. */
|
|
18
|
+
previousId?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function setSampleRates(session: number, replay: number): void;
|
|
21
|
+
export declare function onSessionRenew(fn: (s: SessionData, previous: SessionData | null) => void): void;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the live session, starting a new one when there is none or
|
|
24
|
+
* the last one ran out. `activity` marks user-visible work; background
|
|
25
|
+
* work such as periodic view updates passes false so it cannot keep an
|
|
26
|
+
* idle session alive.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getSession(activity?: boolean): SessionData;
|
|
29
|
+
export declare function getSessionId(): string;
|
|
30
|
+
/** The session as it is now, without starting or renewing one. */
|
|
31
|
+
export declare function peekSession(): SessionData | null;
|
|
32
|
+
/** True when the stored session would be replaced by the next event. */
|
|
33
|
+
export declare function isSessionExpired(now?: number): boolean;
|
|
34
|
+
/** Ends the session. The next event starts a new one. */
|
|
35
|
+
export declare function stopSession(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Segment indices name the stored replay object, so they must never
|
|
38
|
+
* repeat within a session. The counter is persisted with the session
|
|
39
|
+
* and written through at once, because a lost increment would let the
|
|
40
|
+
* next app start overwrite a stored segment.
|
|
41
|
+
*/
|
|
42
|
+
export declare function nextReplaySegmentIndex(): number;
|
|
43
|
+
/**
|
|
44
|
+
* True once per session, for the event that is sent first. Readers count
|
|
45
|
+
* sessions from this flag, whatever kind of event comes first.
|
|
46
|
+
*/
|
|
47
|
+
export declare function claimSessionStart(sessionId: string): boolean;
|
|
48
|
+
export declare function incrementSessionCount(eventType: string): void;
|
|
49
|
+
export declare function flushSession(): void;
|
|
50
|
+
/** Test hook. */
|
|
51
|
+
export declare function resetSessionState(): void;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SESSION_MAX_DURATION_MS = exports.SESSION_TIMEOUT_MS = void 0;
|
|
4
|
+
exports.setSampleRates = setSampleRates;
|
|
5
|
+
exports.onSessionRenew = onSessionRenew;
|
|
6
|
+
exports.getSession = getSession;
|
|
7
|
+
exports.getSessionId = getSessionId;
|
|
8
|
+
exports.peekSession = peekSession;
|
|
9
|
+
exports.isSessionExpired = isSessionExpired;
|
|
10
|
+
exports.stopSession = stopSession;
|
|
11
|
+
exports.nextReplaySegmentIndex = nextReplaySegmentIndex;
|
|
12
|
+
exports.claimSessionStart = claimSessionStart;
|
|
13
|
+
exports.incrementSessionCount = incrementSessionCount;
|
|
14
|
+
exports.flushSession = flushSession;
|
|
15
|
+
exports.resetSessionState = resetSessionState;
|
|
16
|
+
const ids_1 = require("./ids");
|
|
17
|
+
const native_1 = require("./native");
|
|
18
|
+
const SESSION_KEY = 'session';
|
|
19
|
+
/** A session ends after this much time with no activity. */
|
|
20
|
+
exports.SESSION_TIMEOUT_MS = 15 * 60 * 1000;
|
|
21
|
+
/** A session never lasts longer than this. */
|
|
22
|
+
exports.SESSION_MAX_DURATION_MS = 4 * 60 * 60 * 1000;
|
|
23
|
+
let current = null;
|
|
24
|
+
let loaded = false;
|
|
25
|
+
let sessionRate = 100;
|
|
26
|
+
let replayRate = 100;
|
|
27
|
+
let saveTimer = null;
|
|
28
|
+
const renewListeners = [];
|
|
29
|
+
function setSampleRates(session, replay) {
|
|
30
|
+
sessionRate = session;
|
|
31
|
+
replayRate = replay;
|
|
32
|
+
}
|
|
33
|
+
function roll(rate) {
|
|
34
|
+
return Math.random() * 100 < rate;
|
|
35
|
+
}
|
|
36
|
+
function write() {
|
|
37
|
+
if (saveTimer) {
|
|
38
|
+
clearTimeout(saveTimer);
|
|
39
|
+
saveTimer = null;
|
|
40
|
+
}
|
|
41
|
+
if (current)
|
|
42
|
+
native_1.storage.setJSON(SESSION_KEY, current);
|
|
43
|
+
}
|
|
44
|
+
function scheduleWrite() {
|
|
45
|
+
if (saveTimer)
|
|
46
|
+
return;
|
|
47
|
+
saveTimer = setTimeout(() => {
|
|
48
|
+
saveTimer = null;
|
|
49
|
+
write();
|
|
50
|
+
}, 1000);
|
|
51
|
+
}
|
|
52
|
+
function load() {
|
|
53
|
+
const raw = native_1.storage.getJSON(SESSION_KEY, null);
|
|
54
|
+
if (!raw || typeof raw.id !== 'string')
|
|
55
|
+
return null;
|
|
56
|
+
const now = Date.now();
|
|
57
|
+
return {
|
|
58
|
+
id: raw.id,
|
|
59
|
+
createdAt: raw.createdAt ?? now,
|
|
60
|
+
lastActivity: raw.lastActivity ?? now,
|
|
61
|
+
viewCount: raw.viewCount ?? 0,
|
|
62
|
+
errorCount: raw.errorCount ?? 0,
|
|
63
|
+
actionCount: raw.actionCount ?? 0,
|
|
64
|
+
sampled: raw.sampled ?? true,
|
|
65
|
+
replaySampled: raw.replaySampled ?? false,
|
|
66
|
+
replaySegmentSeq: raw.replaySegmentSeq ?? 0,
|
|
67
|
+
started: raw.started ?? true,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function expired(s, now) {
|
|
71
|
+
return (now - s.lastActivity > exports.SESSION_TIMEOUT_MS ||
|
|
72
|
+
now - s.createdAt > exports.SESSION_MAX_DURATION_MS);
|
|
73
|
+
}
|
|
74
|
+
function onSessionRenew(fn) {
|
|
75
|
+
renewListeners.push(fn);
|
|
76
|
+
}
|
|
77
|
+
function renew(now) {
|
|
78
|
+
const previous = current;
|
|
79
|
+
const sampled = roll(sessionRate);
|
|
80
|
+
current = {
|
|
81
|
+
id: (0, ids_1.uuid)(),
|
|
82
|
+
createdAt: now,
|
|
83
|
+
lastActivity: now,
|
|
84
|
+
viewCount: 0,
|
|
85
|
+
errorCount: 0,
|
|
86
|
+
actionCount: 0,
|
|
87
|
+
sampled,
|
|
88
|
+
replaySampled: sampled && roll(replayRate),
|
|
89
|
+
replaySegmentSeq: 0,
|
|
90
|
+
started: false,
|
|
91
|
+
previousId: previous?.id,
|
|
92
|
+
};
|
|
93
|
+
write();
|
|
94
|
+
for (const fn of renewListeners) {
|
|
95
|
+
try {
|
|
96
|
+
fn(current, previous);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// A listener must not stop the session from starting.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return current;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns the live session, starting a new one when there is none or
|
|
106
|
+
* the last one ran out. `activity` marks user-visible work; background
|
|
107
|
+
* work such as periodic view updates passes false so it cannot keep an
|
|
108
|
+
* idle session alive.
|
|
109
|
+
*/
|
|
110
|
+
function getSession(activity = true) {
|
|
111
|
+
const now = Date.now();
|
|
112
|
+
if (!loaded) {
|
|
113
|
+
loaded = true;
|
|
114
|
+
current = load();
|
|
115
|
+
}
|
|
116
|
+
if (!current || expired(current, now))
|
|
117
|
+
return renew(now);
|
|
118
|
+
if (activity) {
|
|
119
|
+
current.lastActivity = now;
|
|
120
|
+
scheduleWrite();
|
|
121
|
+
}
|
|
122
|
+
return current;
|
|
123
|
+
}
|
|
124
|
+
function getSessionId() {
|
|
125
|
+
return getSession(false).id;
|
|
126
|
+
}
|
|
127
|
+
/** The session as it is now, without starting or renewing one. */
|
|
128
|
+
function peekSession() {
|
|
129
|
+
if (!loaded) {
|
|
130
|
+
loaded = true;
|
|
131
|
+
current = load();
|
|
132
|
+
}
|
|
133
|
+
return current;
|
|
134
|
+
}
|
|
135
|
+
/** True when the stored session would be replaced by the next event. */
|
|
136
|
+
function isSessionExpired(now = Date.now()) {
|
|
137
|
+
const s = peekSession();
|
|
138
|
+
return !s || expired(s, now);
|
|
139
|
+
}
|
|
140
|
+
/** Ends the session. The next event starts a new one. */
|
|
141
|
+
function stopSession() {
|
|
142
|
+
if (current) {
|
|
143
|
+
current.lastActivity = 0;
|
|
144
|
+
write();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Segment indices name the stored replay object, so they must never
|
|
149
|
+
* repeat within a session. The counter is persisted with the session
|
|
150
|
+
* and written through at once, because a lost increment would let the
|
|
151
|
+
* next app start overwrite a stored segment.
|
|
152
|
+
*/
|
|
153
|
+
function nextReplaySegmentIndex() {
|
|
154
|
+
const s = getSession(false);
|
|
155
|
+
const index = s.replaySegmentSeq;
|
|
156
|
+
s.replaySegmentSeq = index + 1;
|
|
157
|
+
write();
|
|
158
|
+
return index;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* True once per session, for the event that is sent first. Readers count
|
|
162
|
+
* sessions from this flag, whatever kind of event comes first.
|
|
163
|
+
*/
|
|
164
|
+
function claimSessionStart(sessionId) {
|
|
165
|
+
const s = peekSession();
|
|
166
|
+
if (!s || s.id !== sessionId || s.started)
|
|
167
|
+
return false;
|
|
168
|
+
s.started = true;
|
|
169
|
+
write();
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
function incrementSessionCount(eventType) {
|
|
173
|
+
const s = getSession(false);
|
|
174
|
+
if (eventType === 'view')
|
|
175
|
+
s.viewCount++;
|
|
176
|
+
else if (eventType === 'error')
|
|
177
|
+
s.errorCount++;
|
|
178
|
+
else if (eventType === 'action')
|
|
179
|
+
s.actionCount++;
|
|
180
|
+
else
|
|
181
|
+
return;
|
|
182
|
+
scheduleWrite();
|
|
183
|
+
}
|
|
184
|
+
function flushSession() {
|
|
185
|
+
write();
|
|
186
|
+
}
|
|
187
|
+
/** Test hook. */
|
|
188
|
+
function resetSessionState() {
|
|
189
|
+
if (saveTimer)
|
|
190
|
+
clearTimeout(saveTimer);
|
|
191
|
+
saveTimer = null;
|
|
192
|
+
current = null;
|
|
193
|
+
loaded = false;
|
|
194
|
+
renewListeners.length = 0;
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/core/session.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAA6B;AAC7B,qCAAmC;AAEnC,MAAM,WAAW,GAAG,SAAS,CAAC;AAC9B,4DAA4D;AAC/C,QAAA,kBAAkB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACjD,8CAA8C;AACjC,QAAA,uBAAuB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAkB1D,IAAI,OAAO,GAAuB,IAAI,CAAC;AACvC,IAAI,MAAM,GAAG,KAAK,CAAC;AACnB,IAAI,WAAW,GAAG,GAAG,CAAC;AACtB,IAAI,UAAU,GAAG,GAAG,CAAC;AACrB,IAAI,SAAS,GAAyC,IAAI,CAAC;AAC3D,MAAM,cAAc,GAAkE,EAAE,CAAC;AAEzF,wBAA+B,OAAe,EAAE,MAAc;IAC5D,WAAW,GAAG,OAAO,CAAC;IACtB,UAAU,GAAG,MAAM,CAAC;AACtB,CAAC;AAED,SAAS,IAAI,CAAC,IAAY;IACxB,OAAO,IAAI,CAAC,MAAM,E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ACR,OAAO,IAAI,CAAC;AACd,CAAC;AAED,+BAAsC,SAAiB;IACrD,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAC5B,IAAI,SAAS,KAAK,MAAM;QAAE,CAAC,CAAC,SAAS,EAAE,CAAC;SACnC,IAAI,SAAS,KAAK,OAAO;QAAE,CAAC,CAAC,UAAU,EAAE,CAAC;SAC1C,IAAI,SAAS,KAAK,QAAQ;QAAE,CAAC,CAAC,WAAW,EAAE,CAAC;;QAC5C,OAAO;IACZ,aAAa,EAAE,CAAC;AAClB,CAAC;AAED;IACE,KAAK,EAAE,CAAC;AACV,CAAC;AAED,iBAAiB;AACjB;IACE,IAAI,SAAS;QAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACvC,SAAS,GAAG,IAAI,CAAC;IACjB,OAAO,GAAG,IAAI,CAAC;IACf,MAAM,GAAG,KAAK,CAAC;IACf,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Byte estimate for a JSON-serializable value.
|
|
3
|
+
*
|
|
4
|
+
* Walks the whole object graph rather than scoring a
|
|
5
|
+
* nested object as a fixed constant. rrweb full
|
|
6
|
+
* snapshots and mutation batches keep all of their
|
|
7
|
+
* weight below the top level, so a shallow estimate
|
|
8
|
+
* reports a multi-megabyte snapshot as ~100 bytes and
|
|
9
|
+
* every size guard built on it silently stops working.
|
|
10
|
+
*
|
|
11
|
+
* Callers only ever compare the result against a
|
|
12
|
+
* threshold, so pass `limit` to stop walking as soon
|
|
13
|
+
* as the value is known to be over it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function estimateJsonBytes(value: unknown, limit?: number): number;
|
package/lib/core/size.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.estimateJsonBytes = estimateJsonBytes;
|
|
4
|
+
const MAX_VISITED_NODES = 500000;
|
|
5
|
+
/**
|
|
6
|
+
* Byte estimate for a JSON-serializable value.
|
|
7
|
+
*
|
|
8
|
+
* Walks the whole object graph rather than scoring a
|
|
9
|
+
* nested object as a fixed constant. rrweb full
|
|
10
|
+
* snapshots and mutation batches keep all of their
|
|
11
|
+
* weight below the top level, so a shallow estimate
|
|
12
|
+
* reports a multi-megabyte snapshot as ~100 bytes and
|
|
13
|
+
* every size guard built on it silently stops working.
|
|
14
|
+
*
|
|
15
|
+
* Callers only ever compare the result against a
|
|
16
|
+
* threshold, so pass `limit` to stop walking as soon
|
|
17
|
+
* as the value is known to be over it.
|
|
18
|
+
*/
|
|
19
|
+
function estimateJsonBytes(value, limit = Number.POSITIVE_INFINITY) {
|
|
20
|
+
let total = 0;
|
|
21
|
+
let visited = 0;
|
|
22
|
+
const stack = [value];
|
|
23
|
+
while (stack.length > 0) {
|
|
24
|
+
if (total >= limit)
|
|
25
|
+
return total;
|
|
26
|
+
if (++visited > MAX_VISITED_NODES)
|
|
27
|
+
return total;
|
|
28
|
+
const v = stack.pop();
|
|
29
|
+
if (v === null || v === undefined) {
|
|
30
|
+
total += 4;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
switch (typeof v) {
|
|
34
|
+
case 'string':
|
|
35
|
+
total += v.length + 2;
|
|
36
|
+
break;
|
|
37
|
+
case 'number':
|
|
38
|
+
total += 8;
|
|
39
|
+
break;
|
|
40
|
+
case 'boolean':
|
|
41
|
+
total += 5;
|
|
42
|
+
break;
|
|
43
|
+
case 'object': {
|
|
44
|
+
if (Array.isArray(v)) {
|
|
45
|
+
total += 2 + v.length;
|
|
46
|
+
for (let i = 0; i < v.length; i++) {
|
|
47
|
+
stack.push(v[i]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
total += 2;
|
|
52
|
+
for (const key in v) {
|
|
53
|
+
if (!Object.prototype.hasOwnProperty.call(v, key)) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
total += key.length + 4;
|
|
57
|
+
stack.push(v[key]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
default:
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return total;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=size.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size.js","sourceRoot":"","sources":["../../src/core/size.ts"],"names":[],"mappings":";;;AAAA,MAAM,iBAAiB,GAAG,MAAO,CAAC;AAElC;;;;;;;;;;;;;GAaG;AACH,2BACE,KAAc,EACd,KAAK,GAAG,MAAM,CAAC,iBAAiB;IAEhC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,MAAM,KAAK,GAAc,CAAC,KAAK,CAAC,CAAC;IAEjC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,IAAI,KAAK,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;QACjC,IAAI,EAAE,OAAO,GAAG,iBAAiB;YAAE,OAAO,KAAK,CAAC;QAEhD,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YAClC,KAAK,IAAI,CAAC,CAAC;YACX,SAAS;QACX,CAAC;QAED,QAAQ,OAAO,CAAC,EAAE,CAAC;YACjB,KAAK,QAAQ;gBACX,KAAK,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;gBACtB,MAAM;YACR,KAAK,QAAQ;gBACX,KAAK,IAAI,CAAC,CAAC;gBACX,MAAM;YACR,KAAK,SAAS;gBACZ,KAAK,IAAI,CAAC,CAAC;gBACX,MAAM;YACR,KAAK,QAAQ,EAAE,CAAC;gBACd,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;oBACrB,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;oBACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;wBAClC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBACnB,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,KAAK,IAAI,CAAC,CAAC;oBACX,KAAK,MAAM,GAAG,IAAI,CAGjB,EAAE,CAAC;wBACF,IACE,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CACnC,CAAC,EACD,GAAG,CACJ,EACD,CAAC;4BACD,SAAS;wBACX,CAAC;wBACD,KAAK,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;wBACxB,KAAK,CAAC,IAAI,CACP,CAA6B,CAAC,GAAG,CAAC,CACpC,CAAC;oBACJ,CAAC;gBACH,CAAC;gBACD,MAAM;YACR,CAAC;YACD;gBACE,MAAM;QACV,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type TagValue } from './config';
|
|
2
|
+
/**
|
|
3
|
+
* Config tags are the base, not a reset: shared code can call setTags()
|
|
4
|
+
* before init() runs, and an explicit setTags() wins on a key both set.
|
|
5
|
+
*/
|
|
6
|
+
export declare function initTags(base: Record<string, string>): void;
|
|
7
|
+
export declare function setTags(next: Record<string, TagValue>): void;
|
|
8
|
+
export declare function removeTag(key: string): void;
|
|
9
|
+
export declare function getTags(): Record<string, string>;
|
|
10
|
+
export declare function resetTags(): void;
|
package/lib/core/tags.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initTags = initTags;
|
|
4
|
+
exports.setTags = setTags;
|
|
5
|
+
exports.removeTag = removeTag;
|
|
6
|
+
exports.getTags = getTags;
|
|
7
|
+
exports.resetTags = resetTags;
|
|
8
|
+
const config_1 = require("./config");
|
|
9
|
+
let tags = {};
|
|
10
|
+
/**
|
|
11
|
+
* Config tags are the base, not a reset: shared code can call setTags()
|
|
12
|
+
* before init() runs, and an explicit setTags() wins on a key both set.
|
|
13
|
+
*/
|
|
14
|
+
function initTags(base) {
|
|
15
|
+
tags = { ...base, ...tags };
|
|
16
|
+
}
|
|
17
|
+
function setTags(next) {
|
|
18
|
+
tags = { ...tags, ...(0, config_1.stringifyTags)(next) };
|
|
19
|
+
}
|
|
20
|
+
function removeTag(key) {
|
|
21
|
+
if (!(key in tags))
|
|
22
|
+
return;
|
|
23
|
+
const copy = { ...tags };
|
|
24
|
+
delete copy[key];
|
|
25
|
+
tags = copy;
|
|
26
|
+
}
|
|
27
|
+
function getTags() {
|
|
28
|
+
return tags;
|
|
29
|
+
}
|
|
30
|
+
function resetTags() {
|
|
31
|
+
tags = {};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=tags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../../src/core/tags.ts"],"names":[],"mappings":";;;;;;;AAAA,qCAAwD;AAExD,IAAI,IAAI,GAA2B,EAAE,CAAC;AAEtC;;;GAGG;AACH,kBAAyB,IAA4B;IACnD,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;AAC9B,CAAC;AAED,iBAAwB,IAA8B;IACpD,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,IAAA,sBAAa,EAAC,IAAI,CAAC,EAAE,CAAC;AAC7C,CAAC;AAED,mBAA0B,GAAW;IACnC,IAAI,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC;QAAE,OAAO;IAC3B,MAAM,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;IACzB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IACjB,IAAI,GAAG,IAAI,CAAC;AACd,CAAC;AAED;IACE,OAAO,IAAI,CAAC;AACd,CAAC;AAED;IACE,IAAI,GAAG,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const COUNTER_NAMES: readonly ['events_rate_limited', 'events_should_send_dropped', 'send_failures', 'compression_failures', 'retry_drops', 'transport_drops', 'replay_events_dropped', 'replay_capture_failures', 'replay_rebases', 'outbox_drops', 'tap_fiber_missing'];
|
|
2
|
+
export type TelemetryCounter = (typeof COUNTER_NAMES)[number];
|
|
3
|
+
export declare function incrTelemetry(key: TelemetryCounter, amount?: number): void;
|
|
4
|
+
/** Returns the counters since the last call, or null when all are zero. */
|
|
5
|
+
export declare function takeTelemetry(): Record<TelemetryCounter, number> | null;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.incrTelemetry = incrTelemetry;
|
|
4
|
+
exports.takeTelemetry = takeTelemetry;
|
|
5
|
+
const COUNTER_NAMES = [
|
|
6
|
+
'events_rate_limited',
|
|
7
|
+
'events_should_send_dropped',
|
|
8
|
+
'send_failures',
|
|
9
|
+
'compression_failures',
|
|
10
|
+
'retry_drops',
|
|
11
|
+
'transport_drops',
|
|
12
|
+
'replay_events_dropped',
|
|
13
|
+
'replay_capture_failures',
|
|
14
|
+
'replay_rebases',
|
|
15
|
+
'outbox_drops',
|
|
16
|
+
// A tap with no React fiber on its event: React internals changed, and
|
|
17
|
+
// taps are not named until the SDK is updated.
|
|
18
|
+
'tap_fiber_missing',
|
|
19
|
+
];
|
|
20
|
+
const counters = Object.fromEntries(COUNTER_NAMES.map((n) => [n, 0]));
|
|
21
|
+
function incrTelemetry(key, amount = 1) {
|
|
22
|
+
counters[key] += amount;
|
|
23
|
+
}
|
|
24
|
+
/** Returns the counters since the last call, or null when all are zero. */
|
|
25
|
+
function takeTelemetry() {
|
|
26
|
+
let any = false;
|
|
27
|
+
for (const n of COUNTER_NAMES)
|
|
28
|
+
if (counters[n] > 0)
|
|
29
|
+
any = true;
|
|
30
|
+
if (!any)
|
|
31
|
+
return null;
|
|
32
|
+
const snapshot = { ...counters };
|
|
33
|
+
for (const n of COUNTER_NAMES)
|
|
34
|
+
counters[n] = 0;
|
|
35
|
+
return snapshot;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=telemetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../src/core/telemetry.ts"],"names":[],"mappings":";;;;AAAA,MAAM,aAAa,GAAG;IACpB,qBAAqB;IACrB,4BAA4B;IAC5B,eAAe;IACf,sBAAsB;IACtB,aAAa;IACb,iBAAiB;IACjB,uBAAuB;IACvB,yBAAyB;IACzB,gBAAgB;IAChB,cAAc;IACd,uEAAuE;IACvE,+CAA+C;IAC/C,mBAAmB;CACX,CAAC;AAIX,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CACjC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CACG,CAAC;AAEtC,uBAA8B,GAAqB,EAAE,MAAM,GAAG,CAAC;IAC7D,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC;AAC1B,CAAC;AAED,2EAA2E;AAC3E;IACE,IAAI,GAAG,GAAG,KAAK,CAAC;IAChB,KAAK,MAAM,CAAC,IAAI,aAAa;QAAE,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC;YAAE,GAAG,GAAG,IAAI,CAAC;IAC/D,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IACtB,MAAM,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;IACjC,KAAK,MAAM,CAAC,IAAI,aAAa;QAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Propagator } from './config';
|
|
2
|
+
export interface TraceIds {
|
|
3
|
+
traceId: string;
|
|
4
|
+
spanId: string;
|
|
5
|
+
sampled: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function newTraceIds(sampleRate: number): TraceIds;
|
|
8
|
+
/** Header names in lower case, as the XHR tracker compares them. */
|
|
9
|
+
export declare function tracingHeaders(ids: TraceIds, propagators: Propagator[]): Record<string, string>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newTraceIds = newTraceIds;
|
|
4
|
+
exports.tracingHeaders = tracingHeaders;
|
|
5
|
+
const ids_1 = require("./ids");
|
|
6
|
+
function newTraceIds(sampleRate) {
|
|
7
|
+
return {
|
|
8
|
+
traceId: (0, ids_1.hexId)(16),
|
|
9
|
+
spanId: (0, ids_1.hexId)(8),
|
|
10
|
+
sampled: Math.random() * 100 < sampleRate,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function hexToDecimal(hex) {
|
|
14
|
+
const big = globalThis
|
|
15
|
+
.BigInt;
|
|
16
|
+
if (typeof big !== 'function')
|
|
17
|
+
return null;
|
|
18
|
+
try {
|
|
19
|
+
return big('0x' + hex).toString(10);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Header names in lower case, as the XHR tracker compares them. */
|
|
26
|
+
function tracingHeaders(ids, propagators) {
|
|
27
|
+
const out = {};
|
|
28
|
+
const flag = ids.sampled ? '01' : '00';
|
|
29
|
+
for (const p of propagators) {
|
|
30
|
+
if (p === 'tracecontext') {
|
|
31
|
+
out.traceparent = `00-${ids.traceId}-${ids.spanId}-${flag}`;
|
|
32
|
+
}
|
|
33
|
+
else if (p === 'b3') {
|
|
34
|
+
out.b3 = `${ids.traceId}-${ids.spanId}-${ids.sampled ? '1' : '0'}`;
|
|
35
|
+
}
|
|
36
|
+
else if (p === 'b3multi') {
|
|
37
|
+
out['x-b3-traceid'] = ids.traceId;
|
|
38
|
+
out['x-b3-spanid'] = ids.spanId;
|
|
39
|
+
out['x-b3-sampled'] = ids.sampled ? '1' : '0';
|
|
40
|
+
}
|
|
41
|
+
else if (p === 'datadog') {
|
|
42
|
+
// Datadog ids are the low 64 bits in decimal; the high 64 bits go
|
|
43
|
+
// in x-datadog-tags.
|
|
44
|
+
const traceLow = hexToDecimal(ids.traceId.slice(16));
|
|
45
|
+
const parent = hexToDecimal(ids.spanId);
|
|
46
|
+
if (traceLow && parent) {
|
|
47
|
+
out['x-datadog-trace-id'] = traceLow;
|
|
48
|
+
out['x-datadog-parent-id'] = parent;
|
|
49
|
+
out['x-datadog-sampling-priority'] = ids.sampled ? '1' : '0';
|
|
50
|
+
out['x-datadog-origin'] = 'rum';
|
|
51
|
+
out['x-datadog-tags'] = `_dd.p.tid=${ids.traceId.slice(0, 16)}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=tracing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../src/core/tracing.ts"],"names":[],"mappings":";;;;AACA,+BAA8B;AAQ9B,qBAA4B,UAAkB;IAC5C,OAAO;QACL,OAAO,EAAE,IAAA,WAAK,EAAC,EAAE,CAAC;QAClB,MAAM,EAAE,IAAA,WAAK,EAAC,CAAC,CAAC;QAChB,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,UAAU;KAC1C,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,GAAW;IAC/B,MAAM,GAA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B,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;YACrD,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACxC,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;gBACvB,GAAG,CAAC,oBAAoB,CAAC,GAAG,QAAQ,CAAC;gBACrC,GAAG,CAAC,qBAAqB,CAAC,GAAG,MAAM,CAAC;gBACpC,GAAG,CAAC,6BAA6B,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;gBAC7D,GAAG,CAAC,kBAAkB,CAAC,GAAG,KAAK,CAAC;gBAChC,GAAG,CAAC,gBAAgB,CAAC,GAAG,aAAa,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;YAClE,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
type Payload = Record<string, unknown>;
|
|
2
|
+
export declare const INGEST_PATH = "/v1/rum/ingest";
|
|
3
|
+
export declare const EVENTS_BATCH_KEY = "events";
|
|
4
|
+
export declare const REPLAY_BATCH_KEY = "replay";
|
|
5
|
+
export declare const TELEMETRY_BATCH_KEY = "sdk_telemetry";
|
|
6
|
+
export interface PostResult {
|
|
7
|
+
status: number;
|
|
8
|
+
rateLimits: string | null;
|
|
9
|
+
/** The response `Date` header, for the clock offset. */
|
|
10
|
+
date?: string | null;
|
|
11
|
+
}
|
|
12
|
+
export type Poster = (url: string, headers: Record<string, string>, body: Uint8Array | string) => Promise<PostResult>;
|
|
13
|
+
/** Test hook: replace the HTTP client. */
|
|
14
|
+
export declare function setPoster(p: Poster | null): void;
|
|
15
|
+
/** Events stay queued while this returns false (consent is pending). */
|
|
16
|
+
export declare function setCanSend(fn: () => boolean): void;
|
|
17
|
+
/**
|
|
18
|
+
* Lets the replay recorder start a new full snapshot when a segment is
|
|
19
|
+
* lost. rrweb events are deltas, so a lost segment breaks every later
|
|
20
|
+
* event until the next full snapshot.
|
|
21
|
+
*/
|
|
22
|
+
export declare function setReplayDropHandler(fn: (() => void) | null): void;
|
|
23
|
+
export declare function enqueue(key: string, item: Payload, bytesHint?: number): void;
|
|
24
|
+
/**
|
|
25
|
+
* Replaces the queued item with the same key, or adds it. `merge` sees the
|
|
26
|
+
* queued item and the new one, and returns what to keep.
|
|
27
|
+
*/
|
|
28
|
+
export declare function upsert(key: string, itemKey: string, item: Payload, merge?: (previous: Payload, next: Payload) => Payload): void;
|
|
29
|
+
export declare function buildEnvelope(sections: Array<{
|
|
30
|
+
type: string;
|
|
31
|
+
items: Payload[];
|
|
32
|
+
}>): string;
|
|
33
|
+
/** Sends everything queued now. No-op while consent is pending. */
|
|
34
|
+
export declare function flush(): void;
|
|
35
|
+
export declare function isServerRateLimited(category: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Returns the wait before retry number `attempts`, a random value
|
|
38
|
+
* between half and all of the exponential step.
|
|
39
|
+
*
|
|
40
|
+
* Without the random part, all devices that lost the collector at the
|
|
41
|
+
* same time retry at the same times, and each wave of retries can make
|
|
42
|
+
* the collector fail again when it comes back. The lower half stays fixed
|
|
43
|
+
* so that a collector that fails fast is not sent requests in a loop.
|
|
44
|
+
*/
|
|
45
|
+
export declare function retryDelayMs(attempts: number, random?: () => number): number;
|
|
46
|
+
/**
|
|
47
|
+
* Writes unsent data to disk. Called when the app goes to the background,
|
|
48
|
+
* after a failed send, and from the fatal error handler, so an app that
|
|
49
|
+
* is killed or crashes sends the data on its next start.
|
|
50
|
+
*
|
|
51
|
+
* Bodies in flight are written too: the app often goes to the background
|
|
52
|
+
* just after a flush, and the OS can end it before the answer comes.
|
|
53
|
+
* When the answer comes, syncOutboxAfterSend takes them out again.
|
|
54
|
+
*
|
|
55
|
+
* The file write runs on a native background thread, so a large queue
|
|
56
|
+
* does not block the JS thread. Only the fatal error handler uses
|
|
57
|
+
* `sync`, because the process can end as soon as it returns.
|
|
58
|
+
*/
|
|
59
|
+
export declare function persistOutbox(opts?: {
|
|
60
|
+
sync?: boolean;
|
|
61
|
+
}): void;
|
|
62
|
+
/** Loads the outbox written by an earlier run and queues it to send. */
|
|
63
|
+
export declare function restoreOutbox(): void;
|
|
64
|
+
/** Drops everything queued, held and persisted (consent withdrawn). */
|
|
65
|
+
export declare function clearAll(): void;
|
|
66
|
+
/** Starts sending again after consent changes to granted. */
|
|
67
|
+
export declare function resume(): void;
|
|
68
|
+
/** Test hook. */
|
|
69
|
+
export declare function resetTransport(): void;
|
|
70
|
+
/** Test hook. */
|
|
71
|
+
export declare function pendingCounts(): {
|
|
72
|
+
queues: Record<string, number>;
|
|
73
|
+
retries: number;
|
|
74
|
+
inFlight: number;
|
|
75
|
+
};
|
|
76
|
+
export {};
|