Unique Request Identifier?
Is there a straightforward way to assign a unique Request ID (eg. x-request-id
), and have it logged and passed to backends? I’m working on improving transaction tracing in our apps, and it’d be nice to extend that to the CDN too.
Looks like Varnish has a X-Varnish header which will do part of that (combined with a timestamp), but I’m not sure if I can get that exposed through Fastly?
-
Hi there,
We don't currently have UUID (as defined by RFC 4122) generational capability, however we do have cryptographic vcl functions available. There are quite a few possibilities to hash values to produce a unique identifier, depending on the level of abstraction you're going for.
This may help achieve what you're looking for:
- Create a new Request Header to be passed to your backend.
- Set the Destination as
http.X-Request-ID
- Set the Source as
digest.hash_sha1(now randomstr(64) req.http.host req.url req.http.Fastly-Client-IP server.identity)
. You set the unique identifier value here.
- Set the Destination as
- To track the X-Request-ID header in your logging set-up, you can reference the header in your logging format string as in
%h %l %u %t %r %>s %b req.http.X-Request-ID
.
Just let us know if we can answer any questions / provide any further help.
- Create a new Request Header to be passed to your backend.
-
Hi there,
I dug a little into RFC 4122 and found that it's possible to generate a version 4 UUID in VCL using the following rather long line:
set req.http.UUID = randomstr(8, "0123456789abcdef") + "-" + randomstr(4, "0123456789abcdef") + "-4" + randomstr(3, "0123456789abcdef") + "-" + randomstr(1, "89ab") + randomstr(3, "0123456789abcdef") + "-" + randomstr(12, "0123456789abcdef");
... which generates something like
ae3d4fde-d1d7-4047-9108-baf2c5e4ace2
.The only caveat is that we're generating this with a pseudo-random number generator. If your application requires an RFC 4122 UUID then the above is one way to go, but the answer provided by @ccole would have higher entropy.
Regards, Leon
-
Hi all,
We are happy to announce that now you can simply generate a UUID with new UUID VCL functions. Below is an example of generating a UUID version4.
set req.http.X-Unique-Id = uuid.version4();
We have added not only UUID generate functions, but also several useful UUID functions that can be used for validating. Please check the following document for more detail.
Cheers!
Please sign in to leave a comment.
Comments
6 comments