Skip to content

Commit cf8da86

Browse files
authored
chore(examples): lint examples/grpc-census-prop using shared top-level eslint config (#2900)
Refs: #2891
1 parent 12cdc69 commit cf8da86

File tree

7 files changed

+121
-13
lines changed

7 files changed

+121
-13
lines changed
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/grpc-census-prop/.npmrc

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

examples/grpc-census-prop/capitalize_client.js

Lines changed: 28 additions & 5 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');
@@ -8,7 +24,10 @@ let tracer;
824
if (censusTracer) {
925
tracer = require('./tracer_census')();
1026
} else {
11-
tracer = require('./tracer')('example-grpc-capitalize-client', binaryPropagator);
27+
tracer = require('./tracer')(
28+
'example-grpc-capitalize-client',
29+
binaryPropagator
30+
);
1231
}
1332

1433
const path = require('path');
@@ -27,7 +46,7 @@ const { Fetch } = grpc.load(PROTO_PATH).rpc;
2746
function main() {
2847
const client = new Fetch(
2948
'localhost:50051',
30-
grpc.credentials.createInsecure(),
49+
grpc.credentials.createInsecure()
3150
);
3251
const data = process.argv[2] || 'opentelemetry';
3352
console.log('> ', data);
@@ -41,15 +60,19 @@ function main() {
4160
// The process must live for at least the interval past any traces that
4261
// must be exported, or some risk being lost if they are recorded after the
4362
// last export.
44-
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.');
45-
setTimeout(() => { console.log('Completed.'); }, 5000);
63+
console.log(
64+
'Sleeping 5 seconds before shutdown to ensure all records are flushed.'
65+
);
66+
setTimeout(() => {
67+
console.log('Completed.');
68+
}, 5000);
4669
}
4770

4871
/**
4972
* Makes the gRPC call wrapped in an OpenCensus-style span
5073
*/
5174
function capitalizeWithCensusTracing(client, data) {
52-
tracer.startRootSpan({ name: 'tutorialsClient.capitalize' }, (rootSpan) => {
75+
tracer.startRootSpan({ name: 'tutorialsClient.capitalize' }, rootSpan => {
5376
client.capitalize({ data: Buffer.from(data) }, (err, response) => {
5477
if (err) {
5578
console.log('could not get grpc response');

examples/grpc-census-prop/capitalize_server.js

Lines changed: 24 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 global-require */
@@ -10,7 +26,10 @@ if (censusTracer) {
1026
tracer = require('./tracer_census')();
1127
({ SpanKind } = require('@opencensus/core'));
1228
} else {
13-
tracer = require('./tracer')('example-grpc-capitalize-server', binaryPropagator);
29+
tracer = require('./tracer')(
30+
'example-grpc-capitalize-server',
31+
binaryPropagator
32+
);
1433
({ SpanKind } = require('@opentelemetry/api'));
1534
}
1635

@@ -20,7 +39,10 @@ const protoLoader = require('@grpc/proto-loader');
2039

2140
const PROTO_PATH = path.join(__dirname, 'protos/defs.proto');
2241
const PROTO_OPTIONS = {
23-
keepCase: true, enums: String, defaults: true, oneofs: true,
42+
keepCase: true,
43+
enums: String,
44+
defaults: true,
45+
oneofs: true,
2446
};
2547
const definition = protoLoader.loadSync(PROTO_PATH, PROTO_OPTIONS);
2648
const rpcProto = grpc.loadPackageDefinition(definition).rpc;

examples/grpc-census-prop/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"description": "Example of using propagator-grpc-census-binary",
55
"main": "index.js",
66
"scripts": {
7+
"lint": "eslint . --ext=ts,js,mjs",
8+
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
79
"server:otel:defprop": "cross-env node ./capitalize_server.js",
810
"server:otel:binprop": "cross-env BINARY_PROPAGATOR=true node ./capitalize_server.js",
911
"server:census": "cross-env CENSUS_TRACER=true node ./capitalize_server.js",

examples/grpc-census-prop/tracer.js

Lines changed: 24 additions & 5 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 opentelemetry = require('@opentelemetry/api');
420
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
5-
const { SimpleSpanProcessor, ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base');
21+
const {
22+
SimpleSpanProcessor,
23+
ConsoleSpanExporter,
24+
} = require('@opentelemetry/sdk-trace-base');
625
const { HttpTraceContextPropagator } = require('@opentelemetry/core');
7-
const { GrpcCensusPropagator } = require('@opentelemetry/propagator-grpc-census-binary');
26+
const {
27+
GrpcCensusPropagator,
28+
} = require('@opentelemetry/propagator-grpc-census-binary');
829
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
930
const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc');
1031

@@ -33,9 +54,7 @@ module.exports = (serviceName, binaryPropagator) => {
3354
}
3455

3556
registerInstrumentations({
36-
instrumentations: [
37-
new GrpcInstrumentation(),
38-
],
57+
instrumentations: [new GrpcInstrumentation()],
3958
});
4059

4160
return opentelemetry.trace.getTracer(serviceName);

examples/grpc-census-prop/tracer_census.js

Lines changed: 16 additions & 1 deletion
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 tracing = require('@opencensus/nodejs');
@@ -13,7 +29,6 @@ const defaultBufferConfig = {
1329
*/
1430
module.exports = () => {
1531
const { tracer } = tracing.start({
16-
1732
samplingRate: 1,
1833
plugins: {
1934
grpc: '@opencensus/instrumentation-grpc',

0 commit comments

Comments
 (0)