-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(turbo): telemetry client (#6743)
- Loading branch information
Showing
21 changed files
with
1,581 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use async_trait::async_trait; | ||
use reqwest::Method; | ||
use turborepo_vercel_api::TelemetryEvent; | ||
|
||
use crate::{retry, AnonAPIClient, Error}; | ||
|
||
const TELEMETRY_ENDPOINT: &str = "/api/turborepo/v1/events"; | ||
|
||
#[async_trait] | ||
pub trait TelemetryClient { | ||
async fn record_telemetry( | ||
&self, | ||
events: Vec<TelemetryEvent>, | ||
telemetry_id: &str, | ||
session_id: &str, | ||
) -> Result<(), Error>; | ||
} | ||
|
||
#[async_trait] | ||
impl TelemetryClient for AnonAPIClient { | ||
async fn record_telemetry( | ||
&self, | ||
events: Vec<TelemetryEvent>, | ||
telemetry_id: &str, | ||
session_id: &str, | ||
) -> Result<(), Error> { | ||
let url = self.make_url(TELEMETRY_ENDPOINT); | ||
let telemetry_request = self | ||
.client | ||
.request(Method::POST, url) | ||
.header("User-Agent", self.user_agent.clone()) | ||
.header("Content-Type", "application/json") | ||
.header("x-turbo-telemetry-id", telemetry_id) | ||
.header("x-turbo-session-id", session_id) | ||
.json(&events); | ||
|
||
retry::make_retryable_request(telemetry_request) | ||
.await? | ||
.error_for_status()?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.