Skip to content

Commit e848caf

Browse files
authored
Remove extra generic from with_http_client (#1307)
* Remove extra generic from with_http_client This generic type parameter is not being used anywhere, so when you try to use `with_http_client`, it requires you to specify a dummy type that implements `HttpClient + 'static`. So this does not work: ```rust new_pipeline().with_http_client(Arc::new(client)) ``` But these work, even though they don't necessarily match the actual type of `client`: ```rust new_pipeline::<Arc<dyn HttpClient>>().with_http_client(Arc::new(client)) new_pipeline::<reqwest::Client>().with_http_client(Arc::new(client)) ``` * Add test and CHANGELOG entry
1 parent 2fb0c2e commit e848caf

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

opentelemetry-datadog/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Fixed
1010

1111
- Do not set an empty span as the active span when the propagator does not find a remote span.
12+
- Change type signature of `with_http_client()` to use the provided generic as argument.
1213

1314
## V0.8.0
1415

opentelemetry-datadog/src/exporter/mod.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,8 @@ impl DatadogPipelineBuilder {
347347
}
348348

349349
/// Choose the http client used by uploader
350-
pub fn with_http_client<T: HttpClient + 'static>(
351-
mut self,
352-
client: Arc<dyn HttpClient>,
353-
) -> Self {
354-
self.client = Some(client);
350+
pub fn with_http_client<T: HttpClient + 'static>(mut self, client: T) -> Self {
351+
self.client = Some(Arc::new(client));
355352
self
356353
}
357354

@@ -496,4 +493,25 @@ mod tests {
496493
);
497494
assert!(invalid.is_err())
498495
}
496+
497+
#[derive(Debug)]
498+
struct DummyClient;
499+
500+
#[async_trait::async_trait]
501+
impl HttpClient for DummyClient {
502+
async fn send(
503+
&self,
504+
_request: Request<Vec<u8>>,
505+
) -> Result<http::Response<bytes::Bytes>, opentelemetry_http::HttpError> {
506+
Ok(http::Response::new("dummy response".into()))
507+
}
508+
}
509+
510+
#[test]
511+
fn test_custom_http_client() {
512+
new_pipeline()
513+
.with_http_client(DummyClient)
514+
.build_exporter()
515+
.unwrap();
516+
}
499517
}

0 commit comments

Comments
 (0)