fix(workbench): enrich api resource timing at rum flush (#1935)
This commit is contained in:
@@ -528,7 +528,7 @@ function flushWorkbenchPerformance(useBeacon: boolean): void {
|
||||
flushTimer = null;
|
||||
}
|
||||
if (!queue.length || typeof window === "undefined") return;
|
||||
const events = queue.splice(0, queue.length);
|
||||
const events = queue.splice(0, queue.length).map(enrichWorkbenchEventForFlush);
|
||||
const body = JSON.stringify({ schemaVersion: SCHEMA_VERSION, serviceId: "hwlab-cloud-web", page: pageRoute(), events });
|
||||
if (useBeacon && navigator.sendBeacon) {
|
||||
navigator.sendBeacon("/v1/web-performance", new Blob([body], { type: "application/json" }));
|
||||
@@ -537,6 +537,15 @@ function flushWorkbenchPerformance(useBeacon: boolean): void {
|
||||
void fetch("/v1/web-performance", { method: "POST", headers: { "content-type": "application/json" }, body, credentials: "same-origin", keepalive: true }).catch(() => undefined);
|
||||
}
|
||||
|
||||
function enrichWorkbenchEventForFlush(event: WorkbenchPerformanceEvent): WorkbenchPerformanceEvent {
|
||||
if (event.kind !== "workbench_ui_event" || event.eventType !== "api_request") return event;
|
||||
if (event.resourceDurationMs !== undefined) return event;
|
||||
const route = safeText(event.route);
|
||||
if (!route || !Number.isFinite(event.startedAtEpochMs) || !Number.isFinite(event.endedAtEpochMs)) return event;
|
||||
const timing = resourceTimingForApiRequest(route, Number(event.startedAtEpochMs), Number(event.endedAtEpochMs));
|
||||
return Object.keys(timing).length > 0 ? { ...event, ...timing } : event;
|
||||
}
|
||||
|
||||
function ensureInstalled(): void {
|
||||
if (installed || typeof document === "undefined") return;
|
||||
installed = true;
|
||||
|
||||
Reference in New Issue
Block a user