From 0e38d23040693cf399303332130d46a27266f0c3 Mon Sep 17 00:00:00 2001 From: Dmitry Filimonov Date: Fri, 12 Apr 2024 11:10:01 -0700 Subject: [PATCH 1/4] docs: adds README for node --- .../nodejs/README.md | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 examples/language-sdk-instrumentation/nodejs/README.md diff --git a/examples/language-sdk-instrumentation/nodejs/README.md b/examples/language-sdk-instrumentation/nodejs/README.md new file mode 100644 index 0000000000..f26ba9fa48 --- /dev/null +++ b/examples/language-sdk-instrumentation/nodejs/README.md @@ -0,0 +1,56 @@ +## Continuous Profiling for Node applications +### Profiling a Node Rideshare App with Pyroscope + +![golang_example_architecture_new_00](https://user-images.githubusercontent.com/23323466/173370161-f8ba5c0a-cacf-4b3b-8d84-dd993019c486.gif) + +Note: For documentation on Pyroscope's Node integration visit [our website](https://grafana.com/docs/pyroscope/latest/configure-client/language-sdks/nodejs/). + +## Background +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`: +- `/bike` : calls the `bikeSearchHandler()` function to order a bike +- `/car` : calls the `carSearchHandler()` function to order a car +- `/scooter` : calls the `scooterSearchHandler()` function to order a scooter + +We also simulate running 3 distinct servers in 3 different regions (via [docker-compose.yml](./express/docker-compose.yml)) +- us-east +- eu-north +- ap-south + +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: +- `region`: statically tags the region of the server running the code + + +## Tagging static region +Tagging something static, like the `region`, can be done in the initialization code in the `main()` function: +```js + Pyroscope.init({ + appName: 'nodejs', + serverAddress: process.env['PYROSCOPE_SERVER'] || 'http://pyroscope:4040', + tags: { region: process.env['REGION'] || 'default' } + }); +``` + +## Resulting flame graph / performance results from the example +### Running the example + +There are 3 examples: +* `express` - basic integration example +* `express-ts` - type script example +* `express-pull` — pull mode example + +To run any of them example run the following commands: +```shell +# change directory +cd express # or cd express-ts / cs express-pull + +# Pull latest pyroscope image: +docker pull grafana/pyroscope:latest + +# Run the example project: +docker-compose up --build + +# Reset the database (if needed): +docker-compose down +``` + +This example will run all the code mentioned above and also send some mock-load to the 3 servers as well as their respective 3 endpoints. If you select our application: `nodejs.wall` from the dropdown, you should see a flame graph that looks like this (below). After we give 20-30 seconds for the flame graph to update and then 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. From d8c78f1e04a490eb40363aef04599ec42e73e4fa Mon Sep 17 00:00:00 2001 From: Kim Nylander <104772500+knylander-grafana@users.noreply.github.com> Date: Tue, 14 May 2024 18:17:41 -0400 Subject: [PATCH 2/4] Update examples/language-sdk-instrumentation/nodejs/README.md --- examples/language-sdk-instrumentation/nodejs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/language-sdk-instrumentation/nodejs/README.md b/examples/language-sdk-instrumentation/nodejs/README.md index f26ba9fa48..f3ff6d88e3 100644 --- a/examples/language-sdk-instrumentation/nodejs/README.md +++ b/examples/language-sdk-instrumentation/nodejs/README.md @@ -6,7 +6,7 @@ Note: For documentation on Pyroscope's Node integration visit [our website](https://grafana.com/docs/pyroscope/latest/configure-client/language-sdks/nodejs/). ## Background -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`: +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`: - `/bike` : calls the `bikeSearchHandler()` function to order a bike - `/car` : calls the `carSearchHandler()` function to order a car - `/scooter` : calls the `scooterSearchHandler()` function to order a scooter From 92909ddfef4eb8f987132d00456dc3d8da1d5605 Mon Sep 17 00:00:00 2001 From: Kim Nylander <104772500+knylander-grafana@users.noreply.github.com> Date: Tue, 14 May 2024 18:17:52 -0400 Subject: [PATCH 3/4] Update examples/language-sdk-instrumentation/nodejs/README.md --- examples/language-sdk-instrumentation/nodejs/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/language-sdk-instrumentation/nodejs/README.md b/examples/language-sdk-instrumentation/nodejs/README.md index f3ff6d88e3..32d81c2134 100644 --- a/examples/language-sdk-instrumentation/nodejs/README.md +++ b/examples/language-sdk-instrumentation/nodejs/README.md @@ -53,4 +53,5 @@ docker-compose up --build docker-compose down ``` -This example will run all the code mentioned above and also send some mock-load to the 3 servers as well as their respective 3 endpoints. If you select our application: `nodejs.wall` from the dropdown, you should see a flame graph that looks like this (below). After we give 20-30 seconds for the flame graph to update and then 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. +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). +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. From 041c8456e096f0e4ab60aaa8d15156b8647762e4 Mon Sep 17 00:00:00 2001 From: Kim Nylander <104772500+knylander-grafana@users.noreply.github.com> Date: Tue, 14 May 2024 18:18:40 -0400 Subject: [PATCH 4/4] Update examples/language-sdk-instrumentation/nodejs/README.md --- examples/language-sdk-instrumentation/nodejs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/language-sdk-instrumentation/nodejs/README.md b/examples/language-sdk-instrumentation/nodejs/README.md index 32d81c2134..5099d66cf9 100644 --- a/examples/language-sdk-instrumentation/nodejs/README.md +++ b/examples/language-sdk-instrumentation/nodejs/README.md @@ -38,7 +38,7 @@ There are 3 examples: * `express-ts` - type script example * `express-pull` — pull mode example -To run any of them example run the following commands: +To use any of the examples, run the following commands: ```shell # change directory cd express # or cd express-ts / cs express-pull