@timber-js/app 0.1.45 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server/logger.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export declare function logRequestCompleted(data: {
|
|
|
30
30
|
path: string;
|
|
31
31
|
status: number;
|
|
32
32
|
durationMs: number;
|
|
33
|
+
/** Number of concurrent in-flight requests (including this one) at completion time. */
|
|
34
|
+
concurrency?: number;
|
|
33
35
|
}): void;
|
|
34
36
|
/** Log request received. Level: debug. */
|
|
35
37
|
export declare function logRequestReceived(data: {
|
|
@@ -42,6 +44,8 @@ export declare function logSlowRequest(data: {
|
|
|
42
44
|
path: string;
|
|
43
45
|
durationMs: number;
|
|
44
46
|
threshold: number;
|
|
47
|
+
/** Number of concurrent in-flight requests at the time the slow request completed. */
|
|
48
|
+
concurrency?: number;
|
|
45
49
|
}): void;
|
|
46
50
|
/** Log middleware short-circuit. Level: debug. */
|
|
47
51
|
export declare function logMiddlewareShortCircuit(data: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/server/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,6FAA6F;AAC7F,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACxD,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACxD,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzD,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM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O,EACZ,eAAe,EAAE,OAAO,KACrB,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACnC;AAID;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CA+V1F"}
|
package/package.json
CHANGED
package/src/server/logger.ts
CHANGED
|
@@ -67,6 +67,8 @@ export function logRequestCompleted(data: {
|
|
|
67
67
|
path: string;
|
|
68
68
|
status: number;
|
|
69
69
|
durationMs: number;
|
|
70
|
+
/** Number of concurrent in-flight requests (including this one) at completion time. */
|
|
71
|
+
concurrency?: number;
|
|
70
72
|
}): void {
|
|
71
73
|
_logger?.info('request completed', withTraceContext(data));
|
|
72
74
|
}
|
|
@@ -82,6 +84,8 @@ export function logSlowRequest(data: {
|
|
|
82
84
|
path: string;
|
|
83
85
|
durationMs: number;
|
|
84
86
|
threshold: number;
|
|
87
|
+
/** Number of concurrent in-flight requests at the time the slow request completed. */
|
|
88
|
+
concurrency?: number;
|
|
85
89
|
}): void {
|
|
86
90
|
_logger?.warn('slow request exceeded threshold', withTraceContext(data));
|
|
87
91
|
}
|
package/src/server/pipeline.ts
CHANGED
|
@@ -173,11 +173,16 @@ export function createPipeline(config: PipelineConfig): (req: Request) => Promis
|
|
|
173
173
|
onPipelineError,
|
|
174
174
|
} = config;
|
|
175
175
|
|
|
176
|
+
// Concurrent request counter — tracks how many requests are in-flight.
|
|
177
|
+
// Logged with each request for diagnosing resource contention.
|
|
178
|
+
let activeRequests = 0;
|
|
179
|
+
|
|
176
180
|
return async (req: Request): Promise<Response> => {
|
|
177
181
|
const url = new URL(req.url);
|
|
178
182
|
const method = req.method;
|
|
179
183
|
const path = url.pathname;
|
|
180
184
|
const startTime = performance.now();
|
|
185
|
+
activeRequests++;
|
|
181
186
|
|
|
182
187
|
// Establish per-request trace ID scope (design/17-logging.md §"trace_id is Always Set").
|
|
183
188
|
// This runs before runWithRequestContext so traceId() is available from the
|
|
@@ -215,9 +220,9 @@ export function createPipeline(config: PipelineConfig): (req: Request) => Promis
|
|
|
215
220
|
// DevSpanProcessor reads this for tree/summary output.
|
|
216
221
|
await setSpanAttribute('http.response.status_code', result.status);
|
|
217
222
|
|
|
218
|
-
// Append Server-Timing header
|
|
219
|
-
//
|
|
220
|
-
//
|
|
223
|
+
// Append Server-Timing header.
|
|
224
|
+
// In dev mode: detailed per-phase breakdown (proxy, middleware, render).
|
|
225
|
+
// In production: single total duration — safe to expose, no phase names.
|
|
221
226
|
// Response.redirect() creates immutable headers, so we must
|
|
222
227
|
// ensure mutability before writing Server-Timing.
|
|
223
228
|
if (enableServerTiming) {
|
|
@@ -226,6 +231,13 @@ export function createPipeline(config: PipelineConfig): (req: Request) => Promis
|
|
|
226
231
|
result = ensureMutableResponse(result);
|
|
227
232
|
result.headers.set('Server-Timing', serverTiming);
|
|
228
233
|
}
|
|
234
|
+
} else {
|
|
235
|
+
// Production: emit total request duration only.
|
|
236
|
+
// No phase breakdown — prevents information disclosure
|
|
237
|
+
// while giving browser DevTools useful timing data.
|
|
238
|
+
const totalMs = Math.round(performance.now() - startTime);
|
|
239
|
+
result = ensureMutableResponse(result);
|
|
240
|
+
result.headers.set('Server-Timing', `total;dur=${totalMs}`);
|
|
229
241
|
}
|
|
230
242
|
|
|
231
243
|
return result;
|
|
@@ -235,10 +247,12 @@ export function createPipeline(config: PipelineConfig): (req: Request) => Promis
|
|
|
235
247
|
// Post-span: structured production logging
|
|
236
248
|
const durationMs = Math.round(performance.now() - startTime);
|
|
237
249
|
const status = response.status;
|
|
238
|
-
|
|
250
|
+
const concurrency = activeRequests;
|
|
251
|
+
activeRequests--;
|
|
252
|
+
logRequestCompleted({ method, path, status, durationMs, concurrency });
|
|
239
253
|
|
|
240
254
|
if (slowRequestMs > 0 && durationMs > slowRequestMs) {
|
|
241
|
-
logSlowRequest({ method, path, durationMs, threshold: slowRequestMs });
|
|
255
|
+
logSlowRequest({ method, path, durationMs, threshold: slowRequestMs, concurrency });
|
|
242
256
|
}
|
|
243
257
|
|
|
244
258
|
return response;
|
|
@@ -474,6 +488,16 @@ export function createPipeline(config: PipelineConfig): (req: Request) => Promis
|
|
|
474
488
|
markResponseFlushed();
|
|
475
489
|
return response;
|
|
476
490
|
} catch (error) {
|
|
491
|
+
// DenySignal leaked from render (e.g. notFound() in metadata()).
|
|
492
|
+
// Return the deny status code instead of 500.
|
|
493
|
+
if (error instanceof DenySignal) {
|
|
494
|
+
return new Response(null, { status: error.status });
|
|
495
|
+
}
|
|
496
|
+
// RedirectSignal leaked from render — honour the redirect.
|
|
497
|
+
if (error instanceof RedirectSignal) {
|
|
498
|
+
responseHeaders.set('Location', error.location);
|
|
499
|
+
return new Response(null, { status: error.status, headers: responseHeaders });
|
|
500
|
+
}
|
|
477
501
|
logRenderError({ method, path, error });
|
|
478
502
|
await fireOnRequestError(error, req, 'render');
|
|
479
503
|
if (onPipelineError && error instanceof Error) onPipelineError(error, 'render');
|