From 976dbc9862afaaccd0c1a29ed8a163da2e877ad0 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Mon, 9 May 2022 15:30:16 -0700 Subject: [PATCH] Fix sharing resource in batched exported spans --- exporters/otlp/src/otlp_recordable_utils.cc | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/exporters/otlp/src/otlp_recordable_utils.cc b/exporters/otlp/src/otlp_recordable_utils.cc index 483f01f905..b981448de1 100644 --- a/exporters/otlp/src/otlp_recordable_utils.cc +++ b/exporters/otlp/src/otlp_recordable_utils.cc @@ -259,25 +259,19 @@ void OtlpRecordableUtils::PopulateRequest( return; } - auto resource_span = request->add_resource_spans(); - auto instrumentation_lib = resource_span->add_instrumentation_library_spans(); - bool first_pass = true; - for (auto &recordable : spans) { auto rec = std::unique_ptr(static_cast(recordable.release())); + auto resource_span = request->add_resource_spans(); + auto instrumentation_lib = resource_span->add_instrumentation_library_spans(); + *instrumentation_lib->add_spans() = std::move(rec->span()); *instrumentation_lib->mutable_instrumentation_library() = rec->GetProtoInstrumentationLibrary(); - if (first_pass) - { - instrumentation_lib->set_schema_url(rec->GetInstrumentationLibrarySchemaURL()); + instrumentation_lib->set_schema_url(rec->GetInstrumentationLibrarySchemaURL()); - *resource_span->mutable_resource() = rec->ProtoResource(); - resource_span->set_schema_url(rec->GetResourceSchemaURL()); - - first_pass = false; - } + *resource_span->mutable_resource() = rec->ProtoResource(); + resource_span->set_schema_url(rec->GetResourceSchemaURL()); } }