Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

chore(web): log timing for each desktop source commit page

Richie McIlroy279eff1b0084
diff --git a/apps/web/__tests__/unit/finalize-desktop-recording.test.ts b/apps/web/__tests__/unit/finalize-desktop-recording.test.ts
index f5461d3d9..111e8f514 100644
--- a/apps/web/__tests__/unit/finalize-desktop-recording.test.ts
+++ b/apps/web/__tests__/unit/finalize-desktop-recording.test.ts
@@ -579,6 +579,35 @@ describe("bounded source commitment steps", () => {
expect(mocks.persist).not.toHaveBeenCalled();
});
+ it("logs the timing of every commit page without storage keys", async () => {
+ mocks.commitSource.mockImplementation(async (_video, checkpoint) =>
+ checkpoint.revision === 1
+ ? { source }
+ : advanceCheckpoint(_video, checkpoint),
+ );
+ const info = vi.spyOn(console, "info").mockImplementation(() => {});
+ try {
+ expect(await commitDesktopRecordingAttempt(fixture)).toBe("ready");
+ const events = info.mock.calls
+ .map(([line]) => JSON.parse(String(line)))
+ .filter((event) => event.event === "desktop_source_commit_advance");
+ expect(events).toHaveLength(2);
+ expect(events[0]).toMatchObject({
+ videoId: "video",
+ attemptId: "attempt",
+ outcome: "progress",
+ });
+ expect(events[1]).toMatchObject({ next: "committed", outcome: "ready" });
+ for (const event of events) {
+ for (const key of ["loadMs", "heartbeatMs", "advanceMs", "persistMs"])
+ expect(event[key]).toBeGreaterThanOrEqual(0);
+ expect(JSON.stringify(event)).not.toContain(source.inventoryKey);
+ }
+ } finally {
+ info.mockRestore();
+ }
+ });
+
it("includes checkpoint persistence latency in the batch budget", async () => {
mocks.commitSource.mockImplementation(advanceCheckpoint);
mocks.saveCheckpoint.mockImplementation(async (_attempt, checkpoint) => {
diff --git a/apps/web/workflows/finalize-desktop-recording.ts b/apps/web/workflows/finalize-desktop-recording.ts
index 2caeb0482..d61b94ca7 100644
--- a/apps/web/workflows/finalize-desktop-recording.ts
+++ b/apps/web/workflows/finalize-desktop-recording.ts
@@ -296,6 +296,7 @@ export async function commitDesktopRecordingAttempt(
async function advanceDesktopRecordingAttempt(
attempt: DesktopRecordingAttempt,
): Promise<SourceCommitResult> {
+ const startedAt = performance.now();
const current = await getProcessingState(attempt);
if (!current || current.attemptId !== attempt.attemptId) return "superseded";
if (current.source) return "ready";
@@ -309,24 +310,45 @@ async function advanceDesktopRecordingAttempt(
try {
const checkpoint = await initializeSourceCommitCheckpoint(attempt);
if (!checkpoint) return "superseded";
+ const loadedAt = performance.now();
+ let heartbeatMs = 0;
const result = await advanceDesktopRecordingSourceCommit(
video,
checkpoint,
current.verification ?? undefined,
async () => {
- if (!(await heartbeatAttempt(attempt))) {
+ const heartbeatAt = performance.now();
+ const alive = await heartbeatAttempt(attempt);
+ heartbeatMs += performance.now() - heartbeatAt;
+ if (!alive) {
throw new Error("Recording source commit lease was superseded");
}
},
);
- if ("checkpoint" in result) {
- return (await persistSourceCommitCheckpoint(attempt, result.checkpoint))
- ? "progress"
- : "superseded";
- }
- return (await persistCommittedSource(attempt, result.source))
- ? "ready"
- : "superseded";
+ const advancedAt = performance.now();
+ const outcome =
+ "checkpoint" in result
+ ? (await persistSourceCommitCheckpoint(attempt, result.checkpoint))
+ ? "progress"
+ : "superseded"
+ : (await persistCommittedSource(attempt, result.source))
+ ? "ready"
+ : "superseded";
+ console.info(
+ JSON.stringify({
+ event: "desktop_source_commit_advance",
+ videoId: attempt.videoId,
+ attemptId: attempt.attemptId,
+ phase: checkpoint.phase,
+ next: "checkpoint" in result ? result.checkpoint.phase : "committed",
+ outcome,
+ loadMs: Math.round(loadedAt - startedAt),
+ heartbeatMs: Math.round(heartbeatMs),
+ advanceMs: Math.round(advancedAt - loadedAt),
+ persistMs: Math.round(performance.now() - advancedAt),
+ }),
+ );
+ return outcome;
} catch (error) {
const code = getSourceErrorCode(error);
if (!code) throw error;