From 8302f33b977a249822e0e28c55b7128bc09b0459 Mon Sep 17 00:00:00 2001 From: Moritz Sternemann <3034168+moritzsternemann@users.noreply.github.com> Date: Wed, 13 Apr 2022 10:25:59 +0200 Subject: [PATCH] Add Tracing to the Apodini Service (#93) Co-authored-by: Paul Schmiedmayer Co-authored-by: Philipp Zagar --- .env | 5 +++++ .../otel-collector/collector-config.yml | 21 +++++++++++++++++++ WebService/Package.swift | 1 + WebService/Sources/WebService/main.swift | 10 +++++++++ docker-compose-develop.yml | 18 ++++++++++++++++ docker-compose.yml | 20 ++++++++++++++++++ 6 files changed, 75 insertions(+) create mode 100644 Observability/otel-collector/collector-config.yml diff --git a/.env b/.env index a3519e71..1c540e09 100644 --- a/.env +++ b/.env @@ -22,4 +22,9 @@ KIBANA_SYSTEM_PASSWORD=FA2021 LOGSTASH_SYSTEM_USER=logstash_system LOGSTASH_SYSTEM_PASSWORD=FA2021 +# OpenTelemetry + +OTLP_HOST=otel-collector +OTLP_PORT=4137 + REACT_APP_SCIENCE_LAB_MAP_ACCESS_TOKEN= diff --git a/Observability/otel-collector/collector-config.yml b/Observability/otel-collector/collector-config.yml new file mode 100644 index 00000000..33e5ebd1 --- /dev/null +++ b/Observability/otel-collector/collector-config.yml @@ -0,0 +1,21 @@ +receivers: + otlp: + protocols: + grpc: + endpoint: otel-collector:4317 + +exporters: + logging: + logLevel: debug + + jaeger: + endpoint: "jaeger:14250" + tls: + insecure: true + + +service: + pipelines: + traces: + receivers: otlp + exporters: [logging, jaeger] diff --git a/WebService/Package.swift b/WebService/Package.swift index 9f42f74e..c559464b 100644 --- a/WebService/Package.swift +++ b/WebService/Package.swift @@ -28,6 +28,7 @@ let package = Package( .product(name: "ApodiniREST", package: "Apodini"), .product(name: "ApodiniObserve", package: "Apodini"), .product(name: "ApodiniObservePrometheus", package: "ApodiniObservePrometheus"), + .product(name: "ApodiniObserveOpenTelemetry", package: "Apodini"), .product(name: "ApodiniOpenAPI", package: "Apodini"), .product(name: "ApodiniDatabase", package: "Apodini"), .product(name: "ApodiniAuthorization", package: "Apodini"), diff --git a/WebService/Sources/WebService/main.swift b/WebService/Sources/WebService/main.swift index 246f70e1..e83c9218 100644 --- a/WebService/Sources/WebService/main.swift +++ b/WebService/Sources/WebService/main.swift @@ -1,6 +1,7 @@ import Foundation import Apodini import ApodiniObserve +import ApodiniObserveOpenTelemetry import ApodiniObservePrometheus import ApodiniOpenAPI import ApodiniREST @@ -57,6 +58,11 @@ struct FA2021WebService: WebService { ), systemMetricsConfiguration: .default ) + + // Setup of Tracing with an OpenTelemetry backend + TracingConfiguration( + .defaultOpenTelemetry(serviceName: "FA2021") + ) // Setup of ApodiniAuthorization JWTSigner(.hs256(key: "secret")) @@ -83,12 +89,16 @@ struct FA2021WebService: WebService { var content: some Component { MeasurementComponent() .record(.all) + .trace() SensorTypeComponent() .record(.all) + .trace() AuthComponent() .record(.all) + .trace() DummyComponent() .record(.all) + .trace() } } diff --git a/docker-compose-develop.yml b/docker-compose-develop.yml index 89e1d68a..ebfa1598 100644 --- a/docker-compose-develop.yml +++ b/docker-compose-develop.yml @@ -132,6 +132,24 @@ services: depends_on: - prometheus + otel-collector: + image: otel/opentelemetry-collector-contrib:latest + container_name: otel-collector-develop + command: ["--config=/etc/config.yml"] + volumes: + - ./Observability/otel-collector/collector-config.yml:/etc/config.yml + ports: + # Expose on host port 4317 + - 4317:4317 + depends_on: [jaeger] + + jaeger: + image: jaegertracing/all-in-one:latest + container_name: jaeger-develop + ports: + # Expose on host port 16686 + - 16686:16686 + volumes: database-data: # Volume for PostgreSQL elasticsearch: # Volume for ElasticSearch diff --git a/docker-compose.yml b/docker-compose.yml index a79046e9..e1b72a33 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,6 +36,8 @@ services: POSTGRES_DB: ${POSTGRES_DB} LOGSTASH_HOST: ${LOGSTASH_HOST} LOGSTASH_PORT: ${LOGSTASH_PORT} + OTLP_HOST: ${OTLP_HOST} + OTLP_PORT: ${OTLP_PORT} expose: # The webservice is exposed internally to the reverse proxy - "8080" @@ -222,6 +224,24 @@ services: depends_on: - prometheus + otel-collector: + image: otel/opentelemetry-collector-contrib:latest + container_name: otel-collector + command: ["--config=/etc/config.yml"] + volumes: + - ./Observability/otel-collector/collector-config.yml:/etc/config.yml + ports: + # Expose on host port 4317 + - 4317:4317 + depends_on: [jaeger] + + jaeger: + image: jaegertracing/all-in-one:latest + container_name: jaeger + ports: + # Expose on host port 16686 + - 16686:16686 + volumes: database-data: # Volume for PostgreSQL elasticsearch: # Volume for ElasticSearch