19
19
20
20
USERVER_NAMESPACE_BEGIN
21
21
22
+ namespace {
23
+
24
+ constexpr std::string_view kAttributeKey = " attributes" ;
25
+
26
+ template <typename Value>
27
+ void GetAttributes (const Value& item, tracing::Span::Event& event) {
28
+ if (item.HasMember (kAttributeKey )) {
29
+ item[kAttributeKey ].CheckObject ();
30
+
31
+ for (const auto & [key, value] : formats::common::Items (item[kAttributeKey ])) {
32
+ if (value.IsString ()) {
33
+ event.attributes .emplace (key, value.template As <std::string>());
34
+ } else if (value.IsDouble ()) {
35
+ event.attributes .emplace (key, value.template As <double >());
36
+ } else if (value.IsInt ()) {
37
+ event.attributes .emplace (key, value.template As <int64_t >());
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ } // namespace
44
+
22
45
namespace formats ::parse {
23
46
24
47
template <typename Value>
25
48
tracing::Span::Event Parse (const Value& value, formats::parse::To<tracing::Span::Event>) {
26
- return {value[" name" ].template As <std::string>(), value[" time_unix_nano" ].template As <uint64_t >()};
49
+ tracing::Span::Event event{
50
+ value[" name" ].template As <std::string>(), value[" time_unix_nano" ].template As <uint64_t >()
51
+ };
52
+
53
+ GetAttributes (value, event);
54
+
55
+ return event;
27
56
}
28
57
29
58
} // namespace formats::parse
@@ -35,7 +64,6 @@ namespace {
35
64
constexpr std::string_view kTelemetrySdkLanguage = " telemetry.sdk.language" ;
36
65
constexpr std::string_view kTelemetrySdkName = " telemetry.sdk.name" ;
37
66
constexpr std::string_view kServiceName = " service.name" ;
38
- constexpr std::string_view kAttributeKey = " attributes" ;
39
67
40
68
const std::string kTimestampFormat = " %Y-%m-%dT%H:%M:%E*S" ;
41
69
@@ -62,22 +90,6 @@ struct AttributeToTraceVisitor {
62
90
::opentelemetry::proto::trace::v1::Span_Event& span_event_;
63
91
};
64
92
65
- void GetAttributes (formats::json::Value item, tracing::Span::Event& event) {
66
- if (item.HasMember (kAttributeKey )) {
67
- item[kAttributeKey ].CheckObject ();
68
-
69
- for (const auto & [key, value] : formats::common::Items (item[kAttributeKey ])) {
70
- if (value.IsString ()) {
71
- event.attributes .emplace (key, value.As <std::string>());
72
- } else if (value.IsDouble ()) {
73
- event.attributes .emplace (key, value.As <double >());
74
- } else if (value.IsInt ()) {
75
- event.attributes .emplace (key, value.As <int64_t >());
76
- }
77
- }
78
- }
79
- }
80
-
81
93
std::vector<tracing::Span::Event> GetEventsFromValue (const std::string_view value) {
82
94
std::vector<tracing::Span::Event> events;
83
95
@@ -87,7 +99,6 @@ std::vector<tracing::Span::Event> GetEventsFromValue(const std::string_view valu
87
99
88
100
for (const auto & item : json_value) {
89
101
tracing::Span::Event event{item.As <tracing::Span::Event>()};
90
- GetAttributes (item, event);
91
102
events.emplace_back (std::move (event));
92
103
}
93
104
0 commit comments