Skip to content

Commit

Permalink
Fix sharing resource in batched exported spans (open-telemetry#1386)
Browse files Browse the repository at this point in the history
Co-authored-by: Lalit Kumar Bhasin <[email protected]>
  • Loading branch information
ThomsonTan and lalitb authored May 11, 2022
1 parent 95effbd commit 88e23ad
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions exporters/otlp/src/otlp_recordable_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<OtlpRecordable>(static_cast<OtlpRecordable *>(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());
}
}

Expand Down

0 comments on commit 88e23ad

Please sign in to comment.