Skip to content

Commit

Permalink
impl(pubsub): fix scopes (#13027)
Browse files Browse the repository at this point in the history
  • Loading branch information
alevenberg authored Nov 3, 2023
1 parent 4110eeb commit dbe26c9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions google/cloud/pubsub/internal/tracing_message_batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ class TracingMessageBatch : public MessageBatch {

// The first span in `batch_sink_spans` is the parent to the other spans in
// the vector.
internal::OTelScope scope(batch_sink_spans.front());
return [oc = opentelemetry::context::RuntimeContext::GetCurrent(),
auto scope =
std::make_shared<internal::OTelScope>(batch_sink_spans.front());
// Capture the scope so it stays alive until the returned function
// is called.
return [scope = std::move(scope),
oc = opentelemetry::context::RuntimeContext::GetCurrent(),
next = child_->Flush(),
spans = std::move(batch_sink_spans)](auto f) mutable {
for (auto& span : spans) {
Expand Down

0 comments on commit dbe26c9

Please sign in to comment.