-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: fix and update getting-started (#1553)
* docs: fix and update getting-started * docs: fix and update app.ts * Fix conflict in ts-example package.json
- Loading branch information
Showing
16 changed files
with
194 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,43 @@ | ||
"use strict"; | ||
|
||
const { MeterProvider } = require('@opentelemetry/metrics'); | ||
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus'); | ||
|
||
|
||
const prometheusPort = PrometheusExporter.DEFAULT_OPTIONS.port | ||
const prometheusEndpoint = PrometheusExporter.DEFAULT_OPTIONS.endpoint | ||
|
||
const exporter = new PrometheusExporter( | ||
{ | ||
startServer: true, | ||
}, | ||
() => { | ||
console.log( | ||
`prometheus scrape endpoint: http://localhost:${PrometheusExporter.DEFAULT_OPTIONS.port}${PrometheusExporter.DEFAULT_OPTIONS.endpoint}`, | ||
`prometheus scrape endpoint: http://localhost:${prometheusPort}${prometheusEndpoint}`, | ||
); | ||
}, | ||
); | ||
|
||
const meter = new MeterProvider({ | ||
exporter, | ||
interval: 1000, | ||
}).getMeter('example-monitored'); | ||
|
||
}).getMeter('your-meter-name'); | ||
const requestCount = meter.createCounter("requests", { | ||
description: "Count all incoming requests" | ||
}); | ||
|
||
const boundInstruments = new Map(); | ||
|
||
module.exports.countAllRequests = () => { | ||
return (req, res, next) => { | ||
if (!boundInstruments.has(req.path)) { | ||
const labels = { route: req.path }; | ||
const boundCounter = requestCount.bind(labels); | ||
boundInstruments.set(req.path, boundCounter); | ||
} | ||
|
||
boundInstruments.get(req.path).add(1); | ||
next(); | ||
}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as express from "express"; | ||
import axios from "axios"; | ||
|
||
const PORT: string = process.env.PORT || "8080"; | ||
|
||
const app = express(); | ||
|
||
app.get("/", (req, res) => { | ||
axios | ||
.get(`http://localhost:${PORT}/middle-tier`) | ||
.then(() => axios.get(`http://localhost:${PORT}/middle-tier`)) | ||
.then(response => { | ||
res.send(response.data); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
res.status(500).send(); | ||
}); | ||
}); | ||
|
||
app.get("/middle-tier", (req, res) => { | ||
axios | ||
.get(`http://localhost:${PORT}/backend`) | ||
.then(() => axios.get(`http://localhost:${PORT}/backend`)) | ||
.then(response => { | ||
res.send(response.data); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
res.status(500).send(); | ||
}); | ||
}); | ||
|
||
app.get("/backend", (req, res) => { | ||
res.send("Hello from the backend"); | ||
}); | ||
|
||
app.listen(parseInt(PORT, 10), () => { | ||
console.log(`Listening for requests on http://localhost:${PORT}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@opentelemetry/getting-started-ts-example", | ||
"version": "0.11.0", | ||
"description": "This repository provides everything required to follow the OpenTelemetry Getting Started Guide", | ||
"main": "app.ts", | ||
"scripts": { | ||
"start": "ts-node app.ts" | ||
}, | ||
"author": "OpenTelemetry Authors", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@types/express": "4.17.7", | ||
"@types/node": "14.0.27", | ||
"ts-node": "8.10.2" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.19.1", | ||
"express": "^4.17.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 10 additions & 8 deletions
18
getting-started/ts-example/monitoring.ts → ...s-example/monitored-example/monitoring.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "@opentelemetry/getting-started-monitored-ts-example", | ||
"version": "0.11.0", | ||
"description": "This repository provides everything required to follow the OpenTelemetry Getting Started Guide", | ||
"main": "app.ts", | ||
"scripts": { | ||
"start": "ts-node app.ts" | ||
}, | ||
"author": "OpenTelemetry Authors", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@types/express": "4.17.7", | ||
"@types/node": "14.0.27", | ||
"ts-node": "8.10.2" | ||
}, | ||
"dependencies": { | ||
"@opentelemetry/exporter-prometheus": "^0.11.0", | ||
"@opentelemetry/metrics": "^0.11.0", | ||
"axios": "^0.19.1", | ||
"express": "^4.17.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as express from "express"; | ||
import axios from "axios"; | ||
|
||
const PORT: string = process.env.PORT || "8080"; | ||
|
||
const app = express(); | ||
|
||
app.get("/", (req, res) => { | ||
axios | ||
.get(`http://localhost:${PORT}/middle-tier`) | ||
.then(() => axios.get(`http://localhost:${PORT}/middle-tier`)) | ||
.then(result => { | ||
res.send(result.data); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
res.status(500).send(); | ||
}); | ||
}); | ||
|
||
app.get("/middle-tier", (req, res) => { | ||
axios | ||
.get(`http://localhost:${PORT}/backend`) | ||
.then(() => axios.get(`http://localhost:${PORT}/backend`)) | ||
.then(result => { | ||
res.send(result.data); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
res.status(500).send(); | ||
}); | ||
}); | ||
|
||
app.get("/backend", (req, res) => { | ||
res.send("Hello from the backend"); | ||
}); | ||
|
||
app.listen(parseInt(PORT, 10), () => { | ||
console.log(`Listening for requests on http://localhost:${PORT}`); | ||
}); |
Oops, something went wrong.