From 7c9c07fc91a0d23c5fc54a9375b3ec31b68f9168 Mon Sep 17 00:00:00 2001 From: Andrew Hayworth Date: Wed, 3 Aug 2022 11:58:27 -0500 Subject: [PATCH] emailservice: remove explicit `PORT` env variable (#254) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a follow-up to #248, which in turn was resolving: https://github.com/open-telemetry/opentelemetry-demo/pull/242#discussion_r933603430 The ruby app is relying on convention, and by convention a `PORT` env varable will determine which port the `puma` webserver actually listens on. So - we don't need to set it explicitly in the compose file, but that means we need to set it elsewhere somehow. I tried a few hacks with the dockerfile: - Trying to pass `PORT=$EMAIL_SERVICE_PORT` - Trying to pass `-p $EMAIL_SERVICE_PORT` in the command But those didn't work and I gave up. So instead we just set it directly in the sinatra app ourselves. (Please don't ask me how that actually gets set down all the way through sinatra -> rack -> puma, because truthfully I do not know: rack-based servers are basically magic). We can see that it works: ``` @ahayworth ➜ /workspaces/opentelemetry-demo-webstore (ahayworth/emailservice-port-things ✗) $ git grep EMAIL_SERVICE_P ORT .env:EMAIL_SERVICE_PORT=6060 ``` ``` @ahayworth ➜ /workspaces/opentelemetry-demo-webstore (ahayworth/emailservice-port-things ✗) $ docker-compose up --build emailservice email-service | == Sinatra (v2.2.0) has taken the stage on 6060 for production with backup from Puma email-service | I, [2022-08-03T13:08:27.643291 #1] INFO -- : Instrumentation: OpenTelemetry::Instrumentation::Sinatra was successfully installed with the following options {} email-service | Puma starting in single mode... email-service | * Puma version: 5.6.4 (ruby 3.1.2-p20) ("Birdie's Version") email-service | * Min threads: 0 email-service | * Max threads: 5 email-service | * Environment: production email-service | * PID: 1 email-service | * Listening on http://0.0.0.0:6060 email-service | Use Ctrl-C to stop ``` Co-authored-by: Carter Socha <43380952+cartersocha@users.noreply.github.com> --- docker-compose.yml | 2 +- src/emailservice/email_server.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index ea476dbb54..9937c65cf6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -145,7 +145,7 @@ services: - "${EMAIL_SERVICE_PORT}:${EMAIL_SERVICE_PORT}" environment: - APP_ENV=production - - PORT=${EMAIL_SERVICE_PORT} + - EMAIL_SERVICE_PORT - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://otelcol:4318/v1/traces - OTEL_RESOURCE_ATTRIBUTES=service.name=emailservice depends_on: diff --git a/src/emailservice/email_server.rb b/src/emailservice/email_server.rb index 268b790fd4..1c4df4e9ff 100644 --- a/src/emailservice/email_server.rb +++ b/src/emailservice/email_server.rb @@ -6,6 +6,8 @@ require "opentelemetry/exporter/otlp" require "opentelemetry/instrumentation/sinatra" +set :port, ENV["EMAIL_SERVICE_PORT"] + OpenTelemetry::SDK.configure do |c| c.use "OpenTelemetry::Instrumentation::Sinatra" end