Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

feat: enhance logging for database and Redis connections, update access log middleware to exclude /assets/ (#746)

Sujai Kumar Gupta7dc875746518
diff --git a/.changeset/postgres-redis-startup-access-logs.md b/.changeset/postgres-redis-startup-access-logs.md
new file mode 100644
index 000000000..f8040841b
--- /dev/null
+++ b/.changeset/postgres-redis-startup-access-logs.md
@@ -0,0 +1,5 @@
+---
+"@truefoundry/trueforge": patch
+---
+
+Log while connecting to Postgres and Redis on startup, and skip access logs for `/assets/`.
diff --git a/packages/trueforge/src/app.ts b/packages/trueforge/src/app.ts
index a89ecfedb..a8c9ef36e 100644
--- a/packages/trueforge/src/app.ts
+++ b/packages/trueforge/src/app.ts
@@ -72,17 +72,18 @@ function withAdminAuth(router: OpenAPIHono, middleware: MiddlewareHandler): Open
return shell;
}
-/** One line per request: method, path, status, duration. Skips `/healthz`. */
+/** One line per request: method, path, status, duration. Skips `/healthz` and `/assets/`. */
export function createAccessLogMiddleware(logger: Logger): MiddlewareHandler {
return async (c, next) => {
const started = performance.now();
await next();
- if (c.req.path === '/healthz') {
+ const path = c.req.path;
+ if (path === '/healthz' || path.startsWith('/assets/')) {
return;
}
logger.info('request', {
method: c.req.method,
- path: c.req.path,
+ path,
status: c.res.status,
duration_ms: Math.round(performance.now() - started),
});
diff --git a/packages/trueforge/src/config.ts b/packages/trueforge/src/config.ts
index 51c109608..770f68367 100644
--- a/packages/trueforge/src/config.ts
+++ b/packages/trueforge/src/config.ts
@@ -430,7 +430,7 @@ export interface OIDCConfig {
export interface SharedServerConfiguration {
/** Log level. Env: `LOG_LEVEL`. */
LOG_LEVEL: string;
- /** Log one line per HTTP request (except `/healthz`). Env: `ACCESS_LOGS`. Default true. */
+ /** Log one line per HTTP request (except `/healthz` and `/assets/`). Env: `ACCESS_LOGS`. Default true. */
ACCESS_LOGS: boolean;
/** Node environment. Env: `NODE_ENV`. */
NODE_ENV: string | undefined;
diff --git a/packages/trueforge/src/controller-main.ts b/packages/trueforge/src/controller-main.ts
index 238d704bc..d786a38f8 100644
--- a/packages/trueforge/src/controller-main.ts
+++ b/packages/trueforge/src/controller-main.ts
@@ -34,6 +34,7 @@ try {
process.exit(0);
}
+ logger.info('Connecting to Postgres');
const db = createDb({
connectionString: configuration.DATABASE_URL,
poolMax: configuration.DATABASE_POOL_MAX,
diff --git a/packages/trueforge/src/main.ts b/packages/trueforge/src/main.ts
index 62b786166..a08c8f38e 100644
--- a/packages/trueforge/src/main.ts
+++ b/packages/trueforge/src/main.ts
@@ -384,6 +384,7 @@ async function createDistributedPersistence(options: {
{ PostgresScheduleStore },
] = postgresStores;
+ logger.info('Connecting to Postgres');
const db = createDb({
connectionString: databaseUrl,
poolMax: databasePoolMax,
@@ -391,7 +392,6 @@ async function createDistributedPersistence(options: {
idleInTransactionSessionTimeoutMs,
});
await migrateToLatest(db);
- logger.info('Distributed mode: postgres');
logger.info(`Executor id: ${executorId}`);
const serviceFoundryClient = createServiceFoundryServerClient(logger);
const tokenStore = new PostgresOAuthTokenStore(db);
diff --git a/packages/trueforge/src/runtime/redis.ts b/packages/trueforge/src/runtime/redis.ts
index df61a6820..3710c4db7 100644
--- a/packages/trueforge/src/runtime/redis.ts
+++ b/packages/trueforge/src/runtime/redis.ts
@@ -8,6 +8,7 @@ import { createClient, type RedisClientType } from 'redis';
import type { Logger } from 'winston';
export async function connectRedis(input: { url: string; logger: Logger }): Promise<RedisClientType> {
+ input.logger.info('Connecting to Redis');
const client: RedisClientType = createClient({ url: input.url });
// Without an 'error' listener node-redis crashes the process on emit;
// reconnects are automatic, so log and keep running.
@@ -15,5 +16,6 @@ export async function connectRedis(input: { url: string; logger: Logger }): Prom
input.logger.error('[Redis] Client error', extractErrorLogFields(error));
});
await client.connect();
+ input.logger.info('Connected to Redis');
return client;
}