Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion libdd-data-pipeline/src/trace_exporter/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ impl TraceExporterBuilder {
self
}

/// Opt in to the V1 trace protocol.
///
/// V1 is only used after runtime negotiation with the agent via `/info`. When the agent does
/// not advertise the `/v1.0/traces` endpoint, the exporter falls back to V0.4 transparently.
/// V1 is only compatible with V0.4 input.
pub fn enable_v1_protocol(&mut self) -> &mut Self {
self.output_format = TraceExporterOutputFormat::V1;
self
}

/// Set the header indicating the tracer has computed the top-level tag
pub fn set_client_computed_top_level(&mut self) -> &mut Self {
self.client_computed_top_level = true;
Expand Down Expand Up @@ -465,7 +475,9 @@ impl TraceExporterBuilder {
},
input_format: self.input_format,
output_format: self.output_format,
serializer: TraceSerializer::new(self.output_format),
v1_active: std::sync::atomic::AtomicBool::new(false),
v1_unavailable_logged: std::sync::Once::new(),
serializer: TraceSerializer::new(),
client_computed_top_level: self.client_computed_top_level,
shared_runtime,
dogstatsd,
Expand Down Expand Up @@ -621,4 +633,54 @@ mod tests {
BuilderErrorKind::InvalidUri("empty string".to_string())
);
}

#[test]
fn test_enable_v1_protocol_sets_output_format() {
let mut builder = TraceExporterBuilder::default();
builder.enable_v1_protocol();
assert!(matches!(
builder.output_format,
TraceExporterOutputFormat::V1
));
}

#[test]
fn test_v1_input_v05_incompatible() {
let mut builder = TraceExporterBuilder::default();
builder
.set_input_format(TraceExporterInputFormat::V05)
.set_output_format(TraceExporterOutputFormat::V1);
let result = builder.build::<NativeCapabilities>();
assert!(matches!(
result,
Err(TraceExporterError::Builder(
BuilderErrorKind::InvalidConfiguration(_)
))
));
}

#[cfg_attr(miri, ignore)]
#[test]
fn test_build_with_v1_starts_inactive() {
let mut builder = TraceExporterBuilder::default();
builder
.set_input_format(TraceExporterInputFormat::V04)
.enable_v1_protocol();
let exporter = builder.build::<NativeCapabilities>().unwrap();

assert!(matches!(
exporter.output_format,
TraceExporterOutputFormat::V1
));
assert!(!exporter
.v1_active
.load(std::sync::atomic::Ordering::Relaxed));
assert_eq!(
exporter
.effective_output_format()
.add_path(&exporter.endpoint.url)
.to_string(),
"http://127.0.0.1:8126/v0.4/traces"
);
}
}
Loading
Loading