{"id":23421093,"url":"https://github.com/nhsdigital/ndr_error","last_synced_at":"2025-04-12T14:04:44.951Z","repository":{"id":35724240,"uuid":"40002586","full_name":"NHSDigital/ndr_error","owner":"NHSDigital","description":"Error logging Rails engine","archived":false,"fork":false,"pushed_at":"2025-03-23T16:01:59.000Z","size":489,"stargazers_count":1,"open_issues_count":8,"forks_count":3,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-03-23T16:16:32.167Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NHSDigital.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-31T11:37:50.000Z","updated_at":"2025-03-23T16:00:31.000Z","dependencies_parsed_at":"2024-11-20T11:17:05.088Z","dependency_job_id":"755e7b92-ac7f-4f96-847e-d1095f65ed48","html_url":"https://github.com/NHSDigital/ndr_error","commit_stats":{"total_commits":171,"total_committers":7,"mean_commits":"24.428571428571427","dds":"0.26900584795321636","last_synced_commit":"180d26d43236a5f3b8210e1b857f7c5abeddec6f"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NHSDigital%2Fndr_error","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NHSDigital%2Fndr_error/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NHSDigital%2Fndr_error/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NHSDigital%2Fndr_error/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NHSDigital","download_url":"https://codeload.github.com/NHSDigital/ndr_error/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248578860,"owners_count":21127713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-23T02:14:00.715Z","updated_at":"2025-04-12T14:04:44.929Z","avatar_url":"https://github.com/NHSDigital.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NdrError [![Build Status](https://github.com/NHSDigital/ndr_error/workflows/Test/badge.svg)](https://github.com/NHSDigital/ndr_error/actions?query=workflow%3Atest) [![Gem Version](https://badge.fury.io/rb/ndr_error.svg)](https://rubygems.org/gems/ndr_error)\n\nThis is the NHS Digital (NHS-D) National Disease Registers (NDR) Error ruby gem. It is a \nRails engine that provides error logging, viewing, and grouping capabilities.\n\nExceptions are logged as `NdrError::Log` records, which can be associated by instances\n`NdrError::Fingerprint`. Grouping is done by fuzzy matching of exception description and backtrace.\nThe grouping used can be customised by the host application (see below).\n\n## Installation / Setup\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'ndr_error'\n```\n\nAnd then execute:\n\n    $ bundle\n\n### Schema setup\n\n`NdrError` bundles two migrations, for adding `ERROR_LOG` and `ERROR_FINGERPRINT` tables. These\ncan be cloned from the engine into the host application's `db/migrate` folder with:\n\n    $ bundle exec rake ndr_error:install:migrations\n\nThe `ERROR_LOG` table created does not contain a column for user context, but it does require one.\nNot adding it by default allows the host application to choose a sensible name to fit in with it's\nschema. Once a column has been added, `NdrError` can be informed with `user_column=` (see below).\n\n### Error interception\n\nThere are a variety of methods for trapping exceptions in a Rails app; therefore, `NdrError` does\nnot automatically configurate itself to operate in any particular way. That said, it does bundle\na Rack application that can be used as part of the Rails exception-handling middleware.\n\nIn the host application's `application.rb`, the following configuration can be added:\n\nTo log the error, but have the host application's routing respond:\n```ruby\nconfig.exceptions_app = NdrError::Recorder.new(self.routes)\n```\nor log the error, then serve error templates from `public/` (legacy):\n```ruby\nrequire 'ndr_error/middleware/public_exceptions'\n# Configure the ActionDispatch::ShowExceptions middleware to use NdrError's exception logger:\nconfig.exceptions_app = NdrError::Middleware::PublicExceptions.new(Rails.public_path)\n```\n\n## Configuration\n\n`NdrError` is generally pre-configured with sensible defaults, but with some notable exceptions\nthat require manual setup.\n\nConfiguration | Description\n--- | ---\n`user_column` | The `ERROR_LOG` table doesn't have a user-identifying column by default. `NdrError` expects you to add one; use this variable to inform it of the column name you chose. Regardless of the column name, the attribute is aliased to `user_id`.\n`log_parameters` | A callable object that should return a hash specifying (at minimum) the `user_id`. This is invoked when an exception is being logged, to tag it with some context.\n`check_current_user_authentication` | A callable object that should return whether or not the current user should be able to view logged exceptions.\n\nOther configuration:\n\nConfiguration | Default | Description\n--- | --- | ---\n`abstract_model_class` | `ActiveRecord::Base` | An abstract model class to be used as the parent for Fingerprints and Logs.\n`exception_app_callback` | `-\u003e { true }` | A callback that is fired when an exception is being logged. Can be used for e.g. sending email notifications. Returning false will abort the logging.\n`check_current_user_permissions` | `-\u003e { true }` | A callable object that should return whether or not the current user should be able to tag / delete logged exceptions.\n`filtered_parameters` | derived from host app | The context logging tries to capture request parameters. Use this to list sensitive parameters which should not be logged.\n`hostname_identifier` | `-\u003e { 'unknown host' }` | A callable object that returns the hostname of the machine on which Rails is running.\n`database_identifier` | `-\u003e { 'unknown database' }` | A callable object that returns an identifier of the current database.\n`database_time_checker` | `-\u003e { nil }` | A callable object, which can return the current database time; if so, DB-webapp clock drift can be calculated.\n`fingerprint_threshold` | `100` | The number of full logs of a given fingerprint that should be retained, before only a counter is incremented.\n`log_grace_period` | `90.days` | The soft-delete window, after which the `ERROR_LOG` table is periodically purged.\n`compress_backtrace` | `true` | As much of the exception backtrace as possible is logged. By default, it is compressed to be make efficient use of the available space. However, if human-readability is desired, this can be disabled.\n`description_fuzzers` | ... | An array of objects which are called in order with the exception's description, in order to \"fuzz\" it for fingerprinting. By default, object details are stripped (e.g. hexidecimal identifiers).\n`ticket_url_format` | `nil` | Authorised users can tag fingerprints with a (ticket) url; if present, this configuration a regular expression to validate the format of any given URLs.\n\nFor example, in a host application initializer:\n\n```ruby\n# Configure user:\nNdrError.user_column    = :person_id\nNdrError.log_parameters = lambda do |request|\n  { user_id: Person.currently_authenticated.try(:id) || request.user_id || 'N/A' }\nend\n\n# Remove SQL from Oracle exceptions:\nNdrError.description_fuzzers.unshift(lambda { |description|\n  description.gsub(/(OCIError: ORA-[0-9]*:)(.*)/m, '\\1')\n})  \n```\n\n## Contributing\n\n1. Fork it ( https://github.com/NHSDigital/ndr_error/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n### RuboCop\nThis project is configured to use RuboCop. Please ensure any contributions meet style guides,\nwherever possible. You can run RuboCop with:\n\n    $ rubocop .\n\n### Coverage\nTest coverage is measured by `simplecov` as part of the test suite. Its output can be viewed with:\n\n    $ open coverage/index.html\n\nPlease note that this project is released with a Contributor Code of Conduct. By participating\nin this project you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhsdigital%2Fndr_error","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhsdigital%2Fndr_error","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhsdigital%2Fndr_error/lists"}