@@ -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+
122132class OtSpan : public ot ::Span {
123133public:
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 &) {
0 commit comments