@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 nais
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,528 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nais/apm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A drop-in browser telemetry SDK for applications running on [nais](https://nais.io). `@nais/apm` wraps [`@grafana/faro-web-sdk`](https://github.com/grafana/faro-web-sdk) with a Sentry-like developer experience — zero-config initialization on nais, `captureException`/`captureMessage`/`setUser`-style APIs, mandatory PII scrubbing, a fixed console-capture bug, and opt-in session replay / crash snapshots — and ships everything to your team's self-hosted Grafana LGTM stack (Alloy `faro.receiver` → Loki/Tempo/Mimir) instead of a third-party SaaS.
|
|
4
|
+
|
|
5
|
+
> **Status: pre-1.0.** In active development and released continuously (see [Releases](https://github.com/nais/apm/releases) for the current version). The public API may still change before 1.0 — pin an exact version and expect breaking changes to land in minor releases until then. Feedback and issues are very welcome: [nais/apm/issues](https://github.com/nais/apm/issues).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
`@nais/apm` is published to the **GitHub Package Registry** (GHPR) under the `nais` org, not to npmjs.org (yet).
|
|
10
|
+
|
|
11
|
+
GHPR requires an authenticated request to resolve _any_ package under a scope — including public ones — so even though `@nais/apm` itself is public, installing it needs a GitHub [Personal Access Token](https://github.com/settings/tokens) with the **`read:packages`** scope. This is a one-time setup per machine/CI job.
|
|
12
|
+
|
|
13
|
+
1. Create a classic PAT with the `read:packages` scope (fine-grained tokens work too, as long as they can read packages for the `nais` org).
|
|
14
|
+
2. Add these two lines to your project's `.npmrc` (create the file if it doesn't exist):
|
|
15
|
+
|
|
16
|
+
```ini
|
|
17
|
+
@nais:registry=https://npm.pkg.github.com
|
|
18
|
+
//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
3. Export the token in your shell (or CI secret store) as `GITHUB_PACKAGES_TOKEN`:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
export GITHUB_PACKAGES_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
4. Install:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
pnpm add @nais/apm
|
|
31
|
+
# or: npm install @nais/apm / yarn add @nais/apm
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
> This friction is a GHPR limitation, not a `@nais/apm` design choice. A future move to npmjs.org (`npmjs.com/package/@nais/apm`) would let anyone `npm install @nais/apm` with no token at all — it's on the roadmap once the package is stable.
|
|
35
|
+
|
|
36
|
+
## Quickstart
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
// main.tsx — the canonical call: two code-time constants, everything else resolved
|
|
40
|
+
import { init } from '@nais/apm';
|
|
41
|
+
|
|
42
|
+
init({ app: 'my-app', namespace: 'my-team' });
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
For a standalone frontend, add
|
|
46
|
+
`tracing: true` for it to appear in Grafana APM. See [Browser tracing](#browser-tracing).
|
|
47
|
+
|
|
48
|
+
`app` and `namespace` are constants — identical in every environment — so passing
|
|
49
|
+
them in code is correct, not a compromise. What actually varies per deploy
|
|
50
|
+
(`environment`, the collector URL) is resolved at runtime; how depends on how your
|
|
51
|
+
app is served — see [Setup per serving architecture](#setup-per-serving-architecture).
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
// Sentry-style usage anywhere in your app
|
|
55
|
+
import { captureException, captureMessage, setUser, setContext } from '@nais/apm';
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
await save(form);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
captureException(e, { context: { form: 'checkout-step-2' } });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
captureMessage('fallback flow used', 'warning');
|
|
64
|
+
setUser({ id: hashedSubject });
|
|
65
|
+
setContext('feature', { newCheckoutFlow: 'variant-b' });
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
That's it on nais: `init()` resolves app name, version, environment, and the collector URL automatically (see [Configuration resolution](#configuration-resolution) below). Off nais — e.g. on `localhost` — nothing is sent over the network; every signal is echoed to the browser console instead (see [Local development](#local-development)).
|
|
69
|
+
|
|
70
|
+
## API reference
|
|
71
|
+
|
|
72
|
+
### `init(options?)`
|
|
73
|
+
|
|
74
|
+
Initializes the SDK. Safe to call once; a second call warns and returns the existing instance.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { init } from '@nais/apm';
|
|
78
|
+
|
|
79
|
+
init({
|
|
80
|
+
// Each field resolves independently if omitted (see below). `namespace` (the
|
|
81
|
+
// owning nais team) is effectively required — telemetry without it can't be
|
|
82
|
+
// attributed to a team; if it can't be resolved the SDK loud-warns and falls
|
|
83
|
+
// back to `unknown-team` (it never throws).
|
|
84
|
+
app: 'my-app',
|
|
85
|
+
namespace: 'my-team',
|
|
86
|
+
version: '2026.07.04-abc1234',
|
|
87
|
+
environment: 'prod-gcp',
|
|
88
|
+
telemetryUrl: undefined, // usually omitted — resolved automatically on nais
|
|
89
|
+
|
|
90
|
+
beforeSend: (item) => item, // runs before the mandatory PII scrubber
|
|
91
|
+
ignoreErrors: [/some noisy vendor error/],
|
|
92
|
+
dangerouslyDisablePiiScrubbing: false, // see Privacy section — don't flip this without a reason
|
|
93
|
+
faro: {}, // escape hatch: raw Faro BrowserConfig overrides
|
|
94
|
+
|
|
95
|
+
sessionReplay: { enabled: false }, // see Session replay & crash snapshots
|
|
96
|
+
screenshotOnError: false,
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### Configuration resolution
|
|
101
|
+
|
|
102
|
+
Each field (`app`, `namespace`, `version`, `environment`, `telemetryUrl`) resolves independently, highest priority first:
|
|
103
|
+
|
|
104
|
+
1. **Explicit `init()` options.**
|
|
105
|
+
2. **nais meta tags** in the served HTML:
|
|
106
|
+
```html
|
|
107
|
+
<meta name="nais-app" content="my-app" />
|
|
108
|
+
<meta name="nais-team" content="my-team" />
|
|
109
|
+
<meta name="nais-cluster" content="prod-gcp" />
|
|
110
|
+
<meta name="nais-version" content="2026.07.03-abc1234" />
|
|
111
|
+
<meta name="nais-telemetry-url" content="https://telemetry.<tenant>.example/collect" />
|
|
112
|
+
```
|
|
113
|
+
The tags are rendered by **your app's own server** — the platform does not inject
|
|
114
|
+
them into HTML. Don't write them by hand: use `<NaisMetaTags />` /
|
|
115
|
+
`getNaisMetaTags()` (see below), which read the pod's runtime env for you.
|
|
116
|
+
3. **Environment variables** — `NAIS_APP_NAME`, `NAIS_TEAM` (or `NAIS_NAMESPACE`), `NAIS_FRONTEND_TELEMETRY_COLLECTOR_URL`, and a version derived from `GITHUB_SHA` or `NAIS_APP_IMAGE`'s tag. These are **pod-runtime** values (SSR); in a browser bundle they only exist if your bundler inlines `process.env.*` at build time — which is only ever correct for `version` (via `GITHUB_SHA`, which CI has). **Do not inline `NAIS_CLUSTER_NAME`**: the cluster is unknowable at build time — one image deploys to many clusters — so a baked-in value is wrong in at least one of them.
|
|
117
|
+
4. **Tenant fallback** — with no explicit/meta/env collector URL, the collector is derived from the cluster name (when known) or — on non-local hosts — from the page's hostname (`*.nav.no` → prod collector, `*.dev.nav.no` → dev collector). Built in for the nav tenant only, and explicitly interim: it is demoted once the platform serves config on a well-known URL. Other tenants pass their own `tenant` profile or rely on the platform channels; `tenant: false` disables derivation.
|
|
118
|
+
5. **Dev mode / loud failure** — if no collector URL resolves at all: on a genuinely local host (`localhost`, `127.0.0.1`, `*.local`) nothing is sent and everything echoes to the console (see [Local development](#local-development)); on **any other host this is a misconfiguration** and the SDK emits a specific `console.error` naming what's missing and how to fix it. It never throws.
|
|
119
|
+
|
|
120
|
+
Diagnose any resolution question with `init({ debug: true })` — it prints a per-field table of which source won.
|
|
121
|
+
|
|
122
|
+
The `namespace` (owning nais team) is special: the plugin groups and attributes all telemetry by team, so browser telemetry without it can't be reliably attributed. It resolves via the same precedence (`init({ namespace })` → `nais-team`/`nais-namespace` meta → `NAIS_TEAM`/`NAIS_NAMESPACE` env) and is wired to Faro's `app.namespace`, which the collector emits as the `app_namespace` log field. If it can't be resolved the SDK does **not** throw (that would take down your app) — it loud-warns (`console.error` on real hosts, `console.warn` in local dev) and falls back to `unknown-team`.
|
|
123
|
+
|
|
124
|
+
#### Setup per serving architecture
|
|
125
|
+
|
|
126
|
+
The nais platform provides frontend config through `spec.frontend.generatedConfig`
|
|
127
|
+
([nais docs](https://docs.nais.io/observability/frontend/)): naiserator mounts a
|
|
128
|
+
`nais.js` module (collector URL, app name/namespace/version, environment) into the
|
|
129
|
+
pod and sets `NAIS_FRONTEND_TELEMETRY_COLLECTOR_URL`. Pick the consumption path that
|
|
130
|
+
matches how your app serves HTML:
|
|
131
|
+
|
|
132
|
+
**SSR (Next.js & friends)** — render the meta tags server-side from the pod env; the
|
|
133
|
+
browser-side `init()` picks them up:
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
// app/layout.tsx (App Router) or _document.tsx <Head> (Pages Router)
|
|
137
|
+
import { NaisMetaTags } from '@nais/apm/react';
|
|
138
|
+
|
|
139
|
+
<head>
|
|
140
|
+
<NaisMetaTags />
|
|
141
|
+
</head>
|
|
142
|
+
|
|
143
|
+
// instrumentation-client.ts
|
|
144
|
+
import { initNaisAPMClient } from '@nais/apm/react';
|
|
145
|
+
initNaisAPMClient({ app: 'my-app', namespace: 'my-team' });
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Non-React SSR: `renderNaisMetaTags()` returns the same tags as an HTML string, and
|
|
149
|
+
`getNaisMetaTags()` as data. Servers that import the mounted module directly can pass
|
|
150
|
+
it through instead: `init(fromNaisConfig((await import('/app/nais.js')).default))`.
|
|
151
|
+
|
|
152
|
+
**Static SPA served from a pod (nginx/Node)** — point `generatedConfig.mountPath` into
|
|
153
|
+
your web root so the file is served, then fetch-and-init:
|
|
154
|
+
|
|
155
|
+
```yaml
|
|
156
|
+
# nais.yaml
|
|
157
|
+
spec:
|
|
158
|
+
frontend:
|
|
159
|
+
generatedConfig:
|
|
160
|
+
mountPath: /usr/share/nginx/html/nais.js
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
naiserator mounts `nais.json` (same payload, JSON) next to the `nais.js` module
|
|
164
|
+
(nais/naiserator#687), so both are served from the web root.
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
import { initFromConfigUrl } from '@nais/apm';
|
|
168
|
+
|
|
169
|
+
// Fetches the served config, then initializes. Errors thrown while the fetch
|
|
170
|
+
// is in flight are buffered and sent after init — nothing is lost. If the
|
|
171
|
+
// fetch fails, init proceeds with the standard resolution chain (loudly).
|
|
172
|
+
void initFromConfigUrl('/nais.json', { app: 'my-app', namespace: 'my-team' });
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Prefer the ESM module instead? Import it natively (keep it out of the bundle with
|
|
176
|
+
your bundler's ignore comment) and pass it through:
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
import { init, fromNaisConfig } from '@nais/apm';
|
|
180
|
+
|
|
181
|
+
const cfg = await import(/* @vite-ignore */ /* webpackIgnore: true */ '/nais.js');
|
|
182
|
+
init({ ...fromNaisConfig(cfg.default), namespace: 'my-team' });
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**CDN-served (no pod serves your HTML)** — there is no runtime injection point, so
|
|
186
|
+
pass what you know in code and let `version` come from CI:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
init({
|
|
190
|
+
app: 'my-app',
|
|
191
|
+
namespace: 'my-team',
|
|
192
|
+
// version: inlined from GITHUB_SHA by your bundler (safe — CI knows the SHA)
|
|
193
|
+
});
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
On nav domains this works as-is: the collector is derived from the page's hostname
|
|
197
|
+
(the interim tenant fallback above). Off nav domains, pass `telemetryUrl` explicitly
|
|
198
|
+
until the platform serves config on a well-known URL.
|
|
199
|
+
|
|
200
|
+
### `captureException(error, options?)`
|
|
201
|
+
|
|
202
|
+
Sentry-compatible exception capture. Note: unlike Sentry, no event ID is returned (a Faro limitation).
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
import { captureException } from '@nais/apm';
|
|
206
|
+
|
|
207
|
+
try {
|
|
208
|
+
risky();
|
|
209
|
+
} catch (e) {
|
|
210
|
+
captureException(e, {
|
|
211
|
+
context: { orderId: '123' },
|
|
212
|
+
fingerprint: 'checkout-timeout', // custom grouping key
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
If `error` is an `Error` instance, it is forwarded to Faro's `pushError` as `originalError` too. Combine this with Faro's `preserveOriginalError` (via the `faro` escape hatch) to get the actual thrown instance inside your own `beforeSend`, e.g. to branch on error type/shape in one central place before reporting:
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
init({
|
|
221
|
+
faro: { preserveOriginalError: true },
|
|
222
|
+
beforeSend: (item) => {
|
|
223
|
+
if (item.type === 'exception') {
|
|
224
|
+
const original = (item.payload as { originalError?: Error }).originalError;
|
|
225
|
+
// inspect `original` (e.g. `instanceof SomeCustomError`) and adjust/drop `item`
|
|
226
|
+
}
|
|
227
|
+
return item;
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
`originalError` is stripped from the payload right after your `beforeSend` hooks run, so it never reaches the collector — only the composed hook sees it.
|
|
233
|
+
|
|
234
|
+
This also covers errors the SDK captures automatically, not just explicit `captureException` calls: `init()` installs `NaisErrorsInstrumentation` in place of Faro's built-in `window.onerror`/`unhandledrejection` instrumentation, so `originalError` is forwarded consistently for uncaught throws *and* unhandled promise rejections (Faro's own instrumentation only forwards it for `window.onerror`, not `unhandledrejection`). If your app has its own `unhandledrejection` listener that calls `captureException(reason)` for the same rejection, you can remove it: the SDK's listener already reports it (with `originalError`) before yours would run, and Faro's `dedupe` would otherwise have silently swallowed your call anyway (see below).
|
|
235
|
+
|
|
236
|
+
> **Heads up — Faro's `dedupe` (on by default) can hide this in quick manual tests.** Faro compares each pushed error's `type`/`value`/`stacktrace`/`context`/`fingerprint`/`fatal` against the previous one; if it's identical to the last push, the call is dropped **before `beforeSend` ever runs** — so `originalError` (and the whole item) never shows up. This is why re-triggering the exact same error twice without a `fingerprint` can look like `originalError` "only works with `fingerprint`": adding a `fingerprint` (or any other context) simply makes the payload distinct enough to bypass dedupe, it isn't required for `originalError` itself. Throw/capture visibly different errors when testing, or disable it with `init({ faro: { dedupe: false } })` if you need every identical capture reported.
|
|
237
|
+
|
|
238
|
+
### `captureMessage(message, level?)`
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
import { captureMessage } from '@nais/apm';
|
|
242
|
+
|
|
243
|
+
captureMessage('fallback flow used', 'warning'); // 'fatal' | 'error' | 'warning' | 'log' | 'info' | 'debug'
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### `setUser(user)` / `clearUser()`
|
|
247
|
+
|
|
248
|
+
NAV operates on **identities**, not emails — and identities are PII that must **not** reach the shared Loki instance (every team shares it). Pass only an **opaque, non-identifying** correlation key: a salted hash of the identity, never a raw NAV ident, fødselsnummer, email, or name.
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
import { setUser, clearUser } from '@nais/apm';
|
|
252
|
+
|
|
253
|
+
setUser({ id: hashedSubject }); // hashedSubject = a salted hash, NOT an ident/fnr/email
|
|
254
|
+
// ... on logout:
|
|
255
|
+
clearUser();
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
As a safety net, `setUser` defensively drops any `id`/`username`/`attributes` value that looks like PII (fødselsnummer, email, or a raw NAV ident) and warns once; the `email` field is **deprecated** and dropped unconditionally.
|
|
259
|
+
|
|
260
|
+
### `setTag(key, value)`
|
|
261
|
+
|
|
262
|
+
Approximation of `Sentry.setTag` — Faro has no first-class tag/label concept, so the value rides along as context on every subsequent capture rather than as an indexed label.
|
|
263
|
+
|
|
264
|
+
```ts
|
|
265
|
+
import { setTag } from '@nais/apm';
|
|
266
|
+
|
|
267
|
+
setTag('featureFlag.newCheckout', true);
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### `setContext(name, context)`
|
|
271
|
+
|
|
272
|
+
Attaches named context, flattened as `name.key`, to every subsequent capture. Pass `null` to remove a previously set context.
|
|
273
|
+
|
|
274
|
+
```ts
|
|
275
|
+
import { setContext } from '@nais/apm';
|
|
276
|
+
|
|
277
|
+
setContext('order', { id: '123', total: 499 });
|
|
278
|
+
setContext('order', null); // remove it
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### `pushMeasurement(type, values, options?)` / `pushEvent(name, attributes?, domain?)`
|
|
282
|
+
|
|
283
|
+
Safe, documented entry points for **custom telemetry** — a thin wrapper over Faro's `pushMeasurement`/`pushEvent` so you don't have to reach for the raw `faro` instance. Both ride the same guarded transport as everything else, so the mandatory PII scrubbing (below) — including **NAV-ident redaction** on the string labels — runs on the way out.
|
|
284
|
+
|
|
285
|
+
```ts
|
|
286
|
+
import { pushMeasurement, pushEvent } from '@nais/apm';
|
|
287
|
+
|
|
288
|
+
// A numeric metric. `values` are numbers (the metric itself, never scrubbed).
|
|
289
|
+
pushMeasurement('checkout_latency', { ms: 812 }, { context: { page: 'oversikt' } });
|
|
290
|
+
|
|
291
|
+
// A structured event with string attributes.
|
|
292
|
+
pushEvent('feature_flag_evaluated', { flag: 'new-checkout', value: 'on' });
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Do **not** put identities (NAV idents, fødselsnummer, emails, names) in the `context`/`attributes` labels — those are string fields that land on the **shared** Loki instance. Ident-shaped values (`Z994455`), fnr, email, and token params are scrubbed automatically, but names are not pattern-shaped and will not be caught.
|
|
296
|
+
|
|
297
|
+
### `captureFeedback(message, options?)`
|
|
298
|
+
|
|
299
|
+
Free-text user feedback capture — no direct Sentry equivalent, this is `@nais/apm`'s own addition. Feedback is joined to the current session automatically, and optionally to a specific issue via `fingerprint`.
|
|
300
|
+
|
|
301
|
+
> **Preview — internal-pilot only, not GA.** The free-text `message` lands in the shared Loki instance, so any UI you wire to this **must** show a clear "do not enter personal information" warning next to the input, and — like session replay — it is gated on the personvernombud process for citizen-facing use.
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
import { captureFeedback } from '@nais/apm';
|
|
305
|
+
|
|
306
|
+
captureFeedback('The export button did nothing', {
|
|
307
|
+
category: 'bug', // 'bug' | 'idea' | 'other', default 'other'
|
|
308
|
+
email: 'user@example.com', // optional, only sent if it looks like a real email
|
|
309
|
+
fingerprint: 'export-button-noop',
|
|
310
|
+
context: { page: 'reports' },
|
|
311
|
+
});
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### `isInitialized()`
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
import { isInitialized } from '@nais/apm';
|
|
318
|
+
|
|
319
|
+
if (!isInitialized()) {
|
|
320
|
+
init();
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### `markErrorCaptured(error)`
|
|
325
|
+
|
|
326
|
+
For teams with their own React error boundary (instead of `ApmErrorBoundary` from `@nais/apm/react`) who call `captureException` directly. Marks an error as already reported so `NaisConsoleInstrumentation` doesn't report it a second time — React 19 logs every caught error via `console.error` (the default `onCaughtError`) before `componentDidCatch` runs, and the console instrumentation would otherwise treat that as a brand-new, unreported error.
|
|
327
|
+
|
|
328
|
+
Call it from `getDerivedStateFromError`, not `componentDidCatch` — the console log happens in between, so marking it any later is too late:
|
|
329
|
+
|
|
330
|
+
```tsx
|
|
331
|
+
import { captureException, markErrorCaptured } from '@nais/apm';
|
|
332
|
+
|
|
333
|
+
class MyErrorBoundary extends Component<Props, State> {
|
|
334
|
+
static getDerivedStateFromError(error: Error) {
|
|
335
|
+
markErrorCaptured(error);
|
|
336
|
+
return { error };
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
componentDidCatch(error: Error, info: ErrorInfo) {
|
|
340
|
+
captureException(error, { context: { componentStack: info.componentStack } });
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// ...render fallback UI
|
|
344
|
+
}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### `scrubString(value)`
|
|
348
|
+
|
|
349
|
+
Exposes the PII scrubber directly, e.g. if you want to sanitize a string before logging it yourself.
|
|
350
|
+
|
|
351
|
+
```ts
|
|
352
|
+
import { scrubString } from '@nais/apm';
|
|
353
|
+
|
|
354
|
+
console.log(scrubString('contact me at user@example.com'));
|
|
355
|
+
// -> "contact me at [email]"
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
## Privacy: PII scrubbing (mandatory)
|
|
359
|
+
|
|
360
|
+
Every outgoing signal (exception values, stack traces, log lines, context values, custom measurement/event labels, and the page URL) passes through a `beforeSend` scrubbing pipeline before it leaves the browser:
|
|
361
|
+
|
|
362
|
+
- **Norwegian fødselsnummer** (11 digits, sanity-checked against a plausible date prefix, including D-numbers, H-numbers, and synthetic test numbers) → `[fnr]`. A run glued to an ASCII letter or `_` (`bruker01017000027`) is caught too, but only when its mod11 control digits check out — that keeps case numbers and external identifiers that merely contain a plausible 11-digit run intact. A run glued to another digit is never masked: 11 digits inside a longer number are not an fnr. Neither is a run sitting between two lowercase hex letters, which is a slice of a traceId or UUID rather than an fnr. A non-ASCII neighbour (`æøå`) counts as a delimiter, so those runs mask on the date prefix alone — the same asymmetry the old `\b` had, and it errs toward more scrubbing.
|
|
363
|
+
- **Email addresses** → `[email]`
|
|
364
|
+
- **Token-bearing URL parameters** (`token`, `access_token`, `id_token`, `refresh_token`, `code`, `state`) → `[redacted]`
|
|
365
|
+
- **Raw NAV idents** (a letter + six digits, e.g. `Z994455`) in custom measurement `context` and event `attributes` → `[ident]`. Whole-value match only, so ordinary low-cardinality labels are left alone; numeric measurement `values` are the metric and are never touched. Names (e.g. an `enhetNavn`) are not pattern-shaped and are **not** caught — don't put them in labels.
|
|
366
|
+
|
|
367
|
+
Your own `init({ beforeSend })` hook (if any) runs **first** and may drop items by returning `null`; the scrubber always runs **last**, so it also sees anything your hook added.
|
|
368
|
+
|
|
369
|
+
Opt-out requires an explicit `init({ dangerouslyDisablePiiScrubbing: true })`. If you do that, your team owns the GDPR consequences of everything the app sends to Loki. Scrubbing is regex-based and best-effort — it is a safety net, **not** a GDPR guarantee. Do not put personal data in error messages in the first place.
|
|
370
|
+
|
|
371
|
+
## Session replay & crash snapshots (preview — opt-in, not GA)
|
|
372
|
+
|
|
373
|
+
> **Preview, not GA.** `sessionReplay` and `screenshotOnError` (like `captureFeedback`) push DOM/snapshot/free-text data that lands in the **shared** Loki instance — they can carry user content into a shared log store. They are **internal-apps-first** and gated on NAV's **personvernombud** (data protection officer) process. Do **not** enable them on citizen-facing apps without sign-off. The masking floor below is a safety net, not a substitute for that assessment.
|
|
374
|
+
|
|
375
|
+
Two related, disabled-by-default features let a team see what a user did around an error:
|
|
376
|
+
|
|
377
|
+
- **`sessionReplay`** — captures a session timeline. It has two independent knobs:
|
|
378
|
+
- **`tier`** — _what_ is captured (the privacy tier):
|
|
379
|
+
- `'events'` **(default)** — a lightweight **interaction timeline** derived from DOM events: navigation, clicks, rage-clicks, and coarse scroll, carrying only element **tag/role**, click **coordinates**, and **timestamps**. There is **no DOM node tree and no `rrweb` capture at all** on this path — structurally nothing to leak beyond URLs (which are scrubbed). This tier is safe by construction and does not pull `rrweb` into your bundle.
|
|
380
|
+
- `'wireframe'` — reserved (planned); currently falls back to `'events'`.
|
|
381
|
+
- `'dom'` — the full **masked DOM recording** (via `rrweb`). This is the pre-existing behavior and pushes DOM data into shared Loki, so it is the one tier gated on the personvernombud process.
|
|
382
|
+
- **`mode`** — _when_ the timeline is shipped (the capture trigger, unchanged): `'on-error'` (default) buffers in memory and ships only once an error occurs; `'always'` streams continuously, gated by `sampleRate`.
|
|
383
|
+
- **`screenshotOnError`** — folded into the tier model: with `tier: 'dom'` it captures one masked DOM snapshot per new error (throttled, capped per session); otherwise it degrades to a text-free **events-tier breadcrumb** (URL + viewport, no node tree). Adds nothing when a session-replay collector/recorder is already active for the session.
|
|
384
|
+
|
|
385
|
+
> **Preview default change.** `sessionReplay: { enabled: true }` with no `tier` now resolves to the **`events`** tier (no DOM). Previously it produced the masked DOM recording. Pass `tier: 'dom'` to keep DOM capture. A one-time `console.warn` flags this.
|
|
386
|
+
|
|
387
|
+
```ts
|
|
388
|
+
// Safe default: DOM-free interaction timeline.
|
|
389
|
+
init({
|
|
390
|
+
sessionReplay: {
|
|
391
|
+
enabled: true,
|
|
392
|
+
mode: 'on-error', // or 'always'
|
|
393
|
+
sampleRate: 0.5, // fraction of sessions recorded, 0..1
|
|
394
|
+
},
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// Full masked DOM recording (personvernombud-gated).
|
|
398
|
+
init({
|
|
399
|
+
sessionReplay: {
|
|
400
|
+
enabled: true,
|
|
401
|
+
tier: 'dom',
|
|
402
|
+
block: ['.no-record-me'], // extra CSS selectors to block; tighten-only
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
**These features are opt-in for a reason: a team must decide, deliberately, to turn on screen recording for its own users.** This is not a technical toggle to flip lightly — it reflects NAV's personvernombud (data protection officer) process, and each team is responsible for making that call for its own application and users, in line with its own privacy assessment.
|
|
408
|
+
|
|
409
|
+
The events tier avoids this exposure by construction — it never serializes the DOM, so there is no text/input/node content to mask. The masking floor below applies to the **DOM tier** (`tier: 'dom'` and the `tier: 'dom'` `screenshotOnError` snapshot), and is a **non-overridable** floor applied in the browser before any byte leaves the user's machine:
|
|
410
|
+
|
|
411
|
+
- every form input value is masked, with no exceptions — inputs can never be unmasked, not even via the allowlist below;
|
|
412
|
+
- all text is masked, except elements explicitly marked with a `data-apm-unmask` attribute;
|
|
413
|
+
- images, video, audio, canvas, iframes, embeds, and anything marked `data-apm-block` are always blocked, never inlined;
|
|
414
|
+
- stylesheets and images are never inlined into the capture.
|
|
415
|
+
|
|
416
|
+
The `block` option can only add more selectors to block — there is no option to relax any part of the masking floor.
|
|
417
|
+
|
|
418
|
+
## Local development
|
|
419
|
+
|
|
420
|
+
On a genuinely local host (`localhost`, `127.0.0.1`, `*.local`, `*.localhost`) with no collector URL resolved, `init()`:
|
|
421
|
+
|
|
422
|
+
- warns once: `[@nais/apm] No telemetry collector URL resolved …`,
|
|
423
|
+
- sends **nothing** over the network,
|
|
424
|
+
- echoes every signal to the browser console instead, so you can see exactly what would have been sent.
|
|
425
|
+
|
|
426
|
+
If the echo is more noise than help, turn it off:
|
|
427
|
+
|
|
428
|
+
```ts
|
|
429
|
+
init({ devConsoleEcho: false });
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
This silences both the echo and the once-only dev-mode notice — telemetry is still dropped, nothing is sent. It has no effect when a collector is resolved, and it never silences the loud misconfiguration error on non-local hosts.
|
|
433
|
+
|
|
434
|
+
Calling `captureException`/`captureMessage`/`setUser`/etc. before `init()` is a safe no-op (with a single warning).
|
|
435
|
+
|
|
436
|
+
## Escape hatch
|
|
437
|
+
|
|
438
|
+
`init({ faro: { ... } })` accepts raw Faro `BrowserConfig` overrides for anything this package doesn't expose directly. `beforeSend` is the one exception — it stays composed with the mandatory PII scrubber rather than being fully overridden.
|
|
439
|
+
|
|
440
|
+
## Browser tracing
|
|
441
|
+
|
|
442
|
+
Opt in with `init({ tracing: true })`. This lazily loads `@grafana/faro-web-tracing` (kept out of your bundle unless you enable it) and starts propagating W3C trace-context headers so browser spans join their backend traces in Tempo.
|
|
443
|
+
|
|
444
|
+
Set `app` to the same name as the corresponding backend app so Grafana APM can
|
|
445
|
+
group the frontend data with that backend. Tracing enables browser spans and
|
|
446
|
+
their connection to backend traces. Tracing is not required to send other frontend
|
|
447
|
+
telemetry to the collector.
|
|
448
|
+
|
|
449
|
+
```ts
|
|
450
|
+
init({ app: 'my-app', namespace: 'my-team', tracing: true });
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
Trace headers are only ever sent to **nais-owned backends**: a non-overridable floor restricts propagation to the app's own origin and any `https://*.nav.no` host. You can add more origins, but you can never remove the floor (and it is not reachable through the `faro` escape hatch):
|
|
454
|
+
|
|
455
|
+
```ts
|
|
456
|
+
init({ tracing: { propagateExtraOrigins: ['https://api.partner.example'] } });
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
## React — `@nais/apm/react`
|
|
460
|
+
|
|
461
|
+
A separate entry point with React helpers. React and `react-router` are optional peer dependencies; importing this entry requires them (plus `@grafana/faro-react` for the React Router v6 wiring). The root `@nais/apm` entry stays free of React and OpenTelemetry.
|
|
462
|
+
|
|
463
|
+
**Error boundary** — catches render errors and reports them once through `captureException` (so they get the SDK's fingerprint/context pipeline):
|
|
464
|
+
|
|
465
|
+
```tsx
|
|
466
|
+
import { ApmErrorBoundary } from '@nais/apm/react';
|
|
467
|
+
|
|
468
|
+
<ApmErrorBoundary fingerprint="checkout" fallback={<p>Something went wrong.</p>}>
|
|
469
|
+
<Checkout />
|
|
470
|
+
</ApmErrorBoundary>;
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
There is also a `withApmErrorBoundary(Component, props?)` HOC.
|
|
474
|
+
|
|
475
|
+
**Route tracking (React Router v6)** — call once after `init()`, passing your own react-router-dom exports, then render `<ApmRoutes>` in place of `<Routes>`:
|
|
476
|
+
|
|
477
|
+
```tsx
|
|
478
|
+
import { createRoutesFromChildren, matchRoutes, Routes, useLocation, useNavigationType } from 'react-router-dom';
|
|
479
|
+
import { enableApmReactRouterV6, ApmRoutes } from '@nais/apm/react';
|
|
480
|
+
|
|
481
|
+
enableApmReactRouterV6({ createRoutesFromChildren, matchRoutes, Routes, useLocation, useNavigationType });
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
**Route tracking (Next.js App Router)** — use the `useApmRouteTracking` hook in a client component:
|
|
485
|
+
|
|
486
|
+
```tsx
|
|
487
|
+
'use client';
|
|
488
|
+
import { usePathname, useSearchParams } from 'next/navigation';
|
|
489
|
+
import { useApmRouteTracking } from '@nais/apm/react';
|
|
490
|
+
|
|
491
|
+
export function ApmRouteTracker() {
|
|
492
|
+
useApmRouteTracking(usePathname(), useSearchParams());
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
**Next.js client init** — `initNaisAPMClient` is the entry for Next 15+ `instrumentation-client.ts` (and the Pages Router `_app.tsx`). It no-ops on the server and is idempotent under StrictMode:
|
|
498
|
+
|
|
499
|
+
```ts
|
|
500
|
+
// instrumentation-client.ts
|
|
501
|
+
import { initNaisAPMClient } from '@nais/apm/react';
|
|
502
|
+
initNaisAPMClient({ namespace: 'my-team', tracing: true });
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
React Router v5/v7 and the data-router variants are follow-ups.
|
|
506
|
+
|
|
507
|
+
## Versioning & stability
|
|
508
|
+
|
|
509
|
+
This package follows semver, but is **pre-1.0**: expect the public API to keep moving (new options, renamed fields, new exports like tracing and React helpers) across `0.x` minor releases. Pin an exact version in your `package.json` and read the [CHANGELOG](./CHANGELOG.md) before upgrading. Breaking changes will be called out there.
|
|
510
|
+
|
|
511
|
+
## Not yet supported
|
|
512
|
+
|
|
513
|
+
Planned for later `0.x` releases:
|
|
514
|
+
|
|
515
|
+
- **React Router v5/v7 & data routers** — route tracking currently covers React Router v6 and the Next.js App Router.
|
|
516
|
+
- **Registry** — published to GitHub Package Registry only; a move to npmjs.org (dropping the `read:packages` token requirement for installs) is under consideration.
|
|
517
|
+
|
|
518
|
+
## Development
|
|
519
|
+
|
|
520
|
+
```sh
|
|
521
|
+
pnpm install
|
|
522
|
+
pnpm test # vitest (jsdom)
|
|
523
|
+
pnpm build # tsc -> dist/
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
## License
|
|
527
|
+
|
|
528
|
+
[MIT](./LICENSE)
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry-compatible convenience API on top of Faro.
|
|
3
|
+
*
|
|
4
|
+
* Mapping:
|
|
5
|
+
* - `captureException(err, { context, fingerprint })` → `faro.api.pushError`
|
|
6
|
+
* (`fingerprint` becomes `context.fingerprint`, consumed by the owned
|
|
7
|
+
* fingerprinting pipeline, nais/grafana-apm-app#62)
|
|
8
|
+
* - `captureMessage(msg, level)` → `faro.api.pushLog`
|
|
9
|
+
* - `setUser` / `clearUser` → `faro.api.setUser` / `faro.api.resetUser`
|
|
10
|
+
* - `setTag` / `setContext` → module-level context merged into every
|
|
11
|
+
* pushError context. Faro has no first-class tag concept, so this is an
|
|
12
|
+
* approximation: values ride along as exception context, they are not
|
|
13
|
+
* indexed labels.
|
|
14
|
+
*/
|
|
15
|
+
export interface CaptureExceptionOptions {
|
|
16
|
+
/** Extra key/value context attached to the exception. Values are stringified. */
|
|
17
|
+
context?: Record<string, unknown>;
|
|
18
|
+
/** Custom grouping key; mapped to `context.fingerprint` (see #62). */
|
|
19
|
+
fingerprint?: string;
|
|
20
|
+
}
|
|
21
|
+
export type SeverityLevel = 'fatal' | 'error' | 'warning' | 'log' | 'info' | 'debug';
|
|
22
|
+
/**
|
|
23
|
+
* Capture an exception. Sentry-compatible replacement for
|
|
24
|
+
* `Sentry.captureException`. Note: Faro's `pushError` returns no event ID.
|
|
25
|
+
*
|
|
26
|
+
* When `error` is an `Error` instance, it is also forwarded as Faro's
|
|
27
|
+
* `originalError` pushError option. Combined with `init({ faro: {
|
|
28
|
+
* preserveOriginalError: true } })`, the real Error instance rides along on
|
|
29
|
+
* `item.payload.originalError` and is visible to a custom `beforeSend` hook
|
|
30
|
+
* before Faro strips it — a single place to branch on error type/shape before
|
|
31
|
+
* reporting.
|
|
32
|
+
*/
|
|
33
|
+
export declare function captureException(error: unknown, options?: CaptureExceptionOptions): void;
|
|
34
|
+
/** Capture a message as a log line. Replacement for `Sentry.captureMessage`. */
|
|
35
|
+
export declare function captureMessage(message: string, level?: SeverityLevel): void;
|
|
36
|
+
export interface User {
|
|
37
|
+
/**
|
|
38
|
+
* An **opaque, non-identifying** correlation key — e.g. a salted hash of the
|
|
39
|
+
* user's identity. It MUST NOT be a raw NAV ident, fødselsnummer, email, or
|
|
40
|
+
* name: identities are PII and MUST NOT reach the shared Loki instance (all
|
|
41
|
+
* teams share it). PII-shaped values are dropped by {@link setUser}.
|
|
42
|
+
*/
|
|
43
|
+
id?: string;
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Do not send email — it is PII and MUST NOT reach shared Loki.
|
|
46
|
+
* Any value passed here is dropped by {@link setUser}. Kept only so existing
|
|
47
|
+
* callers still type-check while they migrate off it.
|
|
48
|
+
*/
|
|
49
|
+
email?: string;
|
|
50
|
+
/** Opaque, non-identifying label — same rules as {@link User.id}. */
|
|
51
|
+
username?: string;
|
|
52
|
+
/** Extra opaque attributes. PII-shaped values are scrubbed like other fields. */
|
|
53
|
+
attributes?: Record<string, string>;
|
|
54
|
+
}
|
|
55
|
+
/** @internal test helper — resets the once-only setUser PII warning. */
|
|
56
|
+
export declare function _resetUserPiiWarning(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Set the active user. Replacement for `Sentry.setUser(user)`.
|
|
59
|
+
*
|
|
60
|
+
* Structured Faro user fields BYPASS the transport-level PII scrubber, so this
|
|
61
|
+
* guards defensively: any `id`/`username`/`attributes` value that looks like
|
|
62
|
+
* PII (fødselsnummer, email, or a raw NAV ident) is dropped, and `email` is
|
|
63
|
+
* dropped unconditionally. Pass an opaque, non-identifying id — never a raw
|
|
64
|
+
* ident, fnr, email, or name.
|
|
65
|
+
*
|
|
66
|
+
* @example setUser({ id: hashedSubject }) // hashedSubject = a salted hash, not an ident
|
|
67
|
+
*/
|
|
68
|
+
export declare function setUser(user: User | null): void;
|
|
69
|
+
export interface PushMeasurementOptions {
|
|
70
|
+
/**
|
|
71
|
+
* Extra string labels attached to the measurement. Low-cardinality labels
|
|
72
|
+
* only — these land as fields on the shared Loki instance and go through the
|
|
73
|
+
* PII scrubber (fnr/email/token + NAV-ident redaction). Do NOT put identities
|
|
74
|
+
* here; the numeric `values` are the metric and are never scrubbed.
|
|
75
|
+
*/
|
|
76
|
+
context?: Record<string, string>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Record a custom numeric measurement (a metric). Safe, documented entry point
|
|
80
|
+
* over `faro.api.pushMeasurement` so teams don't drop to raw Faro. It rides the
|
|
81
|
+
* same guarded transport, so the mandatory PII scrubber runs on the way out —
|
|
82
|
+
* including NAV-ident redaction on `context`. No-op before `init()`.
|
|
83
|
+
*
|
|
84
|
+
* @example pushMeasurement('checkout_latency', { ms: 812 })
|
|
85
|
+
*/
|
|
86
|
+
export declare function pushMeasurement(type: string, values: Record<string, number>, options?: PushMeasurementOptions): void;
|
|
87
|
+
/**
|
|
88
|
+
* Record a custom event with string attributes. Safe, documented entry point
|
|
89
|
+
* over `faro.api.pushEvent` so teams don't drop to raw Faro. It rides the same
|
|
90
|
+
* guarded transport, so the mandatory PII scrubber runs on the way out —
|
|
91
|
+
* including NAV-ident redaction on `attributes`. No-op before `init()`.
|
|
92
|
+
*
|
|
93
|
+
* @example pushEvent('feature_flag_evaluated', { flag: 'new-checkout', value: 'on' })
|
|
94
|
+
*/
|
|
95
|
+
export declare function pushEvent(name: string, attributes?: Record<string, string>, domain?: string): void;
|
|
96
|
+
/** Clear the active user. Replacement for `Sentry.setUser(null)`. */
|
|
97
|
+
export declare function clearUser(): void;
|
|
98
|
+
/**
|
|
99
|
+
* Set a tag merged into every subsequent `captureException`/`captureMessage`
|
|
100
|
+
* context. Approximation of `Sentry.setTag` — Faro has no tag concept.
|
|
101
|
+
*/
|
|
102
|
+
export declare function setTag(key: string, value: string | number | boolean): void;
|
|
103
|
+
/**
|
|
104
|
+
* Attach named context merged (flattened as `name.key`) into every subsequent
|
|
105
|
+
* capture. Approximation of `Sentry.setContext`. Pass `null` to remove.
|
|
106
|
+
*/
|
|
107
|
+
export declare function setContext(name: string, context: Record<string, unknown> | null): void;
|
|
108
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAQH,MAAM,WAAW,uBAAuB;IACtC,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;AA8CrF;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,uBAA4B,GAAG,IAAI,CAsB5F;AAED,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,aAAsB,GAAG,IAAI,CAQnF;AAED,MAAM,WAAW,IAAI;IACnB;;;;;OAKG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAID,wEAAwE;AACxE,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAiD/C;AAED,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,OAAO,GAAE,sBAA2B,GACnC,IAAI,CAQN;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,MAAM,CAAC,EAAE,MAAM,GACd,IAAI,CAEN;AAED,qEAAqE;AACrE,wBAAgB,SAAS,IAAI,IAAI,CAEhC;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAE1E;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,IAAI,CActF"}
|