diff --git a/changelog.d/21878_request_body_of_honeycomb_sink.fix.md b/changelog.d/21878_request_body_of_honeycomb_sink.fix.md new file mode 100644 index 0000000000000..8bd41956086c5 --- /dev/null +++ b/changelog.d/21878_request_body_of_honeycomb_sink.fix.md @@ -0,0 +1,3 @@ +The request body of the Honeycomb sink should be encoded as an array according to [the API docs](https://docs.honeycomb.io/api/tag/Events#operation/createEvents). + +authors: hgiasac diff --git a/src/sinks/honeycomb/encoder.rs b/src/sinks/honeycomb/encoder.rs index 0b9ccd429063d..7f0f0634cc4a1 100644 --- a/src/sinks/honeycomb/encoder.rs +++ b/src/sinks/honeycomb/encoder.rs @@ -1,6 +1,6 @@ //! Encoding for the `honeycomb` sink. -use bytes::BytesMut; +use bytes::Bytes; use chrono::{SecondsFormat, Utc}; use serde_json::{json, to_vec}; use std::io; @@ -21,8 +21,8 @@ impl SinkEncoder> for HoneycombEncoder { writer: &mut dyn io::Write, ) -> io::Result<(usize, GroupedCountByteSize)> { let mut byte_size = telemetry().create_request_count_byte_size(); - let mut body = BytesMut::new(); let n_events = events.len(); + let mut json_events: Vec = Vec::with_capacity(n_events); for mut event in events { self.transformer.transform(&mut event); @@ -37,15 +37,15 @@ impl SinkEncoder> for HoneycombEncoder { Utc::now() }; - let data = to_vec(&json!({ + let data = json!({ "time": timestamp.to_rfc3339_opts(SecondsFormat::Nanos, true), "data": log.convert_to_fields(), - }))?; + }); - body.extend(&data); + json_events.push(data); } - let body = body.freeze(); + let body = Bytes::from(to_vec(&serde_json::Value::Array(json_events))?); write_all(writer, n_events, body.as_ref()).map(|()| (body.len(), byte_size)) }