pub fn encode_traces<T: TraceData>(
traces: &[Vec<Span<T>>],
out: &mut impl Write,
max_line_size: usize,
) -> Result<EncodeStats>Expand description
Encodes traces into newline-delimited JSON “log exporter” lines, writing
them to out.
All spans across all input traces are flattened and greedily packed into
lines no larger than max_line_size bytes (including the {"traces":[[ /
]]}\n framing). Each line contains a single inner trace array, matching the
reference dd-trace-js exporter. A span whose own serialized size plus the
framing overhead exceeds max_line_size is dropped (counted in
EncodeStats::spans_dropped) and never split across lines.
The caller is responsible for flushing out (e.g. stdout) after this returns.
§Errors
Returns any std::io::Error produced while writing to out.
§Examples
use libdd_trace_utils::json_log_encoder::encode_traces;
use libdd_trace_utils::span::v04::SpanSlice;
let span = SpanSlice {
service: "my-fn".into(),
name: "aws.lambda".into(),
resource: "my-fn".into(),
trace_id: 1,
span_id: 2,
..Default::default()
};
let traces = vec![vec![span]];
let mut out = Vec::new();
let stats = encode_traces(&traces, &mut out, 64 * 1024).unwrap();
assert_eq!(stats.spans_written, 1);
assert!(out.ends_with(b"\n"));