Skip to content

Commit

Permalink
Merge branch 'main' into tm-dep-check-with-knip
Browse files Browse the repository at this point in the history
  • Loading branch information
trentm authored Oct 11, 2024
2 parents 971f52e + d11efb3 commit 793a566
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 57 deletions.
29 changes: 2 additions & 27 deletions examples/mysql/README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -54,29 +52,6 @@ Go to Zipkin with your browser <http://localhost:9411/zipkin/traces/(your-trace-

<p align="center"><img alt="Zipkin UI with trace" src="./images/zipkin-ui.png?raw=true"/></p>

### 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 <http://localhost:16686/trace/(your-trace-id)> (e.g <http://localhost:16686/trace/4815c3d576d930189725f1f1d1bdfcc6>)

<p align="center"><img alt="Jaeger UI with trace" src="images/jaeger-ui.png?raw=true"/></p>

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand Down
13 changes: 4 additions & 9 deletions examples/mysql/docker/collector/otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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]
14 changes: 2 additions & 12 deletions examples/mysql/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions examples/mysql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -32,15 +30,15 @@
},
"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",
"@opentelemetry/instrumentation-mysql": "^0.31.0",
"@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",
Expand Down
1 change: 0 additions & 1 deletion examples/mysql/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
3 changes: 0 additions & 3 deletions examples/mysql/src/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ describe('pg-pool', () => {
metricReader = testUtils.initMeterProvider(instrumentation);
});

it('should generate `db.client.connection.count` and `db.client.connection.pending_requests` metrics', async () => {
it('should generate `db.client.connection.count` and `db.client.connection.pending_requests` metrics', done => {
pool.connect((err, client, release) => {
if (err) {
throw new Error(err.message);
Expand Down Expand Up @@ -563,6 +563,7 @@ describe('pg-pool', () => {
0,
'expected to have 0 pending requests'
);
done();
});
});
});
Expand Down

0 comments on commit 793a566

Please sign in to comment.