diff --git a/config/environments/development.rb b/config/environments/development.rb index d7b3cb6f23..08efda0b4d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -92,4 +92,5 @@ config.log_level = :debug # Or :info config.log_format = :color # Console colorised non-json output config.semantic_logger.backtrace_level = :debug # Show file and line number (expensive: not for production) + config.dfe_analytics = true end diff --git a/config/environments/production.rb b/config/environments/production.rb index 21b9b7fd6d..198f0fdd0c 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -94,4 +94,5 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + config.dfe_analytics = false end diff --git a/config/environments/test.rb b/config/environments/test.rb index a92b501287..6ee1f1380a 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -71,4 +71,5 @@ Bullet.add_safelist type: :unused_eager_loading, class_name: "TslrClaim", association: :current_school Bullet.add_safelist type: :n_plus_one_query, class_name: "School", association: :local_authority end + config.dfe_analytics = false end diff --git a/config/initializers/dfe_analytics.rb b/config/initializers/dfe_analytics.rb index c73aa65d20..15decc1d74 100644 --- a/config/initializers/dfe_analytics.rb +++ b/config/initializers/dfe_analytics.rb @@ -1,14 +1,58 @@ -require "hosting_environment" - DfE::Analytics.configure do |config| - config.queue = :analytics - config.environment = HostingEnvironment.environment_name + # Whether to log events instead of sending them to BigQuery. + # + config.log_only = false + + # Whether to use ActiveJob or dispatch events immediately. + # + config.async = true config.entity_table_checks_enabled = true - config.enable_analytics = - proc do - disabled_by_default = Rails.env.development? - ENV.fetch("BIGQUERY_DISABLE", disabled_by_default.to_s) != "true" - end + # Which ActiveJob queue to put events on + # + config.queue = :analytics + + # The name of the BigQuery table we’re writing to. + # + # config.bigquery_table_name = ENV['BIGQUERY_TABLE_NAME'] + + # The name of the BigQuery project we’re writing to. + # + # config.bigquery_project_id = ENV['BIGQUERY_PROJECT_ID'] + + # The name of the BigQuery dataset we're writing to. + # + # config.bigquery_dataset = ENV['BIGQUERY_DATASET'] + + # Service account JSON key for the BigQuery API. See + # https://cloud.google.com/bigquery/docs/authentication/service-account-file + # + # We base64 encode the secret otherwise the raw JSON is mangled when it gets + #  written to/read from the Azure keyvault. + config.bigquery_api_json_key = ENV['BIGQUERY_API_JSON_KEY'] ? Base64.decode64(ENV['BIGQUERY_API_JSON_KEY']) : nil + + # Passed directly to the retries: option on the BigQuery client + # + # config.bigquery_retries = 3 + + # Passed directly to the timeout: option on the BigQuery client + # + # config.bigquery_timeout = 120 + + # A proc which returns true or false depending on whether you want to + # enable analytics. You might want to hook this up to a feature flag or + # environment variable. + # + config.enable_analytics = proc { Rails.application.config.dfe_analytics } + + config.user_identifier = proc { |user| user&.sub } + + # The environment we’re running in. This value will be attached + # to all events we send to BigQuery. + # + # config.environment = ENV.fetch('RAILS_ENV', 'development') + + config.bigquery_maintenance_window = "08-09-2024 18:00..08-09-2024 19:00" + config.azure_federated_auth = ENV.include? "GOOGLE_CLOUD_CREDENTIALS" end