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

Commit

Permalink
Merge pull request #57 from DeterminateSystems/hoverbear/ds-267-telem…
Browse files Browse the repository at this point in the history
…etry-ids-should-be-obscured-in-log
  • Loading branch information
cole-h authored Aug 26, 2022
2 parents 9e9a67c + 084cb3e commit 9487138
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,31 @@ impl Telemetry {
self
}

#[tracing::instrument(skip_all)]
pub(crate) async fn send(&self) -> eyre::Result<Response> {
let header_data = self.as_header_data()?;
tracing::trace!(data = %header_data, "Sending telemetry data to {TELEMETRY_REMOTE_URL}");
tracing::trace!(data = %self.redact_header_data(header_data.clone()), "Sending telemetry data to {TELEMETRY_REMOTE_URL}");
let http_client = reqwest::Client::new();
let req = http_client
.post(TELEMETRY_REMOTE_URL)
.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}");
tracing::debug!(telemetry = %self.redact_header_data(header_data.clone()), "Sent telemetry data to {TELEMETRY_REMOTE_URL}");
Ok(res)
}

pub(crate) fn as_header_data(&self) -> Result<String, serde_json::Error> {
serde_json::to_string(&self)
}

pub(crate) fn redact_header_data(&self, mut val: String) -> String {
if let Some(distinct_id) = self.distinct_id {
let distinct_id_string = distinct_id.to_string();
val = val.replace(&distinct_id_string, "<redacted>");
}
val
}
}

async fn distinct_id() -> eyre::Result<Uuid> {
Expand Down

0 comments on commit 9487138

Please sign in to comment.