@@ -305,6 +305,17 @@ void ObjectDescriptorImpl::Flush(std::unique_lock<std::mutex> lk,
305305 google::storage::v2::BidiReadObjectRequest request;
306306 request.Swap (&it->stream ->next_request );
307307
308+ #if defined(GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS) || \
309+ defined (GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY )
310+ auto t4_stamp = std::chrono::steady_clock::now ();
311+ for (auto const & rr : request.read_ranges ()) {
312+ auto const l = it->active_ranges .find (rr.read_id ());
313+ if (l != it->active_ranges .end ()) {
314+ l->second ->SetT4 (t4_stamp);
315+ }
316+ }
317+ #endif
318+
308319 // Assign CurrentStream to a temporary variable to prevent
309320 // lifetime extension which can cause the lock to be held until the
310321 // end of the block.
@@ -362,10 +373,22 @@ void ObjectDescriptorImpl::OnRead(
362373 // Release the lock while notifying the ranges. The notifications may trigger
363374 // application code, and that code may callback on this class.
364375 lk.unlock ();
376+
377+ #if defined(GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS) || \
378+ defined (GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY )
379+ auto t5_stamp = std::chrono::steady_clock::now ();
380+ #endif
381+
365382 for (auto & range_data : *response->mutable_object_data_ranges ()) {
366383 auto id = range_data.read_range ().read_id ();
367384 auto const l = copy.find (id);
368385 if (l == copy.end ()) continue ;
386+
387+ #if defined(GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS) || \
388+ defined (GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY )
389+ l->second ->SetT5 (t5_stamp);
390+ #endif
391+
369392 // TODO(#15104) - Consider returning if the range is done, and then
370393 // skipping CleanupDoneRanges().
371394 l->second ->OnRead (std::move (range_data), is_transcoded, object_size);
0 commit comments