Skip to content
This repository was archived by the owner on Oct 10, 2023. It is now read-only.

Start telemetry earlier and add a timeout #55

Merged
merged 6 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 11 additions & 6 deletions src/dependency_registry/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use crate::{
Copy link
Member

Choose a reason for hiding this comment

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

Extremely nit-picky, so feel free to ignore, but it'd be swell to group std, external, and internal imports near each-other

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a rustfmt setting if I recall...

Copy link
Member

Choose a reason for hiding this comment

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

telemetry::{Telemetry, TELEMETRY_HEADER_NAME},
FSM_XDG_PREFIX,
};
use eyre::eyre;
use serde::Deserialize;
use std::{path::Path, sync::Arc};
use tokio::{
Expand All @@ -8,11 +13,6 @@ use tokio::{
};
use xdg::{BaseDirectories, BaseDirectoriesError};

use crate::{
telemetry::{Telemetry, TELEMETRY_HEADER_NAME},
FSM_XDG_PREFIX,
};

use self::rust::RustDependencyRegistryData;

pub(crate) mod rust;
Expand Down Expand Up @@ -44,6 +44,7 @@ pub struct DependencyRegistry {
impl DependencyRegistry {
#[tracing::instrument(skip_all, fields(%disable_telemetry))]
pub async fn new(disable_telemetry: bool) -> Result<Self, DependencyRegistryError> {
let telemetry_handle = tokio::spawn(Telemetry::new());
let xdg_dirs = BaseDirectories::with_prefix(FSM_XDG_PREFIX)?;
// Create the directory if needed
let cached_registry_pathbuf =
Expand Down Expand Up @@ -80,7 +81,11 @@ impl DependencyRegistry {
// Refresh the cache
// We don't want to fail if we can't build telemetry data...
let telemetry = if !disable_telemetry {
match Telemetry::new().await.as_header_data() {
match telemetry_handle
.await
.map_err(|v| eyre!(v))
.and_then(|v| v.as_header_data().map_err(|e| eyre!(e)))
{
Ok(telemetry) => Some(telemetry), // But we do want to fail if we can build it but can't parse it
Err(err) => {
tracing::debug!(%err, "Telemetry build error");
Expand Down
5 changes: 3 additions & 2 deletions src/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashSet, path::Path};
use std::{collections::HashSet, path::Path, time::Duration};

use clap::Parser;
use eyre::eyre;
Expand Down Expand Up @@ -110,7 +110,8 @@ impl Telemetry {
let http_client = reqwest::Client::new();
let req = http_client
.post(TELEMETRY_REMOTE_URL)
.header(TELEMETRY_HEADER_NAME, &header_data);
.header(TELEMETRY_HEADER_NAME, &header_data)
.timeout(Duration::from_millis(250));
let res = req.send().await?;
tracing::debug!(telemetry = %header_data, "Sent telemetry data to {TELEMETRY_REMOTE_URL}");
Ok(res)
Expand Down