Skip to content

Commit

Permalink
out_nrlogs: wrap output in an array to match the API
Browse files Browse the repository at this point in the history
While the current format will send the data successfully, New Relic interprets the whole payload as a stringified array. By sending as an array, we meet the New Relic MELT API spec, and are able to distinguish individual key/values from the payload.

Sample spec can be seen here: https://docs.newrelic.com/docs/logs/new-relic-logs/log-api/introduction-log-api#log-attribute-examples

Signed-off-by: Julian Giuca <[email protected]>
  • Loading branch information
Julian Giuca authored and edsiper committed Jul 16, 2020
1 parent b3604db commit 4f822aa
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions plugins/out_nrlogs/newrelic.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,17 @@ static flb_sds_t newrelic_compose_payload(struct flb_newrelic *ctx,
* Following the New Relic Fluentd implementation, this is the
* suggested structure for our payload:
*
* payload = {
* 'common' => {
* 'attributes' => {
* 'plugin' => {
* 'type' => 'fluentd',
* 'version' => NewrelicFluentdOutput::VERSION,
* payload = {[
* 'common' => {
* 'attributes' => {
* 'plugin' => {
* 'type' => 'fluentd',
* 'version' => NewrelicFluentdOutput::VERSION,
* }
* }
* }
* },
* 'logs' => []
* },
* 'logs' => []
* ]}
*/

/* Count number of records */
Expand All @@ -178,6 +179,9 @@ static flb_sds_t newrelic_compose_payload(struct flb_newrelic *ctx,
msgpack_sbuffer_init(&mp_sbuf);
msgpack_packer_init(&mp_pck, &mp_sbuf, msgpack_sbuffer_write);

/* The New Relic MELT API format is wrapped in an array */
msgpack_pack_array(&mp_pck, 1);

/* Map for 'common' and 'logs' */
msgpack_pack_map(&mp_pck, 2);

Expand Down

0 comments on commit 4f822aa

Please sign in to comment.