EN VI

C# - why Activity.Id has two leading 0s and trailing 01?

2024-03-09 23:00:24
C# - why Activity.Id has two leading 0s and trailing 01?
using (Activity activity = source.StartActivity("demo"))
{
    Console.WriteLine(activity?.Id);
}

the output is something like 00-bbd8c75b04cda7f7fe9ee03b54b2d7ba-72dc8c0dc24fc406-01

and it always has two leading 0s and trailing 01, what does those two leading 0s and trailing 01 mean?

also the trace id is bbd8c75b04cda7f7fe9ee03b54b2d7ba, according to the w3c format, trace-id that is 16 bytes. but isn't that bbd8c75b04cda7f7fe9ee03b54b2d7ba 32 bytes since it has 32 characters?

Solution:

It looks like you're using the W3C activity ID format. (See the DefaultIdFormat property for details of that.

The W3C format is documented here as traceparent. Importantly:

value           = version "-" version-format

...

Version (version) is 1 byte representing an 8-bit unsigned integer. Version ff is invalid. The current specification assumes the version is set to 00.

...

trace-flags An 8-bit field that controls tracing flags such as sampling, trace level, etc. [...] The current version of this specification (00) only supports a single flag called sampled. When set, the least significant bit (right-most), denotes that the caller may have recorded trace data.

So basically the 00 is the version, and 01 is the trace flag, meaning "sampled".

The trace ID is 32 characters because it's hex-encoded binary data - it's only 16 bytes. (Just like the version number is a single byte, encoded as two hex digits.)

Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login