Skip to content

Commit b1bf08a

Browse files
rochdevtlhunter
authored andcommitted
reuse http client between exports
1 parent f0ec0a8 commit b1bf08a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

collector/src/exporting/agent.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
use crate::tracing::{Trace, Traces};
22
use super::Exporter;
33
use async_trait::async_trait;
4+
use hyper::{Body, Client, Request};
5+
use hyper::client::HttpConnector;
46
use rmp::encode;
57
use rmp::encode::ByteBuf;
68
use hashbrown::HashMap;
79

8-
pub struct AgentExporter {}
10+
pub struct AgentExporter {
11+
client: Client<HttpConnector>
12+
}
913

1014
#[async_trait]
1115
impl Exporter for AgentExporter {
@@ -18,9 +22,8 @@ impl Exporter for AgentExporter {
1822

1923
self.encode_traces(&mut wr, traces);
2024

21-
let client = hyper::Client::new();
2225
let data: Vec<u8> = wr.as_vec().to_vec();
23-
let req = hyper::Request::builder()
26+
let req = Request::builder()
2427
.method(hyper::Method::PUT)
2528
.uri("http://localhost:8126/v0.4/traces")
2629
.header("Content-Type", "application/msgpack")
@@ -29,10 +32,10 @@ impl Exporter for AgentExporter {
2932
// .header("Datadog-Meta-Lang", "")
3033
// .header("Datadog-Meta-Lang-Version", "")
3134
// .header("Datadog-Meta-Lang-Interpreter", "")
32-
.body(hyper::Body::from(data))
35+
.body(Body::from(data))
3336
.unwrap();
3437

35-
client.request(req).await.unwrap();
38+
self.client.request(req).await.unwrap();
3639
}
3740
}
3841
}
@@ -45,7 +48,9 @@ impl Default for AgentExporter {
4548

4649
impl AgentExporter {
4750
pub fn new() -> Self {
48-
Self {}
51+
Self {
52+
client: Client::new()
53+
}
4954
}
5055

5156
fn encode_traces(&self, wr: &mut ByteBuf, traces: Traces) {

0 commit comments

Comments
 (0)