Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions instrumentation-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,37 @@ Sentry.init({
debug: environment === "development",
environment,
enabled: environment === "production",
// Normalize transaction names for parameterized routes to enable per-page analysis
// Sentry uses formats like "/:locale/:slug*" for catch-all routes
beforeSendTransaction(event) {
const op = event.contexts?.trace?.op
const transaction = event.transaction

// Matches patterns like ":locale", ":slug*", ":id", ":post", etc.
const isParameterizedRoute = transaction && /:\w+/.test(transaction)
const isPageTransaction = op === "pageload" || op === "navigation"

if (isParameterizedRoute && isPageTransaction) {
const url = event.request?.url || (event.tags?.url as string | undefined)
if (url) {
try {
const pathname = new URL(url).pathname
// Remove locale prefix (e.g., "/en/", "/fil/", "/zh-tw/", "/pt-br/"), keeping just the page path
// e.g., "/en/developers/docs" -> "/developers/docs"
// Only match complete path segments (must be followed by "/" or end of string)
const normalizedPath = pathname.replace(
/^\/[a-z]{2,3}(-[a-z]{2})?(?=\/|$)/,
""
)
event.transaction = normalizedPath || "/"
} catch {
// Keep original transaction name if URL parsing fails
}
}
}
return event
},

beforeBreadcrumb(breadcrumb, hint) {
if (breadcrumb.category === "ui.click") {
const element = hint?.event?.target
Expand Down