forked from ethereum/ethereum-org-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstrumentation-client.ts
More file actions
50 lines (40 loc) · 1.46 KB
/
instrumentation-client.ts
File metadata and controls
50 lines (40 loc) · 1.46 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
import * as Sentry from "@sentry/nextjs"
const environment = process.env.NEXT_PUBLIC_CONTEXT || "development"
/**
* Finds the closest element (including the element itself) that has an id attribute
* @param element - The starting element to search from
* @param maxDepth - Maximum number of parent levels to search (default: 3)
* @returns The first found attribute value in priority order, null otherwise
*/
function findClosestElementId(
element: Element | null | undefined,
maxDepth: number = 3
): string | null {
if (!element || maxDepth < 0) return null
const sentryId = element.getAttribute("data-testid")
if (sentryId) return sentryId
const ariaLabel = element.getAttribute("aria-label")
if (ariaLabel) return ariaLabel
const id = element.getAttribute("id")
if (id) return id
// Recursively check parent elements up to maxDepth
return findClosestElementId(element.parentElement, maxDepth - 1)
}
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
tracesSampleRate: 0.01,
debug: environment === "development",
environment,
enabled: environment === "production",
beforeBreadcrumb(breadcrumb, hint) {
if (breadcrumb.category === "ui.click") {
const element = hint?.event?.target
const id = findClosestElementId(element)
if (id) {
breadcrumb.message = id + " (" + breadcrumb.message + ")"
}
}
return breadcrumb
},
})
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart