Skip to content

Commit e96eb64

Browse files
authored
chore(examples): lint examples/meta-node using shared top-level eslint config (#2905)
Refs: #2891
1 parent 12d3aa6 commit e96eb64

File tree

6 files changed

+104
-21
lines changed

6 files changed

+104
-21
lines changed

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

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

examples/meta-node/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
@@ -19,8 +35,12 @@ function makeRequest() {
1935
span.setStatus({ code: api.SpanStatusCode.ERROR, message: e.message });
2036
}
2137
span.end();
22-
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.');
23-
setTimeout(() => { console.log('Completed.'); }, 5000);
38+
console.log(
39+
'Sleeping 5 seconds before shutdown to ensure all records are flushed.'
40+
);
41+
setTimeout(() => {
42+
console.log('Completed.');
43+
}, 5000);
2444
});
2545
}
2646

examples/meta-node/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"description": "Example of using meta package for default auto instrumentations in node",
66
"main": "index.js",
77
"scripts": {
8-
"lint": "eslint . --ext .js",
9-
"lint:fix": "eslint . --ext .js --fix",
8+
"lint": "eslint . --ext=ts,js,mjs",
9+
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
1010
"zipkin:server": "cross-env EXPORTER=zipkin node ./server.js",
1111
"zipkin:client": "cross-env EXPORTER=zipkin node ./client.js"
1212
},
@@ -31,8 +31,7 @@
3131
},
3232
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib#readme",
3333
"devDependencies": {
34-
"cross-env": "^6.0.0",
35-
"eslint": "^7.4.0"
34+
"cross-env": "^6.0.0"
3635
},
3736
"dependencies": {
3837
"@opentelemetry/api": "^1.0.2",

examples/meta-node/server.js

Lines changed: 27 additions & 9 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
@@ -35,16 +51,18 @@ async function setupRoutes() {
3551
app.use(express.json());
3652

3753
app.get('/run_test', async (req, res) => {
38-
const createdCat = await axios.post(`http://localhost:${PORT}/cats`, {
39-
name: 'Tom',
40-
friends: [
41-
'Jerry',
42-
],
43-
}, {
44-
headers: {
45-
Authorization: 'secret_token',
54+
const createdCat = await axios.post(
55+
`http://localhost:${PORT}/cats`,
56+
{
57+
name: 'Tom',
58+
friends: ['Jerry'],
4659
},
47-
});
60+
{
61+
headers: {
62+
Authorization: 'secret_token',
63+
},
64+
}
65+
);
4866

4967
return res.status(201).send(createdCat.data);
5068
});

examples/meta-node/tracer.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
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 {
4-
diag, trace, DiagConsoleLogger, DiagLogLevel,
20+
diag,
21+
trace,
22+
DiagConsoleLogger,
23+
DiagLogLevel,
524
} = require('@opentelemetry/api');
625
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
7-
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
26+
const {
27+
getNodeAutoInstrumentations,
28+
} = require('@opentelemetry/auto-instrumentations-node');
829
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
930
const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
1031
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
@@ -18,17 +39,15 @@ module.exports = () => {
1839
});
1940

2041
const provider = new NodeTracerProvider({
21-
spanProcessors: [
22-
new SimpleSpanProcessor(exporter),
23-
],
42+
spanProcessors: [new SimpleSpanProcessor(exporter)],
2443
});
2544
provider.register();
2645

2746
registerInstrumentations({
2847
instrumentations: [
2948
getNodeAutoInstrumentations({
3049
'@opentelemetry/instrumentation-http': {
31-
applyCustomAttributesOnSpan: (span) => {
50+
applyCustomAttributesOnSpan: span => {
3251
span.setAttribute('foo2', 'bar2');
3352
},
3453
},

0 commit comments

Comments
 (0)