diff --git a/Gemfile b/Gemfile index 837107e1..a9bb3e0b 100644 --- a/Gemfile +++ b/Gemfile @@ -61,6 +61,9 @@ gem 'redis-namespace', '~>1.8' gem 'rack', '~> 2.2.8' gem 'sinatra', '~> 2.2.4' gem 'sinatra-contrib', '~> 2.2.4' +gem "opentelemetry-sdk", "~> 1.5" +gem "opentelemetry-instrumentation-sinatra", "~> 0.24.1" +gem "opentelemetry-exporter-otlp", "~> 0.29.0" # Optional external error logging services gem 'bugsnag', '~> 6', require: nil gem 'yabeda-prometheus', '~> 0.5.0' diff --git a/Gemfile.lock b/Gemfile.lock index 159e6857..4e142c3a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,6 +100,11 @@ GEM fiber-annotation (0.2.0) fiber-local (1.0.0) gli (2.16.1) + google-protobuf (4.28.0) + bigdecimal + rake (>= 13) + googleapis-common-protos-types (1.15.0) + google-protobuf (>= 3.18, < 5.a) hiredis-client (0.22.1) redis-client (= 0.22.1) i18n (1.14.5) @@ -134,6 +139,36 @@ GEM mini_portile2 (~> 2.8.2) racc (~> 1.4) openssl (3.2.0) + opentelemetry-api (1.4.0) + opentelemetry-common (0.21.0) + opentelemetry-api (~> 1.0) + opentelemetry-exporter-otlp (0.29.0) + google-protobuf (>= 3.18) + googleapis-common-protos-types (~> 1.3) + opentelemetry-api (~> 1.1) + opentelemetry-common (~> 0.20) + opentelemetry-sdk (~> 1.2) + opentelemetry-semantic_conventions + opentelemetry-instrumentation-base (0.22.6) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.21) + opentelemetry-registry (~> 0.1) + opentelemetry-instrumentation-rack (0.24.6) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.22.1) + opentelemetry-instrumentation-sinatra (0.24.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.22.1) + opentelemetry-instrumentation-rack (~> 0.21) + opentelemetry-registry (0.3.1) + opentelemetry-api (~> 1.1) + opentelemetry-sdk (1.5.0) + opentelemetry-api (~> 1.1) + opentelemetry-common (~> 0.20) + opentelemetry-registry (~> 0.2) + opentelemetry-semantic_conventions + opentelemetry-semantic_conventions (1.10.1) + opentelemetry-api (~> 1.0) pkg-config (1.1.9) power_assert (2.0.3) process-metrics (0.2.1) @@ -276,6 +311,9 @@ DEPENDENCIES license_finder (~> 7.0) mocha (~> 1.3) nokogiri (~> 1.16.5) + opentelemetry-exporter-otlp (~> 0.29.0) + opentelemetry-instrumentation-sinatra (~> 0.24.1) + opentelemetry-sdk (~> 1.5) pkg-config (~> 1.1.7) pry (~> 0.14) pry-byebug (~> 3) diff --git a/docs/configuration.md b/docs/configuration.md index ddff16b0..20af0e25 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -10,6 +10,7 @@ variables. - [Integration with Porta](#integration-with-porta) - [Logging](#logging) - [Prometheus metrics](#prometheus-metrics) +- [OpenTelemetry](#opentelemetry) - [Feature flags](#feature-flags) - [Async](#async) - [Performance](#performance) @@ -356,6 +357,14 @@ print the logs in both formats. - Applies to: worker. - Format: integer. +## OpenTelemetry + +### CONFIG_OPENTELEMETRY_ENABLED + +- Enables OpenTelemetry instrumentation +- Optional. Defaults to `false`. +- Applies to: listener. +- Format: `true` or `false`. ## Feature flags diff --git a/lib/3scale/backend/configuration.rb b/lib/3scale/backend/configuration.rb index 3ef4ef39..77fc732c 100644 --- a/lib/3scale/backend/configuration.rb +++ b/lib/3scale/backend/configuration.rb @@ -49,6 +49,7 @@ def parse_int(value, default) config.add_section(:internal_api, :user, :password) config.add_section(:master, :metrics) config.add_section(:worker_prometheus_metrics, :enabled, :port) + config.add_section(:opentelemetry, :enabled) config.add_section( :async_worker, diff --git a/lib/3scale/backend/opentelemetry.rb b/lib/3scale/backend/opentelemetry.rb new file mode 100644 index 00000000..ca00f4bf --- /dev/null +++ b/lib/3scale/backend/opentelemetry.rb @@ -0,0 +1,9 @@ +require 'opentelemetry/sdk' +require 'opentelemetry/instrumentation/sinatra' +require 'opentelemetry-exporter-otlp' +require '3scale/backend/configuration' + +OpenTelemetry::SDK.configure do |c| + c.service_name = '3scale-backend' + c.use 'OpenTelemetry::Instrumentation::Sinatra' +end if ThreeScale::Backend.configuration.opentelemetry.enabled diff --git a/lib/3scale/backend/server.rb b/lib/3scale/backend/server.rb index a9e94ee7..cf7132c4 100644 --- a/lib/3scale/backend/server.rb +++ b/lib/3scale/backend/server.rb @@ -1,4 +1,5 @@ require '3scale/backend/util' +require '3scale/backend/opentelemetry' module ThreeScale module Backend diff --git a/openshift/3scale_backend.conf b/openshift/3scale_backend.conf index 590b0e78..e1c2f003 100644 --- a/openshift/3scale_backend.conf +++ b/openshift/3scale_backend.conf @@ -74,4 +74,5 @@ ThreeScale::Backend.configure do |config| config.async_worker.max_pending_jobs = parse_int_env('CONFIG_ASYNC_WORKER_MAX_PENDING_JOBS') config.async_worker.seconds_before_fetching_more = parse_int_env('CONFIG_ASYNC_WORKER_WAIT_SECONDS_FETCHING') config.legacy_referrer_filters = parse_boolean_env('CONFIG_LEGACY_REFERRER_FILTERS') + config.opentelemetry.enabled = parse_boolean_env('CONFIG_OPENTELEMETRY_ENABLED') end