Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
2.2 kB ยท 73 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374import { db as defaultDb } from "@openstatus/db";
import { type ServiceContext, defaultTb } from "../context";import { ForbiddenError, NotFoundError, ValidationError } from "../errors";import { getMonitorInWorkspace } from "./internal";import type { ResponseLogListItem } from "./list-response-logs";import { redactSensitiveHeaders } from "./response-logs-internal";import { GetResponseLogInput } from "./schemas";
export type ResponseLogDetail = ResponseLogListItem & { url: string; error: boolean; message: string | null; /** Already redacted at the service boundary. */ headers: Record<string, string>; assertions: string | null;};
export async function getResponseLog(args: { ctx: ServiceContext; input: GetResponseLogInput;}): Promise<ResponseLogDetail> { const { ctx } = args; const input = GetResponseLogInput.parse(args.input); if (!ctx.workspace.limits["response-logs"]) { throw new ForbiddenError("Response logs are not enabled on this plan."); } const db = ctx.db ?? defaultDb;
const record = await getMonitorInWorkspace({ tx: db, id: input.monitorId, workspaceId: ctx.workspace.id, }); if (record.jobType !== "http") { throw new ValidationError( `getResponseLog only supports HTTP monitors (got '${record.jobType}').`, ); }
const result = await (ctx.tb ?? defaultTb).httpGetBiweekly({ id: input.logId, monitorId: String(record.id), }); const log = result.data[0]; if (!log) throw new NotFoundError("response_log", input.logId);
return { id: log.id ?? null, monitorId: log.monitorId, region: log.region, requestStatus: log.requestStatus ?? null, trigger: log.trigger ?? null, statusCode: log.statusCode ?? null, latency: log.latency, cronTimestamp: log.cronTimestamp, timestamp: log.timestamp, timing: log.timing ? { dns: log.timing.dns, connect: log.timing.connect, tls: log.timing.tls, ttfb: log.timing.ttfb, transfer: log.timing.transfer, } : null, url: log.url, error: log.error, message: log.message ?? null, headers: redactSensitiveHeaders(log.headers), assertions: log.assertions ?? null, };}