-
-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathrequest_context.js
More file actions
24 lines (17 loc) · 801 Bytes
/
request_context.js
File metadata and controls
24 lines (17 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { core, internals } from "ext:core/mod.js";
const { AsyncVariable } = core;
const requestTraceIdVar = new AsyncVariable();
// Header injected by the runtime's fetch / node:http into every outbound
// request to propagate the request-local trace ID for rate limiting.
// Defined once here and shared via internals to avoid scattered string literals.
const FETCH_TRACE_ID_HEADER = "x-er-fetch-trace-id";
function enterRequestContext(traceId) {
return requestTraceIdVar.enter(traceId);
}
function getRequestTraceId() {
return requestTraceIdVar.get();
}
internals.enterRequestContext = enterRequestContext;
internals.getRequestTraceId = getRequestTraceId;
internals.FETCH_TRACE_ID_HEADER = FETCH_TRACE_ID_HEADER;
export { enterRequestContext, FETCH_TRACE_ID_HEADER, getRequestTraceId };