feat(logging): record repository, user and viewer on log records

Handlers that resolve an anonymized repository, pull request or gist now
put its public ID on the log context, so request, job and error records
carry repoId, pullRequestId or gistId. The signed-in user's internal _id
(userId) is recorded on account routes. On routes that serve anonymized
content, userId is kept only when the user owns, co-authors or
administers the project; otherwise the record carries viewer "visitor"
or "anonymous" and no userId. The collector, the Redis mirror and the
admin log APIs apply the same rule. Jobs carry repoId and the owner's
userId stamped at enqueue time.

The admin Errors page links repoId to the admin repository search and
userId to the admin user page, which now accepts a user _id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Thomas DurieuxandClaude Opus 5.5 committed 2026-11-29 12:36:09 +00:00
1 parent 2f38fc6a51
commit 86a35d62f1
22 files changed
+474 -70

No files matched your search

+2
View File
@@ -19,6 +19,8 @@ export interface RepoJobData {
repoId: string;
requestId?: string;
logJobId?: string;
/** Owner's internal user _id, for log records only. */
ownerId?: string;
}
const IN_FLIGHT_STATUSES: RepositoryStatus[] = [
+4 -1
View File
@@ -1,7 +1,7 @@
import { logMemory } from "../core/log-memory";
import { randomUUID } from "crypto";
import { SandboxedJob } from "bullmq";
import { logContext, validTraceId } from "../core/log-context";
import { logContext, validProjectId, validTraceId, validUserId } from "../core/log-context";
import { createLogger, reportOutputDrops } from "../core/logger";
import type { RepoJobData } from "./index";
const logger = createLogger("queue");
@@ -10,6 +10,9 @@ export function loggedJob(queue: "download" | "remove" | "cache", work: (job: Sa
service: "worker", jobId: validTraceId(job.data.logJobId) ? job.data.logJobId : randomUUID(),
requestId: validTraceId(job.data.requestId) ? job.data.requestId : undefined,
attempt: job.attemptsMade + 1,
// Owner _id is stamped at enqueue time (jobTrace); no lookup per job.
...(validProjectId(job.data.repoId) ? { repoId: job.data.repoId } : {}),
...(validUserId(job.data.ownerId) ? { userId: job.data.ownerId } : {}),
}, async () => {
logger.info("job started", { queue });
const started = Date.now();