From f45d99f268070ee1cdf51f1e166abb64c96db92d Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Thu, 21 Dec 2023 12:08:12 +0100 Subject: [PATCH] chore: remove grpc-dynamic-codegen example (#1871) --- examples/grpc_dynamic_codegen/README.md | 61 ------------------- .../grpc_dynamic_codegen/capitalize_client.js | 46 -------------- .../grpc_dynamic_codegen/capitalize_server.js | 47 -------------- examples/grpc_dynamic_codegen/package.json | 43 ------------- .../grpc_dynamic_codegen/protos/defs.proto | 19 ------ examples/grpc_dynamic_codegen/tracer.js | 41 ------------- 6 files changed, 257 deletions(-) delete mode 100644 examples/grpc_dynamic_codegen/README.md delete mode 100644 examples/grpc_dynamic_codegen/capitalize_client.js delete mode 100644 examples/grpc_dynamic_codegen/capitalize_server.js delete mode 100644 examples/grpc_dynamic_codegen/package.json delete mode 100644 examples/grpc_dynamic_codegen/protos/defs.proto delete mode 100644 examples/grpc_dynamic_codegen/tracer.js diff --git a/examples/grpc_dynamic_codegen/README.md b/examples/grpc_dynamic_codegen/README.md deleted file mode 100644 index 55dd6717c2..0000000000 --- a/examples/grpc_dynamic_codegen/README.md +++ /dev/null @@ -1,61 +0,0 @@ -# Overview - -Our service takes in a payload containing bytes and capitalizes them. - -Using OpenTelemetry gRPC Instrumentation, we can collect traces of our system and export them to the backend of our choice (we can use Zipkin or Jaeger for this example), to give observability to our distributed systems. - -> This is the dynamic code generation variant of the gRPC examples. Code in these examples is generated at runtime using Protobuf.js. - -## Installation - -```sh -# from this directory -npm install -``` - -Setup [Zipkin Tracing](https://zipkin.io/pages/quickstart.html) -or -Setup [Jaeger Tracing](https://www.jaegertracing.io/docs/latest/getting-started/#all-in-one) - -## Run the Application - -### Zipkin - -- Run the server - - ```sh - # from this directory - npm run zipkin:server - ``` - -- Run the client - - ```sh - # from this directory - npm run zipkin:client - ``` - -### Jaeger - -- Run the server - - ```sh - # from this directory - npm run jaeger:server - ``` - -- Run the client - - ```sh - # from this directory - npm run jaeger:client - ``` - -## Useful links - -- For more information on OpenTelemetry, visit: -- For more information on OpenTelemetry for Node.js, visit: - -## LICENSE - -Apache License 2.0 diff --git a/examples/grpc_dynamic_codegen/capitalize_client.js b/examples/grpc_dynamic_codegen/capitalize_client.js deleted file mode 100644 index 6c0f29e9bc..0000000000 --- a/examples/grpc_dynamic_codegen/capitalize_client.js +++ /dev/null @@ -1,46 +0,0 @@ -'use strict'; - -const api = require('@opentelemetry/api'); -// eslint-disable-next-line import/order -const tracer = require('./tracer')('example-grpc-capitalize-client'); -const path = require('path'); -const grpc = require('grpc'); -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, -}; -const definition = protoLoader.loadSync(PROTO_PATH, PROTO_OPTIONS); -const rpcProto = grpc.loadPackageDefinition(definition).rpc; - -function main() { - const client = new rpcProto.Fetch( - 'localhost:50051', - grpc.credentials.createInsecure(), - ); - const data = process.argv[2] || 'opentelemetry'; - console.log('> ', data); - - const span = tracer.startSpan('tutorialsClient.capitalize'); - api.context.with(api.trace.setSpan(api.ROOT_CONTEXT, span), () => { - client.capitalize({ data: Buffer.from(data) }, (err, response) => { - if (err) { - console.log('could not get grpc response'); - return; - } - console.log('< ', response.data.toString('utf8')); - // display traceid in the terminal - console.log(`traceid: ${span.spanContext().traceId}`); - span.end(); - }); - }); - - // 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); -} - -main(); diff --git a/examples/grpc_dynamic_codegen/capitalize_server.js b/examples/grpc_dynamic_codegen/capitalize_server.js deleted file mode 100644 index f67ed75083..0000000000 --- a/examples/grpc_dynamic_codegen/capitalize_server.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -// eslint-disable-next-line import/order -const tracer = require('./tracer')('example-grpc-capitalize-server'); -const { SpanKind } = require('@opentelemetry/api'); -const path = require('path'); -const grpc = require('grpc'); -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, -}; -const definition = protoLoader.loadSync(PROTO_PATH, PROTO_OPTIONS); -const rpcProto = grpc.loadPackageDefinition(definition).rpc; - -/** Implements the Capitalize RPC method. */ -function capitalize(call, callback) { - const currentSpan = tracer.getCurrentSpan(); - // display traceid in the terminal - console.log(`traceid: ${currentSpan.spanContext().traceId}`); - - const span = tracer.startSpan('tutorials.FetchImpl.capitalize', { - kind: SpanKind.SERVER, - }); - - const data = call.request.data.toString('utf8'); - const capitalized = data.toUpperCase(); - for (let i = 0; i < 100000000; i += 1) { - // empty - } - span.end(); - callback(null, { data: Buffer.from(capitalized) }); -} - -/** - * Starts an RPC server that receives requests for the Fetch service at the - * sample server port. - */ -function main() { - const server = new grpc.Server(); - server.addService(rpcProto.Fetch.service, { capitalize }); - server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); - server.start(); -} - -main(); diff --git a/examples/grpc_dynamic_codegen/package.json b/examples/grpc_dynamic_codegen/package.json deleted file mode 100644 index 027965b3e6..0000000000 --- a/examples/grpc_dynamic_codegen/package.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "name": "grpc-dynamic-codegen-example", - "version": "0.23.0", - "description": "Example of gRPC integration with OpenTelemetry", - "main": "index.js", - "scripts": { - "zipkin:server": "cross-env EXPORTER=zipkin node ./capitalize_server.js", - "zipkin:client": "cross-env EXPORTER=zipkin node ./capitalize_client.js", - "jaeger:server": "cross-env EXPORTER=jaeger node ./capitalize_server.js", - "jaeger:client": "cross-env EXPORTER=jaeger node ./capitalize_client.js" - }, - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/open-telemetry/opentelemetry-js.git" - }, - "keywords": [ - "opentelemetry", - "grpc", - "tracing" - ], - "engines": { - "node": ">=8" - }, - "author": "OpenTelemetry Authors", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/open-telemetry/opentelemetry-js/issues" - }, - "dependencies": { - "@grpc/proto-loader": "^0.4.0", - "@opentelemetry/api": "^1.0.2", - "@opentelemetry/exporter-jaeger": "^0.25.0", - "@opentelemetry/exporter-zipkin": "^0.25.0", - "@opentelemetry/sdk-trace-node": "^0.25.0", - "@opentelemetry/instrumentation-grpc": "^0.25.0", - "@opentelemetry/sdk-trace-base": "^0.25.0", - "grpc": "^1.24.6" - }, - "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", - "devDependencies": { - "cross-env": "^7.0.3" - } -} diff --git a/examples/grpc_dynamic_codegen/protos/defs.proto b/examples/grpc_dynamic_codegen/protos/defs.proto deleted file mode 100644 index cc4a40334c..0000000000 --- a/examples/grpc_dynamic_codegen/protos/defs.proto +++ /dev/null @@ -1,19 +0,0 @@ -syntax = "proto3"; - -option java_multiple_files = true; -option java_package = "io.grpc.examples.helloworld"; -option java_outer_classname = "HelloWorldProto"; -option objc_class_prefix = "HLW"; - -package rpc; - -service Fetch { - // Sends a capitalizes payload - rpc Capitalize(Payload) returns (Payload) {} -} - -// The request and response payload containing the id and data. -message Payload { - int32 id = 1; - bytes data = 2; -} diff --git a/examples/grpc_dynamic_codegen/tracer.js b/examples/grpc_dynamic_codegen/tracer.js deleted file mode 100644 index 768edfab1e..0000000000 --- a/examples/grpc_dynamic_codegen/tracer.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -const opentelemetry = require('@opentelemetry/api'); -const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); -const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base'); -const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); -const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); -const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc'); - -const EXPORTER = process.env.EXPORTER || ''; - -module.exports = (serviceName) => { - const provider = new NodeTracerProvider(); - - let exporter; - if (EXPORTER.toLowerCase().startsWith('z')) { - exporter = new ZipkinExporter({ - serviceName, - }); - } else { - exporter = new JaegerExporter({ - serviceName, - }); - } - - // It is recommended to use this `BatchSpanProcessor` for better performance - // and optimization, especially in production. - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - - // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings - provider.register(); - - registerInstrumentations({ - instrumentations: [ - new GrpcInstrumentation(), - ], - }); - - return opentelemetry.trace.getTracer('grpc-dynamic-codegen-example'); -};