Unique Request Identifier?

Comments

6 comments

  • Caslyn Cole

    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:

    1. 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.
    2. 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.

    0
    Comment actions Permalink
  • Robert Coup

    Excellent, that gives me something to work with.

    Out of interest, what is server.identity likely to look like?

    0
    Comment actions Permalink
  • Rogier Mulhuijzen

    cache-jfk1024-JFK is an example of server.identity

    0
    Comment actions Permalink
  • Leon Brocard

    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

    0
    Comment actions Permalink
  • Rogier Mulhuijzen

    I'd use sha256 instead of sha1, but yes. Is that not sufficient?

    0
    Comment actions Permalink
  • Shohei Maeda

    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!

    0
    Comment actions Permalink

Please sign in to leave a comment.