Repository: qdrant/qdrant
File: src/common/telemetry.rs (Rust)

Code before:
            settings,
            dispatcher,
            app_telemetry_collector: AppBuildTelemetryCollector::new(),
            actix_telemetry_collector: Arc::new(Mutex::new(ActixTelemetryCollector {
                workers: Vec::new(),
            })),
            tonic_telemetry_collector: Arc::new(Mutex::new(TonicTelemetryCollector {
                workers: Vec::new(),
            })),
        }
    }

    pub async fn prepare_data(&self, access: &Access, detail: TelemetryDetail) -> TelemetryData {
        // Use blocking pool because the collection telemetry acquires several sync. locks.
        let collections_telemetry = {
            let toc = self
                .dispatcher
                .toc(access, &new_unchecked_verification_pass())
                .clone();
            let runtime_handle = toc.general_runtime_handle().clone();
            let access_collection = access.clone();
            runtime_handle
                .spawn_blocking(move || {
                    // Re-enter the async runtime in this blocking thread
                    tokio::runtime::Handle::current().block_on(async move {
                        CollectionsTelemetry::collect(detail, &access_collection, &toc).await
                    })
                })
                .await
        };

        let collections_telemetry = collections_telemetry
            .map_err(|err| log::error!("Failed to generate collection telemetry {err}"))
            .unwrap_or_default();

        TelemetryData {
            id: self.process_id.to_string(),
            collections: collections_telemetry,
            app: AppBuildTelemetry::collect(detail, &self.app_telemetry_collector, &self.settings),
            cluster: ClusterTelemetry::collect(access, detail, &self.dispatcher, &self.settings),
            requests: RequestsTelemetry::collect(
                access,
                &self.actix_telemetry_collector.lock(),
                &self.tonic_telemetry_collector.lock(),
                detail,
            ),
            memory: (detail.level > DetailsLevel::Level0)
                .then(|| MemoryTelemetry::collect(access))
                .flatten(),
            hardware: (detail.level > DetailsLevel::Level0)
                .then(|| HardwareTelemetry::new(&self.dispatcher, access)),

Review comment (suggestion):
`AbortOnDrop` is fine here, but... why we do this in the first place? Blocking calls inside `CollectionsTelemetry::collect`?

```rust
runtime_handle.spawn(async move {
    CollectionsTelemetry::collect(detail, &access_collection, &toc).await
})
.await
```

Code after:
            process_id: id,
            settings,
            dispatcher,
            app_telemetry_collector: AppBuildTelemetryCollector::new(),
            actix_telemetry_collector: Arc::new(Mutex::new(ActixTelemetryCollector {
                workers: Vec::new(),
            })),
            tonic_telemetry_collector: Arc::new(Mutex::new(TonicTelemetryCollector {
                workers: Vec::new(),
            })),
        }
    }

    pub async fn prepare_data(&self, access: &Access, detail: TelemetryDetail) -> TelemetryData {
        // Use blocking pool because the collection telemetry acquires several sync. locks.
        let collections_telemetry = {
            let toc = self
                .dispatcher
                .toc(access, &new_unchecked_verification_pass())
                .clone();
            let runtime_handle = toc.general_runtime_handle().clone();
            let access_collection = access.clone();
            let handle = runtime_handle.spawn_blocking(move || {
                // Re-enter the async runtime in this blocking thread
                tokio::runtime::Handle::current().block_on(async move {
                    CollectionsTelemetry::collect(detail, &access_collection, &toc).await
                })
            });
            AbortOnDropHandle::new(handle).await
        };

        let collections_telemetry = collections_telemetry
            .map_err(|err| log::error!("Failed to generate collection telemetry {err}"))
            .unwrap_or_default();

        TelemetryData {
            id: self.process_id.to_string(),
            collections: collections_telemetry,
            app: AppBuildTelemetry::collect(detail, &self.app_telemetry_collector, &self.settings),
            cluster: ClusterTelemetry::collect(access, detail, &self.dispatcher, &self.settings),
            requests: RequestsTelemetry::collect(
                access,
                &self.actix_telemetry_collector.lock(),
                &self.tonic_telemetry_collector.lock(),
                detail,
            ),
            memory: (detail.level > DetailsLevel::Level0)
                .then(|| MemoryTelemetry::collect(access))
                .flatten(),
            hardware: (detail.level > DetailsLevel::Level0)
                .then(|| HardwareTelemetry::new(&self.dispatcher, access)),