Skip to content

Commit

Permalink
fix(honeycomb sink): The batch body should be encoded as array (#21878)
Browse files Browse the repository at this point in the history
* honeycomb sink: batch body should be encoded as array

* add changelog

* fix changelog

* fix the changelog file name format

* fix the changelog file name again (sorry)
  • Loading branch information
hgiasac authored Nov 25, 2024
1 parent 5c7db96 commit a7204fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions changelog.d/21878_request_body_of_honeycomb_sink.fix.md
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions src/sinks/honeycomb/encoder.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,8 +21,8 @@ impl SinkEncoder<Vec<Event>> 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<serde_json::Value> = Vec::with_capacity(n_events);

for mut event in events {
self.transformer.transform(&mut event);
Expand All @@ -37,15 +37,15 @@ impl SinkEncoder<Vec<Event>> 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))
}
Expand Down

0 comments on commit a7204fa

Please sign in to comment.