Skip to content

Commit 1a9be94

Browse files
committed
Review
1 parent 9d04f9f commit 1a9be94

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

core/src/tracing/span.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ void HandleEventAttributes(const Span::Event& events, formats::json::StringBuild
9191
builder.Key("attributes");
9292
const formats::json::StringBuilder::ObjectGuard attributes_guard(builder);
9393

94+
AttributeToJsonVisitor visitor{builder};
95+
9496
for (const auto& [key, value] : events.attributes) {
9597
builder.Key(key);
96-
std::visit(AttributeToJsonVisitor{builder}, value);
98+
std::visit(visitor, value);
9799
}
98100
}
99101

otlp/src/otlp/logs/logger.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,40 @@
1919

2020
USERVER_NAMESPACE_BEGIN
2121

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+
2245
namespace formats::parse {
2346

2447
template <typename Value>
2548
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;
2756
}
2857

2958
} // namespace formats::parse
@@ -35,7 +64,6 @@ namespace {
3564
constexpr std::string_view kTelemetrySdkLanguage = "telemetry.sdk.language";
3665
constexpr std::string_view kTelemetrySdkName = "telemetry.sdk.name";
3766
constexpr std::string_view kServiceName = "service.name";
38-
constexpr std::string_view kAttributeKey = "attributes";
3967

4068
const std::string kTimestampFormat = "%Y-%m-%dT%H:%M:%E*S";
4169

@@ -62,22 +90,6 @@ struct AttributeToTraceVisitor {
6290
::opentelemetry::proto::trace::v1::Span_Event& span_event_;
6391
};
6492

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-
8193
std::vector<tracing::Span::Event> GetEventsFromValue(const std::string_view value) {
8294
std::vector<tracing::Span::Event> events;
8395

@@ -87,7 +99,6 @@ std::vector<tracing::Span::Event> GetEventsFromValue(const std::string_view valu
8799

88100
for (const auto& item : json_value) {
89101
tracing::Span::Event event{item.As<tracing::Span::Event>()};
90-
GetAttributes(item, event);
91102
events.emplace_back(std::move(event));
92103
}
93104

0 commit comments

Comments
 (0)