@@ -78,6 +78,7 @@ pub enum Compression {
78
78
None ,
79
79
}
80
80
81
+ #[ derive( Clone ) ]
81
82
pub struct SendDataBuilder {
82
83
pub ( crate ) tracer_payloads : TracerPayloadCollection ,
83
84
pub ( crate ) size : usize ,
@@ -114,6 +115,16 @@ impl SendDataBuilder {
114
115
self
115
116
}
116
117
118
+ pub fn with_api_key ( mut self , api_key : & str ) -> SendDataBuilder {
119
+ self . target . api_key = Some ( api_key. to_string ( ) . into ( ) ) ;
120
+ self
121
+ }
122
+
123
+ pub fn with_retry_strategy ( mut self , retry_strategy : RetryStrategy ) -> SendDataBuilder {
124
+ self . retry_strategy = retry_strategy;
125
+ self
126
+ }
127
+
117
128
pub fn build ( self ) -> SendData {
118
129
SendData {
119
130
tracer_payloads : self . tracer_payloads ,
@@ -420,6 +431,7 @@ where
420
431
#[ cfg( test) ]
421
432
mod tests {
422
433
use super :: * ;
434
+ use crate :: send_with_retry:: { RetryBackoffType , RetryStrategy } ;
423
435
use crate :: test_utils:: create_test_no_alloc_span;
424
436
use crate :: trace_utils:: { construct_trace_chunk, construct_tracer_payload, RootSpanTags } ;
425
437
use crate :: tracer_header_tags:: TracerHeaderTags ;
@@ -1030,4 +1042,29 @@ mod tests {
1030
1042
#[ cfg( feature = "compression" ) ]
1031
1043
assert ! ( matches!( new_data. compression, Compression :: None ) ) ;
1032
1044
}
1045
+
1046
+ #[ test]
1047
+ fn test_builder ( ) {
1048
+ let header_tags = HEADER_TAGS ;
1049
+ let payload = setup_payload ( & header_tags) ;
1050
+ let retry_strategy = RetryStrategy :: new ( 5 , 100 , RetryBackoffType :: Constant , None ) ;
1051
+
1052
+ let send_data = SendDataBuilder :: new (
1053
+ 100 ,
1054
+ TracerPayloadCollection :: V07 ( vec ! [ payload] ) ,
1055
+ header_tags,
1056
+ & Endpoint :: default ( ) ,
1057
+ )
1058
+ // Test with_api_key()
1059
+ . with_api_key ( "TEST-KEY" )
1060
+ // Test with_retry_strategy()
1061
+ . with_retry_strategy ( retry_strategy. clone ( ) )
1062
+ . build ( ) ;
1063
+
1064
+ assert_eq ! (
1065
+ send_data. target. api_key,
1066
+ Some ( std:: borrow:: Cow :: Borrowed ( "TEST-KEY" ) )
1067
+ ) ;
1068
+ assert_eq ! ( send_data. retry_strategy, retry_strategy) ;
1069
+ }
1033
1070
}
0 commit comments