-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstrumentation-client.ts
More file actions
61 lines (58 loc) · 2.05 KB
/
Copy pathinstrumentation-client.ts
File metadata and controls
61 lines (58 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Client-side error tracking (Sentry browser SDK).
//
// Next 16 runs this file on the client only (it is aliased to
// `private-next-instrumentation-client`), so it is safe in a static export
// (`output: 'export'`) - there is no server runtime and nothing here touches
// server APIs. We keep tracing lightly sampled and session replay disabled to
// improve production health signals without materially increasing cost.
//
// This is a complete no-op until `NEXT_PUBLIC_SENTRY_DSN` is provided. For a
// static export the value is inlined at build time, so without it Sentry is
// never initialised and the SDK stays dormant.
import * as Sentry from "@sentry/react";
const dsn = process.env["NEXT_PUBLIC_SENTRY_DSN"];
if (dsn) {
const configuredTracesSampleRate =
process.env["NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE"];
const parsedTracesSampleRate = configuredTracesSampleRate
? Number(configuredTracesSampleRate)
: undefined;
const tracesSampleRate =
parsedTracesSampleRate !== undefined &&
Number.isFinite(parsedTracesSampleRate) &&
parsedTracesSampleRate >= 0 &&
parsedTracesSampleRate <= 1
? parsedTracesSampleRate
: process.env.NODE_ENV === "production"
? 0.05
: 0;
Sentry.init({
dsn,
environment:
process.env["NEXT_PUBLIC_SENTRY_ENVIRONMENT"] ?? process.env.NODE_ENV,
release: process.env["NEXT_PUBLIC_SENTRY_RELEASE"],
sendDefaultPii: false,
tracesSampleRate,
integrations: [
Sentry.browserTracingIntegration({
enableInp: true,
instrumentNavigation: true,
instrumentPageLoad: true,
}),
],
// Bound error volume: report half of captured errors.
sampleRate: 0.5,
// Drop common, actionable-by-nobody browser/extension noise.
ignoreErrors: [
/ResizeObserver loop/,
/Non-Error promise rejection captured/,
"Network request failed",
"Failed to fetch",
"Load failed",
"AbortError",
// Browser extensions / injected scripts.
/^chrome-extension:\/\//,
/^moz-extension:\/\//,
],
});
}