@@ -9,6 +9,7 @@ use crate::trace_utils::TracerHeaderTags;
9
9
use crate :: tracer_payload:: TracerPayloadCollection ;
10
10
use anyhow:: { anyhow, Context } ;
11
11
use datadog_trace_protobuf:: pb:: { AgentPayload , TracerPayload } ;
12
+ use ddcommon:: HttpClient ;
12
13
use ddcommon:: {
13
14
header:: {
14
15
APPLICATION_MSGPACK_STR , APPLICATION_PROTOBUF_STR , DATADOG_SEND_REAL_HTTP_STATUS_STR ,
@@ -42,6 +43,7 @@ use zstd::stream::write::Encoder;
42
43
/// use datadog_trace_utils::trace_utils::TracerHeaderTags;
43
44
/// use datadog_trace_utils::tracer_payload::TracerPayloadCollection;
44
45
/// use ddcommon::Endpoint;
46
+ /// use ddcommon::hyper_migration::new_default_client;
45
47
///
46
48
/// #[cfg_attr(miri, ignore)]
47
49
/// async fn update_send_results_example() {
@@ -58,8 +60,9 @@ use zstd::stream::write::Encoder;
58
60
///
59
61
/// send_data.set_retry_strategy(retry_strategy);
60
62
///
63
+ /// let client = new_default_client();
61
64
/// // Send the data
62
- /// let result = send_data.send().await;
65
+ /// let result = send_data.send(&client ).await;
63
66
/// }
64
67
/// ```
65
68
pub struct SendData {
@@ -234,24 +237,15 @@ impl SendData {
234
237
/// # Returns
235
238
///
236
239
/// A `SendDataResult` instance containing the result of the operation.
237
- pub async fn send ( & self ) -> SendDataResult {
238
- self . send_internal ( None ) . await
240
+ pub async fn send ( & self , http_client : & HttpClient ) -> SendDataResult {
241
+ self . send_internal ( http_client ) . await
239
242
}
240
243
241
- /// Sends the data to the target endpoint.
242
- ///
243
- /// # Returns
244
- ///
245
- /// A `SendDataResult` instance containing the result of the operation.
246
- pub async fn send_proxy ( & self , http_proxy : Option < & str > ) -> SendDataResult {
247
- self . send_internal ( http_proxy) . await
248
- }
249
-
250
- async fn send_internal ( & self , http_proxy : Option < & str > ) -> SendDataResult {
244
+ async fn send_internal ( & self , http_client : & HttpClient ) -> SendDataResult {
251
245
if self . use_protobuf ( ) {
252
- self . send_with_protobuf ( http_proxy ) . await
246
+ self . send_with_protobuf ( http_client ) . await
253
247
} else {
254
- self . send_with_msgpack ( http_proxy ) . await
248
+ self . send_with_msgpack ( http_client ) . await
255
249
}
256
250
}
257
251
@@ -260,17 +254,17 @@ impl SendData {
260
254
chunks : u64 ,
261
255
payload : Vec < u8 > ,
262
256
headers : HashMap < & ' static str , String > ,
263
- http_proxy : Option < & str > ,
257
+ http_client : & HttpClient ,
264
258
) -> ( SendWithRetryResult , u64 , u64 ) {
265
259
#[ allow( clippy:: unwrap_used) ]
266
260
let payload_len = u64:: try_from ( payload. len ( ) ) . unwrap ( ) ;
267
261
(
268
262
send_with_retry (
263
+ http_client,
269
264
& self . target ,
270
265
payload,
271
266
& headers,
272
267
& self . retry_strategy ,
273
- http_proxy,
274
268
)
275
269
. await ,
276
270
payload_len,
@@ -304,7 +298,7 @@ impl SendData {
304
298
}
305
299
}
306
300
307
- async fn send_with_protobuf ( & self , http_proxy : Option < & str > ) -> SendDataResult {
301
+ async fn send_with_protobuf ( & self , http_client : & HttpClient ) -> SendDataResult {
308
302
let mut result = SendDataResult :: default ( ) ;
309
303
310
304
#[ allow( clippy:: unwrap_used) ]
@@ -331,7 +325,7 @@ impl SendData {
331
325
request_headers. insert ( CONTENT_TYPE . as_str ( ) , APPLICATION_PROTOBUF_STR . to_string ( ) ) ;
332
326
333
327
let ( response, bytes_sent, chunks) = self
334
- . send_payload ( chunks, final_payload, request_headers, http_proxy )
328
+ . send_payload ( chunks, final_payload, request_headers, http_client )
335
329
. await ;
336
330
337
331
result. update ( response, bytes_sent, chunks) ;
@@ -342,7 +336,7 @@ impl SendData {
342
336
}
343
337
}
344
338
345
- async fn send_with_msgpack ( & self , http_proxy : Option < & str > ) -> SendDataResult {
339
+ async fn send_with_msgpack ( & self , http_client : & HttpClient ) -> SendDataResult {
346
340
let mut result = SendDataResult :: default ( ) ;
347
341
let mut futures = FuturesUnordered :: new ( ) ;
348
342
@@ -360,7 +354,7 @@ impl SendData {
360
354
Err ( e) => return result. error ( anyhow ! ( e) ) ,
361
355
} ;
362
356
363
- futures. push ( self . send_payload ( chunks, payload, headers, http_proxy ) ) ;
357
+ futures. push ( self . send_payload ( chunks, payload, headers, http_client ) ) ;
364
358
}
365
359
}
366
360
TracerPayloadCollection :: V04 ( payload) => {
@@ -372,7 +366,7 @@ impl SendData {
372
366
373
367
let payload = msgpack_encoder:: v04:: to_vec ( payload) ;
374
368
375
- futures. push ( self . send_payload ( chunks, payload, headers, http_proxy ) ) ;
369
+ futures. push ( self . send_payload ( chunks, payload, headers, http_client ) ) ;
376
370
}
377
371
TracerPayloadCollection :: V05 ( payload) => {
378
372
#[ allow( clippy:: unwrap_used) ]
@@ -386,7 +380,7 @@ impl SendData {
386
380
Err ( e) => return result. error ( anyhow ! ( e) ) ,
387
381
} ;
388
382
389
- futures. push ( self . send_payload ( chunks, payload, headers, http_proxy ) ) ;
383
+ futures. push ( self . send_payload ( chunks, payload, headers, http_client ) ) ;
390
384
}
391
385
}
392
386
@@ -592,7 +586,8 @@ mod tests {
592
586
) ;
593
587
594
588
let data_payload_len = compute_payload_len ( & data. tracer_payloads ) ;
595
- let res = data. send ( ) . await ;
589
+ let client = ddcommon:: hyper_migration:: new_default_client ( ) ;
590
+ let res = data. send ( & client) . await ;
596
591
597
592
mock. assert_async ( ) . await ;
598
593
@@ -637,7 +632,8 @@ mod tests {
637
632
) ;
638
633
639
634
let data_payload_len = compute_payload_len ( & data. tracer_payloads ) ;
640
- let res = data. send ( ) . await ;
635
+ let client = ddcommon:: hyper_migration:: new_default_client ( ) ;
636
+ let res = data. send ( & client) . await ;
641
637
642
638
mock. assert_async ( ) . await ;
643
639
@@ -696,7 +692,8 @@ mod tests {
696
692
) ;
697
693
698
694
let data_payload_len = rmp_compute_payload_len ( & data. tracer_payloads ) ;
699
- let res = data. send ( ) . await ;
695
+ let client = ddcommon:: hyper_migration:: new_default_client ( ) ;
696
+ let res = data. send ( & client) . await ;
700
697
701
698
mock. assert_async ( ) . await ;
702
699
@@ -754,7 +751,8 @@ mod tests {
754
751
) ;
755
752
756
753
let data_payload_len = rmp_compute_payload_len ( & data. tracer_payloads ) ;
757
- let res = data. send ( ) . await ;
754
+ let client = ddcommon:: hyper_migration:: new_default_client ( ) ;
755
+ let res = data. send ( & client) . await ;
758
756
759
757
mock. assert_async ( ) . await ;
760
758
@@ -798,7 +796,8 @@ mod tests {
798
796
) ;
799
797
800
798
let data_payload_len = rmp_compute_payload_len ( & data. tracer_payloads ) ;
801
- let res = data. send ( ) . await ;
799
+ let client = ddcommon:: hyper_migration:: new_default_client ( ) ;
800
+ let res = data. send ( & client) . await ;
802
801
803
802
mock. assert_calls_async ( 2 ) . await ;
804
803
@@ -839,7 +838,8 @@ mod tests {
839
838
} ,
840
839
) ;
841
840
842
- let res = data. send ( ) . await ;
841
+ let client = ddcommon:: hyper_migration:: new_default_client ( ) ;
842
+ let res = data. send ( & client) . await ;
843
843
844
844
mock. assert_calls_async ( 5 ) . await ;
845
845
@@ -871,7 +871,8 @@ mod tests {
871
871
} ,
872
872
) ;
873
873
874
- let res = data. send ( ) . await ;
874
+ let client = ddcommon:: hyper_migration:: new_default_client ( ) ;
875
+ let res = data. send ( & client) . await ;
875
876
876
877
assert ! ( res. last_result. is_err( ) ) ;
877
878
match std:: env:: consts:: OS {
@@ -938,7 +939,8 @@ mod tests {
938
939
} ,
939
940
) ;
940
941
941
- let res = data. send ( ) . await ;
942
+ let client = ddcommon:: hyper_migration:: new_default_client ( ) ;
943
+ let res = data. send ( & client) . await ;
942
944
943
945
mock. assert_calls_async ( 5 ) . await ;
944
946
@@ -980,7 +982,8 @@ mod tests {
980
982
} ,
981
983
) ;
982
984
983
- let res = data. send ( ) . await ;
985
+ let client = ddcommon:: hyper_migration:: new_default_client ( ) ;
986
+ let res = data. send ( & client) . await ;
984
987
985
988
mock. assert_calls_async ( 10 ) . await ;
986
989
0 commit comments