Slide 40
Slide 40 text
どのように活⽤できるか
AsyncContext.Variableの例: 分散トレーシング
// ① トレースライブラリ( npm)
const currentTrace = new AsyncContext.Variable();
export function startTrace(fn) {
return currentTrace.run(newId(), fn);
}
export function tracedFetch(url, opts){
const traceId = currentTrace.get();
return fetch(url, { ...opts, headers: { "x-trace-id": traceId }});
}
// ② アプリ
button.onclick = () => tracing.startTrace(async () => {
await validateForm();
await tracing.tracedFetch("/api/orders", {
method: "POST", body,
});
});
© PeopleX Inc.
41