Skip to content

Commit 406fa58

Browse files
authored
docs: add nodejs example (#11)
1 parent 59d4bb9 commit 406fa58

File tree

7 files changed

+1563
-3
lines changed

7 files changed

+1563
-3
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ bin
1515
.aws-sam
1616
out.txt
1717

18-
hello-world
19-
!hello-world/main.go
18+
examples/go
19+
!examples/go/main.go
20+
21+
node_modules

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ You can run the extension in dev mode. It will not register the extension.
5353

5454
It's useful to test the relay server initialization.
5555
Keep in mind there's no lambda execution, therefore to test data is being relayed correctly you need
56-
to ingest manually.
56+
to ingest manually (hitting `http://localhost:4040/ingest`).
5757

5858
`PYROSCOPE_DEV_MODE=true go run main.go`
5959

@@ -92,3 +92,8 @@ aws lambda publish-layer-version \
9292
--region=$YOUR_REGION \
9393
--zip-file "fileb://extension.zip"
9494
```
95+
96+
# Publishing
97+
```
98+
deno run --allow-env --allow-read --allow-run scripts/publish.ts --name=pyroscope-extension --dry-run=false
99+
```
File renamed without changes.

examples/nodejs/.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 16.16.0

examples/nodejs/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const Pyroscope = require("@pyroscope/nodejs");
2+
3+
Pyroscope.init({
4+
serverAddress: "http://localhost:4040",
5+
appName: "my-node-service",
6+
});
7+
Pyroscope.start();
8+
9+
function doWork(number) {
10+
for (let i = 0; i < number; i++) {}
11+
}
12+
13+
exports.handler = async (event, context) => {
14+
try {
15+
response = {
16+
"statusCode": 200,
17+
"body": JSON.stringify({
18+
message: "hello world",
19+
}),
20+
};
21+
} catch (err) {
22+
console.log(err);
23+
return err;
24+
}
25+
26+
doWork(99999999);
27+
doWork(99999999);
28+
29+
return response;
30+
};

0 commit comments

Comments
 (0)