@navikt/apm 0.0.0-stage → 0.7.3
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 +21 -0
- package/README.md +527 -2
- package/dist/api.d.ts +108 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +220 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +150 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +268 -0
- package/dist/config.js.map +1 -0
- package/dist/console.d.ts +28 -0
- package/dist/console.d.ts.map +1 -0
- package/dist/console.js +71 -0
- package/dist/console.js.map +1 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +177 -0
- package/dist/errors.js.map +1 -0
- package/dist/feedback.d.ts +42 -0
- package/dist/feedback.d.ts.map +1 -0
- package/dist/feedback.js +72 -0
- package/dist/feedback.js.map +1 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +249 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +47 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +129 -0
- package/dist/internal.js.map +1 -0
- package/dist/metaTags.d.ts +34 -0
- package/dist/metaTags.d.ts.map +1 -0
- package/dist/metaTags.js +76 -0
- package/dist/metaTags.js.map +1 -0
- package/dist/react/ErrorBoundary.d.ts +59 -0
- package/dist/react/ErrorBoundary.d.ts.map +1 -0
- package/dist/react/ErrorBoundary.js +92 -0
- package/dist/react/ErrorBoundary.js.map +1 -0
- package/dist/react/NaisMetaTags.d.ts +25 -0
- package/dist/react/NaisMetaTags.d.ts.map +1 -0
- package/dist/react/NaisMetaTags.js +6 -0
- package/dist/react/NaisMetaTags.js.map +1 -0
- package/dist/react/index.d.ts +17 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +14 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/nextClient.d.ts +25 -0
- package/dist/react/nextClient.d.ts.map +1 -0
- package/dist/react/nextClient.js +29 -0
- package/dist/react/nextClient.js.map +1 -0
- package/dist/react/routing.d.ts +56 -0
- package/dist/react/routing.d.ts.map +1 -0
- package/dist/react/routing.js +89 -0
- package/dist/react/routing.js.map +1 -0
- package/dist/replay/constants.d.ts +26 -0
- package/dist/replay/constants.d.ts.map +1 -0
- package/dist/replay/constants.js +24 -0
- package/dist/replay/constants.js.map +1 -0
- package/dist/replay/events.d.ts +74 -0
- package/dist/replay/events.d.ts.map +1 -0
- package/dist/replay/events.js +258 -0
- package/dist/replay/events.js.map +1 -0
- package/dist/replay/hash.d.ts +8 -0
- package/dist/replay/hash.d.ts.map +1 -0
- package/dist/replay/hash.js +14 -0
- package/dist/replay/hash.js.map +1 -0
- package/dist/replay/masking.d.ts +89 -0
- package/dist/replay/masking.d.ts.map +1 -0
- package/dist/replay/masking.js +199 -0
- package/dist/replay/masking.js.map +1 -0
- package/dist/replay/options.d.ts +52 -0
- package/dist/replay/options.d.ts.map +1 -0
- package/dist/replay/options.js +66 -0
- package/dist/replay/options.js.map +1 -0
- package/dist/replay/recording.d.ts +60 -0
- package/dist/replay/recording.d.ts.map +1 -0
- package/dist/replay/recording.js +120 -0
- package/dist/replay/recording.js.map +1 -0
- package/dist/replay/snapshot.d.ts +41 -0
- package/dist/replay/snapshot.d.ts.map +1 -0
- package/dist/replay/snapshot.js +97 -0
- package/dist/replay/snapshot.js.map +1 -0
- package/dist/replay/transport.d.ts +82 -0
- package/dist/replay/transport.d.ts.map +1 -0
- package/dist/replay/transport.js +188 -0
- package/dist/replay/transport.js.map +1 -0
- package/dist/scrub.d.ts +69 -0
- package/dist/scrub.d.ts.map +1 -0
- package/dist/scrub.js +317 -0
- package/dist/scrub.js.map +1 -0
- package/dist/serialize.d.ts +15 -0
- package/dist/serialize.d.ts.map +1 -0
- package/dist/serialize.js +68 -0
- package/dist/serialize.js.map +1 -0
- package/dist/tracing.d.ts +37 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +70 -0
- package/dist/tracing.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/package.json +94 -4
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-replay option normalization (nais/grafana-apm-app#82 — replay privacy).
|
|
3
|
+
*
|
|
4
|
+
* Resolves the privacy *tier* independently of the capture *trigger* (`mode`):
|
|
5
|
+
*
|
|
6
|
+
* - `mode` ('on-error' | 'always') is the CAPTURE TRIGGER — unchanged. It
|
|
7
|
+
* decides *when* the timeline is shipped, not *what* is captured.
|
|
8
|
+
* - `tier` ('events' | 'wireframe' | 'dom') is the PRIVACY TIER — new. It
|
|
9
|
+
* decides *what* is captured: an interaction timeline with no DOM (`events`,
|
|
10
|
+
* the safe default), a coarse wireframe (`wireframe`, Phase 3), or the full
|
|
11
|
+
* masked DOM recording (`dom`, personvernombud-gated).
|
|
12
|
+
*
|
|
13
|
+
* `enabled:true` with `tier` omitted resolves to `events` — a BREAKING (preview)
|
|
14
|
+
* change from the old masked-DOM default, so the affected pilots get a one-time
|
|
15
|
+
* deprecation warning telling them how to keep DOM capture.
|
|
16
|
+
*
|
|
17
|
+
* Kept out of the eager `config.ts`/`index.ts` bundle path proper: it is only
|
|
18
|
+
* reached from init()'s replay branch and carries no heavy imports.
|
|
19
|
+
*/
|
|
20
|
+
const VALID_TIERS = ['events', 'wireframe', 'dom'];
|
|
21
|
+
const DEFAULT_TIER = 'events';
|
|
22
|
+
const DEFAULT_TIER_DEPRECATION = "[@nais/apm] session replay now defaults to the events tier (no DOM); " +
|
|
23
|
+
"pass tier:'dom' to keep DOM capture (requires personvernombud sign-off).";
|
|
24
|
+
let warnedDefaultTier = false;
|
|
25
|
+
/** @internal test helper — resets the one-time default-tier deprecation warning. */
|
|
26
|
+
export function _resetSessionReplayWarningForTesting() {
|
|
27
|
+
warnedDefaultTier = false;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Normalize the raw `sessionReplay` option into a resolved shape: apply the
|
|
31
|
+
* default tier, validate the tier enum (unknown → `events` + warn), and emit a
|
|
32
|
+
* one-time deprecation warning when an ENABLED replay relies on the new events
|
|
33
|
+
* default (the masked-DOM behavior change). Never throws.
|
|
34
|
+
*/
|
|
35
|
+
export function normalizeSessionReplay(options) {
|
|
36
|
+
const enabled = options?.enabled === true;
|
|
37
|
+
const requestedTier = options?.tier;
|
|
38
|
+
let tier;
|
|
39
|
+
if (requestedTier === undefined) {
|
|
40
|
+
tier = DEFAULT_TIER;
|
|
41
|
+
// The default flipped from masked-DOM to the events tier. Only warn when a
|
|
42
|
+
// replay is actually enabled — that is the config whose behavior changed.
|
|
43
|
+
if (enabled && !warnedDefaultTier) {
|
|
44
|
+
warnedDefaultTier = true;
|
|
45
|
+
// eslint-disable-next-line no-console
|
|
46
|
+
console.warn(DEFAULT_TIER_DEPRECATION);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (VALID_TIERS.includes(requestedTier)) {
|
|
50
|
+
tier = requestedTier;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
tier = DEFAULT_TIER;
|
|
54
|
+
// eslint-disable-next-line no-console
|
|
55
|
+
console.warn(`[@nais/apm] unknown session replay tier ${JSON.stringify(requestedTier)}; ` +
|
|
56
|
+
`falling back to the '${DEFAULT_TIER}' tier.`);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
enabled,
|
|
60
|
+
tier,
|
|
61
|
+
mode: options?.mode === 'always' ? 'always' : 'on-error',
|
|
62
|
+
sampleRate: options?.sampleRate,
|
|
63
|
+
block: options?.block,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/replay/options.ts"],"names":[],"mappings":"AAAA;;;;;;;;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AAE,UAAU;QAC/B,KAAK,EAAE,OAAO,EAAE,KAAK;KACtB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error-triggered / continuous session recording (nais/grafana-apm-app#58).
|
|
3
|
+
*
|
|
4
|
+
* `startRecording()` runs rrweb `record()` (Grafana's fork) with
|
|
5
|
+
* `checkoutEveryNms: 60_000` and the non-overridable masking floor.
|
|
6
|
+
*
|
|
7
|
+
* - `mode: 'on-error'` (default): the last two checkout segments
|
|
8
|
+
* (~60–120 s) are kept in a memory ring buffer; nothing leaves the
|
|
9
|
+
* browser. On the first captured error the buffer is flushed through the
|
|
10
|
+
* chunked transport (`mode="recording"`) and recording keeps streaming for
|
|
11
|
+
* the rest of the session (Sentry semantics).
|
|
12
|
+
* - `mode: 'always'`: streams continuously, gated by a deterministic
|
|
13
|
+
* per-session `sampleRate`.
|
|
14
|
+
*/
|
|
15
|
+
import type { eventWithTime } from '@grafana/rrweb';
|
|
16
|
+
import type { PushChunk } from './transport.js';
|
|
17
|
+
export declare const CHECKOUT_EVERY_NMS = 60000;
|
|
18
|
+
/**
|
|
19
|
+
* Deterministic per-session sampling: the same session id always lands on the
|
|
20
|
+
* same side of the rate, so a session is either fully recorded or not at all.
|
|
21
|
+
* Falls back to a single random draw when no session id is available.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isSessionSampled(sessionId: string | undefined, sampleRate: number): boolean;
|
|
24
|
+
type StopFn = () => void;
|
|
25
|
+
type RecordFn = (options: {
|
|
26
|
+
emit: (event: eventWithTime, isCheckout?: boolean) => void;
|
|
27
|
+
checkoutEveryNms: number;
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}) => StopFn | undefined;
|
|
30
|
+
export interface RecordingHandle {
|
|
31
|
+
/**
|
|
32
|
+
* Notify the recorder that an error was captured. In `on-error` mode the
|
|
33
|
+
* first call flushes the ring buffer and switches to streaming; subsequent
|
|
34
|
+
* calls (and all calls in `always` mode) are no-ops.
|
|
35
|
+
*/
|
|
36
|
+
notifyError(): void;
|
|
37
|
+
/** Stop recording and flush whatever is already streaming. */
|
|
38
|
+
stop(): void;
|
|
39
|
+
/** True once events are being streamed (always-mode, or after the first error). */
|
|
40
|
+
readonly isStreaming: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface StartRecordingOptions {
|
|
43
|
+
mode: 'on-error' | 'always';
|
|
44
|
+
/** Fraction of sessions recorded, 0..1. Default 1. */
|
|
45
|
+
sampleRate?: number;
|
|
46
|
+
/** Extra block selectors (tighten-only). */
|
|
47
|
+
block?: readonly string[];
|
|
48
|
+
push: PushChunk;
|
|
49
|
+
/** Faro session id, used for deterministic sampling. */
|
|
50
|
+
sessionId?: string;
|
|
51
|
+
/** @internal test seam: replaces the lazily imported rrweb `record`. */
|
|
52
|
+
recordFn?: RecordFn;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Start recording. Resolves to `undefined` when the session is sampled out or
|
|
56
|
+
* rrweb fails to start; never throws.
|
|
57
|
+
*/
|
|
58
|
+
export declare function startRecording(options: StartRecordingOptions): Promise<RecordingHandle | undefined>;
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=recording.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recording.d.ts","sourceRoot":"","sources":["../../src/replay/recording.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAKpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,eAAO,MAAM,kBAAkB,QAAS,CAAC;AAKzC;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAW3F;AAED,KAAK,MAAM,GAAG,MAAM,IAAI,CAAC;AACzB,KAAK,QAAQ,GAAG,CAAC,OAAO,EAAE;IACxB,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,UAAU,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3D,gBAAgB,EAAE,MAAM,CAAC;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,KAAK,MAAM,GAAG,SAAS,CAAC;AAEzB,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,WAAW,IAAI,IAAI,CAAC;IACpB,8DAA8D;IAC9D,IAAI,IAAI,IAAI,CAAC;IACb,mFAAmF;IACnF,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC5B,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,SAAS,CAAC;IAChB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAiFzG"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error-triggered / continuous session recording (nais/grafana-apm-app#58).
|
|
3
|
+
*
|
|
4
|
+
* `startRecording()` runs rrweb `record()` (Grafana's fork) with
|
|
5
|
+
* `checkoutEveryNms: 60_000` and the non-overridable masking floor.
|
|
6
|
+
*
|
|
7
|
+
* - `mode: 'on-error'` (default): the last two checkout segments
|
|
8
|
+
* (~60–120 s) are kept in a memory ring buffer; nothing leaves the
|
|
9
|
+
* browser. On the first captured error the buffer is flushed through the
|
|
10
|
+
* chunked transport (`mode="recording"`) and recording keeps streaming for
|
|
11
|
+
* the rest of the session (Sentry semantics).
|
|
12
|
+
* - `mode: 'always'`: streams continuously, gated by a deterministic
|
|
13
|
+
* per-session `sampleRate`.
|
|
14
|
+
*/
|
|
15
|
+
import { hashString } from './hash.js';
|
|
16
|
+
import { buildRecordMaskingOptions } from './masking.js';
|
|
17
|
+
import { ReplayTransport } from './transport.js';
|
|
18
|
+
export const CHECKOUT_EVERY_NMS = 60000;
|
|
19
|
+
const RRWEB_TYPE_FULL_SNAPSHOT = 2;
|
|
20
|
+
const RRWEB_TYPE_META = 4;
|
|
21
|
+
/**
|
|
22
|
+
* Deterministic per-session sampling: the same session id always lands on the
|
|
23
|
+
* same side of the rate, so a session is either fully recorded or not at all.
|
|
24
|
+
* Falls back to a single random draw when no session id is available.
|
|
25
|
+
*/
|
|
26
|
+
export function isSessionSampled(sessionId, sampleRate) {
|
|
27
|
+
if (!(sampleRate > 0)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (sampleRate >= 1) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (sessionId === undefined || sessionId === '') {
|
|
34
|
+
return Math.random() < sampleRate;
|
|
35
|
+
}
|
|
36
|
+
return hashString(sessionId) / 4294967296 < sampleRate;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Start recording. Resolves to `undefined` when the session is sampled out or
|
|
40
|
+
* rrweb fails to start; never throws.
|
|
41
|
+
*/
|
|
42
|
+
export async function startRecording(options) {
|
|
43
|
+
try {
|
|
44
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
if (!isSessionSampled(options.sessionId, options.sampleRate ?? 1)) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const recordFn = options.recordFn ?? (await import('@grafana/rrweb')).record;
|
|
51
|
+
const transport = new ReplayTransport('recording', options.push);
|
|
52
|
+
let streaming = options.mode === 'always';
|
|
53
|
+
// Ring buffer: the previous completed checkout segment + the one being filled.
|
|
54
|
+
let previousSegment = [];
|
|
55
|
+
let currentSegment = [];
|
|
56
|
+
const emit = (event, isCheckout) => {
|
|
57
|
+
try {
|
|
58
|
+
if (streaming) {
|
|
59
|
+
transport.enqueue(event);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
// A checkout emits Meta (type 4) then FullSnapshot (type 2). Rotate the
|
|
63
|
+
// ring on the Meta event; fall back to the FullSnapshot when a checkout
|
|
64
|
+
// arrives without a preceding Meta.
|
|
65
|
+
const lastType = currentSegment[currentSegment.length - 1]?.type;
|
|
66
|
+
const isBoundary = currentSegment.length > 0 &&
|
|
67
|
+
(event.type === RRWEB_TYPE_META ||
|
|
68
|
+
(event.type === RRWEB_TYPE_FULL_SNAPSHOT && isCheckout === true && lastType !== RRWEB_TYPE_META));
|
|
69
|
+
if (isBoundary) {
|
|
70
|
+
previousSegment = currentSegment;
|
|
71
|
+
currentSegment = [];
|
|
72
|
+
}
|
|
73
|
+
currentSegment.push(event);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Recording must never break the host app.
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const stopFn = recordFn({
|
|
80
|
+
emit,
|
|
81
|
+
checkoutEveryNms: CHECKOUT_EVERY_NMS,
|
|
82
|
+
// The masking floor is spread LAST so nothing can override it.
|
|
83
|
+
...buildRecordMaskingOptions(options.block),
|
|
84
|
+
});
|
|
85
|
+
if (stopFn === undefined) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
get isStreaming() {
|
|
90
|
+
return streaming;
|
|
91
|
+
},
|
|
92
|
+
notifyError() {
|
|
93
|
+
if (streaming) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
streaming = true;
|
|
97
|
+
const buffered = [...previousSegment, ...currentSegment];
|
|
98
|
+
previousSegment = [];
|
|
99
|
+
currentSegment = [];
|
|
100
|
+
// Historical events go out immediately; live events keep streaming
|
|
101
|
+
// through the buffered transport afterwards.
|
|
102
|
+
transport.enqueueAll(buffered);
|
|
103
|
+
transport.flush();
|
|
104
|
+
},
|
|
105
|
+
stop() {
|
|
106
|
+
try {
|
|
107
|
+
stopFn();
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// ignore
|
|
111
|
+
}
|
|
112
|
+
transport.dispose();
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=recording.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recording.js","sourceRoot":"","sources":["../../src/replay/recording.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAM,CAAC;AAEzC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AACnC,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAA6B,EAAE,UAAkB;IAChF,IAAI,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,UAAU,IAAI,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC;IACpC,CAAC;IACD,OAAO,UAAU,CAAC,SAAS,CAAC,GAAG,UAAa,GAAG,UAAU,CAAC;AAC5D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grafana-apm-app#67).
|
|
3
|
+
*
|
|
4
|
+
* `captureSnapshot()` serializes the current document with rrweb-snapshot
|
|
5
|
+
* under the non-overridable masking floor, wraps the result as a synthetic
|
|
6
|
+
* one-frame replay — `[Meta (type 4), FullSnapshot (type 2)]` — and ships it
|
|
7
|
+
* through the chunked transport with `mode="snapshot"`, renderable by the
|
|
8
|
+
* exact player #58 ships, paused at t=0.
|
|
9
|
+
*
|
|
10
|
+
* Guardrails:
|
|
11
|
+
* - skip when the document has more than 15 000 nodes (capture jank),
|
|
12
|
+
* - throttle: max 1 snapshot per error-message hash per session (proxy for
|
|
13
|
+
* the fingerprint, which is not known SDK-side before #62 tier 0),
|
|
14
|
+
* - hard cap of 3 snapshots per session,
|
|
15
|
+
* - everything wrapped in try/catch — a failing snapshot must never break
|
|
16
|
+
* error reporting itself.
|
|
17
|
+
*/
|
|
18
|
+
import type { PushChunk } from './transport.js';
|
|
19
|
+
export declare const MAX_SNAPSHOT_DOM_NODES = 15000;
|
|
20
|
+
export declare const MAX_SNAPSHOTS_PER_SESSION = 3;
|
|
21
|
+
/** @internal test helper */
|
|
22
|
+
export declare function _resetSnapshotStateForTesting(): void;
|
|
23
|
+
/** Stable throttling key for an error message (djb2, hex). */
|
|
24
|
+
export declare function hashErrorMessage(message: string): string;
|
|
25
|
+
type SnapshotFn = (doc: Document, options?: Record<string, unknown>) => unknown;
|
|
26
|
+
export interface CaptureSnapshotOptions {
|
|
27
|
+
/** Extra block selectors (tighten-only), from `sessionReplay.block`-style config. */
|
|
28
|
+
block?: readonly string[];
|
|
29
|
+
/** @internal test seam: replaces the lazily imported rrweb-snapshot `snapshot`. */
|
|
30
|
+
snapshotFn?: SnapshotFn;
|
|
31
|
+
/** @internal test seam: overrides {@link MAX_SNAPSHOT_DOM_NODES}. */
|
|
32
|
+
maxNodes?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Capture one masked DOM snapshot for the given error message and push it as
|
|
36
|
+
* `mode="snapshot"` chunk(s). Returns `true` when a snapshot was sent, `false`
|
|
37
|
+
* when skipped (throttled, oversized DOM, or capture failure). Never throws.
|
|
38
|
+
*/
|
|
39
|
+
export declare function captureSnapshot(errorMessage: string, push: PushChunk, options?: CaptureSnapshotOptions): Promise<boolean>;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/replay/snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAQH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,eAAO,MAAM,sBAAsB,QAAS,CAAC;AAC7C,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAS3C,4BAA4B;AAC5B,wBAAgB,6BAA6B,IAAI,IAAI,CAGpD;AAED,8DAA8D;AAC9D,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,KAAK,UAAU,GAAG,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;AAEhF,MAAM,WAAW,sBAAsB;IACrC,qFAAqF;IACrF,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,mFAAmF;IACnF,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,SAAS,EACf,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,OAAO,CAAC,CAwDlB"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Masked DOM snapshot on crash — "screenshot on error" (nais/grafana-apm-app#67).
|
|
3
|
+
*
|
|
4
|
+
* `captureSnapshot()` serializes the current document with rrweb-snapshot
|
|
5
|
+
* under the non-overridable masking floor, wraps the result as a synthetic
|
|
6
|
+
* one-frame replay — `[Meta (type 4), FullSnapshot (type 2)]` — and ships it
|
|
7
|
+
* through the chunked transport with `mode="snapshot"`, renderable by the
|
|
8
|
+
* exact player #58 ships, paused at t=0.
|
|
9
|
+
*
|
|
10
|
+
* Guardrails:
|
|
11
|
+
* - skip when the document has more than 15 000 nodes (capture jank),
|
|
12
|
+
* - throttle: max 1 snapshot per error-message hash per session (proxy for
|
|
13
|
+
* the fingerprint, which is not known SDK-side before #62 tier 0),
|
|
14
|
+
* - hard cap of 3 snapshots per session,
|
|
15
|
+
* - everything wrapped in try/catch — a failing snapshot must never break
|
|
16
|
+
* error reporting itself.
|
|
17
|
+
*/
|
|
18
|
+
import { scrubUrl } from '../scrub.js';
|
|
19
|
+
import { hashString } from './hash.js';
|
|
20
|
+
import { buildSnapshotMaskingOptions } from './masking.js';
|
|
21
|
+
import { sendEvents } from './transport.js';
|
|
22
|
+
export const MAX_SNAPSHOT_DOM_NODES = 15000;
|
|
23
|
+
export const MAX_SNAPSHOTS_PER_SESSION = 3;
|
|
24
|
+
/** rrweb event types used for the synthetic one-frame replay. */
|
|
25
|
+
const RRWEB_TYPE_FULL_SNAPSHOT = 2;
|
|
26
|
+
const RRWEB_TYPE_META = 4;
|
|
27
|
+
let snapshotCount = 0;
|
|
28
|
+
const capturedErrorHashes = new Set();
|
|
29
|
+
/** @internal test helper */
|
|
30
|
+
export function _resetSnapshotStateForTesting() {
|
|
31
|
+
snapshotCount = 0;
|
|
32
|
+
capturedErrorHashes.clear();
|
|
33
|
+
}
|
|
34
|
+
/** Stable throttling key for an error message (djb2, hex). */
|
|
35
|
+
export function hashErrorMessage(message) {
|
|
36
|
+
return hashString(message).toString(16);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Capture one masked DOM snapshot for the given error message and push it as
|
|
40
|
+
* `mode="snapshot"` chunk(s). Returns `true` when a snapshot was sent, `false`
|
|
41
|
+
* when skipped (throttled, oversized DOM, or capture failure). Never throws.
|
|
42
|
+
*/
|
|
43
|
+
export async function captureSnapshot(errorMessage, push, options = {}) {
|
|
44
|
+
try {
|
|
45
|
+
if (typeof document === 'undefined' || typeof window === 'undefined') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (snapshotCount >= MAX_SNAPSHOTS_PER_SESSION) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const hash = hashErrorMessage(errorMessage);
|
|
52
|
+
if (capturedErrorHashes.has(hash)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const maxNodes = options.maxNodes ?? MAX_SNAPSHOT_DOM_NODES;
|
|
56
|
+
if (document.getElementsByTagName('*').length > maxNodes) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
// Consume the throttle slot before capturing so an error storm on a page
|
|
60
|
+
// where capture keeps failing cannot retry the (expensive) traversal.
|
|
61
|
+
capturedErrorHashes.add(hash);
|
|
62
|
+
snapshotCount += 1;
|
|
63
|
+
const snapshotFn = options.snapshotFn ?? (await import('@grafana/rrweb-snapshot')).snapshot;
|
|
64
|
+
const node = snapshotFn(document, { ...buildSnapshotMaskingOptions(options.block) });
|
|
65
|
+
if (node == null) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const timestamp = Date.now();
|
|
69
|
+
const events = [
|
|
70
|
+
{
|
|
71
|
+
type: RRWEB_TYPE_META,
|
|
72
|
+
data: {
|
|
73
|
+
// The Meta href ships verbatim in the first frame; scrub the query
|
|
74
|
+
// string and PII-shaped path segments before it leaves the browser.
|
|
75
|
+
href: scrubUrl(window.location.href),
|
|
76
|
+
width: window.innerWidth,
|
|
77
|
+
height: window.innerHeight,
|
|
78
|
+
},
|
|
79
|
+
timestamp,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: RRWEB_TYPE_FULL_SNAPSHOT,
|
|
83
|
+
data: {
|
|
84
|
+
node,
|
|
85
|
+
initialOffset: { left: window.scrollX || 0, top: window.scrollY || 0 },
|
|
86
|
+
},
|
|
87
|
+
timestamp,
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
sendEvents(events, 'snapshot', push);
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../src/replay/snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAM,CAAC;AAC7C,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAE3C,iEAAiE;AACjE,MAAM,wBAAwB,GAAG,CAAC,CAAC;AACnC,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B,IAAI,aAAa,GAAG,CAAC,CAAC;AACtB,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAU,CAAC;AAE9C,4BAA4B;AAC5B,MAAM,UAAU,6BAA6B;IAC3C,aAAa,GAAG,CAAC,CAAC;IAClB,mBAAmB,CAAC,KAAK,EAAE,CAAC;AAC9B,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC1C,CAAC;AAaD;;;;GAIG;AACH,MAAM,CAAC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MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;oBACpC,KAAK,EAAE,MAAM,CAAC,UAAU;oBACxB,MAAM,EAAE,MAAM,CAAC,WAAW;iBAC3B;gBACD,SAAS;aACV;YACD;gBACE,IAAI,EAAE,wBAAwB;gBAC9B,IAAI,EAAE;oBACJ,IAAI;oBACJ,aAAa,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,OAAO,IAAI,CAAC,EAAE;iBACvE;gBACD,SAAS;aACV;SAC4B,CAAC;QAEhC,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chunked, compressed replay transport (nais/grafana-apm-app#58, #67).
|
|
3
|
+
*
|
|
4
|
+
* Wire contract (the plugin reader is built against this — do not deviate):
|
|
5
|
+
* each chunk is one Faro event `faro.session_recording.chunk` with string
|
|
6
|
+
* attributes:
|
|
7
|
+
* - `chunk_seq`: monotonically increasing integer per session, starting 0
|
|
8
|
+
* - `mode`: "snapshot" (#67) or "recording" (#58)
|
|
9
|
+
* - `enc`: "gzip+b64" (versions the format)
|
|
10
|
+
* - `count`: number of rrweb events in the chunk
|
|
11
|
+
* - `first_ts`/`last_ts`: epoch ms of first/last rrweb event in the chunk
|
|
12
|
+
* - `data`: base64(gzip(JSON.stringify(eventWithTime[]))), ≤ 96 000 chars
|
|
13
|
+
* - `dropped`: (optional) events dropped because a single rrweb event
|
|
14
|
+
* exceeded the cap on its own
|
|
15
|
+
*
|
|
16
|
+
* Compression: fflate `gzipSync`. Chosen over native `CompressionStream`
|
|
17
|
+
* because it is a single synchronous code path (no stream plumbing, no async
|
|
18
|
+
* fallback fork), ~8 KB, works identically in every browser and in jsdom
|
|
19
|
+
* tests, and the inputs are small (≤ 64 KB buffers; snapshots up to a few MB
|
|
20
|
+
* compress in low tens of ms). This module is only ever loaded lazily, so its
|
|
21
|
+
* size never touches apps that don't opt in.
|
|
22
|
+
*/
|
|
23
|
+
import type { eventWithTime } from '@grafana/rrweb';
|
|
24
|
+
import type { ReplayMode } from './constants.js';
|
|
25
|
+
export { REPLAY_CHUNK_EVENT_NAME, REPLAY_ENCODING, MAX_CHUNK_B64_CHARS } from './constants.js';
|
|
26
|
+
export type { ReplayMode } from './constants.js';
|
|
27
|
+
/** Sink for one chunk event; in production this wraps `faro.api.pushEvent`. */
|
|
28
|
+
export type PushChunk = (name: string, attributes: Record<string, string>) => void;
|
|
29
|
+
/** @internal test helper */
|
|
30
|
+
export declare function _resetChunkSeqForTesting(): void;
|
|
31
|
+
/**
|
|
32
|
+
* base64(gzip(JSON.stringify(events))) — the `data` attr payload.
|
|
33
|
+
*
|
|
34
|
+
* A PII scrub pass runs over the serialized rrweb events BEFORE gzip: this is
|
|
35
|
+
* the last (and only) point where `scrub.ts`'s fnr/email/token patterns can
|
|
36
|
+
* reach attribute values and URLs inside the node tree — once gzipped, Faro's
|
|
37
|
+
* `beforeSend` scrubber is structurally blind to the content.
|
|
38
|
+
*/
|
|
39
|
+
export declare function encodeEvents(events: readonly eventWithTime[]): string;
|
|
40
|
+
interface BuiltChunk {
|
|
41
|
+
data: string;
|
|
42
|
+
events: eventWithTime[];
|
|
43
|
+
}
|
|
44
|
+
export interface BuildChunksResult {
|
|
45
|
+
chunks: BuiltChunk[];
|
|
46
|
+
/** Events dropped because a single event exceeded the cap on its own. */
|
|
47
|
+
dropped: number;
|
|
48
|
+
droppedFirstTs: number | undefined;
|
|
49
|
+
droppedLastTs: number | undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Split an event array into encoded chunks whose `data` never exceeds
|
|
53
|
+
* `maxB64Chars` (binary split, order-preserving).
|
|
54
|
+
*/
|
|
55
|
+
export declare function buildChunks(events: readonly eventWithTime[], maxB64Chars?: number): BuildChunksResult;
|
|
56
|
+
/**
|
|
57
|
+
* Chunk, compress and push an event batch per the wire contract. Assigns the
|
|
58
|
+
* session-scoped `chunk_seq`. Never throws.
|
|
59
|
+
*/
|
|
60
|
+
export declare function sendEvents(events: readonly eventWithTime[], mode: ReplayMode, push: PushChunk): void;
|
|
61
|
+
/**
|
|
62
|
+
* Buffering front-end: accumulates rrweb events and flushes a chunk batch
|
|
63
|
+
* after ≤ `MAX_BUFFER_MS` or once ≥ `MAX_BUFFER_BYTES` of serialized JSON has
|
|
64
|
+
* accumulated, whichever comes first.
|
|
65
|
+
*/
|
|
66
|
+
export declare class ReplayTransport {
|
|
67
|
+
private readonly mode;
|
|
68
|
+
private readonly push;
|
|
69
|
+
private readonly maxBufferMs;
|
|
70
|
+
private readonly maxBufferBytes;
|
|
71
|
+
private buffer;
|
|
72
|
+
private bufferedBytes;
|
|
73
|
+
private timer;
|
|
74
|
+
constructor(mode: ReplayMode, push: PushChunk, maxBufferMs?: number, maxBufferBytes?: number);
|
|
75
|
+
enqueue(event: eventWithTime): void;
|
|
76
|
+
enqueueAll(events: readonly eventWithTime[]): void;
|
|
77
|
+
/** Flush pending events immediately (also used for the on-error ring buffer). */
|
|
78
|
+
flush(): void;
|
|
79
|
+
/** Flush and stop the timer; the transport can still be reused afterwards. */
|
|
80
|
+
dispose(): void;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/replay/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAWpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,mBAAmB,EA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