diff --git a/getting-started/example/app.js b/getting-started/example/app.js index 86c1a6e802..aa7a396362 100644 --- a/getting-started/example/app.js +++ b/getting-started/example/app.js @@ -1,40 +1,38 @@ -"use strict"; +const PORT = process.env.PORT || '8080'; -const PORT = process.env.PORT || "8080"; - -const express = require("express"); -const axios = require("axios"); +const express = require('express'); +const axios = require('axios'); const app = express(); -app.get("/", (req, res) => { +app.get('/', (req, res) => { axios .get(`http://localhost:${PORT}/middle-tier`) .then(() => axios.get(`http://localhost:${PORT}/middle-tier`)) - .then(result => { + .then((result) => { res.send(result.data); }) - .catch(err => { + .catch((err) => { console.error(err); res.status(500).send(); }); }); -app.get("/middle-tier", (req, res) => { +app.get('/middle-tier', (req, res) => { axios .get(`http://localhost:${PORT}/backend`) .then(() => axios.get(`http://localhost:${PORT}/backend`)) - .then(result => { + .then((result) => { res.send(result.data); }) - .catch(err => { + .catch((err) => { console.error(err); res.status(500).send(); }); }); -app.get("/backend", (req, res) => { - res.send("Hello from the backend"); +app.get('/backend', (req, res) => { + res.send('Hello from the backend'); }); app.listen(parseInt(PORT, 10), () => { diff --git a/getting-started/monitored-example/app.js b/getting-started/monitored-example/app.js index 2144423d6a..6189d314e8 100644 --- a/getting-started/monitored-example/app.js +++ b/getting-started/monitored-example/app.js @@ -1,42 +1,41 @@ -"use strict"; +const PORT = process.env.PORT || '8080'; -const PORT = process.env.PORT || "8080"; +const express = require('express'); +const axios = require('axios'); -const express = require("express"); -const axios = require("axios"); +const { countAllRequests } = require('./monitoring'); -const { countAllRequests } = require("./monitoring"); const app = express(); app.use(countAllRequests()); -app.get("/", (req, res) => { +app.get('/', (req, res) => { axios .get(`http://localhost:${PORT}/middle-tier`) .then(() => axios.get(`http://localhost:${PORT}/middle-tier`)) - .then(result => { + .then((result) => { res.send(result.data); }) - .catch(err => { + .catch((err) => { console.error(err); res.status(500).send(); }); }); -app.get("/middle-tier", (req, res) => { +app.get('/middle-tier', (req, res) => { axios .get(`http://localhost:${PORT}/backend`) .then(() => axios.get(`http://localhost:${PORT}/backend`)) - .then(result => { + .then((result) => { res.send(result.data); }) - .catch(err => { + .catch((err) => { console.error(err); res.status(500).send(); }); }); -app.get("/backend", (req, res) => { - res.send("Hello from the backend"); +app.get('/backend', (req, res) => { + res.send('Hello from the backend'); }); app.listen(parseInt(PORT, 10), () => { diff --git a/getting-started/monitored-example/monitoring.js b/getting-started/monitored-example/monitoring.js index 473dd79a1f..1e2399f287 100644 --- a/getting-started/monitored-example/monitoring.js +++ b/getting-started/monitored-example/monitoring.js @@ -1,11 +1,9 @@ -"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 prometheusPort = PrometheusExporter.DEFAULT_OPTIONS.port; +const prometheusEndpoint = PrometheusExporter.DEFAULT_OPTIONS.endpoint; + const exporter = new PrometheusExporter( { startServer: true, @@ -16,28 +14,25 @@ const exporter = new PrometheusExporter( ); }, ); - + const meter = new MeterProvider({ exporter, interval: 1000, }).getMeter('your-meter-name'); - -const requestCount = meter.createCounter("requests", { - description: "Count all incoming requests" + +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(); - }; -}; +module.exports.countAllRequests = () => (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(); +}; diff --git a/getting-started/traced-example/app.js b/getting-started/traced-example/app.js index 86c1a6e802..aa7a396362 100644 --- a/getting-started/traced-example/app.js +++ b/getting-started/traced-example/app.js @@ -1,40 +1,38 @@ -"use strict"; +const PORT = process.env.PORT || '8080'; -const PORT = process.env.PORT || "8080"; - -const express = require("express"); -const axios = require("axios"); +const express = require('express'); +const axios = require('axios'); const app = express(); -app.get("/", (req, res) => { +app.get('/', (req, res) => { axios .get(`http://localhost:${PORT}/middle-tier`) .then(() => axios.get(`http://localhost:${PORT}/middle-tier`)) - .then(result => { + .then((result) => { res.send(result.data); }) - .catch(err => { + .catch((err) => { console.error(err); res.status(500).send(); }); }); -app.get("/middle-tier", (req, res) => { +app.get('/middle-tier', (req, res) => { axios .get(`http://localhost:${PORT}/backend`) .then(() => axios.get(`http://localhost:${PORT}/backend`)) - .then(result => { + .then((result) => { res.send(result.data); }) - .catch(err => { + .catch((err) => { console.error(err); res.status(500).send(); }); }); -app.get("/backend", (req, res) => { - res.send("Hello from the backend"); +app.get('/backend', (req, res) => { + res.send('Hello from the backend'); }); app.listen(parseInt(PORT, 10), () => { diff --git a/getting-started/traced-example/tracing.js b/getting-started/traced-example/tracing.js index e1ac8b3264..1f80c37349 100644 --- a/getting-started/traced-example/tracing.js +++ b/getting-started/traced-example/tracing.js @@ -1,18 +1,16 @@ -"use strict"; - -const { NodeTracerProvider } = require("@opentelemetry/node"); -const { SimpleSpanProcessor } = require("@opentelemetry/tracing"); +const { NodeTracerProvider } = require('@opentelemetry/node'); +const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { Resource } = require('@opentelemetry/resources'); const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); -const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin"); +const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express'); const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http'); const provider = new NodeTracerProvider({ resource: new Resource({ - [ResourceAttributes.SERVICE_NAME]: "getting-started", - }) + [ResourceAttributes.SERVICE_NAME]: 'getting-started', + }), }); provider.addSpanProcessor( @@ -21,8 +19,8 @@ provider.addSpanProcessor( // If you are running your tracing backend on another host, // you can point to it using the `url` parameter of the // exporter config. - }) - ) + }), + ), ); provider.register(); @@ -35,4 +33,4 @@ registerInstrumentations({ ], }); -console.log("tracing initialized"); +console.log('tracing initialized'); diff --git a/getting-started/ts-example/example/app.ts b/getting-started/ts-example/example/app.ts index e4267e1421..a252668ebe 100644 --- a/getting-started/ts-example/example/app.ts +++ b/getting-started/ts-example/example/app.ts @@ -1,38 +1,38 @@ -import * as express from "express"; -import axios from "axios"; +import * as express from 'express'; +import axios from 'axios'; -const PORT: string = process.env.PORT || "8080"; +const PORT: string = process.env.PORT || '8080'; const app = express(); -app.get("/", (req, res) => { +app.get('/', (req, res) => { axios .get(`http://localhost:${PORT}/middle-tier`) .then(() => axios.get(`http://localhost:${PORT}/middle-tier`)) - .then(response => { + .then((response) => { res.send(response.data); }) - .catch(err => { + .catch((err) => { console.error(err); res.status(500).send(); }); }); -app.get("/middle-tier", (req, res) => { +app.get('/middle-tier', (req, res) => { axios .get(`http://localhost:${PORT}/backend`) .then(() => axios.get(`http://localhost:${PORT}/backend`)) - .then(response => { + .then((response) => { res.send(response.data); }) - .catch(err => { + .catch((err) => { console.error(err); res.status(500).send(); }); }); -app.get("/backend", (req, res) => { - res.send("Hello from the backend"); +app.get('/backend', (req, res) => { + res.send('Hello from the backend'); }); app.listen(parseInt(PORT, 10), () => { diff --git a/getting-started/ts-example/monitored-example/app.ts b/getting-started/ts-example/monitored-example/app.ts index 047c263836..9307eba1ac 100644 --- a/getting-started/ts-example/monitored-example/app.ts +++ b/getting-started/ts-example/monitored-example/app.ts @@ -1,40 +1,40 @@ -import * as express from "express"; -import axios from "axios"; - -const PORT: string = process.env.PORT || "8080"; +import * as express from 'express'; +import axios from 'axios'; import { countAllRequests } from './monitoring'; + +const PORT: string = process.env.PORT || '8080'; const app = express(); app.use(countAllRequests()); -app.get("/", (req, res) => { +app.get('/', (req, res) => { axios .get(`http://localhost:${PORT}/middle-tier`) .then(() => axios.get(`http://localhost:${PORT}/middle-tier`)) - .then(result => { + .then((result) => { res.send(result.data); }) - .catch(err => { + .catch((err) => { console.error(err); res.status(500).send(); }); }); -app.get("/middle-tier", (req, res) => { +app.get('/middle-tier', (req, res) => { axios .get(`http://localhost:${PORT}/backend`) .then(() => axios.get(`http://localhost:${PORT}/backend`)) - .then(result => { + .then((result) => { res.send(result.data); }) - .catch(err => { + .catch((err) => { console.error(err); res.status(500).send(); }); }); -app.get("/backend", (req, res) => { - res.send("Hello from the backend"); +app.get('/backend', (req, res) => { + res.send('Hello from the backend'); }); app.listen(parseInt(PORT, 10), () => { diff --git a/getting-started/ts-example/monitored-example/monitoring.ts b/getting-started/ts-example/monitored-example/monitoring.ts index dd9432d5b0..807c2645ac 100644 --- a/getting-started/ts-example/monitored-example/monitoring.ts +++ b/getting-started/ts-example/monitored-example/monitoring.ts @@ -27,15 +27,13 @@ const requestCount = meter.createCounter('requests', { const handles = new Map(); -export const countAllRequests = () => { - return (req: Request, _res: Response, next: NextFunction) => { - if (!handles.has(req.path)) { - const labels = { route: req.path }; - const handle = requestCount.bind(labels); - handles.set(req.path, handle); - } +export const countAllRequests = () => (req: Request, _res: Response, next: NextFunction): void => { + if (!handles.has(req.path)) { + const labels = { route: req.path }; + const handle = requestCount.bind(labels); + handles.set(req.path, handle); + } - handles.get(req.path).add(1); - next(); - }; + handles.get(req.path).add(1); + next(); }; diff --git a/getting-started/ts-example/traced-example/app.ts b/getting-started/ts-example/traced-example/app.ts index 41b6a43394..58fb8ab589 100644 --- a/getting-started/ts-example/traced-example/app.ts +++ b/getting-started/ts-example/traced-example/app.ts @@ -1,38 +1,38 @@ -import * as express from "express"; -import axios from "axios"; +import * as express from 'express'; +import axios from 'axios'; -const PORT: string = process.env.PORT || "8080"; +const PORT: string = process.env.PORT || '8080'; const app = express(); -app.get("/", (req, res) => { +app.get('/', (req, res) => { axios .get(`http://localhost:${PORT}/middle-tier`) .then(() => axios.get(`http://localhost:${PORT}/middle-tier`)) - .then(result => { + .then((result) => { res.send(result.data); }) - .catch(err => { + .catch((err) => { console.error(err); res.status(500).send(); }); }); -app.get("/middle-tier", (req, res) => { +app.get('/middle-tier', (req, res) => { axios .get(`http://localhost:${PORT}/backend`) .then(() => axios.get(`http://localhost:${PORT}/backend`)) - .then(result => { + .then((result) => { res.send(result.data); }) - .catch(err => { + .catch((err) => { console.error(err); res.status(500).send(); }); }); -app.get("/backend", (req, res) => { - res.send("Hello from the backend"); +app.get('/backend', (req, res) => { + res.send('Hello from the backend'); }); app.listen(parseInt(PORT, 10), () => { diff --git a/getting-started/ts-example/traced-example/tracing.ts b/getting-started/ts-example/traced-example/tracing.ts index 1d0f400fe4..6d37532870 100644 --- a/getting-started/ts-example/traced-example/tracing.ts +++ b/getting-started/ts-example/traced-example/tracing.ts @@ -1,9 +1,10 @@ import { NodeTracerProvider } from '@opentelemetry/node'; -const { Resource } = require('@opentelemetry/resources'); -const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); import { SimpleSpanProcessor } from '@opentelemetry/tracing'; import { ZipkinExporter } from '@opentelemetry/exporter-zipkin'; + +const { Resource } = require('@opentelemetry/resources'); +const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); // For Jaeger, use the following line instead: // import { JaegerExporter } from '@opentelemetry/exporter-jaeger'; @@ -36,5 +37,4 @@ registerInstrumentations({ ], }); - console.log('tracing initialized');