diff --git a/examples/grpc-census-prop/.eslintrc.js b/examples/grpc-census-prop/.eslintrc.js new file mode 100644 index 0000000000..53452072e2 --- /dev/null +++ b/examples/grpc-census-prop/.eslintrc.js @@ -0,0 +1,26 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const baseConfig = require('../../eslint.config'); + +module.exports = { + ...baseConfig, + env: { + node: true, + }, +}; diff --git a/examples/grpc-census-prop/.npmrc b/examples/grpc-census-prop/.npmrc new file mode 100644 index 0000000000..43c97e719a --- /dev/null +++ b/examples/grpc-census-prop/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/examples/grpc-census-prop/capitalize_client.js b/examples/grpc-census-prop/capitalize_client.js index 8a50846c72..e04947a045 100644 --- a/examples/grpc-census-prop/capitalize_client.js +++ b/examples/grpc-census-prop/capitalize_client.js @@ -1,3 +1,19 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + 'use strict'; const api = require('@opentelemetry/api'); @@ -8,7 +24,10 @@ let tracer; if (censusTracer) { tracer = require('./tracer_census')(); } else { - tracer = require('./tracer')('example-grpc-capitalize-client', binaryPropagator); + tracer = require('./tracer')( + 'example-grpc-capitalize-client', + binaryPropagator + ); } const path = require('path'); @@ -27,7 +46,7 @@ const { Fetch } = grpc.load(PROTO_PATH).rpc; function main() { const client = new Fetch( 'localhost:50051', - grpc.credentials.createInsecure(), + grpc.credentials.createInsecure() ); const data = process.argv[2] || 'opentelemetry'; console.log('> ', data); @@ -41,15 +60,19 @@ function main() { // The process must live for at least the interval past any traces that // must be exported, or some risk being lost if they are recorded after the // last export. - console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); - setTimeout(() => { console.log('Completed.'); }, 5000); + console.log( + 'Sleeping 5 seconds before shutdown to ensure all records are flushed.' + ); + setTimeout(() => { + console.log('Completed.'); + }, 5000); } /** * Makes the gRPC call wrapped in an OpenCensus-style span */ function capitalizeWithCensusTracing(client, data) { - tracer.startRootSpan({ name: 'tutorialsClient.capitalize' }, (rootSpan) => { + tracer.startRootSpan({ name: 'tutorialsClient.capitalize' }, rootSpan => { client.capitalize({ data: Buffer.from(data) }, (err, response) => { if (err) { console.log('could not get grpc response'); diff --git a/examples/grpc-census-prop/capitalize_server.js b/examples/grpc-census-prop/capitalize_server.js index a46ed4921a..f992994dd7 100644 --- a/examples/grpc-census-prop/capitalize_server.js +++ b/examples/grpc-census-prop/capitalize_server.js @@ -1,3 +1,19 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + 'use strict'; /* eslint-disable global-require */ @@ -10,7 +26,10 @@ if (censusTracer) { tracer = require('./tracer_census')(); ({ SpanKind } = require('@opencensus/core')); } else { - tracer = require('./tracer')('example-grpc-capitalize-server', binaryPropagator); + tracer = require('./tracer')( + 'example-grpc-capitalize-server', + binaryPropagator + ); ({ SpanKind } = require('@opentelemetry/api')); } @@ -20,7 +39,10 @@ const protoLoader = require('@grpc/proto-loader'); const PROTO_PATH = path.join(__dirname, 'protos/defs.proto'); const PROTO_OPTIONS = { - keepCase: true, enums: String, defaults: true, oneofs: true, + keepCase: true, + enums: String, + defaults: true, + oneofs: true, }; const definition = protoLoader.loadSync(PROTO_PATH, PROTO_OPTIONS); const rpcProto = grpc.loadPackageDefinition(definition).rpc; diff --git a/examples/grpc-census-prop/package.json b/examples/grpc-census-prop/package.json index def36ae586..cc5d9dc855 100644 --- a/examples/grpc-census-prop/package.json +++ b/examples/grpc-census-prop/package.json @@ -4,6 +4,8 @@ "description": "Example of using propagator-grpc-census-binary", "main": "index.js", "scripts": { + "lint": "eslint . --ext=ts,js,mjs", + "lint:fix": "eslint . --ext=ts,js,mjs --fix", "server:otel:defprop": "cross-env node ./capitalize_server.js", "server:otel:binprop": "cross-env BINARY_PROPAGATOR=true node ./capitalize_server.js", "server:census": "cross-env CENSUS_TRACER=true node ./capitalize_server.js", diff --git a/examples/grpc-census-prop/tracer.js b/examples/grpc-census-prop/tracer.js index 7fcb590fdc..e78cf16000 100644 --- a/examples/grpc-census-prop/tracer.js +++ b/examples/grpc-census-prop/tracer.js @@ -1,10 +1,31 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + 'use strict'; const opentelemetry = require('@opentelemetry/api'); const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); -const { SimpleSpanProcessor, ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base'); +const { + SimpleSpanProcessor, + ConsoleSpanExporter, +} = require('@opentelemetry/sdk-trace-base'); const { HttpTraceContextPropagator } = require('@opentelemetry/core'); -const { GrpcCensusPropagator } = require('@opentelemetry/propagator-grpc-census-binary'); +const { + GrpcCensusPropagator, +} = require('@opentelemetry/propagator-grpc-census-binary'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc'); @@ -33,9 +54,7 @@ module.exports = (serviceName, binaryPropagator) => { } registerInstrumentations({ - instrumentations: [ - new GrpcInstrumentation(), - ], + instrumentations: [new GrpcInstrumentation()], }); return opentelemetry.trace.getTracer(serviceName); diff --git a/examples/grpc-census-prop/tracer_census.js b/examples/grpc-census-prop/tracer_census.js index adf346f82a..d43f5b4859 100644 --- a/examples/grpc-census-prop/tracer_census.js +++ b/examples/grpc-census-prop/tracer_census.js @@ -1,3 +1,19 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + 'use strict'; const tracing = require('@opencensus/nodejs'); @@ -13,7 +29,6 @@ const defaultBufferConfig = { */ module.exports = () => { const { tracer } = tracing.start({ - samplingRate: 1, plugins: { grpc: '@opencensus/instrumentation-grpc',