{"record":{"id":"62da7e19d6d6d007","repo":"instructure/canvas-lms","slug":"pv5-is-not-configured-for-this-environment","errorCode":null,"errorMessage":"PV5 is not configured for this environment","messagePattern":"PV5 is not configured for this environment","errorType":"exception","errorClass":"Common::ConfigurationError","httpStatus":null,"severity":"error","filePath":"app/services/page_views/configuration.rb","lineNumber":30,"sourceCode":"# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY\n# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more\n# details.\n#\n# You should have received a copy of the GNU Affero General Public License along\n# with this program. If not, see <http://www.gnu.org/licenses/>.\n\nmodule PageViews\n  class Configuration\n    attr_reader :uri\n\n    def self.configured?\n      ConfigFile.load(\"pv5\").present?\n    end\n\n    def initialize(region: nil)\n      config = ConfigFile.load(\"pv5\")\n      raise Common::ConfigurationError, \"PV5 is not configured for this environment\" unless config.present?\n\n      regional_config = get_regional_config(config, region) || {}\n      @uri = URI.parse(regional_config[\"uri\"] || config[\"uri\"])\n    rescue URI::InvalidURIError => e\n      raise Common::ConfigurationError, \"Invalid URI in pv5 config: #{e.message}\"\n    end\n\n    private\n\n    def get_regional_config(config, region)\n      return unless config[\"regions\"].is_a?(Hash)\n\n      regional_config = config[\"regions\"][region]\n      return unless regional_config.is_a?(Hash)\n\n      regional_config\n    end\n  end","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/services/page_views/configuration.rb#L12-L48","documentation":"PageViews::Configuration loads the 'pv5' config file (config/page_views.yml via ConfigFile). Its constructor raises Common::ConfigurationError with 'PV5 is not configured for this environment' when no pv5 config is present, because the service cannot know where to send page view events.","triggerScenarios":"Instantiating PageViews::Configuration.new (directly or via addInstance/removeInstance) in an environment where ConfigFile.load('pv5') returns nil — no pv5 config file loaded, empty config, or the environment's Rails env has no pv5 key.","commonSituations":"Local/dev or test environments without config/page_views.yml; pv5 config not deployed to the environment via config store; YAML key mismatch (wrong env section); PV5 feature disabled intentionally but code still constructs the client.","solutions":["Add a pv5 config (config/page_views.yml or environment config store) with at least a 'uri' key for the current Rails env.","Confirm ConfigFile can load the file: check RAILS_ENV section naming in the YAML.","If PV5 is intentionally off, guard callers with PageViews::Configuration.configured? before constructing.","Deploy the pv4->pv5 config migration to the environment if this is a rollout issue."],"exampleFix":"# before\nPageViews::Configuration.new # raises: PV5 is not configured\n# after\nPageViews::Configuration.new if PageViews::Configuration.configured?\n# and add config/page_views.yml:\n# production:\n#   uri: https://pageviews.example.com/notifications","handlingStrategy":"fallback","validationCode":"raise 'pv5 not configured' unless PageViews::Configuration.configured?","typeGuard":null,"tryCatchPattern":"begin\n  PageViews::Configuration.new(region: region)\nrescue Common::ConfigurationError => e\n  Rails.logger.warn(e.message)\n  fall_back_to_no_op_page_view_logger\nend","preventionTips":["Check PageViews::Configuration.configured? before constructing","Ship config/page_views.yml with a uri for every Rails env","Add a boot-time check that pv5 config loads in environments where PV5 is required","Coordinate pv5 config deployment with the code rollout"],"tags":["ruby","configuration","page-views"],"backgroundTag":"missing-required-config","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}