randomint(0, 9223372036854775807) does not work
Hi,
I want to create a random 64bit unsigned integer in fastly,
and pass it to origin servers so that we can use it as a datadog apm trace id.
I tried
```
declare local var.id INTEGER;
set var.id = randomint(0, 9223372036854775807);
set req.http.x-datadog-trace-id = var.id;
set req.http.x-datadog-parent-id = var.id;
```
but I got `x-datadog-trace-id: 0` in the origin server.
For a time being, I'm creating random integers by every 32bits.
```
declare local var.id INTEGER;
set var.id = randomint(0, 2147483647);
set var.id <<= 32;
set var.id |= randomint(0, 4294967295);
```
I hope that `randomint(0, 9223372036854775807)` works.
Also, if there were more reasonable ways to create datadog apm trace ids in fastly, I would like to know them.
Thanks.
-
Hi,
Despite our type INTEGER being a 64-bit variable, the function randomint() currently only populates 32-bit of value. This is being worked on.
However, if you need to generate a unique identifier, have you tried the randomstr() function or uuid.is_version4()?
Best regards.
-
Hi, Pablo
> This is being worked on.
I'm happy to hear that!
> if you need to generate a unique identifier, have you tried the randomstr() function or uuid.is_version4()?
It seems that datadog apm clients actually hold trace ids as 64bit unsigned integers, not just as strings.
So we cannot use uuid strings as datadog trace ids here. -
Just for others looking into this, there is also this approach that is not perfect but should also work:
# See: https://github.com/DataDog/dd-trace-go/blob/0b8ad4fc38b8ddc9d507e825b7394da16af74a52/ddtrace/tracer/span.go#L63
# Type uint64 in Golang is the set of all unsigned 64-bit integers. The set ranges from 0 to 18446744073709551615.
# In our logic we are going for a set from 10000000000000000000 to 17999999999999999999.
declare local var.id STRING;
set var.id = "1" randomstr(1, "01234567") randomstr(18, "0123456789");
Please sign in to leave a comment.
Comments
4 comments