@@ -49,48 +49,6 @@ If padding of the field is required (`traceparent` needs to be serialized into
4949the bigger buffer) - any number of bytes can be appended to the end of the
5050serialized value.
5151
52- ## De-serialization of ` traceparent `
53-
54- Let's assume the algorithm takes a buffer and can set and shift cursor in the
55- buffer as well as validate whether the end of the buffer was reached or will be
56- reached after reading the given number of bytes. De-serialization of
57- ` traceparent ` should be done in the following sequence:
58-
59- 1 . If buffer is empty - return invalid status ` BUFFER_EMPTY ` . Set a cursor to
60- the first byte.
61- 2 . Read the ` version ` byte at the cursor position. Shift cursor to ` 1 ` byte.
62- 3 . If all three fields (` trace-id ` , ` parent-id ` , ` trace-flags ` ) already read -
63- return them with the status ` OK ` if ` version ` is ` 0 ` or status
64- ` DOWNGRADED_TO_ZERO ` otherwise.
65- 4 . If at the end of the buffer return invalid status ` TRACEPARENT_INCOMPLETE ` .
66- Otherwise read the field identifier byte at the cursor position. Field
67- identifier should be read as unsigned byte assuming big-endian bits order.
68- 1 . If ` 0 ` - check that remaining buffer size is more or equal to ` 16 ` bytes.
69- If shorter - return invalid status ` TRACE_ID_TOO_SHORT ` . Otherwise read
70- the next ` 16 ` bytes for ` trace-id ` and shift cursor to the end of those
71- ` 16 ` bytes. Go to step ` 3 ` . If ` trace-id ` is represented as a byte array
72- - first byte should be set into the first element of that array. See
73- comment in serialization section.
74- 2 . If ` 1 ` - check that remaining buffer size is more or equal to ` 8 ` bytes.
75- If shorter - return invalid status ` PARENT_ID_TOO_SHORT ` . Otherwise read
76- the next ` 8 ` bytes for ` parent-id ` and shift cursor to the end of those
77- ` 8 ` bytes. Go to step ` 3 ` .
78- 3 . If ` 2 ` - check the remaining size of the buffer. If at the end of the
79- buffer - return invalid status. Otherwise - read the ` trace-flags `
80- byte. Least significant bit will represent ` recorded ` value. Go to step
81- ` 3 ` .
82- 4 . In case of any other value - if ` version ` read at step ` 2 ` is ` 0 ` -
83- return invalid status ` INVALID_FIELD_ID ` . If ` version ` has any other
84- value - ` INCOMPATIBLE_VERSION ` .
85-
86- _ Note_ , that invalid status names are given for readability and not part of the
87- specification.
88-
89- _ Note_ , that parsing should not treat any additional bytes in the end of the
90- buffer as an invalid status. Those fields can be added for padding purposes.
91- Optionally implementation can check that the buffer is longer than ` 29 ` bytes as
92- a very first step if this check is not expensive.
93-
9452## ` traceparent ` example
9553
9654``` js
@@ -105,7 +63,7 @@ This corresponds to:
10563- ` trace-id ` is
10664 ` {75, 249, 47, 53, 119, 179, 77, 166, 163, 206, 146, 157, 0, 14, 71, 54} ` or
10765 ` 4bf9273577b34da6a3ce929d000e4736 ` .
108- - ` span -id` is ` {52, 240, 103, 170, 11, 169, 2, 183} ` or ` 34f067aa0ba902b7 ` .
66+ - ` parent -id` is ` {52, 240, 103, 170, 11, 169, 2, 183} ` or ` 34f067aa0ba902b7 ` .
10967- ` trace-flags ` is ` 1 ` with the meaning ` recorded ` is true.
11068
11169## ` tracestate ` binary format
@@ -128,4 +86,16 @@ value-len = 1BYTE ; length of the value string
12886Zero length key (` key-len == 0 ` ) indicates the end of the ` tracestate ` . So when
12987` tracestate ` should be serialized into the buffer that is longer than it
13088requires - ` { 0, 0 } ` (field id ` 0 ` and key-len ` 0 ` ) will indicate the end of
131- the ` tracestate ` .
89+ the ` tracestate ` .
90+
91+ ## ` tracestate ` example
92+
93+ ``` js
94+ { 0 , 3 , 102 , 111 , 111 , 16 , 51 , 52 , 102 , 48 , 54 , 55 , 97 , 97 , 48 , 98 , 97 , 57 , 48 , 50 , 98 , 55 ,
95+ 0 , 3 , 98 , 97 , 114 , 4 , 48 , 46 , 50 , 53 , }
96+
97+ ```
98+
99+ This corresponds to 2 tracestate entries:
100+
101+ ` foo=34f067aa0ba902b7,bar=0.25 `
0 commit comments