Skip to content

Commit 97ab22b

Browse files
committed
support debug logs
1 parent 0274eb9 commit 97ab22b

12 files changed

+144
-210
lines changed

apps/webapp/app/env.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,7 @@ const EnvironmentSchema = z
11211121
EVENTS_CLICKHOUSE_BATCH_SIZE: z.coerce.number().int().default(1000),
11221122
EVENTS_CLICKHOUSE_FLUSH_INTERVAL_MS: z.coerce.number().int().default(1000),
11231123
EVENT_REPOSITORY_DEFAULT_STORE: z.enum(["postgres", "clickhouse"]).default("postgres"),
1124+
EVENTS_CLICKHOUSE_MAX_TRACE_SUMMARY_VIEW_COUNT: z.coerce.number().int().default(250_000),
11241125

11251126
// Bootstrap
11261127
TRIGGER_BOOTSTRAP_ENABLED: z.string().default("0"),

apps/webapp/app/presenters/v3/RunPresenter.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createTreeFromFlatItems, flattenTree } from "~/components/primitives/Tr
33
import { prisma, type PrismaClient } from "~/db.server";
44
import { createTimelineSpanEventsFromSpanEvents } from "~/utils/timelineSpanEvents";
55
import { getUsername } from "~/utils/username";
6-
import { resolveEventRepositoryForStore } from "~/v3/eventRepository";
6+
import { resolveEventRepositoryForStore } from "~/v3/eventRepository/index.server";
77
import { SpanSummary } from "~/v3/eventRepository/eventRepository.types";
88
import { getTaskEventStoreTableForRun } from "~/v3/taskEventStore.server";
99
import { isFinalRunStatus } from "~/v3/taskStatus";

apps/webapp/app/presenters/v3/SpanPresenter.server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { isFailedRunStatus, isFinalRunStatus } from "~/v3/taskStatus";
1717
import { BasePresenter } from "./basePresenter.server";
1818
import { WaitpointPresenter } from "./WaitpointPresenter.server";
1919
import { engine } from "~/v3/runEngine.server";
20-
import { resolveEventRepositoryForStore } from "~/v3/eventRepository";
20+
import { resolveEventRepositoryForStore } from "~/v3/eventRepository/index.server";
2121
import { IEventRepository, SpanDetail } from "~/v3/eventRepository/eventRepository.types";
2222

2323
type Result = Awaited<ReturnType<SpanPresenter["call"]>>;
@@ -492,7 +492,6 @@ export class SpanPresenter extends BasePresenter {
492492
isPartial: span.isPartial,
493493
isCancelled: span.isCancelled,
494494
level: span.level,
495-
kind: span.kind,
496495
startTime: span.startTime,
497496
duration: span.duration,
498497
events: span.events,
Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,3 @@
1-
import { TypedResponse } from "@remix-run/server-runtime";
2-
import { assertExhaustive } from "@trigger.dev/core/utils";
3-
import { RunId } from "@trigger.dev/core/v3/isomorphic";
4-
import {
5-
WorkerApiDebugLogBody,
6-
WorkerApiRunAttemptStartResponseBody,
7-
} from "@trigger.dev/core/v3/workers";
8-
import { z } from "zod";
9-
import { prisma } from "~/db.server";
10-
import { logger } from "~/services/logger.server";
11-
import { createActionApiRoute } from "~/services/routeBuilders/apiBuilder.server";
12-
import { recordRunDebugLog } from "~/v3/eventRepository/eventRepository.server";
13-
14-
// const { action } = createActionApiRoute(
15-
// {
16-
// params: z.object({
17-
// runFriendlyId: z.string(),
18-
// }),
19-
// body: WorkerApiDebugLogBody,
20-
// method: "POST",
21-
// },
22-
// async ({
23-
// authentication,
24-
// body,
25-
// params,
26-
// }): Promise<TypedResponse<WorkerApiRunAttemptStartResponseBody>> => {
27-
// const { runFriendlyId } = params;
28-
29-
// try {
30-
// const run = await prisma.taskRun.findFirst({
31-
// where: {
32-
// friendlyId: params.runFriendlyId,
33-
// runtimeEnvironmentId: authentication.environment.id,
34-
// },
35-
// });
36-
37-
// if (!run) {
38-
// throw new Response("You don't have permissions for this run", { status: 401 });
39-
// }
40-
41-
// const eventResult = await recordRunDebugLog(
42-
// RunId.fromFriendlyId(runFriendlyId),
43-
// body.message,
44-
// {
45-
// attributes: {
46-
// properties: body.properties,
47-
// },
48-
// startTime: body.time,
49-
// }
50-
// );
51-
52-
// if (eventResult.success) {
53-
// return new Response(null, { status: 204 });
54-
// }
55-
56-
// switch (eventResult.code) {
57-
// case "FAILED_TO_RECORD_EVENT":
58-
// return new Response(null, { status: 400 }); // send a 400 to prevent retries
59-
// case "RUN_NOT_FOUND":
60-
// return new Response(null, { status: 404 });
61-
// default:
62-
// return assertExhaustive(eventResult.code);
63-
// }
64-
// } catch (error) {
65-
// logger.error("Failed to record dev log", {
66-
// environmentId: authentication.environment.id,
67-
// error,
68-
// });
69-
// throw error;
70-
// }
71-
// }
72-
// );
73-
74-
// export { action };
75-
76-
// Create a generic JSON action in remix
771
export function action() {
782
return new Response(null, { status: 204 });
793
}

apps/webapp/app/routes/engine.v1.worker-actions.runs.$runFriendlyId.logs.debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RunId } from "@trigger.dev/core/v3/isomorphic";
33
import { WorkerApiDebugLogBody } from "@trigger.dev/core/v3/runEngineWorker";
44
import { z } from "zod";
55
import { createActionWorkerApiRoute } from "~/services/routeBuilders/apiBuilder.server";
6-
import { recordRunDebugLog } from "~/v3/eventRepository/eventRepository.server";
6+
import { recordRunDebugLog } from "~/v3/eventRepository/index.server";
77

