Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sharing resource in batched exported spans #1386

Merged
merged 3 commits into from
May 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member

@lalitb lalitb May 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can resource_span be initialized outside the loop? Otel-cpp doesn't support multiple TracerProviders, so the resource attributes would be always the same for all the events.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lalitb, could otel-cpp create multiple TracerProvider, and set each of them as the global one in alternative?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes possible. Have approved it as it was just a nit comment :) should be good to merge.

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