@@ -78,6 +78,12 @@ void TracingConnection::CleanupCompletedTasks() {
7878 bg_tasks_.end ());
7979}
8080
81+ void TracingConnection::EnrichSpan (opentelemetry::trace::Span& span,
82+ BucketCacheEntry const & entry) {
83+ span.SetAttribute (" gcp.resource.destination.id" , entry.id );
84+ span.SetAttribute (" gcp.resource.destination.location" , entry.location );
85+ }
86+
8187void TracingConnection::MaybeTriggerBackgroundFetch (
8288 std::string const & bucket_name) {
8389 CleanupCompletedTasks ();
@@ -87,30 +93,20 @@ void TracingConnection::MaybeTriggerBackgroundFetch(
8793 }
8894
8995 auto current_options = google::cloud::internal::SaveCurrentOptions ();
90- auto f =
91- std::async (std::launch::async, [this , bucket_name, current_options]() {
92- google::cloud::internal::OptionsSpan span (current_options);
93- storage::internal::GetBucketMetadataRequest request (bucket_name);
94- auto result = impl_->GetBucketMetadata (request);
95-
96- BucketCacheEntry entry;
97- if (result.ok ()) {
98- entry.id = " projects/" + std::to_string (result->project_number ()) +
99- " /buckets/" + result->name ();
100- entry.location = result->location ();
101- if (result->location_type () == " multi-region" ||
102- result->location_type () == " dual-region" ) {
103- entry.location = " global" ;
104- }
105- cache ().Put (bucket_name, std::move (entry));
106- } else if (result.status ().code () == StatusCode::kPermissionDenied ) {
107- entry.id = " projects/_/buckets/" + bucket_name;
108- entry.location = " global" ;
109- cache ().Put (bucket_name, std::move (entry));
110- }
111-
112- cache ().EndFetch (bucket_name);
113- });
96+ auto f = std::async (std::launch::async, [this , bucket_name,
97+ current_options]() {
98+ google::cloud::internal::OptionsSpan span (current_options);
99+ storage::internal::GetBucketMetadataRequest request (bucket_name);
100+ auto result = impl_->GetBucketMetadata (request);
101+
102+ if (result.ok ()) {
103+ cache ().Put (bucket_name, BucketCacheEntry::FromMetadata (*result));
104+ } else if (result.status ().code () == StatusCode::kPermissionDenied ) {
105+ cache ().Put (bucket_name, {" projects/_/buckets/" + bucket_name, " global" });
106+ }
107+
108+ cache ().EndFetch (bucket_name);
109+ });
114110
115111 bg_tasks_.push_back (std::move (f));
116112}
@@ -120,8 +116,7 @@ void TracingConnection::EnrichSpan(opentelemetry::trace::Span& span,
120116 if (bucket_name.empty ()) return ;
121117 auto entry = cache ().Get (bucket_name);
122118 if (entry.has_value ()) {
123- span.SetAttribute (" gcp.resource.destination.id" , entry->id );
124- span.SetAttribute (" gcp.resource.destination.location" , entry->location );
119+ EnrichSpan (span, *entry);
125120 } else {
126121 MaybeTriggerBackgroundFetch (bucket_name);
127122 }
0 commit comments