pyroscope
pyroscope copied to clipboard
Issues running with jest + react + tsx files (error happened while parsing request body)
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)
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
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
@louisgjohnson yes that would be extremely helpful if we could recreate this for us being able to fix it faster.
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)
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.