Skip to content

Commit

Permalink
THREESCALE-9682: Add support for OpenTelemetry (#405)
Browse files Browse the repository at this point in the history
* Install OpenTelemetry gems

* Add support for OpenTelemetry

* Add env var to enable otel

`CONFIG_OPENTELEMETRY_ENABLED`

---------

Co-authored-by: Eguzki Astiz Lezaun <[email protected]>
  • Loading branch information
jlledom and eguzki authored Sep 16, 2024
1 parent 385ea14 commit 58baa5c
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
38 changes: 38 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions lib/3scale/backend/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions lib/3scale/backend/opentelemetry.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/3scale/backend/server.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require '3scale/backend/util'
require '3scale/backend/opentelemetry'

module ThreeScale
module Backend
Expand Down
1 change: 1 addition & 0 deletions openshift/3scale_backend.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 58baa5c

Please sign in to comment.