Skip to content

Commit 8a49c7d

Browse files
authored
Add functions to SendDataBuilder (#1140)
* Add SendData.get_target_mut() * Add SendData.set_api_key() * fmt * SendDataBuilder.with_api_key() * Add SendDataBuilder.is_empty() * Add SendDataBuilder.with_retry_strategy() * Add SendDataBuilder.len() * Add SendDataBuilder.clone() * Add test * Add test for is_empty() * Fix clippy * Remove getters from builder * Remove clone * Add back Clone()
1 parent 81b0e5a commit 8a49c7d

File tree

1 file changed

+37
-0
lines changed
  • datadog-trace-utils/src/send_data

1 file changed

+37
-0
lines changed

datadog-trace-utils/src/send_data/mod.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub enum Compression {
7878
None,
7979
}
8080

81+
#[derive(Clone)]
8182
pub struct SendDataBuilder {
8283
pub(crate) tracer_payloads: TracerPayloadCollection,
8384
pub(crate) size: usize,
@@ -114,6 +115,16 @@ impl SendDataBuilder {
114115
self
115116
}
116117

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+
117128
pub fn build(self) -> SendData {
118129
SendData {
119130
tracer_payloads: self.tracer_payloads,
@@ -420,6 +431,7 @@ where
420431
#[cfg(test)]
421432
mod tests {
422433
use super::*;
434+
use crate::send_with_retry::{RetryBackoffType, RetryStrategy};
423435
use crate::test_utils::create_test_no_alloc_span;
424436
use crate::trace_utils::{construct_trace_chunk, construct_tracer_payload, RootSpanTags};
425437
use crate::tracer_header_tags::TracerHeaderTags;
@@ -1030,4 +1042,29 @@ mod tests {
10301042
#[cfg(feature = "compression")]
10311043
assert!(matches!(new_data.compression, Compression::None));
10321044
}
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+
}
10331070
}

0 commit comments

Comments
 (0)