github.com/grafana/pyroscope@v1.18.0/examples/language-sdk-instrumentation/nodejs/README.md (about) 1 ## Continuous Profiling for Node applications 2 ### Profiling a Node Rideshare App with Pyroscope 3 4  5 6 Note: For documentation on Pyroscope's Node integration visit [our website](https://grafana.com/docs/pyroscope/latest/configure-client/language-sdks/nodejs/). 7 8 ## Background 9 In this example, we show a simplified, basic use case of Pyroscope. We simulate a "ride share" company which has three endpoints found in `main.js`: 10 - `/bike` : calls the `bikeSearchHandler()` function to order a bike 11 - `/car` : calls the `carSearchHandler()` function to order a car 12 - `/scooter` : calls the `scooterSearchHandler()` function to order a scooter 13 14 We also simulate running 3 distinct servers in 3 different regions (via [docker-compose.yml](./express/docker-compose.yml)) 15 - us-east 16 - eu-north 17 - ap-south 18 19 One of the most useful capabilities of Pyroscope is the ability to tag your data in a way that is meaningful to you. In this case, we have two natural divisions, and so we "tag" our data to represent those: 20 - `region`: statically tags the region of the server running the code 21 22 23 ## Tagging static region 24 Tagging something static, like the `region`, can be done in the initialization code in the `main()` function: 25 ```js 26 Pyroscope.init({ 27 appName: 'nodejs', 28 serverAddress: process.env['PYROSCOPE_SERVER'] || 'http://pyroscope:4040', 29 tags: { region: process.env['REGION'] || 'default' } 30 }); 31 ``` 32 33 ## Resulting flame graph / performance results from the example 34 ### Running the example 35 36 There are 3 examples: 37 * `express` - basic integration example 38 * `express-ts` - type script example 39 * `express-pull` — pull mode example 40 41 To use any of the examples, run the following commands: 42 ```shell 43 # change directory 44 cd express # or cd express-ts / cs express-pull 45 46 # Pull latest pyroscope and grafana images: 47 docker pull grafana/pyroscope:latest 48 docker pull grafana/grafana:latest 49 50 # Run the example project: 51 docker-compose up --build 52 53 # Reset the database (if needed): 54 docker-compose down 55 ``` 56 57 This example runs all the code mentioned above and also sends some mock-load to the 3 servers as well as their respective 3 endpoints. If you select `nodejs.wall` from the dropdown, you should see a flame graph that looks like this (below). 58 After 20-30 seconds, the flame graph updates. Click the refresh button. We see our 3 functions at the bottom of the flame graph taking CPU resources _proportional to the size_ of their respective `search_radius` parameters.