Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metric logging does not work as per the docs #135

Open
Antman261 opened this issue Aug 31, 2023 · 0 comments
Open

Metric logging does not work as per the docs #135

Antman261 opened this issue Aug 31, 2023 · 0 comments

Comments

@Antman261
Copy link

When I attempt to send metrics as per the docs, it attempts to JSON parse the graphite string.

in your code:

   const messages = message.map((item) => {
      if (this.config.graphite) {
        return `${item.path} ${item.value} ${Math.round(ts.getTime() / 1000)}`;
      }

conflicts with

batchReadyToSend() {
    if (this.config.batchSize === 0) {
      return this.config.interval === 0;
    } else {
      const pendingMessages = this.pendingLogs.reduce((acc, curr) => {
        const log = JSON.parse(curr);
        return acc + log.msg + '\n';
      }, '');

the code i'm calling with

const sumoLogger = new SumoLogger({
  endpoint: ENV_VARS.SumologicMetricsCollectorEndpoint,
  graphite: true,
  hostName: `WMS-${process.env.COMMIT_HASH}`,
  batchSize: 10000,
  interval: 5000,
});

sumoLogger.log({
  path: 'metric.path', // metric path as a dot separated string
  value: 100, // value of the metric
});

results in

SyntaxError: Unexpected token m in JSON at position 0
    at JSON.parse (<anonymous>)
    at /Users/[redacted]/api/node_modules/sumo-logger/lib/sumoLogger.js:129:26
    at Array.reduce (<anonymous>)
    at SumoLogger.batchReadyToSend (/Users/[redacted]/api/node_modules/sumo-logger/lib/sumoLogger.js:126:48)
    at SumoLogger.log (/Users/[redacted]/api/node_modules/sumo-logger/lib/sumoLogger.js:355:48)
    at Object.<anonymous> (/Users/[redacted]/api/build/config/sumoLogger.js:22:12)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
    at Module.load (node:internal/modules/cjs/loader:1074:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant