diff --git a/examples/restify/README.md b/examples/restify/README.md deleted file mode 100644 index 12adf8eb05..0000000000 --- a/examples/restify/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# Overview - -OpenTelemetry Restify Instrumentation allows the user to automatically collect trace data and export them to the backend of choice (we can use Zipkin or Jaeger for this example). This example demonstrates tracing calls made to Restify API. All generated spans include following attributes: - -- `http.route`: resolved route; -- `restify.method`: server method used to register the handler. One of `use`, `pre`, `del`, `get`, `head`, `opts`, `post`, `put` or `patch`; -- `restify.type`: either `middleware` or `request_handler`; -- `restify.version`: `restify` version running. - -## Setup - -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 - -First install the dependencies: - -```sh -npm install -``` - -### Zipkin - -```sh -npm run zipkin:server # Run the server -npm run zipkin:client # Run the client in a separate terminal -``` - -### Jaeger - -```sh -npm run jaeger:server # Run the server -npm run jaeger:client # Run the client in a separate terminal -``` - -## 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/restify/client.js b/examples/restify/client.js deleted file mode 100644 index 52dffcf4bf..0000000000 --- a/examples/restify/client.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; - -// required to initialize the service name for the auto-instrumentation -require('./tracer')('example-restify-client'); -// eslint-disable-next-line import/order -const http = require('http'); - -/** A function which makes requests and handles response. */ -function makeRequest(path) { - // span corresponds to outgoing requests. Here, we have manually created - // the span, which is created to track work that happens outside of the - // request lifecycle entirely. - http.get({ - host: 'localhost', - headers: { - accept: 'text/plain', - }, - port: 8080, - path, - }, (response) => { - response.on('data', (chunk) => console.log(path, '::', chunk.toString('utf8'))); - response.on('end', () => { - console.log(path, 'status', response.statusCode); - }); - }); - - // 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); -} - -makeRequest('/hello/world'); -makeRequest('/bye/world'); diff --git a/examples/restify/package.json b/examples/restify/package.json deleted file mode 100644 index 2dedc84a4e..0000000000 --- a/examples/restify/package.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "name": "restify-example", - "private": true, - "version": "0.23.0", - "description": "Example of restify integration with OpenTelemetry", - "main": "index.js", - "scripts": { - "zipkin:server": "cross-env EXPORTER=zipkin node ./server.js", - "zipkin:client": "cross-env EXPORTER=zipkin node ./client.js", - "jaeger:server": "cross-env EXPORTER=jaeger node ./server.js", - "jaeger:client": "cross-env EXPORTER=jaeger node ./client.js" - }, - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/open-telemetry/opentelemetry-js.git" - }, - "keywords": [ - "opentelemetry", - "http", - "tracing" - ], - "engines": { - "node": ">=8" - }, - "author": "OpenTelemetry Authors", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/open-telemetry/opentelemetry-js/issues" - }, - "dependencies": { - "@opentelemetry/api": "^1.0.2", - "@opentelemetry/exporter-jaeger": "^0.25.0", - "@opentelemetry/exporter-zipkin": "^0.25.0", - "@opentelemetry/instrumentation": "^0.25.0", - "@opentelemetry/instrumentation-http": "^0.25.0", - "@opentelemetry/instrumentation-restify": "^0.23.0", - "@opentelemetry/sdk-trace-node": "^0.25.0", - "@opentelemetry/sdk-trace-base": "^0.25.0", - "restify": "^4.3.4" - }, - "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", - "devDependencies": { - "cross-env": "^6.0.0" - } -} diff --git a/examples/restify/server.js b/examples/restify/server.js deleted file mode 100644 index 950c8dd7ad..0000000000 --- a/examples/restify/server.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -const api = require('@opentelemetry/api'); - -const { diag, DiagConsoleLogger, DiagLogLevel } = api; -diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.VERBOSE); - -const restify = require('restify'); -require('./tracer')('example-restify-server'); - -const server = restify.createServer(); -const PORT = 8080; - -server.pre((req, res, next) => { - next(); -}); - -// `setDefaultName` shows up in spans as the name -const setDefaultName = (req, res, next) => { - req.defaultName = 'Stranger'; - next(); -}; - -server.use([(req, res, next) => { - /* - noop to showcase use with an array. - as this is an anonymous fn, the name is not known and cannot be displayed in traces. - */ - next(); -}, setDefaultName]); - -// named function to be used in traces -// eslint-disable-next-line prefer-arrow-callback -server.get('/hello/:name', function hello(req, res, next) { - console.log('Handling hello'); - res.send(`Hello, ${req.params.name || req.defaultName}\n`); - return next(); -}); - -server.get('/bye/:name', (req, res, next) => { - console.log('Handling bye'); - return next(new Error('Ooops in bye')); -}); - -server.listen(PORT, () => { - console.log('Ready on %s', server.url); -}); diff --git a/examples/restify/tracer.js b/examples/restify/tracer.js deleted file mode 100644 index b2712adf03..0000000000 --- a/examples/restify/tracer.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -const opentelemetry = require('@opentelemetry/api'); - -const { diag, DiagConsoleLogger, DiagLogLevel } = opentelemetry; -diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.VERBOSE); - -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); -const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); -const { SimpleSpanProcessor, ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base'); -const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); -const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); - -const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http'); -const { RestifyInstrumentation } = require('@opentelemetry/instrumentation-restify'); - -const Exporter = ((exporterParam) => { - if (typeof exporterParam === 'string') { - const exporterString = exporterParam.toLowerCase(); - if (exporterString.startsWith('z')) { - return ZipkinExporter; - } - if (exporterString.startsWith('j')) { - return JaegerExporter; - } - } - return ConsoleSpanExporter; -})(process.env.EXPORTER); - -module.exports = (serviceName) => { - const exporter = new Exporter({ - serviceName, - }); - - const provider = new NodeTracerProvider({ - spanProcessors: [ - new SimpleSpanProcessor(exporter), - ], - }); - - registerInstrumentations({ - tracerProvider: provider, - instrumentations: [ - HttpInstrumentation, - RestifyInstrumentation, - ], - }); - - // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings - provider.register(); - - return opentelemetry.trace.getTracer('restify-example'); -};