Skip to content

Commit 5f9dc60

Browse files
authored
commit sha logging (#2505)
1 parent e2b4ca4 commit 5f9dc60

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

Dockerfile_ui

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ RUN --mount=type=cache,target=/root/.npm \
2222
########### Runtime: minimal production image ###########
2323
FROM node:22-alpine AS runner
2424

25+
ARG COMMIT_SHA
2526
WORKDIR /app
2627

2728
# Set env before install so some libs can optimize for production
2829
ENV NODE_ENV=production
2930
ENV PORT=3030
3031
ENV HOST=0.0.0.0
32+
ENV COMMIT_SHA=${COMMIT_SHA}
3133

3234
# Install only production deps
3335
COPY ui/package.json ui/package-lock.json ./

ui/request-logging.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ export function logRequestInit(method, path, requestId, userId, orgId) {
6161
}));
6262
}
6363

64-
export function logResponse(method, path, requestId, latency, statusCode) {
64+
export function logResponse(method, path, requestId, latency, statusCode, commitSha) {
6565
console.log(JSON.stringify({
6666
event: 'response_sent',
6767
method,
6868
path,
6969
requestId,
7070
latency,
7171
statusCode,
72+
commitSha: commitSha || 'unknown',
7273
}));
7374
}
7475

ui/server-start.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url));
1515
const PORT = process.env.PORT || 3030;
1616
const HOST = process.env.HOST || '0.0.0.0';
1717
const REQUEST_TIMEOUT = 60 * 1000; // 60s timeout for requests
18+
const COMMIT_SHA = process.env.COMMIT_SHA || 'unknown';
1819

1920
// Configure global fetch with connection pooling for much better performance
2021
// Without this, every fetch creates a new TCP connection (DNS + handshake overhead)
@@ -110,7 +111,7 @@ const server = createServer(async (req, res) => {
110111

111112
// Set request timeout
112113
req.setTimeout(REQUEST_TIMEOUT, () => {
113-
console.error(`⏱️ Request timeout (${REQUEST_TIMEOUT}ms): ${req.method} ${req.url} [${requestId}]`);
114+
console.error(`⏱️ Request timeout (${REQUEST_TIMEOUT}ms): ${req.method} ${req.url} [${requestId}] [commitSha: ${COMMIT_SHA}]`);
114115
if (!res.headersSent) {
115116
res.writeHead(408, { 'Content-Type': 'text/plain' });
116117
res.end('Request Timeout');
@@ -140,7 +141,7 @@ const server = createServer(async (req, res) => {
140141
// Log response for static files
141142
try {
142143
const latency = Date.now() - requestStart;
143-
logResponse(method, pathname, requestId, latency, 200);
144+
logResponse(method, pathname, requestId, latency, 200, COMMIT_SHA);
144145
} catch (err) {
145146
console.error(`Response logging error [${requestId}]:`, err);
146147
}
@@ -177,9 +178,9 @@ const server = createServer(async (req, res) => {
177178

178179
// Log slow SSR requests
179180
if (ssrTime > 2000) {
180-
console.debug(`🔥 VERY SLOW SSR: ${req.method} ${pathname} took ${ssrTime}ms [${requestId}]`);
181+
console.debug(`🔥 VERY SLOW SSR: ${req.method} ${pathname} took ${ssrTime}ms [${requestId}] [commitSha: ${COMMIT_SHA}]`);
181182
} else if (ssrTime > 1000) {
182-
console.debug(`⚠️ SLOW SSR: ${req.method} ${pathname} took ${ssrTime}ms [${requestId}]`);
183+
console.debug(`⚠️ SLOW SSR: ${req.method} ${pathname} took ${ssrTime}ms [${requestId}] [commitSha: ${COMMIT_SHA}]`);
183184
}
184185

185186
// Convert Web Standard Response to Node.js response
@@ -270,7 +271,7 @@ const server = createServer(async (req, res) => {
270271
// Log response after sending
271272
try {
272273
const latency = Date.now() - requestStart;
273-
logResponse(method, pathname, requestId, latency, res.statusCode);
274+
logResponse(method, pathname, requestId, latency, res.statusCode, COMMIT_SHA);
274275
} catch (err) {
275276
console.error(`Response logging error [${requestId}]:`, err);
276277
}
@@ -284,7 +285,7 @@ const server = createServer(async (req, res) => {
284285
// Log error response
285286
try {
286287
const latency = Date.now() - requestStart;
287-
logResponse(method, pathname, requestId, latency, res.statusCode || 500);
288+
logResponse(method, pathname, requestId, latency, res.statusCode || 500, COMMIT_SHA);
288289
} catch (err) {
289290
console.error(`Error response logging error [${requestId}]:`, err);
290291
}

0 commit comments

Comments
 (0)