diff --git a/README.md b/README.md index 16ad575..67e9dc8 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,9 @@ end `GovukError.configure` has the same options as the Sentry client, Raven. See [the Raven docs for all configuration options](https://docs.sentry.io/clients/ruby/config). +## Open Telemetry + +To enable Open Telemetry instrumentation for Rails set the ENABLE_OPEN_TELEMETRY="true" environment variable. ## Prometheus monitoring diff --git a/lib/govuk_app_config.rb b/lib/govuk_app_config.rb index f21ba38..98984f5 100644 --- a/lib/govuk_app_config.rb +++ b/lib/govuk_app_config.rb @@ -3,6 +3,7 @@ require "govuk_app_config/govuk_error" require "govuk_app_config/govuk_proxy/static_proxy" require "govuk_app_config/govuk_healthcheck" +require "govuk_app_config/govuk_open_telemetry" require "govuk_app_config/govuk_prometheus_exporter" if defined?(Rails) diff --git a/lib/govuk_app_config/govuk_open_telemetry.rb b/lib/govuk_app_config/govuk_open_telemetry.rb new file mode 100644 index 0000000..59da19c --- /dev/null +++ b/lib/govuk_app_config/govuk_open_telemetry.rb @@ -0,0 +1,18 @@ +module GovukOpenTelemetry + def self.should_configure? + ENV["ENABLE_OPEN_TELEMETRY"] == "true" + end + + def self.configure(service_name) + return unless should_configure? + + require "opentelemetry/sdk" + require "opentelemetry/exporter/otlp" + require "opentelemetry/instrumentation/all" + + OpenTelemetry::SDK.configure do |config| + config.service_name = service_name + config.use_all # enables all instrumentation! + end + end +end diff --git a/lib/govuk_app_config/railtie.rb b/lib/govuk_app_config/railtie.rb index a1158d7..fb4e7bb 100644 --- a/lib/govuk_app_config/railtie.rb +++ b/lib/govuk_app_config/railtie.rb @@ -8,6 +8,10 @@ class Railtie < Rails::Railtie end end + initializer "govuk_app_config.configure_open_telemetry" do |app| + GovukOpenTelemetry.configure(app.class.module_parent_name.underscore) + end + config.before_initialize do GovukLogging.configure if Rails.env.production? end