Skip to content

Commit

Permalink
chore: apply lint on getting-started
Browse files Browse the repository at this point in the history
  • Loading branch information
alisabzevari committed Jun 26, 2021
1 parent 0d15406 commit fa512f0
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 120 deletions.
24 changes: 11 additions & 13 deletions 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), () => {
Expand Down
25 changes: 12 additions & 13 deletions 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), () => {
Expand Down
43 changes: 19 additions & 24 deletions 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,
Expand All @@ -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();
};
24 changes: 11 additions & 13 deletions 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), () => {
Expand Down
18 changes: 8 additions & 10 deletions 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(
Expand All @@ -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();
Expand All @@ -35,4 +33,4 @@ registerInstrumentations({
],
});

console.log("tracing initialized");
console.log('tracing initialized');
22 changes: 11 additions & 11 deletions 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), () => {
Expand Down
24 changes: 12 additions & 12 deletions 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), () => {
Expand Down
18 changes: 8 additions & 10 deletions getting-started/ts-example/monitored-example/monitoring.ts
Expand Up @@ -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();
};

0 comments on commit fa512f0

Please sign in to comment.