File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
include/ydb-cpp-sdk/client/tracing Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ #pragma once
2
+
3
+ #include < string>
4
+ #include < util/random/random.h>
5
+ #include < util/string/hex.h>
6
+
7
+ namespace NYdb {
8
+
9
+ class TTraceUtils {
10
+ public:
11
+ // Генерация traceparent в формате W3C Trace Context
12
+ static std::string GenerateTraceParent () {
13
+ // Формат: 00-<trace-id>-<span-id>-<flags>
14
+ return " 00-" + GenerateRandomHex (32 ) + " -" + GenerateRandomHex (16 ) + " -01" ;
15
+ }
16
+
17
+ private:
18
+ // Генерация случайной hex-строки заданной длины
19
+ static std::string GenerateRandomHex (size_t length) {
20
+ const size_t byteLength = length / 2 ;
21
+ std::string bytes (byteLength, " \0 " );
22
+
23
+ for (size_t i = 0 ; i < byteLength; ++i) {
24
+ bytes[i] = static_cast <char >(RandomNumber<ui8>());
25
+ }
26
+
27
+ return HexEncode (bytes.data (), bytes.size ());
28
+ }
29
+ };
30
+ } // namespace NYdb
You can’t perform that action at this time.
0 commit comments