-
Notifications
You must be signed in to change notification settings - Fork 21
feat(telemetry)!: make telemetry worker wasm-compatible for the TraceExporter #2172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a9251df
800823d
fa53c71
2f63fe1
cb8ddeb
c5b608f
05b4735
74adfb8
9b6dbd9
b7acc91
96930b6
d7aa577
b3aef55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
| //! Native HTTP client implementation backed by hyper. | ||
|
|
||
| mod native { | ||
| use std::fs::OpenOptions; | ||
| use std::io::Write; | ||
| use std::sync::{Arc, OnceLock}; | ||
|
|
||
| use libdd_capabilities::http::{HttpClientCapability, HttpError}; | ||
|
|
@@ -26,6 +28,32 @@ mod native { | |
| } | ||
| } | ||
|
|
||
| /// Write `body` as a newline-terminated record to the file referenced by `uri` (which must | ||
| /// have a `file://` scheme), then return a synthetic 202 response. The same on-disk format | ||
| /// the pre-capability telemetry worker used when configured with a `file://` endpoint, so | ||
| /// downstream tests that diff against the recorded payload bytes keep working. | ||
| fn write_to_file_endpoint( | ||
| uri: &http::Uri, | ||
| body: bytes::Bytes, | ||
| ) -> Result<http::Response<bytes::Bytes>, HttpError> { | ||
| let path = libdd_common::decode_uri_path_in_authority(uri) | ||
| .map_err(|e| HttpError::Other(anyhow::anyhow!("invalid file:// URI: {e}")))?; | ||
| let mut file = OpenOptions::new() | ||
| .create(true) | ||
| .append(true) | ||
| .open(&path) | ||
| .map_err(|e| HttpError::Other(anyhow::anyhow!("opening {path:?}: {e}")))?; | ||
| let mut record = body.to_vec(); | ||
| record.push(b'\n'); | ||
| file.write_all(&record) | ||
| .map_err(|e| HttpError::Other(anyhow::anyhow!("writing {path:?}: {e}")))?; | ||
|
|
||
| http::Response::builder() | ||
| .status(http::StatusCode::ACCEPTED) | ||
| .body(bytes::Bytes::new()) | ||
| .map_err(|e| HttpError::Other(e.into())) | ||
| } | ||
|
|
||
| impl HttpClientCapability for NativeHttpClient { | ||
| fn new_client() -> Self { | ||
| Self { | ||
|
|
@@ -39,8 +67,15 @@ mod native { | |
| req: http::Request<bytes::Bytes>, | ||
| ) -> impl std::future::Future<Output = Result<http::Response<bytes::Bytes>, HttpError>> + MaybeSend | ||
| { | ||
| let client = self.client.get_or_init(new_default_client).clone(); | ||
| let client_lock = self.client.clone(); | ||
| async move { | ||
| // file:// URIs short-circuit to the on-disk recorder used by tests. | ||
| if req.uri().scheme_str() == Some("file") { | ||
| let (parts, body) = req.into_parts(); | ||
| return write_to_file_endpoint(&parts.uri, body); | ||
| } | ||
|
Comment on lines
+73
to
+76
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not blocking since there not using capabilities, but it seems that crashtracker and the reqwest client also bind custom behavior on the |
||
|
|
||
| let client = client_lock.get_or_init(new_default_client).clone(); | ||
| let hyper_req = req.map(Body::from_bytes); | ||
|
|
||
| let response = client | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: too specific