Skip to content

Commit 747e069

Browse files
authored
chore(examples): lint examples/router using shared top-level eslint config (#2911)
Refs: #2891
1 parent fad2a4a commit 747e069

File tree

6 files changed

+114
-27
lines changed

6 files changed

+114
-27
lines changed

examples/router/.eslintrc.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
const baseConfig = require('../../eslint.config');
20+
21+
module.exports = {
22+
...baseConfig,
23+
env: {
24+
node: true,
25+
},
26+
};

examples/router/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

examples/router/client.js

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
'use strict';
218

319
// required to initialize the service name for the auto-instrumentation
@@ -10,25 +26,34 @@ function makeRequest(path) {
1026
// span corresponds to outgoing requests. Here, we have manually created
1127
// the span, which is created to track work that happens outside of the
1228
// request lifecycle entirely.
13-
http.get({
14-
host: 'localhost',
15-
headers: {
16-
accept: 'text/plain',
29+
http.get(
30+
{
31+
host: 'localhost',
32+
headers: {
33+
accept: 'text/plain',
34+
},
35+
port: 8080,
36+
path,
1737
},
18-
port: 8080,
19-
path,
20-
}, (response) => {
21-
response.on('data', (chunk) => console.log(path, '::', chunk.toString('utf8')));
22-
response.on('end', () => {
23-
console.log(path, 'status', response.statusCode);
24-
});
25-
});
38+
response => {
39+
response.on('data', chunk =>
40+
console.log(path, '::', chunk.toString('utf8'))
41+
);
42+
response.on('end', () => {
43+
console.log(path, 'status', response.statusCode);
44+
});
45+
}
46+
);
2647

2748
// The process must live for at least the interval past any traces that
2849
// must be exported, or some risk being lost if they are recorded after the
2950
// last export.
30-
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.');
31-
setTimeout(() => { console.log('Completed.'); }, 5000);
51+
console.log(
52+
'Sleeping 5 seconds before shutdown to ensure all records are flushed.'
53+
);
54+
setTimeout(() => {
55+
console.log('Completed.');
56+
}, 5000);
3257
}
3358

3459
makeRequest('/hello/world');

examples/router/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"description": "Example of router integration with OpenTelemetry",
66
"main": "index.js",
77
"scripts": {
8+
"lint": "eslint . --ext=ts,js,mjs",
9+
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
810
"zipkin:server": "cross-env EXPORTER=zipkin node ./server.js",
911
"zipkin:client": "cross-env EXPORTER=zipkin node ./client.js",
1012
"jaeger:server": "cross-env EXPORTER=jaeger node ./server.js",

examples/router/server.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
'use strict';
218

319
require('./tracer')('example-router-server');
@@ -16,7 +32,8 @@ const router = Router();
1632
router.use(setDefaultName);
1733

1834
router.param('name', (req, res, next, name) => {
19-
req.params.name = typeof name === 'string' ? name.toUpperCase() : req.defaultName;
35+
req.params.name =
36+
typeof name === 'string' ? name.toUpperCase() : req.defaultName;
2037
next();
2138
});
2239

@@ -33,7 +50,7 @@ router.get('/err', function erroringRoute(req, res, next) {
3350

3451
// eslint-disable-next-line prefer-arrow-callback, func-names
3552
const server = http.createServer(function (req, res) {
36-
router(req, res, (error) => {
53+
router(req, res, error => {
3754
if (error) {
3855
res.statusCode = 500;
3956
} else {

examples/router/tracer.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
'use strict';
218

319
const opentelemetry = require('@opentelemetry/api');
@@ -7,14 +23,19 @@ diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.VERBOSE);
723

824
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
925
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
10-
const { SimpleSpanProcessor, ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base');
26+
const {
27+
SimpleSpanProcessor,
28+
ConsoleSpanExporter,
29+
} = require('@opentelemetry/sdk-trace-base');
1130
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
1231
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
1332

1433
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
15-
const { RouterInstrumentation } = require('@opentelemetry/instrumentation-router');
34+
const {
35+
RouterInstrumentation,
36+
} = require('@opentelemetry/instrumentation-router');
1637

17-
const Exporter = ((exporterParam) => {
38+
const Exporter = (exporterParam => {
1839
if (typeof exporterParam === 'string') {
1940
const exporterString = exporterParam.toLowerCase();
2041
if (exporterString.startsWith('z')) {
@@ -27,23 +48,18 @@ const Exporter = ((exporterParam) => {
2748
return ConsoleSpanExporter;
2849
})(process.env.EXPORTER);
2950

30-
module.exports = (serviceName) => {
51+
module.exports = serviceName => {
3152
const exporter = new Exporter({
3253
serviceName,
3354
});
3455

3556
const provider = new NodeTracerProvider({
36-
spanProcessors: [
37-
new SimpleSpanProcessor(exporter),
38-
],
57+
spanProcessors: [new SimpleSpanProcessor(exporter)],
3958
});
4059

4160
registerInstrumentations({
4261
tracerProvider: provider,
43-
instrumentations: [
44-
HttpInstrumentation,
45-
RouterInstrumentation,
46-
],
62+
instrumentations: [HttpInstrumentation, RouterInstrumentation],
4763
});
4864

4965
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings

0 commit comments

Comments
 (0)