Skip to content

Commit 1bb1fc4

Browse files
authored
v4 run engine debug logs now filtered out in SQL by default (#2092)
1 parent 1ca37f5 commit 1bb1fc4

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ export class RunPresenter {
3232
environmentSlug,
3333
runFriendlyId,
3434
showDeletedLogs,
35+
showDebug,
3536
}: {
3637
userId: string;
3738
projectSlug: string;
3839
organizationSlug: string;
3940
environmentSlug: string;
4041
runFriendlyId: string;
4142
showDeletedLogs: boolean;
43+
showDebug: boolean;
4244
}) {
4345
const run = await this.#prismaClient.taskRun.findFirstOrThrow({
4446
select: {
@@ -131,7 +133,8 @@ export class RunPresenter {
131133
getTaskEventStoreTableForRun(run),
132134
run.traceId,
133135
run.rootTaskRun?.createdAt ?? run.createdAt,
134-
run.completedAt ?? undefined
136+
run.completedAt ?? undefined,
137+
{ includeDebugLogs: showDebug }
135138
);
136139
if (!traceSummary) {
137140
return {

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam/route.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import {
9595
} from "~/utils/pathBuilder";
9696
import { useCurrentPlan } from "../_app.orgs.$organizationSlug/route";
9797
import { SpanView } from "../resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.spans.$spanParam/route";
98+
import { useSearchParams } from "~/hooks/useSearchParam";
9899

99100
const resizableSettings = {
100101
parent: {
@@ -133,6 +134,9 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
133134
const impersonationId = await getImpersonationId(request);
134135
const { projectParam, organizationSlug, envParam, runParam } = v3RunParamsSchema.parse(params);
135136

137+
const url = new URL(request.url);
138+
const showDebug = url.searchParams.get("showDebug") === "true";
139+
136140
const presenter = new RunPresenter();
137141
const [error, result] = await tryCatch(
138142
presenter.call({
@@ -142,6 +146,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
142146
projectSlug: projectParam,
143147
runFriendlyId: runParam,
144148
environmentSlug: envParam,
149+
showDebug,
145150
})
146151
);
147152

@@ -505,15 +510,18 @@ function TasksTreeView({
505510
const isAdmin = useHasAdminAccess();
506511
const [filterText, setFilterText] = useState("");
507512
const [errorsOnly, setErrorsOnly] = useState(false);
508-
const [showDebug, setShowDebug] = useState(false);
509513
const [showDurations, setShowDurations] = useState(true);
510514
const [showQueueTime, setShowQueueTime] = useState(false);
511515
const [scale, setScale] = useState(0);
512516
const parentRef = useRef<HTMLDivElement>(null);
513517
const treeScrollRef = useRef<HTMLDivElement>(null);
514518
const timelineScrollRef = useRef<HTMLDivElement>(null);
519+
const { value, replace } = useSearchParams();
520+
521+
const searchValue = value("showDebug");
522+
const showDebug = searchValue !== undefined ? searchValue === "true" : false;
515523

516-
const displayEvents = showDebug ? events : events.filter((event) => !event.data.isDebug);
524+
const displayEvents = events;
517525
const queuedTime = showQueueTime ? undefined : queuedDuration;
518526

519527
const {
@@ -560,7 +568,11 @@ function TasksTreeView({
560568
label="Debug"
561569
shortcut={{ modifiers: ["shift"], key: "D" }}
562570
checked={showDebug}
563-
onCheckedChange={(e) => setShowDebug(e.valueOf())}
571+
onCheckedChange={(checked) => {
572+
replace({
573+
showDebug: checked ? "true" : "false",
574+
});
575+
}}
564576
/>
565577
)}
566578
<Switch

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,14 +433,16 @@ export class EventRepository {
433433
storeTable: TaskEventStoreTable,
434434
traceId: string,
435435
startCreatedAt: Date,
436-
endCreatedAt?: Date
436+
endCreatedAt?: Date,
437+
options?: { includeDebugLogs?: boolean }
437438
): Promise<TraceSummary | undefined> {
438439
return await startActiveSpan("getTraceSummary", async (span) => {
439440
const events = await this.taskEventStore.findTraceEvents(
440441
storeTable,
441442
traceId,
442443
startCreatedAt,
443-
endCreatedAt
444+
endCreatedAt,
445+
{ includeDebugLogs: options?.includeDebugLogs }
444446
);
445447

446448
let preparedEvents: Array<PreparedEvent> = [];

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// TaskEventStore.ts
2-
import type { Prisma, TaskEvent } from "@trigger.dev/database";
2+
import { Prisma, TaskEvent } from "@trigger.dev/database";
33
import type { PrismaClient, PrismaReplicaClient } from "~/db.server";
44
import { env } from "~/env.server";
55

@@ -101,14 +101,24 @@ export class TaskEventStore {
101101

102102
if (table === "taskEventPartitioned") {
103103
return (await this.readReplica.taskEventPartitioned.findMany({
104-
where: finalWhere as Prisma.TaskEventPartitionedWhereInput,
104+
where: {
105+
...(finalWhere as Prisma.TaskEventPartitionedWhereInput),
106+
kind: {
107+
not: "LOG",
108+
},
109+
},
105110
select,
106111
orderBy,
107112
})) as Prisma.TaskEventGetPayload<{ select: TSelect }>[];
108113
} else {
109114
// When partitioning is not enabled, we ignore the createdAt range.
110115
return (await this.readReplica.taskEvent.findMany({
111-
where,
116+
where: {
117+
...(finalWhere as Prisma.TaskEventWhereInput),
118+
kind: {
119+
not: "LOG",
120+
},
121+
},
112122
select,
113123
orderBy,
114124
})) as Prisma.TaskEventGetPayload<{ select: TSelect }>[];
@@ -119,8 +129,12 @@ export class TaskEventStore {
119129
table: TaskEventStoreTable,
120130
traceId: string,
121131
startCreatedAt: Date,
122-
endCreatedAt?: Date
132+
endCreatedAt?: Date,
133+
options?: { includeDebugLogs?: boolean }
123134
) {
135+
const filterDebug =
136+
options?.includeDebugLogs === false || options?.includeDebugLogs === undefined;
137+
124138
if (table === "taskEventPartitioned") {
125139
return await this.readReplica.$queryRaw<TraceEvent[]>`
126140
SELECT
@@ -147,6 +161,11 @@ export class TaskEventStore {
147161
? new Date(endCreatedAt.getTime() + env.TASK_EVENT_PARTITIONED_WINDOW_IN_SECONDS * 1000)
148162
: new Date()
149163
).toISOString()}::timestamp
164+
${
165+
filterDebug
166+
? Prisma.sql`AND \"kind\" <> CAST('LOG'::text AS "public"."TaskEventKind")`
167+
: Prisma.empty
168+
}
150169
ORDER BY "startTime" ASC
151170
LIMIT ${env.MAXIMUM_TRACE_SUMMARY_VIEW_COUNT}
152171
`;
@@ -171,6 +190,11 @@ export class TaskEventStore {
171190
"kind"
172191
FROM "TaskEvent"
173192
WHERE "traceId" = ${traceId}
193+
${
194+
filterDebug
195+
? Prisma.sql`AND \"kind\" <> CAST('LOG'::text AS "public"."TaskEventKind")`
196+
: Prisma.empty
197+
}
174198
ORDER BY "startTime" ASC
175199
LIMIT ${env.MAXIMUM_TRACE_SUMMARY_VIEW_COUNT}
176200
`;

0 commit comments

Comments
 (0)