Point the request-wrapper comments at request-tracking.ts
This commit is contained in:
+1
-1
@@ -183,7 +183,7 @@ export function createApp(options: AppOptions = {}): Server {
|
|||||||
{ handler: serveDashboard, method: "GET", path: "/dashboard", session: true },
|
{ handler: serveDashboard, method: "GET", path: "/dashboard", session: true },
|
||||||
];
|
];
|
||||||
|
|
||||||
// The request handler. Run inside runWithLog (below) so the per-request logger is ambient: every
|
// The request handler. Run inside runWithLog (request-tracking.ts) so the per-request logger is ambient: every
|
||||||
// outbound fetch (the Ory clients via tracedFetch) and any deep module joins this request's trace
|
// outbound fetch (the Ory clients via tracedFetch) and any deep module joins this request's trace
|
||||||
// and correlation with no logger threaded through their signatures.
|
// and correlation with no logger threaded through their signatures.
|
||||||
const handleRequest = async (req: IncomingMessage, res: ServerResponse, reqLog: Log): Promise<void> => {
|
const handleRequest = async (req: IncomingMessage, res: ServerResponse, reqLog: Log): Promise<void> => {
|
||||||
|
|||||||
+2
-2
@@ -38,7 +38,7 @@ export function createLogger(opts: LoggerOptions = {}): Log {
|
|||||||
// The ambient per-request Log (see the header); set by runWithLog, read by currentLog/tracedFetch.
|
// The ambient per-request Log (see the header); set by runWithLog, read by currentLog/tracedFetch.
|
||||||
const requestStore = new AsyncLocalStorage<Log>();
|
const requestStore = new AsyncLocalStorage<Log>();
|
||||||
|
|
||||||
// Run `fn` with `log` as the ambient request logger (app.ts wraps each request). currentLog() reads
|
// Run `fn` with `log` as the ambient request logger (request-tracking.ts wraps each request). currentLog() reads
|
||||||
// it back; returns undefined outside any request (boot, tests) so callers use `currentLog()?.info(…)`.
|
// it back; returns undefined outside any request (boot, tests) so callers use `currentLog()?.info(…)`.
|
||||||
export function runWithLog<T>(log: Log, fn: () => T): T {
|
export function runWithLog<T>(log: Log, fn: () => T): T {
|
||||||
return requestStore.run(log, fn);
|
return requestStore.run(log, fn);
|
||||||
@@ -50,7 +50,7 @@ export function currentLog(): Log | undefined {
|
|||||||
// A drop-in `fetch` that traces through the active request log — a client span under the request
|
// A drop-in `fetch` that traces through the active request log — a client span under the request
|
||||||
// span, with a W3C `traceparent` injected so the downstream service continues the same trace.
|
// span, with a W3C `traceparent` injected so the downstream service continues the same trace.
|
||||||
// Outside a request, or for a non-string/URL input, it is a plain `fetch`. Note log.fetch throws
|
// Outside a request, or for a non-string/URL input, it is a plain `fetch`. Note log.fetch throws
|
||||||
// synchronously once the request log has ended; app.ts ends it only after the handler unwinds.
|
// synchronously once the request log has ended; request-tracking.ts ends it only after the handler unwinds.
|
||||||
export const tracedFetch: typeof fetch = (input, init) => {
|
export const tracedFetch: typeof fetch = (input, init) => {
|
||||||
const log = currentLog();
|
const log = currentLog();
|
||||||
if (log && (typeof input === "string" || input instanceof URL)) return log.fetch(input, init);
|
if (log && (typeof input === "string" || input instanceof URL)) return log.fetch(input, init);
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ const config = loadConfig(); // validates the env (incl. enforced secrets) — f
|
|||||||
// depth, not a boundary (AGENTS.md) — and only ever move this line earlier, never later.
|
// depth, not a boundary (AGENTS.md) — and only ever move this line earlier, never later.
|
||||||
delete process.env["PLUGIN_DB_SECRET"];
|
delete process.env["PLUGIN_DB_SECRET"];
|
||||||
// App-level logger: structured, OTLP-capable when OTLP_ENDPOINT is set. The hot path clones it
|
// App-level logger: structured, OTLP-capable when OTLP_ENDPOINT is set. The hot path clones it
|
||||||
// per request for access logging + a trace span (src/http/app.ts); console-only otherwise.
|
// per request for access logging + a trace span (src/http/request-tracking.ts); console-only otherwise.
|
||||||
const log = createLogger({ format: config.logFormat, level: config.logLevel, otlpEndpoint: config.otlpEndpoint, otlpProtocol: config.otlpProtocol, serviceName: config.serviceName });
|
const log = createLogger({ format: config.logFormat, level: config.logLevel, otlpEndpoint: config.otlpEndpoint, otlpProtocol: config.otlpProtocol, serviceName: config.serviceName });
|
||||||
const menu = await loadMenuConfig(); // config/menu.ts override + branding — fails loud if malformed
|
const menu = await loadMenuConfig(); // config/menu.ts override + branding — fails loud if malformed
|
||||||
// Every outbound Ory call is traced through the active request's logger (a client span continuing
|
// Every outbound Ory call is traced through the active request's logger (a client span continuing
|
||||||
|
|||||||
Reference in New Issue
Block a user