Skip to content

Commit 6535565

Browse files
committed
feat(cli,core): add opt-in dev-only telnet log streaming
Stream dev logs over a local telnet/TCP socket. `trigger dev` mirrors its terminal output on port 6700 by default (override with --telnet-logs-port or TRIGGER_DEV_TELNET_LOGS_PORT, 0 disables). webapp, supervisor, and coordinator each expose an opt-in stream gated on a per-service *_TELNET_LOGS_PORT env var. New @trigger.dev/core/v3/telnetLogServer module (localhost-only, backpressure-safe, plain-text) plus optional static Logger.onLog / SimpleStructuredLogger.onLog sinks.
1 parent 6563793 commit 6535565

17 files changed

Lines changed: 527 additions & 2 deletions

File tree

.changeset/telnet-dev-logs.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 a `@trigger.dev/core/v3/telnetLogServer` module: the shared `TelnetLogServer` (localhost-only, backpressure-safe), `formatLogLine`, and `stripAnsi` helpers, plus an optional static `Logger.onLog` / `SimpleStructuredLogger.onLog` sink used to fan structured logs out to a local dev-only telnet/TCP stream.

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres?schema=publi
88
# See: https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#fields:~:text=the%20shadow%20database.-,directUrl,-No
99
DIRECT_URL=${DATABASE_URL}
1010
REMIX_APP_PORT=3030
11+
# Dev-only: stream the webapp's logs over a local telnet/TCP socket (nc localhost 6767). Unset to disable.
12+
WEBAPP_TELNET_LOGS_PORT=6767
1113
APP_ENV=development
1214
APP_ORIGIN=http://localhost:3030
1315
ELECTRIC_ORIGIN=http://localhost:3060
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: coordinator
3+
type: feature
4+
---
5+
6+
Add an opt-in, dev-only telnet log stream: set `COORDINATOR_TELNET_LOGS_PORT` (e.g. 6770) to tail this process's logs as plain text over a local TCP socket (`nc localhost 6770`). Bound to localhost; off unless the port is set.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: supervisor
3+
type: feature
4+
---
5+
6+
Add an opt-in, dev-only telnet log stream: set `SUPERVISOR_TELNET_LOGS_PORT` (e.g. 6769) to tail this process's logs as plain text over a local TCP socket (`nc localhost 6769`). Bound to localhost; off unless the port is set.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: feature
4+
---
5+
6+
Add an opt-in, dev-only telnet log stream: set `WEBAPP_TELNET_LOGS_PORT` (e.g. 6767) to tail this process's logs as plain text over a local TCP socket (`nc localhost 6767`). Bound to localhost; off unless the port is set.

apps/coordinator/.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
HTTP_SERVER_PORT=8020
22
PLATFORM_ENABLED=true
33
PLATFORM_WS_PORT=3030
4-
SECURE_CONNECTION=false
4+
SECURE_CONNECTION=false
5+
# Dev-only: stream this process's logs over a local telnet/TCP socket (nc localhost 6770). Unset to disable.
6+
COORDINATOR_TELNET_LOGS_PORT=6770

apps/coordinator/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ import { boolFromEnv, numFromEnv, safeJsonParse } from "./util";
1818

1919
import { collectDefaultMetrics, register, Gauge } from "prom-client";
2020
import { SimpleStructuredLogger } from "@trigger.dev/core/v3/utils/structuredLogger";
21+
import { formatLogLine, startTelnetLogServer } from "@trigger.dev/core/v3/telnetLogServer";
2122
collectDefaultMetrics();
2223

2324
const HTTP_SERVER_PORT = Number(process.env.HTTP_SERVER_PORT || 8020);
25+
const TELNET_LOGS_PORT = process.env.COORDINATOR_TELNET_LOGS_PORT
26+
? Number(process.env.COORDINATOR_TELNET_LOGS_PORT)
27+
: undefined;
2428
const NODE_NAME = process.env.NODE_NAME || "coordinator";
2529
const DEFAULT_RETRY_DELAY_THRESHOLD_IN_MS = 30_000;
2630

@@ -1777,5 +1781,11 @@ class TaskCoordinator {
17771781
}
17781782
}
17791783

1784+
// Opt-in, dev-only: mirror this process's structured logs to a local telnet/TCP stream.
1785+
if (TELNET_LOGS_PORT && Number.isFinite(TELNET_LOGS_PORT) && TELNET_LOGS_PORT > 0) {
1786+
const telnetLogServer = startTelnetLogServer({ port: TELNET_LOGS_PORT, name: "coordinator" });
1787+
SimpleStructuredLogger.onLog = (log) => telnetLogServer.broadcast(formatLogLine(log));
1788+
}
1789+
17801790
const coordinator = new TaskCoordinator(HTTP_SERVER_PORT);
17811791
coordinator.listen();

apps/supervisor/.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:3030/otel
1414

1515
# Optional settings
1616
DEBUG=1
17-
TRIGGER_DEQUEUE_INTERVAL_MS=1000
17+
TRIGGER_DEQUEUE_INTERVAL_MS=1000
18+
19+
# Dev-only: stream this process's logs over a local telnet/TCP socket (nc localhost 6769). Unset to disable.
20+
SUPERVISOR_TELNET_LOGS_PORT=6769

apps/supervisor/src/env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export const Env = z
99
TRIGGER_WORKER_INSTANCE_NAME: z.string().default(randomUUID()),
1010
TRIGGER_WORKER_HEARTBEAT_INTERVAL_SECONDS: z.coerce.number().default(30),
1111

12+
// Opt-in, dev-only: stream this process's logs over a local telnet/TCP socket on this port.
13+
SUPERVISOR_TELNET_LOGS_PORT: z.coerce.number().optional(),
14+
1215
// Required settings
1316
TRIGGER_API_URL: z.string().url(),
1417
TRIGGER_WORKER_TOKEN: z.string(), // accepts file:// path to read from a file

apps/supervisor/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { SupervisorSession } from "@trigger.dev/core/v3/workers";
22
import { SimpleStructuredLogger } from "@trigger.dev/core/v3/utils/structuredLogger";
3+
import { formatLogLine, startTelnetLogServer } from "@trigger.dev/core/v3/telnetLogServer";
34
import { env } from "./env.js";
45
import { WorkloadServer } from "./workloadServer/index.js";
56
import type { WorkloadManagerOptions, WorkloadManager } from "./workloadManager/types.js";
@@ -749,5 +750,14 @@ class ManagedSupervisor {
749750
}
750751
}
751752

753+
// Opt-in, dev-only: mirror this process's structured logs to a local telnet/TCP stream.
754+
if (env.SUPERVISOR_TELNET_LOGS_PORT && env.SUPERVISOR_TELNET_LOGS_PORT > 0) {
755+
const telnetLogServer = startTelnetLogServer({
756+
port: env.SUPERVISOR_TELNET_LOGS_PORT,
757+
name: "supervisor",
758+
});
759+
SimpleStructuredLogger.onLog = (log) => telnetLogServer.broadcast(formatLogLine(log));
760+
}
761+
752762
const worker = new ManagedSupervisor();
753763
worker.start();

0 commit comments

Comments
 (0)