feat(analytics): persona logging upgrade and Sentry system config

Add client-logging SDK, expanded event taxonomy, API observability, admin domain events UI, and move SENTRY_DSN to HQ system settings with @sentry/node bootstrap after config preload.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-03 22:30:02 +08:00
parent ab10431001
commit 89fd333702
91 changed files with 1805 additions and 136 deletions
@@ -0,0 +1,93 @@
export type ClientErrorLevel = 'fatal' | 'error' | 'warn' | 'info';
export type ClientErrorCategory =
| 'js_error'
| 'unhandled_rejection'
| 'api_error'
| 'network'
| 'render'
| 'bridge'
| 'other';
export type ClientErrorReporterOptions = {
apiBase: string;
clientApp: string;
getToken?: () => string | null;
};
export function installClientErrorReporting(opts: ClientErrorReporterOptions) {
if (typeof window === 'undefined') return;
const report = (payload: {
level: ClientErrorLevel;
category: ClientErrorCategory;
message: string;
stack?: string;
extra?: Record<string, unknown>;
}) => {
const token = opts.getToken?.() ?? localStorage.getItem('accessToken');
const headers: Record<string, string> = {
'Content-Type': 'application/json',
'X-Client-App': opts.clientApp,
};
if (token) headers.Authorization = `Bearer ${token}`;
void fetch(`${opts.apiBase}/common/client-errors`, {
method: 'POST',
headers,
body: JSON.stringify({
level: payload.level,
category: payload.category,
message: payload.message,
stack: payload.stack,
pagePath: window.location.pathname,
clientApp: opts.clientApp,
extra: payload.extra,
}),
}).catch(() => {});
};
window.addEventListener('error', (ev) => {
report({
level: 'error',
category: 'js_error',
message: ev.message || 'Unknown error',
stack: ev.error instanceof Error ? ev.error.stack : undefined,
});
});
window.addEventListener('unhandledrejection', (ev) => {
const reason = ev.reason;
report({
level: 'error',
category: 'unhandled_rejection',
message: reason instanceof Error ? reason.message : String(reason),
stack: reason instanceof Error ? reason.stack : undefined,
});
});
}
export function reportApiError(
opts: ClientErrorReporterOptions,
input: { message: string; status?: number; url?: string; category?: ClientErrorCategory },
) {
if (typeof window === 'undefined') return;
const token = opts.getToken?.() ?? localStorage.getItem('accessToken');
const headers: Record<string, string> = {
'Content-Type': 'application/json',
'X-Client-App': opts.clientApp,
};
if (token) headers.Authorization = `Bearer ${token}`;
void fetch(`${opts.apiBase}/common/client-errors`, {
method: 'POST',
headers,
body: JSON.stringify({
level: 'warn',
category: input.category ?? 'api_error',
message: input.message.slice(0, 1000),
pagePath: window.location.pathname,
clientApp: opts.clientApp,
extra: { status: input.status, url: input.url },
}),
}).catch(() => {});
}