Skip to content

Commit 2819660

Browse files
authored
chore(examples): lint examples/hapi using shared top-level eslint config (#2892)
Refs: #2891
1 parent b6d293a commit 2819660

File tree

6 files changed

+102
-25
lines changed

6 files changed

+102
-25
lines changed

examples/hapi/.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/hapi/.npmrc

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

examples/hapi/client.js

Lines changed: 22 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
// eslint-disable-next-line import/order
@@ -20,8 +36,12 @@ function makeRequest() {
2036
span.setStatus({ code: api.SpanStatusCode.ERROR, message: e.message });
2137
}
2238
span.end();
23-
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.');
24-
setTimeout(() => { console.log('Completed.'); }, 5000);
39+
console.log(
40+
'Sleeping 5 seconds before shutdown to ensure all records are flushed.'
41+
);
42+
setTimeout(() => {
43+
console.log('Completed.');
44+
}, 5000);
2545
});
2646
}
2747

examples/hapi/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"zipkin:client": "cross-env EXPORTER=zipkin node ./client.js",
1010
"jaeger:server": "cross-env EXPORTER=jaeger node ./server.js",
1111
"jaeger:client": "cross-env EXPORTER=jaeger node ./client.js",
12-
"lint": "eslint . --ext .js",
13-
"lint:fix": "eslint . --ext .js --fix"
12+
"lint": "eslint . --ext=ts,js,mjs",
13+
"lint:fix": "eslint . --ext=ts,js,mjs --fix"
1414
},
1515
"repository": {
1616
"type": "git",
@@ -44,7 +44,6 @@
4444
},
4545
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib#readme",
4646
"devDependencies": {
47-
"cross-env": "^6.0.0",
48-
"eslint": "^7.4.0"
47+
"cross-env": "^6.0.0"
4948
}
5049
}

examples/hapi/server.js

Lines changed: 32 additions & 15 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 api = require('@opentelemetry/api');
@@ -28,27 +44,26 @@ const BlogPostPlugin = {
2844
method: 'GET',
2945
path: '/post/{id}',
3046
handler: showNewPost,
31-
}]);
47+
},
48+
]);
3249
},
3350
};
3451

3552
async function setUp() {
36-
await server.register(
37-
{ plugin: BlogPostPlugin },
38-
);
53+
await server.register({ plugin: BlogPostPlugin });
3954

40-
server.route(
41-
{
42-
method: 'GET',
43-
path: '/run_test',
44-
handler: runTest,
45-
},
46-
);
55+
server.route({
56+
method: 'GET',
57+
path: '/run_test',
58+
handler: runTest,
59+
});
4760

4861
server.ext('onRequest', async (request, h) => {
4962
console.log('No-op Hapi lifecycle extension method');
5063
const syntheticDelay = 50;
51-
await new Promise((r) => setTimeout(r, syntheticDelay));
64+
await new Promise(r => {
65+
setTimeout(r, syntheticDelay);
66+
});
5267
return h.continue;
5368
});
5469

@@ -59,7 +74,7 @@ async function setUp() {
5974

6075
/**
6176
* Blog Post functions: list, add, or show posts
62-
*/
77+
*/
6378
const posts = ['post 0', 'post 1', 'post 2'];
6479

6580
function addPost(_, h) {
@@ -77,7 +92,9 @@ async function showNewPost(request) {
7792
const post = posts[id];
7893
if (!post) throw new Error('Invalid post id');
7994
const syntheticDelay = 200;
80-
await new Promise((r) => setTimeout(r, syntheticDelay));
95+
await new Promise(r => {
96+
setTimeout(r, syntheticDelay);
97+
});
8198
return post;
8299
}
83100

@@ -91,7 +108,7 @@ function runTest(_, h) {
91108
}
92109

93110
setUp();
94-
process.on('unhandledRejection', (err) => {
111+
process.on('unhandledRejection', err => {
95112
console.log(err);
96113
process.exit(1);
97114
});

examples/hapi/tracer.js

Lines changed: 18 additions & 4 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 api = require('@opentelemetry/api');
@@ -11,7 +27,7 @@ const { registerInstrumentations } = require('@opentelemetry/instrumentation');
1127

1228
const EXPORTER = process.env.EXPORTER || '';
1329

14-
module.exports = (serviceName) => {
30+
module.exports = serviceName => {
1531
let exporter;
1632
if (EXPORTER === 'jaeger') {
1733
exporter = new JaegerExporter({ serviceName });
@@ -20,9 +36,7 @@ module.exports = (serviceName) => {
2036
}
2137

2238
const provider = new NodeTracerProvider({
23-
spanProcessors: [
24-
new SimpleSpanProcessor(exporter),
25-
],
39+
spanProcessors: [new SimpleSpanProcessor(exporter)],
2640
});
2741

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

0 commit comments

Comments
 (0)