88
export const action = createActionWorkerApiRoute(
99
{

apps/webapp/app/v3/eventRepository/clickhouseEventRepository.server.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export type ClickhouseEventRepositoryConfig = {
6262
batchSize?: number;
6363
flushInterval?: number;
6464
tracer?: Tracer;
65+
maximumTraceSummaryViewCount?: number;
6566
};
6667

6768
/**
@@ -886,6 +887,10 @@ export class ClickhouseEventRepository implements IEventRepository {
886887

887888
queryBuilder.orderBy("start_time ASC");
888889

890+
if (this._config.maximumTraceSummaryViewCount) {
891+
queryBuilder.limit(this._config.maximumTraceSummaryViewCount);
892+
}
893+
889894
const { query, params } = queryBuilder.build();
890895

891896
logger.debug("ClickhouseEventRepository.getTraceSummary query", {

apps/webapp/app/v3/eventRepository/clickhouseEventRepositoryInstance.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function initializeClickhouseRepository() {
3939
clickhouse: clickhouse,
4040
batchSize: env.EVENTS_CLICKHOUSE_BATCH_SIZE,
4141
flushInterval: env.EVENTS_CLICKHOUSE_FLUSH_INTERVAL_MS,
42+
maximumTraceSummaryViewCount: env.EVENTS_CLICKHOUSE_MAX_TRACE_SUMMARY_VIEW_COUNT,
4243
});
4344

4445
return repository;

apps/webapp/app/v3/eventRepository/eventRepository.server.ts

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,119 +1822,6 @@ export function rehydrateAttribute<T extends AttributeValue>(
18221822
return value as T;
18231823
}
18241824

1825-
export async function findRunForEventCreation(runId: string) {
1826-
return prisma.taskRun.findFirst({
1827-
where: {
1828-
id: runId,
1829-
},
1830-
select: {
1831-
friendlyId: true,
1832-
taskIdentifier: true,
1833-
traceContext: true,
1834-
runtimeEnvironment: {
1835-
select: {
1836-
id: true,
1837-
type: true,
1838-
organizationId: true,
1839-
projectId: true,
1840-
project: {
1841-
select: {
1842-
externalRef: true,
1843-
},
1844-
},
1845-
},
1846-
},
1847-
},
1848-
});
1849-
}
1850-
1851-
export async function recordRunEvent(
1852-
runId: string,
1853-
message: string,
1854-
options: Omit<TraceEventOptions, "environment" | "taskSlug" | "startTime"> & {
1855-
duration?: number;
1856-
parentId?: string;
1857-
startTime?: Date;
1858-
}
1859-
): Promise<
1860-
| {
1861-
success: true;
1862-
}
1863-
| {
1864-
success: false;
1865-
code: "RUN_NOT_FOUND" | "FAILED_TO_RECORD_EVENT";
1866-
error?: unknown;
1867-
}
1868-
> {
1869-
try {
1870-
const foundRun = await findRunForEventCreation(runId);
1871-
1872-
if (!foundRun) {
1873-
logger.error("Failed to find run for event creation", { runId });
1874-
return {
1875-
success: false,
1876-
code: "RUN_NOT_FOUND",
1877-
};
1878-
}
1879-
1880-
const { attributes, startTime, ...optionsRest } = options;
1881-
1882-
await eventRepository.recordEvent(message, {
1883-
environment: foundRun.runtimeEnvironment,
1884-
taskSlug: foundRun.taskIdentifier,
1885-
context: foundRun.traceContext as Record<string, string | undefined>,
1886-
attributes: {
1887-
runId: foundRun.friendlyId,
1888-
...attributes,
1889-
},
1890-
startTime: BigInt((startTime?.getTime() ?? Date.now()) * 1_000_000),
1891-
...optionsRest,
1892-
});
1893-
1894-
return {
1895-
success: true,
1896-
};
1897-
} catch (error) {
1898-
logger.error("Failed to record event for run", {
1899-
error: error instanceof Error ? error.message : error,
1900-
runId,
1901-
});
1902-
1903-
return {
1904-
success: false,
1905-
code: "FAILED_TO_RECORD_EVENT",
1906-
error,
1907-
};
1908-
}
1909-
}
1910-
1911-
export async function recordRunDebugLog(
1912-
runId: string,
1913-
message: string,
1914-
options: Omit<TraceEventOptions, "environment" | "taskSlug" | "startTime"> & {
1915-
duration?: number;
1916-
parentId?: string;
1917-
startTime?: Date;
1918-
}
1919-
): Promise<
1920-
| {
1921-
success: true;
1922-
}
1923-
| {
1924-
success: false;
1925-
code: "RUN_NOT_FOUND" | "FAILED_TO_RECORD_EVENT";
1926-
error?: unknown;
1927-
}
1928-
> {
1929-
return recordRunEvent(runId, message, {
1930-
...options,
1931-
attributes: {
1932-
...options?.attributes,
1933-
isDebug: true,
1934-
},
1935-
});
1936-
}
1937-
19381825
/**
19391826
* Extracts error details from Prisma errors in a type-safe way.
19401827
* Only includes 'code' property for PrismaClientKnownRequestError.

0 commit comments

Comments
 (0)