Skip to content

Optionally disable run debug logs #2116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fuzzy-snakes-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/core": patch
---

Add supervisor http client option to disable debug logs
1 change: 1 addition & 0 deletions apps/supervisor/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const Env = z.object({

// Debug
DEBUG: BoolEnv.default(false),
SEND_RUN_DEBUG_LOGS: BoolEnv.default(false),
});

export const env = Env.parse(stdEnv);
1 change: 1 addition & 0 deletions apps/supervisor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class ManagedSupervisor {
maxConsumerCount: env.TRIGGER_DEQUEUE_MAX_CONSUMER_COUNT,
runNotificationsEnabled: env.TRIGGER_WORKLOAD_API_ENABLED,
heartbeatIntervalSeconds: env.TRIGGER_WORKER_HEARTBEAT_INTERVAL_SECONDS,
sendRunDebugLogs: env.SEND_RUN_DEBUG_LOGS,
preDequeue: async () => {
if (!env.RESOURCE_MONITOR_ENABLED) {
return {};
Expand Down
5 changes: 5 additions & 0 deletions apps/supervisor/src/workloadServer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { HttpServer, type CheckpointClient } from "@trigger.dev/core/v3/serverOnly";
import { type IncomingMessage } from "node:http";
import { register } from "../metrics.js";
import { env } from "../env.js";

// Use the official export when upgrading to [email protected]
interface DefaultEventsMap {
Expand Down Expand Up @@ -374,6 +375,10 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
handler: async ({ req, reply, params, body }) => {
reply.empty(204);

if (!env.SEND_RUN_DEBUG_LOGS) {
return;
}

await this.workerClient.sendDebugLog(
params.runFriendlyId,
body,
Expand Down
115 changes: 60 additions & 55 deletions apps/webapp/app/routes/engine.v1.dev.runs.$runFriendlyId.logs.debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,69 @@ import { logger } from "~/services/logger.server";
import { createActionApiRoute } from "~/services/routeBuilders/apiBuilder.server";
import { recordRunDebugLog } from "~/v3/eventRepository.server";

const { action } = createActionApiRoute(
{
params: z.object({
runFriendlyId: z.string(),
}),
body: WorkerApiDebugLogBody,
method: "POST",
},
async ({
authentication,
body,
params,
}): Promise<TypedResponse<WorkerApiRunAttemptStartResponseBody>> => {
const { runFriendlyId } = params;
// const { action } = createActionApiRoute(
// {
// params: z.object({
// runFriendlyId: z.string(),
// }),
// body: WorkerApiDebugLogBody,
// method: "POST",
// },
// async ({
// authentication,
// body,
// params,
// }): Promise<TypedResponse<WorkerApiRunAttemptStartResponseBody>> => {
// const { runFriendlyId } = params;

try {
const run = await prisma.taskRun.findFirst({
where: {
friendlyId: params.runFriendlyId,
runtimeEnvironmentId: authentication.environment.id,
},
});
// try {
// const run = await prisma.taskRun.findFirst({
// where: {
// friendlyId: params.runFriendlyId,
// runtimeEnvironmentId: authentication.environment.id,
// },
// });

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

const eventResult = await recordRunDebugLog(
RunId.fromFriendlyId(runFriendlyId),
body.message,
{
attributes: {
properties: body.properties,
},
startTime: body.time,
}
);
// const eventResult = await recordRunDebugLog(
// RunId.fromFriendlyId(runFriendlyId),
// body.message,
// {
// attributes: {
// properties: body.properties,
// },
// startTime: body.time,
// }
// );

if (eventResult.success) {
return new Response(null, { status: 204 });
}
// if (eventResult.success) {
// return new Response(null, { status: 204 });
// }

switch (eventResult.code) {
case "FAILED_TO_RECORD_EVENT":
return new Response(null, { status: 400 }); // send a 400 to prevent retries
case "RUN_NOT_FOUND":
return new Response(null, { status: 404 });
default:
return assertExhaustive(eventResult.code);
}
} catch (error) {
logger.error("Failed to record dev log", {
environmentId: authentication.environment.id,
error,
});
throw error;
}
}
);
// switch (eventResult.code) {
// case "FAILED_TO_RECORD_EVENT":
// return new Response(null, { status: 400 }); // send a 400 to prevent retries
// case "RUN_NOT_FOUND":
// return new Response(null, { status: 404 });
// default:
// return assertExhaustive(eventResult.code);
// }
// } catch (error) {
// logger.error("Failed to record dev log", {
// environmentId: authentication.environment.id,
// error,
// });
// throw error;
// }
// }
// );

export { action };
// export { action };

// Create a generic JSON action in remix
export function action() {
return new Response(null, { status: 204 });
}
2 changes: 1 addition & 1 deletion apps/webapp/app/routes/healthcheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LoaderFunction } from "@remix-run/node";

export const loader: LoaderFunction = async ({ request }) => {
try {
await prisma.user.count();
await prisma.$queryRaw`SELECT 1`;
return new Response("OK");
} catch (error: unknown) {
console.log("healthcheck ❌", { error });
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/v3/runEngineWorker/supervisor/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class SupervisorHttpClient {
private readonly workerToken: string;
private readonly instanceName: string;
private readonly defaultHeaders: Record<string, string>;
private readonly sendRunDebugLogs: boolean;

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

Expand All @@ -41,6 +42,7 @@ export class SupervisorHttpClient {
this.workerToken = opts.workerToken;
this.instanceName = opts.instanceName;
this.defaultHeaders = getDefaultWorkerHeaders(opts);
this.sendRunDebugLogs = opts.sendRunDebugLogs ?? false;

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

async sendDebugLog(runId: string, body: WorkerApiDebugLogBody, runnerId?: string): Promise<void> {
if (!this.sendRunDebugLogs) {
return;
}

try {
const res = await wrapZodFetch(
z.unknown(),
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/v3/runEngineWorker/supervisor/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type SupervisorSessionOptions = SupervisorClientCommonOptions & {
preSkip?: PreSkipFn;
maxRunCount?: number;
maxConsumerCount?: number;
sendRunDebugLogs?: boolean;
};

export class SupervisorSession extends EventEmitter<WorkerEvents> {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/v3/runEngineWorker/supervisor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type SupervisorClientCommonOptions = {
instanceName: string;
deploymentId?: string;
managedWorkerSecret?: string;
sendRunDebugLogs?: boolean;
};

export type PreDequeueFn = () => Promise<{
Expand Down