facebook / memlab

A framework for finding JavaScript memory leaks and analyzing heap snapshots
https://facebook.github.io/memlab/
MIT License
4.36k stars 119 forks source link

Add support for error logging only #124

Closed doteric closed 3 weeks ago

doteric commented 4 weeks ago

Hello 👋

We're running Memlab in AWS Lambdas, the amount of produced logs is very high and we've decided to set muteConsole to true, this however means that we do not receive error logs and only receive critical error logs. A nice thing to have would be to decide which type of logs to receive. This way only errors could be logged.

Cheers, Eric

JacksonGL commented 4 weeks ago

I can add an additional config.muteConfig for fine tuning the console mute configuration.

JacksonGL commented 3 weeks ago

The new config.muteConfig option is now available in memlab@1.1.52. Here's an example code snippet for your reference:

const {run} = require('@memlab/api');
const {config} = require('@memlab/core');

config.muteConfig = {
  muteError: false,
  muteWarning: false,
  muteInfo: true,
  muteSuccess: true,
  muteLog: true,
  muteTable: true,
  muteTrace: true,
  muteTopLevel: true,
  muteHighLevel: true,
  muteMidLevel: true,
  muteLowLevel: true,
};

(async function () {
  const scenario = {
    url: () => 'https://www.facebook.com',
    action: async () => {
      throw new Error('test');
    },
  };
  const {leaks} = await run({scenario, skipWarmup: true});
})();
doteric commented 3 weeks ago

That was fast, big thanks @JacksonGL 🙇

doteric commented 2 weeks ago

Hey @JacksonGL , sorry to bother you, just one thing to note, it might be worth changing up the error and warn.

With the following config:

memlabConfig.muteConfig = {
      muteError: false,
      muteWarning: false,
      muteInfo: true,
      muteSuccess: true,
      muteLog: true,
      muteTable: true,
      muteTrace: true,
      muteTopLevel: true,
      muteHighLevel: true,
      muteMidLevel: true,
      muteLowLevel: true,
    };

I get the following log when an interaction fails:

2024-08-26T21:06:56.068ZSTART RequestId: a8ad0c51-3bd6-403f-9065-c8afa88c9a35 Version: $LATEST
  | 2024-08-26T21:08:15.427Z | start is not defined
  | 2024-08-26T21:08:15.428Z | addRow is not defined
  | 2024-08-26T21:08:15.429Z | addRow is not defined
  | 2024-08-26T21:08:15.429Z | addRow is not defined
... (more addRow errors)
  | 2024-08-26T21:08:47.067Z | 
  | 2024-08-26T21:09:22.716Z | 
  | 2024-08-26T21:09:57.444Z | interaction fail, making 1 more attempt(s)...
  | 2024-08-26T21:10:30.485Z | interaction fail
  | 2024-08-26T21:10:34.401Z | END RequestId: a8ad0c51-3bd6-403f-9065-c8afa88c9a35

That means that while the error logs show they aren't really useful as they do not state what exactly has failed. What I would suggest is error logging what interaction (and on what element) exactly has failed.
What do you think about that?

Cheers and really appreciate the work 💪

JacksonGL commented 2 weeks ago

@doteric You might want to add the --verbose flag when running memlab, which should provide a stack trace that pinpoints the line in your test scenario file where the interaction failed.

JacksonGL commented 2 weeks ago

Setting memlabConfig.verbose = true should get the same result.