Skip to content

Commit

Permalink
Merge pull request #303 from alphagov/add-open-telemetry
Browse files Browse the repository at this point in the history
Add support Open Telemetry instrumentation in Rails
  • Loading branch information
theseanything authored Jul 3, 2023
2 parents b5fdbbe + 736656b commit ff06080
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 8.1.0

* Add ability to enable Open Telemetry instrumentation for Rails applications.

# 8.0.2

* Fix the ability to collect Sidekiq metrics in GovukPrometheusExporter. ([#299](https://github.com/alphagov/govuk_app_config/pull/299))
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions govuk_app_config.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Gem::Specification.new do |spec|
spec.require_paths = %w[lib]

spec.add_dependency "logstasher", "~> 2.1"
spec.add_dependency "opentelemetry-exporter-otlp", "~> 0.25.0"
spec.add_dependency "opentelemetry-instrumentation-all", "~> 0.39.1"
spec.add_dependency "opentelemetry-sdk", "~> 1.2"
spec.add_dependency "plek", ">= 4", "< 6"
spec.add_dependency "prometheus_exporter", "~> 2.0"
spec.add_dependency "puma", ">= 5.6", "< 7.0"
Expand Down
1 change: 1 addition & 0 deletions lib/govuk_app_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions lib/govuk_app_config/govuk_open_telemetry.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions lib/govuk_app_config/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/govuk_app_config/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module GovukAppConfig
VERSION = "8.0.2".freeze
VERSION = "8.1.0".freeze
end

0 comments on commit ff06080

Please sign in to comment.