pyroscope icon indicating copy to clipboard operation
pyroscope copied to clipboard

Issues running with jest + react + tsx files (error happened while parsing request body)

Open louiidev opened this issue 2 years ago • 4 comments

Howdy!

I'm trying to profile some frontend tests that are written in typescript, I keep getting this error: error happened while parsing request body

I'm wondering if that's actually something this project supports or I'm using the wrong tool?

I'm also getting seg faults which seems concerning as well: nodejs/npm: line 14: 2471 Segmentation fault "$basedir/node" "$basedir/node_modules/npm/bin/npm-cli.js" "$@"

these test also take about 30s to complete(hence the profiling)

louiidev avatar Jul 11 '22 06:07 louiidev

Thank you for reporting @louisgjohnson we'll take a look and see if it's a quick fix or not and get back to you

Rperry2174 avatar Jul 11 '22 19:07 Rperry2174

Thanks @Rperry2174 i can try and make a small reproducible repo if that helps and I’ll also try and attach more info about my issue, I was just a bit rushed yesterday when I raised it

louiidev avatar Jul 11 '22 22:07 louiidev

@louisgjohnson yes that would be extremely helpful if we could recreate this for us being able to fix it faster.

Rperry2174 avatar Jul 12 '22 15:07 Rperry2174

Hey! I played with this a little bit, but take my comments with a grain of salt.

You need to run with --runInBand, so that it runs serially with a single worker. Then you need to setup globalSetup and globalTeardown in jest.config.js

  globalSetup: '<rootDir>/globalSetup.js',
  globalTeardown: '<rootDir>/globalTeardown.js',

globalSetup.js

const Pyroscope = require('@pyroscope/nodejs');

module.exports = function () {
  Pyroscope.init({
    appName: 'myapp',
    serverAddress: 'http://localhost:4040',
  });

  Pyroscope.start();
};

globalTeardown.js

const Pyroscope = require('@pyroscope/nodejs');

module.exports = function () {
  Pyroscope.stop();
};

Here's an example running against this repo (similar setup, typescript/tsx) https://flamegraph.com/share/88ff2fd2-039a-11ed-9ca9-86120e7f0849

All that being said, there are a few quirks:

  • I could not get stacktraces from the tests. Dunno why yet.
  • Pyroscope.stop() does not flush the profiling data
  • As I mentioned above, we gotta run with a single worker

Also I could not reproduce the segmentation fault you brought up. Running node v14.17.0 with latest pyroscope integration (0.2.4 https://github.com/pyroscope-io/pyroscope-nodejs/releases/tag/v0.2.4)

eh-am avatar Jul 14 '22 20:07 eh-am

Just a heads up, we implemented a way to track ci executions (https://pyroscope.io/docs/ci/). For node it works pretty much how I explained above, but there's an example here if you want to try.

eh-am avatar Jan 30 '23 22:01 eh-am