loggly / node-loggly-bulk

A client implementation for Loggly in node.js
https://www.loggly.com/docs/node-js-logs/
Other
20 stars 19 forks source link

Bulk log sending is broken in v4.0.1 #71

Open Klem3n opened 1 year ago

Klem3n commented 1 year ago

Sending logs in bulk is currently broken in version 4.0.1 of the library, because only one of the logs is sent to Loggly while others are disarded. The http request options contain the wrong data.

Reproduction script:

import loggly from "node-loggly-bulk";

const subdomain = "REPLACE_ME";
const token = "REPLACE_ME"

const client = loggly.createClient({
  subdomain,
  json: true,
  token,
  tags: ["test"],
  isBulk: true,
  useTagHeader: false,
  bufferOptions: {
    size: 2
  },
});

client.log({
  message: "test",
  id: 10091
});
client.log({
  message: "test",
  id: 10091
});

//Wait for request to finish before exiting
console.log("Press any key to exit");

process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on("data", process.exit.bind(process, 0));

Sent axios request options

{
  uri: 'https://logs-01.loggly.com/bulk/xxx/tag/test/',
  method: 'POST',
  headers: {},
  proxy: null,
  data: '{"message":"test","id":10091}',
  body: '{"message":"test","id":10091}\n{"message":"test","id":10091}'
}

Expected axios request options

{
  uri: 'https://logs-01.loggly.com/bulk/xxx/tag/test/',
  method: 'POST',
  headers: {},
  proxy: null,
  data: '{"message":"test","id":10091}\n{"message":"test","id":10091}'
}

I think the issue is related to migration from request library to axios library. The data in requestOptions is set to body.

Fix

This issue can be fixed by changing .body to .data in common.js#236. But I'm not sure if this is the correct solution.

https://github.com/loggly/node-loggly-bulk/blob/39163147f9bc028850935a08faa76bbe09cd01f8/lib/loggly/common.js#L236C21-L236C21