Skip to content

Commit f6de564

Browse files
docs: adds README for node (#3212)
* docs: adds README for node * Update examples/language-sdk-instrumentation/nodejs/README.md * Update examples/language-sdk-instrumentation/nodejs/README.md * Update examples/language-sdk-instrumentation/nodejs/README.md --------- Co-authored-by: Kim Nylander <[email protected]>
1 parent 2063655 commit f6de564

File tree

1 file changed

+57
-0
lines changed
  • examples/language-sdk-instrumentation/nodejs

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## Continuous Profiling for Node applications
2+
### Profiling a Node Rideshare App with Pyroscope
3+
4+
![golang_example_architecture_new_00](https://user-images.githubusercontent.com/23323466/173370161-f8ba5c0a-cacf-4b3b-8d84-dd993019c486.gif)
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 image:
47+
docker pull grafana/pyroscope:latest
48+
49+
# Run the example project:
50+
docker-compose up --build
51+
52+
# Reset the database (if needed):
53+
docker-compose down
54+
```
55+
56+
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).
57+
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.

0 commit comments

Comments
 (0)