From 7b3eab6e4782f97612201cc9205cd5e88c274bd3 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Tue, 9 Aug 2022 14:40:02 +0200 Subject: [PATCH] chore: update `https` example (#3152) --- CHANGELOG.md | 2 ++ examples/https/README.md | 20 +++++++++++++++---- examples/https/client.js | 2 +- examples/https/docker/docker-compose.yml | 14 +++++++++++++ examples/https/package.json | 25 +++++++++++++----------- examples/https/server.js | 2 +- lerna.json | 3 ++- 7 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 examples/https/docker/docker-compose.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index c972ad4724..4ce2a89d4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ All notable changes to this project will be documented in this file. ### :books: (Refine Doc) +* chore: update https example [#3152](https://github.com/open-telemetry/opentelemetry-js/pull/3152) @pichlermarc + ### :house: (Internal) ## 1.5.0 diff --git a/examples/https/README.md b/examples/https/README.md index 0a57ae77ac..2f93094564 100644 --- a/examples/https/README.md +++ b/examples/https/README.md @@ -1,6 +1,7 @@ # Overview -OpenTelemetry HTTPS 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), to give observability to distributed systems. +OpenTelemetry HTTPS Instrumentation allows the user to automatically collect trace data and export them to the backend +of choice. This example exports directly to Zipkin or Jaeger. This is a simple example that demonstrates tracing HTTPS request from client to server. The example shows key aspects of tracing such as @@ -22,6 +23,14 @@ 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) +or + +```sh +# from this directory, requires docker and docker-compose +npm run docker:start +# Zipkin UI will be available at http://localhost:9411/zipkin/ +# Jaeger UI will be available at http://localhost:16686/ +``` ## Run the Application @@ -44,7 +53,8 @@ Setup [Jaeger Tracing](https://www.jaegertracing.io/docs/latest/getting-started/ #### Zipkin UI `zipkin:server` script should output the `traceid` in the terminal (e.g `traceid: 4815c3d576d930189725f1f1d1bdfcc6`). -Go to Zipkin with your browser (e.g +Go to Zipkin with your browser ( +e.g

@@ -67,14 +77,16 @@ Go to Zipkin with your browser (e.g +Go to Jaeger with your browser ( +e.g

## Useful links - For more information on OpenTelemetry, visit: -- For more information on OpenTelemetry for Node.js, visit: +- For more information on OpenTelemetry for Node.js, + visit: ## LICENSE diff --git a/examples/https/client.js b/examples/https/client.js index 2240399d21..12dbeeddec 100644 --- a/examples/https/client.js +++ b/examples/https/client.js @@ -13,7 +13,7 @@ function makeRequest() { api.context.with(api.trace.setSpan(api.context.active(), span), () => { https.get({ host: 'localhost', - port: 443, + port: 8443, path: '/helloworld', }, (response) => { const body = []; diff --git a/examples/https/docker/docker-compose.yml b/examples/https/docker/docker-compose.yml new file mode 100644 index 0000000000..35fc4757e8 --- /dev/null +++ b/examples/https/docker/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3.8" +services: + # Jaeger + jaeger-all-in-one: + image: jaegertracing/all-in-one:1.37.0 + ports: + - "16686:16686" # frontend + - "14268:14268" # jaeger.thrift via HTTP + - "6832:6832/udp" # jaeger.thrift via UDP (binary) + # Zipkin + zipkin-all-in-one: + image: openzipkin/zipkin:latest + ports: + - "9411:9411" diff --git a/examples/https/package.json b/examples/https/package.json index 177bf07116..fdb05d775a 100644 --- a/examples/https/package.json +++ b/examples/https/package.json @@ -1,7 +1,7 @@ { "name": "https-example", "private": true, - "version": "0.25.0", + "version": "0.31.0", "description": "Example of HTTPs integration with OpenTelemetry", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -9,7 +9,10 @@ "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" + "jaeger:client": "cross-env EXPORTER=jaeger node ./client.js", + "docker:start": "cd ./docker && docker-compose down && docker-compose up", + "docker:startd": "cd ./docker && docker-compose down && docker-compose up -d", + "docker:stop": "cd ./docker && docker-compose down" }, "repository": { "type": "git", @@ -29,15 +32,15 @@ "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/resources": "0.25.0", - "@opentelemetry/semantic-conventions": "0.25.0", - "@opentelemetry/sdk-trace-node": "0.25.0", - "@opentelemetry/sdk-trace-base": "0.25.0" + "@opentelemetry/api": "^1.0.0", + "@opentelemetry/exporter-jaeger": "1.5.0", + "@opentelemetry/exporter-zipkin": "1.5.0", + "@opentelemetry/instrumentation": "0.31.0", + "@opentelemetry/instrumentation-http": "0.31.0", + "@opentelemetry/resources": "1.5.0", + "@opentelemetry/semantic-conventions": "1.5.0", + "@opentelemetry/sdk-trace-node": "1.5.0", + "@opentelemetry/sdk-trace-base": "1.5.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/https", "devDependencies": { diff --git a/examples/https/server.js b/examples/https/server.js index 20460bb2a4..e7905080cc 100644 --- a/examples/https/server.js +++ b/examples/https/server.js @@ -46,4 +46,4 @@ function handleRequest(request, response) { }); } -startServer(443); +startServer(8443); diff --git a/lerna.json b/lerna.json index 98304af897..64b67419c1 100644 --- a/lerna.json +++ b/lerna.json @@ -7,6 +7,7 @@ "experimental/backwards-compatability/*", "integration-tests/*", "selenium-tests", - "examples/otlp-exporter-node" + "examples/otlp-exporter-node", + "examples/https" ] }