Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint configuration for getting-started examples #2297

Merged
merged 9 commits into from
Aug 23, 2021
File renamed without changes.
6 changes: 6 additions & 0 deletions getting-started/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable global-require */
/* eslint-disable strict */

module.exports = {
...require('../examples/.eslintrc.json'),
};
24 changes: 12 additions & 12 deletions getting-started/example/app.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
"use strict";
'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
27 changes: 14 additions & 13 deletions getting-started/monitored-example/app.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
"use strict";
'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
45 changes: 21 additions & 24 deletions getting-started/monitored-example/monitoring.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use strict";
'use strict';

const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');
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 +16,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: 12 additions & 12 deletions getting-started/traced-example/app.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
"use strict";
'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: 9 additions & 9 deletions getting-started/traced-example/tracing.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"use strict";
'use strict';

const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
const { SimpleSpanProcessor } = require("@opentelemetry/sdk-trace-base");
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { Resource } = require('@opentelemetry/resources');
const { SemanticResourceAttributes } = 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({
[SemanticResourceAttributes.SERVICE_NAME]: "getting-started",
})
[SemanticResourceAttributes.SERVICE_NAME]: 'getting-started',
}),
});

provider.addSpanProcessor(
Expand All @@ -21,8 +21,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 +35,4 @@ registerInstrumentations({
],
});

console.log("tracing initialized");
console.log('tracing initialized');
16 changes: 16 additions & 0 deletions getting-started/ts-example/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general, why can't you use our eslint.config.js from main folder and extend from it ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what he did above https://github.com/open-telemetry/opentelemetry-js/pull/2297/files#diff-4bb0b44ed2e9b719ea2593f63cf9aebd302f9e7a1f3a109e5c35f6ee59d95d87R4

I think he probably just forgot to apply the suggestion to both eslintrc files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not able to use the project eslint config for typescript files because it requires that getting-started being added to the projects. I get this error when using the project eslint config:

0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: getting-started/ts-example/traced-example/tracing.ts.
The file must be included in at least one of the projects provided

"plugins": ["@typescript-eslint", "node"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"rules": {
"@typescript-eslint/no-var-requires": 0,
"import/prefer-default-export": "off",
"import/extensions": [
"error",
"ignorePackages",
{
obecny marked this conversation as resolved.
Show resolved Hide resolved
"": "never"
}
]
}
}
22 changes: 11 additions & 11 deletions getting-started/ts-example/example/app.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading