Skip to content

Commit fda9565

Browse files
authored
Optionally disable run debug logs (#2116)
* disable run debug logs by default * lightweight webapp health check * disable debug logs for dev runs * disable run debug logs for supervisor client * add changeset
1 parent 82e7484 commit fda9565

File tree

9 files changed

+81
-56
lines changed

9 files changed

+81
-56
lines changed

.changeset/fuzzy-snakes-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/core": patch
3+
---
4+
5+
Add supervisor http client option to disable debug logs

apps/supervisor/src/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const Env = z.object({
8787

8888
// Debug
8989
DEBUG: BoolEnv.default(false),
90+
SEND_RUN_DEBUG_LOGS: BoolEnv.default(false),
9091
});
9192

9293
export const env = Env.parse(stdEnv);

apps/supervisor/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class ManagedSupervisor {
130130
maxConsumerCount: env.TRIGGER_DEQUEUE_MAX_CONSUMER_COUNT,
131131
runNotificationsEnabled: env.TRIGGER_WORKLOAD_API_ENABLED,
132132
heartbeatIntervalSeconds: env.TRIGGER_WORKER_HEARTBEAT_INTERVAL_SECONDS,
133+
sendRunDebugLogs: env.SEND_RUN_DEBUG_LOGS,
133134
preDequeue: async () => {
134135
if (!env.RESOURCE_MONITOR_ENABLED) {
135136
return {};

apps/supervisor/src/workloadServer/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import { HttpServer, type CheckpointClient } from "@trigger.dev/core/v3/serverOnly";
2525
import { type IncomingMessage } from "node:http";
2626
import { register } from "../metrics.js";
27+
import { env } from "../env.js";
2728

2829
// Use the official export when upgrading to socket.io@4.8.0
2930
interface DefaultEventsMap {
@@ -374,6 +375,10 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
374375
handler: async ({ req, reply, params, body }) => {
375376
reply.empty(204);
376377

378+
if (!env.SEND_RUN_DEBUG_LOGS) {
379+
return;
380+
}
381+
377382
await this.workerClient.sendDebugLog(
378383
params.runFriendlyId,
379384
body,

apps/webapp/app/routes/engine.v1.dev.runs.$runFriendlyId.logs.debug.ts

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,69 @@ import { logger } from "~/services/logger.server";
1111
import { createActionApiRoute } from "~/services/routeBuilders/apiBuilder.server";
1212
import { recordRunDebugLog } from "~/v3/eventRepository.server";
1313

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;
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;
2828

29-
try {
30-
const run = await prisma.taskRun.findFirst({
31-
where: {
32-
friendlyId: params.runFriendlyId,
33-
runtimeEnvironmentId: authentication.environment.id,
34-
},
35-
});
29+
// try {
30+
// const run = await prisma.taskRun.findFirst({
31+
// where: {
32+
// friendlyId: params.runFriendlyId,
33+
// runtimeEnvironmentId: authentication.environment.id,
34+
// },
35+
// });
3636

37-
if (!run) {
38-
throw new Response("You don't have permissions for this run", { status: 401 });
39-
}
37+
// if (!run) {
38+
// throw new Response("You don't have permissions for this run", { status: 401 });
39+
// }
4040

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-
);
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+
// );
5151

52-
if (eventResult.success) {
53-
return new Response(null, { status: 204 });
54-
}
52+
// if (eventResult.success) {
53+
// return new Response(null, { status: 204 });
54+
// }
5555

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-
);
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+
// );
7373

74-
export { action };
74+
// export { action };
75+
76+
// Create a generic JSON action in remix
77+
export function action() {
78+
return new Response(null, { status: 204 });
79+
}

apps/webapp/app/routes/healthcheck.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { LoaderFunction } from "@remix-run/node";
33

44
export const loader: LoaderFunction = async ({ request }) => {
55
try {
6-
await prisma.user.count();
6+
await prisma.$queryRaw`SELECT 1`;
77
return new Response("OK");
88
} catch (error: unknown) {
99
console.log("healthcheck ❌", { error });

packages/core/src/v3/runEngineWorker/supervisor/http.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class SupervisorHttpClient {
3333
private readonly workerToken: string;
3434
private readonly instanceName: string;
3535
private readonly defaultHeaders: Record<string, string>;
36+
private readonly sendRunDebugLogs: boolean;
3637

3738
private readonly logger = new SimpleStructuredLogger("supervisor-http-client");
3839

@@ -41,6 +42,7 @@ export class SupervisorHttpClient {
4142
this.workerToken = opts.workerToken;
4243
this.instanceName = opts.instanceName;
4344
this.defaultHeaders = getDefaultWorkerHeaders(opts);
45+
this.sendRunDebugLogs = opts.sendRunDebugLogs ?? false;
4446

4547
if (!this.apiUrl) {
4648
throw new Error("apiURL is required and needs to be a non-empty string");
@@ -204,6 +206,10 @@ export class SupervisorHttpClient {
204206
}
205207

206208
async sendDebugLog(runId: string, body: WorkerApiDebugLogBody, runnerId?: string): Promise<void> {
209+
if (!this.sendRunDebugLogs) {
210+
return;
211+
}
212+
207213
try {
208214
const res = await wrapZodFetch(
209215
z.unknown(),

packages/core/src/v3/runEngineWorker/supervisor/session.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type SupervisorSessionOptions = SupervisorClientCommonOptions & {
2121
preSkip?: PreSkipFn;
2222
maxRunCount?: number;
2323
maxConsumerCount?: number;
24+
sendRunDebugLogs?: boolean;
2425
};
2526

2627
export class SupervisorSession extends EventEmitter<WorkerEvents> {

packages/core/src/v3/runEngineWorker/supervisor/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type SupervisorClientCommonOptions = {
66
instanceName: string;
77
deploymentId?: string;
88
managedWorkerSecret?: string;
9+
sendRunDebugLogs?: boolean;
910
};
1011

1112
export type PreDequeueFn = () => Promise<{

0 commit comments

Comments
 (0)