I’m trying to add trace-id headers to request entering my system. Ideally since Cloudflare is the front door it would do this for me. I don’t see standard or built in way to do this. I’ve went down the rabbit hole of getting a worker to add it inline before it makes it to my origin server
const genRanHex = size => [...Array(size)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const response = await fetch(request);
// Clone the response so that it's no longer immutable
const newResponse = new Response(response.body, response);
// Add a custom header with a value
newResponse.headers.append('x-workers-hello', 'Hello from Cloudflare Workers');
newResponse.headers.append('traceid', genRanHex(32));
return newResponse;
}
i see it on the response header, but not the request header. I have a webserver that dumps request headers and i don’t see it there either. is there away to add it to the request header?
It does seem i’m editing the response not the request. I’m trying to get this example working. My javascript is limited. so far i haven’t had any luck.