@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 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AA4EH;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,MAA8C;IAC3E,IAAI,MAAM,IAAI,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QACjD,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,OAAO,GAAkB,EAAE,CAAC;IAClC,IAAI,MAAM,CAAC,GAAG,EAAE,IAAI;QAAE,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;IACpD,IAAI,MAAM,CAAC,GAAG,EAAE,SAAS;QAAE,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;IACpE,IAAI,MAAM,CAAC,GAAG,EAAE,OAAO;QAAE,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC;IAC9D,IAAI,MAAM,CAAC,WAAW;QAAE,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IACjE,IAAI,MAAM,CAAC,qBAAqB;QAAE,OAAO,CAAC,YAAY,GAAG,MAAM,CAAC,qBAAqB,CAAC;IACtF,OAAO,OAAO,CAAC;AACjB,CAAC;AAMD;;;;GAIG;AACH,SAAS,OAAO,CAAC,GAA6B;IAC5C,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC;QACpB,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1C,CAAC;IAAC,MAAM,CA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C5E,6EAA6E;IAC7E,6EAA6E;IAC7E,IAAI,iBAAiB,IAAI,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;QACzD,sBAAsB,GAAG,IAAI,CAAC;QAC9B,MAAM,OAAO,GACX,6FAA6F;YAC7F,sFAAsF;YACtF,wDAAwD,CAAC;QAC3D,sCAAsC;QACtC,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO;QACL,GAAG,EAAE,GAAG,IAAI,aAAa;QACzB,SAAS,EAAE,iBAAiB,IAAI,cAAc;QAC9C,OAAO;QACP,WAAW;QACX,YAAY;QACZ,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replacement console-error instrumentation (nais/grafana-apm-app#66, Phase 1).
|
|
3
|
+
*
|
|
4
|
+
* Faro's own console instrumentation only extracts an Error from the *first*
|
|
5
|
+
* argument; `console.error('msg', err)` — the idiom every logger utility uses —
|
|
6
|
+
* gets a synthetic stack polluted with Faro SDK frames and `[object Object]`
|
|
7
|
+
* values. This instrumentation:
|
|
8
|
+
*
|
|
9
|
+
* 1. finds an Error in *any* argument position (Sentry parity) and pushes it
|
|
10
|
+
* with its ORIGINAL stack, moving the remaining args to
|
|
11
|
+
* `context.console_message`;
|
|
12
|
+
* 2. otherwise serializes object args as depth-2, 2 KB-capped, circular-safe
|
|
13
|
+
* JSON (never `[object Object]`, never `{}`) and pushes a synthetic error.
|
|
14
|
+
*
|
|
15
|
+
* Faro must be initialized with `getWebInstrumentations({ captureConsole: false })`
|
|
16
|
+
* so only one console patch is active — `init()` in this package does that.
|
|
17
|
+
*/
|
|
18
|
+
import { BaseInstrumentation } from '@grafana/faro-web-sdk';
|
|
19
|
+
export declare const CONSOLE_ERROR_PREFIX = "console.error: ";
|
|
20
|
+
export declare class NaisConsoleInstrumentation extends BaseInstrumentation {
|
|
21
|
+
readonly name = "@nais/apm-console-instrumentation";
|
|
22
|
+
readonly version = "0.2.0";
|
|
23
|
+
private originalConsoleError;
|
|
24
|
+
initialize(): void;
|
|
25
|
+
destroy(): void;
|
|
26
|
+
private captureConsoleError;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=console.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,mBAAmB,EAAW,MAAM,uBAAuB,CAAC;AAMrE,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AAEtD,qBAAa,0BAA2B,SAAQ,mBAAmB;IACjE,QAAQ,CAAC,IAAI,uCAAuC;IACpD,QAAQ,CAAC,OAAO,WAAW;IAE3B,OAAO,CAAC,oBAAoB,CAA+B;IAE3D,UAAU,IAAI,IAAI,CAejB;IAED,OAAO,IAAI,IAAI,CAKd;IAED,OAAO,CAAC,mBAAmB;CAwB5B"}
|
package/dist/console.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replacement console-error instrumentation (nais/grafana-apm-app#66, Phase 1).
|
|
3
|
+
*
|
|
4
|
+
* Faro's own console instrumentation only extracts an Error from the *first*
|
|
5
|
+
* argument; `console.error('msg', err)` — the idiom every logger utility uses —
|
|
6
|
+
* gets a synthetic stack polluted with Faro SDK frames and `[object Object]`
|
|
7
|
+
* values. This instrumentation:
|
|
8
|
+
*
|
|
9
|
+
* 1. finds an Error in *any* argument position (Sentry parity) and pushes it
|
|
10
|
+
* with its ORIGINAL stack, moving the remaining args to
|
|
11
|
+
* `context.console_message`;
|
|
12
|
+
* 2. otherwise serializes object args as depth-2, 2 KB-capped, circular-safe
|
|
13
|
+
* JSON (never `[object Object]`, never `{}`) and pushes a synthetic error.
|
|
14
|
+
*
|
|
15
|
+
* Faro must be initialized with `getWebInstrumentations({ captureConsole: false })`
|
|
16
|
+
* so only one console patch is active — `init()` in this package does that.
|
|
17
|
+
*/
|
|
18
|
+
import { BaseInstrumentation, isError } from '@grafana/faro-web-sdk';
|
|
19
|
+
import { wasErrorCaptured } from './internal.js';
|
|
20
|
+
import { serializeConsoleArgs } from './serialize.js';
|
|
21
|
+
import { VERSION } from './version.js';
|
|
22
|
+
export const CONSOLE_ERROR_PREFIX = 'console.error: ';
|
|
23
|
+
export class NaisConsoleInstrumentation extends BaseInstrumentation {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
this.name = '@nais/apm-console-instrumentation';
|
|
27
|
+
this.version = VERSION;
|
|
28
|
+
}
|
|
29
|
+
initialize() {
|
|
30
|
+
if (this.originalConsoleError) {
|
|
31
|
+
return; // already patched; stay idempotent
|
|
32
|
+
}
|
|
33
|
+
const original = console.error.bind(console);
|
|
34
|
+
this.originalConsoleError = console.error;
|
|
35
|
+
console.error = (...args) => {
|
|
36
|
+
try {
|
|
37
|
+
this.captureConsoleError(args);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
this.logError('Failed to capture console.error call', err);
|
|
41
|
+
}
|
|
42
|
+
original(...args);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
destroy() {
|
|
46
|
+
if (this.originalConsoleError) {
|
|
47
|
+
console.error = this.originalConsoleError;
|
|
48
|
+
this.originalConsoleError = undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
captureConsoleError(args) {
|
|
52
|
+
const error = args.find((arg) => isError(arg));
|
|
53
|
+
if (error) {
|
|
54
|
+
if (wasErrorCaptured(error)) {
|
|
55
|
+
// Another capture path (ApmErrorBoundary) already owns this error and
|
|
56
|
+
// reports it with fingerprint + component stack. React 19 logs caught
|
|
57
|
+
// render errors through console.error too; skip so it lands once (#36).
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Real Error found (any position): push it as-is so Faro parses the
|
|
61
|
+
// ORIGINAL stack; preserve the remaining args as context.
|
|
62
|
+
const rest = args.filter((arg) => arg !== error);
|
|
63
|
+
this.api.pushError(error, rest.length > 0 ? { context: { console_message: serializeConsoleArgs(rest) } } : undefined);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// No Error anywhere: an honest synthetic error with a readable message.
|
|
67
|
+
const message = serializeConsoleArgs(args);
|
|
68
|
+
this.api.pushError(new Error(CONSOLE_ERROR_PREFIX + message));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAEtD,MAAM,OAAO,0BAA2B,SAAQ,mBAAmB;IAAnE;;QACW,SAAI,GAAG,mCAAmC,CAAC;QAC3C,YAAO,GAAG,OAAO,CAAC;IAoD7B,CAAC;IAhDC,UAAU;QACR,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC9B,OAAO,CAAC,mCAAmC;QAC7C,CAAC;QACD,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7C,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,KAAK,CAAC;QAE1C,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,IAAe,EAAQ,EAAE;YAC3C,IA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AAoB,GAAG,OAAO,CAAC,CAAC,CAAC;IAChE,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replacement `window.onerror` + `unhandledrejection` instrumentation.
|
|
3
|
+
*
|
|
4
|
+
* Faro's built-in `ErrorsInstrumentation` (`@grafana/faro-web-sdk` 2.11.0)
|
|
5
|
+
* already forwards the real `Error` as `pushError`'s `originalError` option
|
|
6
|
+
* for `window.onerror` — but NOT for `unhandledrejection`
|
|
7
|
+
* (`registerOnunhandledrejection` only passes `{ type, stackFrames }`). With
|
|
8
|
+
* `preserveOriginalError` enabled that means a rejected promise's actual
|
|
9
|
+
* Error instance never reaches a custom `beforeSend`. Worse: because Faro's
|
|
10
|
+
* listener is registered first (during `init()`, before application code
|
|
11
|
+
* runs), it pushes its `originalError`-less item first; if the application
|
|
12
|
+
* also listens for `unhandledrejection` and calls `captureException` with the
|
|
13
|
+
* same error, Faro's `dedupe` (on by default) sees an identical payload and
|
|
14
|
+
* silently drops the second, "good" call.
|
|
15
|
+
*
|
|
16
|
+
* This instrumentation is a drop-in replacement for Faro's
|
|
17
|
+
* `ErrorsInstrumentation` — `window.onerror` behavior matches upstream, and
|
|
18
|
+
* `unhandledrejection` is the same logic (including its `reason`/`detail`
|
|
19
|
+
* fallback chain) with `originalError` added — so there is exactly one
|
|
20
|
+
* listener per event type and no dedupe race. Idempotent (`initialize()`
|
|
21
|
+
* twice is a no-op) and `destroy()` only restores a previously-installed
|
|
22
|
+
* `window.onerror` if nothing else has replaced it since. `init()` excludes
|
|
23
|
+
* the built-in `ErrorsInstrumentation` from `getWebInstrumentations()` and
|
|
24
|
+
* registers this one instead (same pattern as `NaisConsoleInstrumentation`,
|
|
25
|
+
* nais/grafana-apm-app#66).
|
|
26
|
+
*/
|
|
27
|
+
import { BaseInstrumentation } from '@grafana/faro-web-sdk';
|
|
28
|
+
/** Name Faro's own instrumentation registers under — excluded in `init()`. */
|
|
29
|
+
export declare const FARO_ERRORS_INSTRUMENTATION_NAME = "@grafana/faro-web-sdk:instrumentation-errors";
|
|
30
|
+
export declare class NaisErrorsInstrumentation extends BaseInstrumentation {
|
|
31
|
+
readonly name = "@nais/apm-errors-instrumentation";
|
|
32
|
+
readonly version = "0.2.0";
|
|
33
|
+
private previousOnerror;
|
|
34
|
+
private installedOnerror;
|
|
35
|
+
/** @internal exposed for tests */
|
|
36
|
+
unhandledRejectionHandler: ((evt: PromiseRejectionEvent) => void) | undefined;
|
|
37
|
+
initialize(): void;
|
|
38
|
+
destroy(): void;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EACL,mBAAmB,EAYpB,MAAM,uBAAuB,CAAC;AAK/B,8EAA8E;AAC9E,eAAO,MAAM,gCAAgC,iDAAiD,CAAC;AAuI/F,qBAAa,yBAA0B,SAAQ,mBAAmB;IAChE,QAAQ,CAAC,IAAI,sCAAsC;IACnD,QAAQ,CAAC,OAAO,WAAW;IAE3B,OAAO,CAAC,eAAe,CAAoC;IAC3D,OAAO,CAAC,gBAAgB,CAAoC;IAC5D,kCAAkC;IAClC,yBAAyB,EAAE,CAAC,CAAC,GAAG,EAAE,qBAAqB,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAE9E,UAAU,IAAI,IAAI,CAQjB;IAED,OAAO,IAAI,IAAI,CAcd;CACF"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replacement `window.onerror` + `unhandledrejection` instrumentation.
|
|
3
|
+
*
|
|
4
|
+
* Faro's built-in `ErrorsInstrumentation` (`@grafana/faro-web-sdk` 2.11.0)
|
|
5
|
+
* already forwards the real `Error` as `pushError`'s `originalError` option
|
|
6
|
+
* for `window.onerror` — but NOT for `unhandledrejection`
|
|
7
|
+
* (`registerOnunhandledrejection` only passes `{ type, stackFrames }`). With
|
|
8
|
+
* `preserveOriginalError` enabled that means a rejected promise's actual
|
|
9
|
+
* Error instance never reaches a custom `beforeSend`. Worse: because Faro's
|
|
10
|
+
* listener is registered first (during `init()`, before application code
|
|
11
|
+
* runs), it pushes its `originalError`-less item first; if the application
|
|
12
|
+
* also listens for `unhandledrejection` and calls `captureException` with the
|
|
13
|
+
* same error, Faro's `dedupe` (on by default) sees an identical payload and
|
|
14
|
+
* silently drops the second, "good" call.
|
|
15
|
+
*
|
|
16
|
+
* This instrumentation is a drop-in replacement for Faro's
|
|
17
|
+
* `ErrorsInstrumentation` — `window.onerror` behavior matches upstream, and
|
|
18
|
+
* `unhandledrejection` is the same logic (including its `reason`/`detail`
|
|
19
|
+
* fallback chain) with `originalError` added — so there is exactly one
|
|
20
|
+
* listener per event type and no dedupe race. Idempotent (`initialize()`
|
|
21
|
+
* twice is a no-op) and `destroy()` only restores a previously-installed
|
|
22
|
+
* `window.onerror` if nothing else has replaced it since. `init()` excludes
|
|
23
|
+
* the built-in `ErrorsInstrumentation` from `getWebInstrumentations()` and
|
|
24
|
+
* registers this one instead (same pattern as `NaisConsoleInstrumentation`,
|
|
25
|
+
* nais/grafana-apm-app#66).
|
|
26
|
+
*/
|
|
27
|
+
import { BaseInstrumentation, buildStackFrame, defaultExceptionType, getStackFramesFromError, isDomError, isDomException, isError, isErrorEvent, isEvent, isObject, isPrimitive, isString, } from '@grafana/faro-web-sdk';
|
|
28
|
+
import { VERSION } from './version.js';
|
|
29
|
+
/** Name Faro's own instrumentation registers under — excluded in `init()`. */
|
|
30
|
+
export const FARO_ERRORS_INSTRUMENTATION_NAME = '@grafana/faro-web-sdk:instrumentation-errors';
|
|
31
|
+
const PRIMITIVE_UNHANDLED_VALUE = 'Non-Error promise rejection captured with value:';
|
|
32
|
+
const PRIMITIVE_UNHANDLED_TYPE = 'UnhandledRejection';
|
|
33
|
+
const DOM_ERROR_TYPE = 'DOMError';
|
|
34
|
+
const DOM_EXCEPTION_TYPE = 'DOMException';
|
|
35
|
+
const OBJECT_EVENT_VALUE = 'Non-Error exception captured with keys:';
|
|
36
|
+
// Ported verbatim from Faro's internal `valueTypeRegex` — extracts an
|
|
37
|
+
// `Error:`-style name/message pair out of a plain onerror string message.
|
|
38
|
+
const VALUE_TYPE_REGEX = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;
|
|
39
|
+
function getValueAndTypeFromMessage(message) {
|
|
40
|
+
const groups = message.match(VALUE_TYPE_REGEX);
|
|
41
|
+
return [groups?.[2] ?? message, groups?.[1] ?? defaultExceptionType];
|
|
42
|
+
}
|
|
43
|
+
/** Port of Faro's internal `getErrorDetails` (window.onerror + unhandledrejection reason parsing). */
|
|
44
|
+
function getErrorDetails(evt) {
|
|
45
|
+
let value;
|
|
46
|
+
let type;
|
|
47
|
+
let stackFrames = [];
|
|
48
|
+
if (isErrorEvent(evt) && evt.error) {
|
|
49
|
+
const error = evt.error;
|
|
50
|
+
value = error.message;
|
|
51
|
+
type = error.name;
|
|
52
|
+
stackFrames = getStackFramesFromError(error);
|
|
53
|
+
}
|
|
54
|
+
else if (isDomError(evt) || isDomException(evt)) {
|
|
55
|
+
const { name, message } = evt;
|
|
56
|
+
type = name || (isDomError(evt) ? DOM_ERROR_TYPE : DOM_EXCEPTION_TYPE);
|
|
57
|
+
value = message ? `${type}: ${message}` : type;
|
|
58
|
+
}
|
|
59
|
+
else if (isError(evt)) {
|
|
60
|
+
type = evt.name;
|
|
61
|
+
value = evt.message;
|
|
62
|
+
stackFrames = getStackFramesFromError(evt);
|
|
63
|
+
}
|
|
64
|
+
else if (isObject(evt) || isEvent(evt)) {
|
|
65
|
+
type = isEvent(evt) ? evt.constructor.name : undefined;
|
|
66
|
+
value = `${OBJECT_EVENT_VALUE} ${Object.keys(evt)}`;
|
|
67
|
+
}
|
|
68
|
+
return { value, type, stackFrames };
|
|
69
|
+
}
|
|
70
|
+
/** Port of Faro's internal `getDetailsFromErrorArgs` (window.onerror's 5-arg callback shape). */
|
|
71
|
+
function getDetailsFromErrorArgs(args) {
|
|
72
|
+
const [evt, source, lineno, colno, error] = args;
|
|
73
|
+
const eventIsString = isString(evt);
|
|
74
|
+
const initialStackFrame = buildStackFrame(source, '?', lineno, colno);
|
|
75
|
+
if (error || !eventIsString) {
|
|
76
|
+
const details = getErrorDetails(error ?? evt);
|
|
77
|
+
return {
|
|
78
|
+
value: details.value,
|
|
79
|
+
type: details.type,
|
|
80
|
+
stackFrames: details.stackFrames.length > 0 ? details.stackFrames : [initialStackFrame],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const [value, type] = getValueAndTypeFromMessage(evt);
|
|
84
|
+
return { value, type, stackFrames: [initialStackFrame] };
|
|
85
|
+
}
|
|
86
|
+
function registerOnerror(instrumentation) {
|
|
87
|
+
const oldOnerror = window.onerror;
|
|
88
|
+
window.onerror = (...args) => {
|
|
89
|
+
try {
|
|
90
|
+
const { value, type, stackFrames } = getDetailsFromErrorArgs(args);
|
|
91
|
+
const originalError = args[4];
|
|
92
|
+
if (value) {
|
|
93
|
+
const options = { type, stackFrames };
|
|
94
|
+
if (originalError != null) {
|
|
95
|
+
options.originalError = originalError;
|
|
96
|
+
}
|
|
97
|
+
instrumentation.api.pushError(new Error(value), options);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
oldOnerror?.apply(window, args);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function registerOnunhandledrejection(instrumentation) {
|
|
106
|
+
const handler = (evt) => {
|
|
107
|
+
const detail = evt.detail;
|
|
108
|
+
// Port of Faro's exact fallback chain: prefer `evt.reason`, then
|
|
109
|
+
// `evt.detail?.reason` (older Cordova/polyfill shape), and — if NEITHER
|
|
110
|
+
// is truthy (e.g. reason is `null`/`undefined`/`0`/`''`) — fall through to
|
|
111
|
+
// treating the whole event itself as the "error" to describe, same as
|
|
112
|
+
// upstream. Losing this fallback would silently drop such rejections
|
|
113
|
+
// instead of reporting a synthetic "Non-Error exception" for them.
|
|
114
|
+
let reason = evt;
|
|
115
|
+
if (evt.reason) {
|
|
116
|
+
reason = evt.reason;
|
|
117
|
+
}
|
|
118
|
+
else if (detail?.reason) {
|
|
119
|
+
reason = detail.reason;
|
|
120
|
+
}
|
|
121
|
+
let value;
|
|
122
|
+
let type;
|
|
123
|
+
let stackFrames = [];
|
|
124
|
+
// The fix: an actual Error reason is the only shape that can carry
|
|
125
|
+
// `originalError` (Faro types it as `Error`) — primitives/plain objects
|
|
126
|
+
// never had one to preserve in the first place.
|
|
127
|
+
const originalError = reason instanceof Error ? reason : undefined;
|
|
128
|
+
if (isPrimitive(reason)) {
|
|
129
|
+
value = `${PRIMITIVE_UNHANDLED_VALUE} ${String(reason)}`;
|
|
130
|
+
type = PRIMITIVE_UNHANDLED_TYPE;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
({ value, type, stackFrames } = getErrorDetails(reason));
|
|
134
|
+
}
|
|
135
|
+
if (value) {
|
|
136
|
+
const options = { type, stackFrames };
|
|
137
|
+
if (originalError) {
|
|
138
|
+
options.originalError = originalError;
|
|
139
|
+
}
|
|
140
|
+
instrumentation.api.pushError(new Error(value), options);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
window.addEventListener('unhandledrejection', handler);
|
|
144
|
+
instrumentation.unhandledRejectionHandler = handler;
|
|
145
|
+
}
|
|
146
|
+
export class NaisErrorsInstrumentation extends BaseInstrumentation {
|
|
147
|
+
constructor() {
|
|
148
|
+
super(...arguments);
|
|
149
|
+
this.name = '@nais/apm-errors-instrumentation';
|
|
150
|
+
this.version = VERSION;
|
|
151
|
+
}
|
|
152
|
+
initialize() {
|
|
153
|
+
if (this.installedOnerror) {
|
|
154
|
+
return; // already patched; stay idempotent (see NaisConsoleInstrumentation)
|
|
155
|
+
}
|
|
156
|
+
this.previousOnerror = window.onerror;
|
|
157
|
+
registerOnerror(this);
|
|
158
|
+
this.installedOnerror = window.onerror;
|
|
159
|
+
registerOnunhandledrejection(this);
|
|
160
|
+
}
|
|
161
|
+
destroy() {
|
|
162
|
+
if (this.unhandledRejectionHandler) {
|
|
163
|
+
window.removeEventListener('unhandledrejection', this.unhandledRejectionHandler);
|
|
164
|
+
this.unhandledRejectionHandler = undefined;
|
|
165
|
+
}
|
|
166
|
+
// Only restore the PRE-init handler if `window.onerror` is still the
|
|
167
|
+
// wrapper we installed — some other code may have replaced it since
|
|
168
|
+
// (e.g. another instrumentation/library); stomping on that would silently
|
|
169
|
+
// disable its error reporting.
|
|
170
|
+
if (this.installedOnerror && window.onerror === this.installedOnerror) {
|
|
171
|
+
window.onerror = this.previousOnerror ?? null;
|
|
172
|
+
}
|
|
173
|
+
this.installedOnerror = undefined;
|
|
174
|
+
this.previousOnerror = undefined;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,UAAU,EACV,cAAc,EACd,OAAO,EACP,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,WAAW,EACX,QAAQ,GACT,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,gCAAgC,GAAG,8CAA8C,CAAC;AAE/F,MAAM,yBAAyB,GAAG,kDAAkD,CAAC;AACrF,MAAM,wBAAwB,GAAG,oBAAoB,CAAC;AACtD,MAAM,cAAc,GAA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AAC;QACD,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC;QACtC,eAAe,CAAC,IAAI,CAAC,CAAC;QACtB,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC;QACvC,4BAA4B,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,OAAO;QACL,IAAI,IAAI,CAAC,yBAAyB,EAAE,CAAC;YACnC,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,IAAI,CAAC,yBAAyB,CAAC,CAAC;YACjF,IAAI,CAAC,yBAAyB,GAAG,SAAS,CAAC;QAC7C,CAAC;QACD,qEAAqE;QACrE,oEAAoE;QACpE,0EAA0E;QAC1E,+BAA+B;QAC/B,IAAI,IAAI,CAAC,gBAAgB,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC;QAChD,CAAC;QACD,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;QAClC,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User feedback capture (M6 seed): captures free-text user feedback as a
|
|
3
|
+
* Faro event so it can be joined to a session (via the Faro session id
|
|
4
|
+
* already on every event) and/or an issue (via `fingerprint`) in Loki.
|
|
5
|
+
*
|
|
6
|
+
* Wire contract (the plugin reader is built against this — do not deviate):
|
|
7
|
+
* one Faro event `faro.feedback` with string attributes:
|
|
8
|
+
* - `message`: free text, scrubbed (fnr/email/token), trimmed, ≤ 4000 chars
|
|
9
|
+
* - `category`: 'bug' | 'idea' | 'other' (default 'other')
|
|
10
|
+
* - `email`: (optional) user-volunteered contact address; included only
|
|
11
|
+
* when explicitly passed AND shaped like an email — this is
|
|
12
|
+
* NOT run through the PII email scrubber (it would just
|
|
13
|
+
* replace the whole value with `[email]`), it is validated
|
|
14
|
+
* instead
|
|
15
|
+
* - `fingerprint`: (optional) joins the feedback to a specific issue
|
|
16
|
+
* - `ctx_<key>`: (optional) flattened caller-supplied context
|
|
17
|
+
*/
|
|
18
|
+
/** Faro event name emitted by {@link captureFeedback}. */
|
|
19
|
+
export declare const FEEDBACK_EVENT_NAME = "faro.feedback";
|
|
20
|
+
export type FeedbackCategory = 'bug' | 'idea' | 'other';
|
|
21
|
+
export interface CaptureFeedbackOptions {
|
|
22
|
+
/** Defaults to 'other'. */
|
|
23
|
+
category?: FeedbackCategory;
|
|
24
|
+
/** User-volunteered contact address. Only sent when it looks email-shaped. */
|
|
25
|
+
email?: string;
|
|
26
|
+
/** Extra key/value context, flattened onto the event as `ctx_<key>` (scrubbed like `message`). */
|
|
27
|
+
context?: Record<string, string>;
|
|
28
|
+
/** Custom grouping key so feedback can be joined to a specific issue (see captureException's `fingerprint`). */
|
|
29
|
+
fingerprint?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Capture free-text user feedback. Sentry has no direct equivalent — this is
|
|
33
|
+
* `@nais/apm`'s own addition (nais/grafana-apm-app#68 M6). No-op before
|
|
34
|
+
* `init()` (a warning is emitted once by the shared Faro-instance guard).
|
|
35
|
+
*
|
|
36
|
+
* PREVIEW — NOT GA. Internal-pilot only for now, gated on the personvernombud
|
|
37
|
+
* process. The free-text `message` lands in shared Loki, so any UI wired to
|
|
38
|
+
* this MUST show a clear "do not enter personal information" warning next to
|
|
39
|
+
* the input. Do not enable on citizen-facing apps without sign-off.
|
|
40
|
+
*/
|
|
41
|
+
export declare function captureFeedback(message: string, options?: CaptureFeedbackOptions): void;
|
|
42
|
+
//# sourceMappingURL=feedback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback.d.ts","sourceRoot":"","sources":["../src/feedback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,0DAA0D;AAC1D,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AAgBnD,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;AAExD,MAAM,WAAW,sBAAsB;IACrC,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kGAAkG;IAClG,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,gHAAgH;IAChH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B,GAAG,IAAI,CAkC3F"}
|
package/dist/feedback.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User feedback capture (M6 seed): captures free-text user feedback as a
|
|
3
|
+
* Faro event so it can be joined to a session (via the Faro session id
|
|
4
|
+
* already on every event) and/or an issue (via `fingerprint`) in Loki.
|
|
5
|
+
*
|
|
6
|
+
* Wire contract (the plugin reader is built against this — do not deviate):
|
|
7
|
+
* one Faro event `faro.feedback` with string attributes:
|
|
8
|
+
* - `message`: free text, scrubbed (fnr/email/token), trimmed, ≤ 4000 chars
|
|
9
|
+
* - `category`: 'bug' | 'idea' | 'other' (default 'other')
|
|
10
|
+
* - `email`: (optional) user-volunteered contact address; included only
|
|
11
|
+
* when explicitly passed AND shaped like an email — this is
|
|
12
|
+
* NOT run through the PII email scrubber (it would just
|
|
13
|
+
* replace the whole value with `[email]`), it is validated
|
|
14
|
+
* instead
|
|
15
|
+
* - `fingerprint`: (optional) joins the feedback to a specific issue
|
|
16
|
+
* - `ctx_<key>`: (optional) flattened caller-supplied context
|
|
17
|
+
*/
|
|
18
|
+
import { getFaroInstance } from './internal.js';
|
|
19
|
+
import { scrubString } from './scrub.js';
|
|
20
|
+
/** Faro event name emitted by {@link captureFeedback}. */
|
|
21
|
+
export const FEEDBACK_EVENT_NAME = 'faro.feedback';
|
|
22
|
+
/** Caps the message length so a runaway paste can't blow up the Loki line. */
|
|
23
|
+
const MAX_MESSAGE_LENGTH = 4000;
|
|
24
|
+
/** Deliberately permissive — this only guards against obvious non-emails, not RFC 5322 validation. */
|
|
25
|
+
const EMAIL_SHAPE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
26
|
+
/**
|
|
27
|
+
* RFC 5321 caps an address at 254 chars; anything longer is not a real email.
|
|
28
|
+
* Bounding the length before EMAIL_SHAPE.test() keeps the (polynomially
|
|
29
|
+
* backtracking) shape check off unbounded untrusted input — see CodeQL
|
|
30
|
+
* js/polynomial-redos.
|
|
31
|
+
*/
|
|
32
|
+
const MAX_EMAIL_LENGTH = 254;
|
|
33
|
+
/**
|
|
34
|
+
* Capture free-text user feedback. Sentry has no direct equivalent — this is
|
|
35
|
+
* `@nais/apm`'s own addition (nais/grafana-apm-app#68 M6). No-op before
|
|
36
|
+
* `init()` (a warning is emitted once by the shared Faro-instance guard).
|
|
37
|
+
*
|
|
38
|
+
* PREVIEW — NOT GA. Internal-pilot only for now, gated on the personvernombud
|
|
39
|
+
* process. The free-text `message` lands in shared Loki, so any UI wired to
|
|
40
|
+
* this MUST show a clear "do not enter personal information" warning next to
|
|
41
|
+
* the input. Do not enable on citizen-facing apps without sign-off.
|
|
42
|
+
*/
|
|
43
|
+
export function captureFeedback(message, options = {}) {
|
|
44
|
+
const faro = getFaroInstance();
|
|
45
|
+
if (!faro) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const trimmed = message.trim().slice(0, MAX_MESSAGE_LENGTH);
|
|
49
|
+
if (trimmed === '') {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const attributes = {
|
|
53
|
+
message: scrubString(trimmed),
|
|
54
|
+
category: options.category ?? 'other',
|
|
55
|
+
};
|
|
56
|
+
if (options.email !== undefined) {
|
|
57
|
+
const email = options.email.trim();
|
|
58
|
+
if (email.length <= MAX_EMAIL_LENGTH && EMAIL_SHAPE.test(email)) {
|
|
59
|
+
attributes['email'] = email;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (options.fingerprint !== undefined) {
|
|
63
|
+
attributes['fingerprint'] = options.fingerprint;
|
|
64
|
+
}
|
|
65
|
+
for (const [key, value] of Object.entries(options.context ?? {})) {
|
|
66
|
+
if (value !== undefined) {
|
|
67
|
+
attributes[`ctx_${key}`] = scrubString(value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
faro.api.pushEvent(FEEDBACK_EVENT_NAME, attributes);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=feedback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback.js","sourceRoot":"","sources":["../src/feedback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,0DAA0D;AAC1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAEnD,8EAA8E;AAC9E,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC,sGAAsG;AACtG,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAe7B;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,OAAO,GAA2B,EAAE;IACnF,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAC/B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO;IACT,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC;IAC5D,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QACnB,OAAO;IACT,CAAC;IAED,MAAM,UAAU,GAA2B;QACzC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC;QAC7B,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,OAAO;KACtC,CAAC;IAEF,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QACnC,IAAI,KAAK,CAAC,MAAM,IAAI,gBAAgB,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAChE,UAAU,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACtC,UAAU,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IAClD,CAAC;IAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;QACjE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,UAAU,CAAC,OAAO,GAAG,EAAE,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;AACtD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nais/apm — opinionated Faro wrapper with a Sentry-like DX for nais apps.
|
|
3
|
+
*
|
|
4
|
+
* Root surface: `init`, `captureException`, `captureMessage`, `setUser`,
|
|
5
|
+
* `clearUser`, `setTag`, `setContext`, and opt-in browser tracing
|
|
6
|
+
* (`init({ tracing: true })`, lazily loaded). React helpers live in the
|
|
7
|
+
* separate `@nais/apm/react` entry point so this root stays free of React and
|
|
8
|
+
* the OpenTelemetry tracing tree.
|
|
9
|
+
*/
|
|
10
|
+
import type { BeforeSendHook, BrowserConfig, Faro, Patterns } from '@grafana/faro-web-sdk';
|
|
11
|
+
import type { ConfigOptions } from './config.js';
|
|
12
|
+
export { captureException, captureMessage, setUser, clearUser, setTag, setContext, pushMeasurement, pushEvent, } from './api.js';
|
|
13
|
+
export type { CaptureExceptionOptions, SeverityLevel, User, PushMeasurementOptions } from './api.js';
|
|
14
|
+
export { captureFeedback, FEEDBACK_EVENT_NAME } from './feedback.js';
|
|
15
|
+
export type { CaptureFeedbackOptions, FeedbackCategory } from './feedback.js';
|
|
16
|
+
export { resolveConfig, versionFromImage, fromNaisConfig, isLocalHost, navTenant } from './config.js';
|
|
17
|
+
export type { ConfigOptions, ResolvedConfig, NaisGeneratedConfig, TenantProfile } from './config.js';
|
|
18
|
+
export { getNaisMetaTags, renderNaisMetaTags } from './metaTags.js';
|
|
19
|
+
export type { NaisMetaTag } from './metaTags.js';
|
|
20
|
+
export { NaisConsoleInstrumentation, CONSOLE_ERROR_PREFIX } from './console.js';
|
|
21
|
+
export { NaisErrorsInstrumentation } from './errors.js';
|
|
22
|
+
export { scrubString } from './scrub.js';
|
|
23
|
+
export { isInitialized, markErrorCaptured } from './internal.js';
|
|
24
|
+
export { VERSION } from './version.js';
|
|
25
|
+
/**
|
|
26
|
+
* Default noise filters: browser-extension frames, benign ResizeObserver
|
|
27
|
+
* loops, and cross-origin "Script error." events without information.
|
|
28
|
+
*/
|
|
29
|
+
export declare const DEFAULT_IGNORE_ERRORS: Patterns;
|
|
30
|
+
export interface InitOptions extends ConfigOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Runs before the mandatory PII scrubber. Return `null` to drop the item.
|
|
33
|
+
* The scrubber always runs last.
|
|
34
|
+
*/
|
|
35
|
+
beforeSend?: BeforeSendHook;
|
|
36
|
+
/** Extra patterns appended to {@link DEFAULT_IGNORE_ERRORS}. */
|
|
37
|
+
ignoreErrors?: Patterns;
|
|
38
|
+
/**
|
|
39
|
+
* Disable the built-in PII scrubbing (fødselsnummer, emails, token URLs).
|
|
40
|
+
* You almost certainly do not want this; you take over GDPR responsibility
|
|
41
|
+
* for everything your app sends to Loki.
|
|
42
|
+
*/
|
|
43
|
+
dangerouslyDisablePiiScrubbing?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Escape hatch: raw Faro `BrowserConfig` overrides merged last (except
|
|
46
|
+
* `beforeSend`, which stays composed with the scrubber). Prefer the
|
|
47
|
+
* top-level options.
|
|
48
|
+
*/
|
|
49
|
+
faro?: Partial<BrowserConfig>;
|
|
50
|
+
/**
|
|
51
|
+
* PREVIEW — NOT GA. Opt-in, internal-apps-first. Session replay
|
|
52
|
+
* (nais/grafana-apm-app#58, #82). Off by default.
|
|
53
|
+
*
|
|
54
|
+
* Two independent knobs:
|
|
55
|
+
*
|
|
56
|
+
* - `tier` — the PRIVACY TIER, i.e. WHAT is captured:
|
|
57
|
+
* - `'events'` (default): a lightweight interaction timeline derived
|
|
58
|
+
* from DOM events — NO DOM node tree, structurally nothing to leak
|
|
59
|
+
* beyond (already-scrubbed) URLs. Safe by construction.
|
|
60
|
+
* - `'wireframe'`: reserved (Phase 3 — currently falls back to events).
|
|
61
|
+
* - `'dom'`: the full masked DOM recording (rrweb). Pushes DOM data into
|
|
62
|
+
* shared Loki, so it is gated on the personvernombud (data protection
|
|
63
|
+
* officer) process — do NOT enable on citizen-facing apps without
|
|
64
|
+
* sign-off. Masked at capture time by a non-overridable privacy floor
|
|
65
|
+
* (all text and inputs; unmasking only via explicit `data-apm-unmask`
|
|
66
|
+
* markup); `block` can only tighten masking.
|
|
67
|
+
*
|
|
68
|
+
* - `mode` — the CAPTURE TRIGGER, i.e. WHEN the timeline is shipped
|
|
69
|
+
* (unchanged): `'on-error'` (default) buffers in memory and sends only
|
|
70
|
+
* once an error occurs; `'always'` streams continuously.
|
|
71
|
+
*
|
|
72
|
+
* BREAKING (preview): `enabled:true` with `tier` omitted now resolves to
|
|
73
|
+
* `'events'`, not the old masked-DOM capture. Pass `tier:'dom'` to keep DOM.
|
|
74
|
+
*/
|
|
75
|
+
sessionReplay?: {
|
|
76
|
+
enabled?: boolean;
|
|
77
|
+
/** Privacy tier — WHAT is captured. Default `'events'` (no DOM). */
|
|
78
|
+
tier?: 'events' | 'wireframe' | 'dom';
|
|
79
|
+
/** Capture trigger — WHEN the timeline ships. 'on-error' (default) or 'always'. */
|
|
80
|
+
mode?: 'on-error' | 'always';
|
|
81
|
+
/** Fraction of sessions recorded, 0..1 (default 1). */
|
|
82
|
+
sampleRate?: number;
|
|
83
|
+
/** Extra CSS selectors to block entirely (tighten-only; DOM tier). */
|
|
84
|
+
block?: string[];
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* PREVIEW — NOT GA. Opt-in. Capture something on the FIRST error, folded into
|
|
88
|
+
* the `sessionReplay.tier` model (nais/grafana-apm-app#67, #82):
|
|
89
|
+
* - with `sessionReplay.tier:'dom'` (and no full recording running): one
|
|
90
|
+
* masked DOM snapshot per new error (throttled, capped, personvernombud-
|
|
91
|
+
* gated — it lands in shared Loki and can carry user content);
|
|
92
|
+
* - otherwise (the events-tier default): a text-free events-tier breadcrumb
|
|
93
|
+
* (URL + viewport, NO node tree) — no DOM leaves the browser.
|
|
94
|
+
* Adds nothing when a session-replay collector/recorder is already active for
|
|
95
|
+
* the session (that path already captures the error).
|
|
96
|
+
*/
|
|
97
|
+
screenshotOnError?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Opt-in browser tracing (nais/grafana-apm-app#80). Off by default. When
|
|
100
|
+
* enabled, `@grafana/faro-web-tracing` is lazily loaded (kept out of the
|
|
101
|
+
* bundle otherwise) and distributed-trace headers are propagated so browser
|
|
102
|
+
* spans join backend traces in Tempo.
|
|
103
|
+
*
|
|
104
|
+
* `true` enables tracing with the mandatory propagation floor (same-origin +
|
|
105
|
+
* `*.nav.no` only). Pass an object with `propagateExtraOrigins` to ALSO
|
|
106
|
+
* propagate trace headers to additional origins — these are appended to the
|
|
107
|
+
* floor and can never replace or empty it (a security restriction: trace
|
|
108
|
+
* headers must not leak to arbitrary third parties). The floor is not
|
|
109
|
+
* reachable through the `faro` escape hatch.
|
|
110
|
+
*/
|
|
111
|
+
tracing?: boolean | {
|
|
112
|
+
propagateExtraOrigins?: (string | RegExp)[];
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Initialize @nais/apm from a served nais generated-config file — the
|
|
117
|
+
* naiserator `spec.frontend.generatedConfig` payload mounted into the app's
|
|
118
|
+
* web root (nais/grafana-apm-app#134), or, later, the platform's well-known
|
|
119
|
+
* config URL. This is the zero-environment-config path for static SPAs: the
|
|
120
|
+
* fetched values fill any field not passed explicitly in `options`.
|
|
121
|
+
*
|
|
122
|
+
* Signals raised while the fetch is in flight (typically early errors) are
|
|
123
|
+
* buffered and flushed into Faro once initialization completes — they are not
|
|
124
|
+
* lost. If the fetch fails, initialization still proceeds with standard
|
|
125
|
+
* resolution (meta tags/env/fallbacks), which is loud about what is missing;
|
|
126
|
+
* this function never throws.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* // main.tsx — nais.json served from the web root via generatedConfig
|
|
130
|
+
* await initFromConfigUrl('/nais.json', { app: 'my-app', namespace: 'my-team' });
|
|
131
|
+
*/
|
|
132
|
+
export declare function initFromConfigUrl(url?: string, options?: InitOptions): Promise<Faro>;
|
|
133
|
+
/**
|
|
134
|
+
* Initialize @nais/apm. Zero-config on nais: app name, version, environment
|
|
135
|
+
* and collector URL are resolved from nais meta tags or build-time env; with
|
|
136
|
+
* no collector resolved (local dev) all telemetry is echoed to the console
|
|
137
|
+
* (silence that with `init({ devConsoleEcho: false })`).
|
|
138
|
+
*
|
|
139
|
+
* Opt into distributed tracing with `init({ tracing: true })`; the tracing
|
|
140
|
+
* machinery (`@grafana/faro-web-tracing`) is lazily loaded so it stays out of
|
|
141
|
+
* the bundle when tracing is not enabled.
|
|
142
|
+
*/
|
|
143
|
+
export declare function init(options?: InitOptions): Faro;
|
|
144
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAG3F,OAAO,KAAK,EAAE,aAAa,EAAuB,MAAM,aAAa,CAAC;AAOtE,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,SAAS,EACT,MAAM,EACN,UAAU,EACV,eAAe,EACf,SAAS,GACV,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,uBAAuB,EAAE,aAAa,EAAE,IAAI,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACrE,YAAY,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACtG,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACpE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC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