Skip to content

Commit

Permalink
fixup! Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcomets committed Apr 17, 2018
1 parent 5625422 commit 2d6b197
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
26 changes: 13 additions & 13 deletions zipkin_opentracing/src/opentracing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ static const OtSpanContext *findSpanContext(
return nullptr;
}

static void appendAnnotations(Span& span, const std::vector<ot::LogRecord>& log_records, Endpoint endpoint) {
for (const auto &lr : log_records) {
const auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(
lr.timestamp.time_since_epoch()).count();
Annotation annotation = toAnnotation({ lr.fields.begin(), lr.fields.end() });
annotation.setTimestamp(timestamp);
annotation.setEndpoint(endpoint);
span.addAnnotation(annotation);
}
}

class OtSpan : public ot::Span {
public:
OtSpan(std::shared_ptr<const ot::Tracer> &&tracer_owner, SpanPtr &&span_owner,
Expand Down Expand Up @@ -221,19 +232,8 @@ class OtSpan : public ot::Span {

std::vector<ot::LogRecord> log_records;
log_records.swap(log_records_);
log_records.reserve(options.log_records.size());
std::copy(options.log_records.begin(), options.log_records.end(),
std::back_inserter(log_records));

for (const auto &lr : log_records) {
const auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(
lr.timestamp.time_since_epoch()).count();
for (const auto& field : lr.fields) {
Annotation annotation = toAnnotation(field.first, field.second);
annotation.setTimestamp(timestamp);
span_->addAnnotation(annotation);
}
}
appendAnnotations(*span_, log_records, endpoint_);
appendAnnotations(*span_, options.log_records, endpoint_);

span_->finish();
} catch (const std::bad_alloc &) {
Expand Down
14 changes: 10 additions & 4 deletions zipkin_opentracing/src/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,17 @@ BinaryAnnotation toBinaryAnnotation(string_view key, const Value &value) {
return annotation;
}

Annotation toAnnotation(string_view key, const Value &value) {
ToStringValueVisitor value_visitor{value};
const std::string str = apply_visitor(value_visitor, value);
Annotation toAnnotation(const std::vector<std::pair<string_view, Value>>& fields) {
rapidjson::StringBuffer buffer;
JsonWriter writer(buffer);
writer.StartObject();
for (auto & field : fields) {
writer.Key(field.first.data());
toJson(writer, field.second);
}
writer.EndObject();
Annotation annotation;
annotation.setValue(std::string(key) + "=" + str);
annotation.setValue(buffer.GetString());
return annotation;
}

Expand Down
3 changes: 1 addition & 2 deletions zipkin_opentracing/src/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace zipkin {
BinaryAnnotation toBinaryAnnotation(opentracing::string_view key,
const opentracing::Value &value);

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

} // namespace zipkin

0 comments on commit 2d6b197

Please sign in to comment.