1
1
use crate :: tracing:: { Trace , Traces } ;
2
2
use super :: Exporter ;
3
3
use async_trait:: async_trait;
4
+ use hyper:: { Body , Client , Request } ;
5
+ use hyper:: client:: HttpConnector ;
4
6
use rmp:: encode;
5
7
use rmp:: encode:: ByteBuf ;
6
8
use hashbrown:: HashMap ;
7
9
8
- pub struct AgentExporter { }
10
+ pub struct AgentExporter {
11
+ client : Client < HttpConnector >
12
+ }
9
13
10
14
#[ async_trait]
11
15
impl Exporter for AgentExporter {
@@ -18,9 +22,8 @@ impl Exporter for AgentExporter {
18
22
19
23
self . encode_traces ( & mut wr, traces) ;
20
24
21
- let client = hyper:: Client :: new ( ) ;
22
25
let data: Vec < u8 > = wr. as_vec ( ) . to_vec ( ) ;
23
- let req = hyper :: Request :: builder ( )
26
+ let req = Request :: builder ( )
24
27
. method ( hyper:: Method :: PUT )
25
28
. uri ( "http://localhost:8126/v0.4/traces" )
26
29
. header ( "Content-Type" , "application/msgpack" )
@@ -29,10 +32,10 @@ impl Exporter for AgentExporter {
29
32
// .header("Datadog-Meta-Lang", "")
30
33
// .header("Datadog-Meta-Lang-Version", "")
31
34
// .header("Datadog-Meta-Lang-Interpreter", "")
32
- . body ( hyper :: Body :: from ( data) )
35
+ . body ( Body :: from ( data) )
33
36
. unwrap ( ) ;
34
37
35
- client. request ( req) . await . unwrap ( ) ;
38
+ self . client . request ( req) . await . unwrap ( ) ;
36
39
}
37
40
}
38
41
}
@@ -45,7 +48,9 @@ impl Default for AgentExporter {
45
48
46
49
impl AgentExporter {
47
50
pub fn new ( ) -> Self {
48
- Self { }
51
+ Self {
52
+ client : Client :: new ( )
53
+ }
49
54
}
50
55
51
56
fn encode_traces ( & self , wr : & mut ByteBuf , traces : Traces ) {
0 commit comments