Skip to content

Commit 72d885c

Browse files
committed
fixup! Review fixes
1 parent 5625422 commit 72d885c

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

zipkin_opentracing/src/opentracing.cc

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ static const OtSpanContext *findSpanContext(
119119
return nullptr;
120120
}
121121

122+
static void addAnnotations(const std::vector<ot::LogRecord>& log_records, Endpoint endpoint) {
123+
for (const auto &lr : log_records) {
124+
const auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(
125+
lr.timestamp.time_since_epoch()).count();
126+
Annotation annotation = toAnnotation({ lr.fields.begin(), lr.fields.end() });
127+
annotation.setTimestamp(timestamp);
128+
annotation.setEndpoint(endpoint);
129+
}
130+
}
131+
122132
class OtSpan : public ot::Span {
123133
public:
124134
OtSpan(std::shared_ptr<const ot::Tracer> &&tracer_owner, SpanPtr &&span_owner,
@@ -221,19 +231,8 @@ class OtSpan : public ot::Span {
221231

222232
std::vector<ot::LogRecord> log_records;
223233
log_records.swap(log_records_);
224-
log_records.reserve(options.log_records.size());
225-
std::copy(options.log_records.begin(), options.log_records.end(),
226-
std::back_inserter(log_records));
227-
228-
for (const auto &lr : log_records) {
229-
const auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(
230-
lr.timestamp.time_since_epoch()).count();
231-
for (const auto& field : lr.fields) {
232-
Annotation annotation = toAnnotation(field.first, field.second);
233-
annotation.setTimestamp(timestamp);
234-
span_->addAnnotation(annotation);
235-
}
236-
}
234+
addAnnotations(log_records, endpoint_);
235+
addAnnotations(options.log_records, endpoint_);
237236

238237
span_->finish();
239238
} catch (const std::bad_alloc &) {

zipkin_opentracing/src/utility.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,17 @@ BinaryAnnotation toBinaryAnnotation(string_view key, const Value &value) {
125125
return annotation;
126126
}
127127

128-
Annotation toAnnotation(string_view key, const Value &value) {
129-
ToStringValueVisitor value_visitor{value};
130-
const std::string str = apply_visitor(value_visitor, value);
128+
Annotation toAnnotation(const std::vector<std::pair<string_view, Value>>& fields) {
129+
rapidjson::StringBuffer buffer;
130+
JsonWriter writer(buffer);
131+
writer.StartObject();
132+
for (auto & field : fields) {
133+
writer.Key(field.first.data());
134+
toJson(writer, field.second);
135+
}
136+
writer.EndObject();
131137
Annotation annotation;
132-
annotation.setValue(std::string(key) + "=" + str);
138+
annotation.setValue(buffer.GetString());
133139
return annotation;
134140
}
135141

zipkin_opentracing/src/utility.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace zipkin {
99
BinaryAnnotation toBinaryAnnotation(opentracing::string_view key,
1010
const opentracing::Value &value);
1111

12-
Annotation toAnnotation(opentracing::string_view key,
13-
const opentracing::Value &value);
12+
Annotation toAnnotation(const std::vector<std::pair<opentracing::string_view, opentracing::Value>>& fields);
1413

1514
} // namespace zipkin

0 commit comments

Comments
 (0)