@naturalcycles/backend-lib 9.85.1 → 9.86.0
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.
|
@@ -10,12 +10,11 @@ const traceIdByRequest = new WeakMap();
|
|
|
10
10
|
* every log line.
|
|
11
11
|
*/
|
|
12
12
|
export function getRequestTraceId(req) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return traceId ?? undefined;
|
|
13
|
+
return traceIdByRequest.getOrInsertComputed(req, getRequestTraceIdOrNull) ?? undefined;
|
|
14
|
+
}
|
|
15
|
+
// Passed by reference, so the per-log-line call allocates no closure
|
|
16
|
+
function getRequestTraceIdOrNull(req) {
|
|
17
|
+
return getRequestTraceContext(req)?.traceId ?? null;
|
|
19
18
|
}
|
|
20
19
|
export function getRequestTraceContext(req) {
|
|
21
20
|
// Reads from `req.headers` and not `req.header()`, so a bare request object (as in tests) works too
|
package/package.json
CHANGED
package/src/server/trace.util.ts
CHANGED
|
@@ -23,12 +23,12 @@ const traceIdByRequest = new WeakMap<BackendRequest, string | null>()
|
|
|
23
23
|
* every log line.
|
|
24
24
|
*/
|
|
25
25
|
export function getRequestTraceId(req: BackendRequest): string | undefined {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return traceId ??
|
|
26
|
+
return traceIdByRequest.getOrInsertComputed(req, getRequestTraceIdOrNull) ?? undefined
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Passed by reference, so the per-log-line call allocates no closure
|
|
30
|
+
function getRequestTraceIdOrNull(req: BackendRequest): string | null {
|
|
31
|
+
return getRequestTraceContext(req)?.traceId ?? null
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export function getRequestTraceContext(req: BackendRequest): TraceContext | undefined {
|