From d11efb33b9cd897d4cd51a1b53e6941cc32bfc95 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Fri, 11 Oct 2024 10:41:13 -0700 Subject: [PATCH] chore(examples/mysql): modernize this example (#2465) - drop Jaeger from examples (given https://github.com/open-telemetry/opentelemetry-specification/issues/3551) - update otel-collector-contib version and switch from logging to debug exporter (lifted from #2441) - various other small fixes to get the README steps basically working Refs: #2441 --- examples/mysql/README.md | 29 ++----------------- .../collector/otel-collector-config.yaml | 13 +++------ examples/mysql/docker/docker-compose.yaml | 14 ++------- examples/mysql/package.json | 6 ++-- examples/mysql/src/server.ts | 1 - examples/mysql/src/tracer.ts | 3 -- 6 files changed, 10 insertions(+), 56 deletions(-) diff --git a/examples/mysql/README.md b/examples/mysql/README.md index 4dd0437442..7c11a80ee3 100644 --- a/examples/mysql/README.md +++ b/examples/mysql/README.md @@ -1,6 +1,6 @@ # Overview -OpenTelemetry MySQL Instrumentation allows the user to automatically collect trace data and metrics and export them to the backend of choice (we can use Zipkin, Jaeger or Grafana for this example), to give observability to distributed systems. +OpenTelemetry MySQL Instrumentation allows the user to automatically collect trace data and metrics and export them to the backend of choice (we can use Zipkin or Grafana for this example), to give observability to distributed systems. This is a modification of the HTTP example that executes multiple parallel requests that interact with a MySQL server backend using the `mysql` npm module. The example displays traces using multiple connection methods. @@ -20,13 +20,11 @@ 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) In case you want to see also metrics: 1. Go to `docker` folder -2. Run `docker compose up`. This will set up Zipkin, Jaeger, otel collector, Prometheus and Grafana. +2. Run `docker compose up`. This will set up Zipkin, otel collector, Prometheus and Grafana. 3. To see your metrics, go to `http://localhost:3000/`. ## Run the Application @@ -54,29 +52,6 @@ Go to Zipkin with your browser Zipkin UI with trace

-### Jaeger - -- Run the server - - ```sh - # from this directory - npm run jaeger:server - ``` - -- Run the client - - ```sh - # from this directory - npm run jaeger:client - ``` - -#### Jaeger UI - -The `jaeger:server` script should output the `traceid` in the terminal (e.g `traceid: 4815c3d576d930189725f1f1d1bdfcc6`). -Go to Jaeger with your browser (e.g ) - -

Jaeger UI with trace

- ## Useful links - For more information on OpenTelemetry, visit: diff --git a/examples/mysql/docker/collector/otel-collector-config.yaml b/examples/mysql/docker/collector/otel-collector-config.yaml index bf4e67b135..710e88d048 100644 --- a/examples/mysql/docker/collector/otel-collector-config.yaml +++ b/examples/mysql/docker/collector/otel-collector-config.yaml @@ -9,18 +9,13 @@ exporters: const_labels: label1: value1 - logging: - loglevel: debug + debug: + verbosity: detailed zipkin: endpoint: "http://zipkin-all-in-one:9411/api/v2/spans" format: proto - jaeger: - endpoint: jaeger-all-in-one:14250 - tls: - insecure: true - processors: batch: @@ -37,8 +32,8 @@ service: traces: receivers: [otlp] processors: [batch] - exporters: [logging] + exporters: [debug] metrics: receivers: [otlp] processors: [batch] - exporters: [logging, prometheus] + exporters: [debug, prometheus] diff --git a/examples/mysql/docker/docker-compose.yaml b/examples/mysql/docker/docker-compose.yaml index b95dabc9ad..3142fbdc00 100644 --- a/examples/mysql/docker/docker-compose.yaml +++ b/examples/mysql/docker/docker-compose.yaml @@ -1,9 +1,9 @@ -version: "2" services: # mysql mysql: image: mysql:5.7 + platform: linux/amd64 command: --init-file /etc/mysql/init.sql volumes: - ./mysql/init.sql:/etc/mysql/init.sql @@ -12,15 +12,6 @@ services: ports: - "3306:3306" -# Jaeger - - jaeger-all-in-one: - image: jaegertracing/all-in-one:latest - ports: - - "16686:16686" - - "14268" - - "14250" - # Zipkin zipkin-all-in-one: @@ -31,7 +22,7 @@ services: # Collector otel-collector: - image: otel/opentelemetry-collector-contrib:0.61.0 + image: otel/opentelemetry-collector-contrib:0.111.0 command: ["--config=/etc/otel-collector-config.yaml", ""] volumes: - ./collector/otel-collector-config.yaml:/etc/otel-collector-config.yaml @@ -43,7 +34,6 @@ services: - "4317:4317" # OTLP gRPC receiver - "55679:55679" # zpages extension depends_on: - - jaeger-all-in-one - zipkin-all-in-one # Prometheus diff --git a/examples/mysql/package.json b/examples/mysql/package.json index 80becff747..d1faf67976 100644 --- a/examples/mysql/package.json +++ b/examples/mysql/package.json @@ -9,8 +9,6 @@ "docker:stop": "docker stop example-mysql && docker rm example-mysql", "zipkin:server": "cross-env EXPORTER=zipkin ts-node src/server.ts", "zipkin:client": "cross-env EXPORTER=zipkin ts-node src/client.ts", - "jaeger:server": "cross-env EXPORTER=jaeger ts-node src/server.ts", - "jaeger:client": "cross-env EXPORTER=jaeger ts-node src/client.ts", "compile": "tsc -p ." }, "repository": { @@ -32,7 +30,7 @@ }, "dependencies": { "@opentelemetry/api": "^1.0.0", - "@opentelemetry/exporter-jaeger": "^1.0.0", + "@opentelemetry/exporter-metrics-otlp-grpc": "^0.48.0", "@opentelemetry/exporter-zipkin": "^1.0.0", "@opentelemetry/instrumentation": "^0.48.0", "@opentelemetry/instrumentation-http": "^0.48.0", @@ -40,7 +38,7 @@ "@opentelemetry/sdk-trace-base": "^1.0.0", "@opentelemetry/sdk-trace-node": "^1.0.0", "@opentelemetry/semantic-conventions": "^1.27.0", - "@opentelemetry/exporter-metrics-otlp-grpc": "^0.48.0", + "@types/node": "^18.18.14", "mysql": "^2.18.1" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/mysql#readme", diff --git a/examples/mysql/src/server.ts b/examples/mysql/src/server.ts index dba7d523c7..180224e2c7 100644 --- a/examples/mysql/src/server.ts +++ b/examples/mysql/src/server.ts @@ -52,7 +52,6 @@ function handleRequest(request: any, response: any) { // display traceid in the terminal const traceId = currentSpan?.spanContext().traceId; console.log(`traceid: ${traceId}`); - console.log(`Jaeger URL: http://localhost:16686/trace/${traceId}`); console.log(`Zipkin URL: http://localhost:9411/zipkin/traces/${traceId}`); try { const body = []; diff --git a/examples/mysql/src/tracer.ts b/examples/mysql/src/tracer.ts index b5c2f522cb..2ded0e2567 100644 --- a/examples/mysql/src/tracer.ts +++ b/examples/mysql/src/tracer.ts @@ -3,7 +3,6 @@ import opentelemetry from '@opentelemetry/api'; import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'; -import { JaegerExporter } from '@opentelemetry/exporter-jaeger'; import { ZipkinExporter } from '@opentelemetry/exporter-zipkin'; import { registerInstrumentations } from '@opentelemetry/instrumentation'; import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; @@ -38,8 +37,6 @@ export const setupTracing = (serviceName: string) => { if (EXPORTER.toLowerCase().startsWith('z')) { tracerProvider.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter())); - } else { - tracerProvider.addSpanProcessor(new SimpleSpanProcessor(new JaegerExporter())); } // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings