Skip to content

Commit a767e2c

Browse files
docs: adds node inline source maps example (#3318)
* docs: adds node inline source maps example * Remove redundant statement --------- Co-authored-by: Christian Simon <[email protected]>
1 parent 1a3a8a1 commit a767e2c

File tree

6 files changed

+1010
-0
lines changed

6 files changed

+1010
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM node:latest
2+
3+
WORKDIR /app
4+
5+
COPY package.json yarn.lock .
6+
COPY tsconfig.json .
7+
RUN yarn
8+
COPY *.ts .
9+
RUN yarn build
10+
ENV DEBUG=pyroscope
11+
CMD ["yarn", "run", "run"]
12+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
version: '3.9'
3+
services:
4+
pyroscope:
5+
image: 'grafana/pyroscope:latest'
6+
ports:
7+
- '4040:4040'
8+
9+
us-east:
10+
ports:
11+
- 5000
12+
environment:
13+
- REGION=us-east
14+
build:
15+
context: .
16+
17+
eu-north:
18+
ports:
19+
- 5000
20+
environment:
21+
- REGION=eu-north
22+
build:
23+
context: .
24+
25+
ap-south:
26+
ports:
27+
- 5000
28+
environment:
29+
- REGION=ap-south
30+
build:
31+
context: .
32+
33+
load-generator:
34+
build:
35+
context: ../
36+
dockerfile: Dockerfile.load-generator
37+
depends_on:
38+
- us-east
39+
- eu-north
40+
- ap-south
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* eslint-disable */
2+
import express from 'express';
3+
import morgan from 'morgan';
4+
5+
const Pyroscope = require('@pyroscope/nodejs');
6+
const SourceMapper = Pyroscope.default.SourceMapper;
7+
8+
const port = process.env['PORT'] || 5000;
9+
10+
const region = process.env['REGION'] || 'default';
11+
12+
const app = express();
13+
app.use(morgan('dev'));
14+
15+
app.get('/', (req, res) => {
16+
res.send('Available routes are: /bike, /car, /scooter');
17+
});
18+
19+
const genericSearchHandler = (p: number) => (req: any, res: any) => {
20+
const time = +new Date() + p * 1000;
21+
let i = 0;
22+
while (+new Date() < time) {
23+
i += Math.random();
24+
}
25+
res.send('Vehicle found');
26+
};
27+
28+
app.get('/bike', function bikeSearchHandler(req, res) {
29+
return genericSearchHandler(0.2)(req, res);
30+
});
31+
app.get('/car', function carSearchHandler(req, res) {
32+
return genericSearchHandler(1)(req, res);
33+
});
34+
app.get('/scooter', function scooterSearchHandler(req, res) {
35+
return genericSearchHandler(0.5)(req, res);
36+
});
37+
38+
SourceMapper.create(["."])
39+
.then((sourceMapper) => {
40+
Pyroscope.init({
41+
appName: 'nodejs',
42+
serverAddress: 'http://pyroscope:4040',
43+
sourceMapper: sourceMapper,
44+
tags: { region },
45+
});
46+
Pyroscope.start();
47+
})
48+
.catch((e) => {
49+
console.error(e)
50+
})
51+
52+
app.listen(port, () => {
53+
console.log(
54+
`Server has started on port ${port}, use http://localhost:${port}`
55+
);
56+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "rideshare-app-express",
3+
"version": "1.0.0",
4+
"description": "",
5+
"scripts": {
6+
"build": "tsc",
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"run": "node build/index.js"
9+
},
10+
"author": "",
11+
"license": "Apache-2.0",
12+
"dependencies": {
13+
"@pyroscope/nodejs": "0.3.10",
14+
"axios": "^0.26.1",
15+
"express": "^4.17.3",
16+
"morgan": "^1.10.0",
17+
"typescript": "^4.6.2"
18+
},
19+
"devDependencies": {
20+
"@types/express": "^4.17.13",
21+
"@types/morgan": "^1.9.3"
22+
},
23+
"resolutions": {
24+
"protobufjs": "^7.2.5",
25+
"tar": "^6.2.1",
26+
"@types/mime": "3.0.4"
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6",
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"rootDir": ".",
7+
"outDir": "build",
8+
"allowSyntheticDefaultImports": true,
9+
"allowJs": true,
10+
"checkJs": true,
11+
"importHelpers": false,
12+
"alwaysStrict": true,
13+
"inlineSourceMap": true,
14+
"esModuleInterop": true,
15+
"forceConsistentCasingInFileNames": false,
16+
"noFallthroughCasesInSwitch": true,
17+
"noImplicitReturns": false,
18+
"noUnusedLocals": false,
19+
"noUnusedParameters": false,
20+
"noImplicitAny": false,
21+
"noImplicitThis": false,
22+
"strictNullChecks": false,
23+
"skipLibCheck": true
24+
},
25+
"include": ["**/*.ts"]
26+
}

0 commit comments

Comments
 (0)