rootstrap / exception_hunter

Crash reporting engine to hunt down bugs 🐞
https://rootstrap.com
MIT License
81 stars 7 forks source link

Adding exception hunter breaks the apartment gem #97

Open CR1AT0RS opened 4 years ago

CR1AT0RS commented 4 years ago

Bug report:

from /Users/narya/.rvm/gems/ruby-2.7.1/gems/activerecord-6.0.3.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:92:in `async_exec' Caused by PG::UndefinedObject: ERROR: operator class "gin_trgm_ops" does not exist for access method "gin"

from /Users/narya/.rvm/gems/ruby-2.7.1/gems/activerecord-6.0.3.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:92:in `async_exec'


* **Steps to Reproduce**: 
  1. install apartment gem: https://github.com/rails-on-services/apartment
  2. bundle exec rails generate apartment:install 
  3. Bind to user model etc.
  4. Apartment::Tenant.create('atlas')

* **Version of the repo**: latest
* **Ruby and Rails Version**: 2.7.1 and 6.0.3
* **Rails Stacktrace**: this can be found in the `log/development.log` or `log/test.log`, if this is applicable.

The problem is that its not able to copy the schema from the exception_hunter gem

I have tried testing this with different rails api projects and all gems except the "exception_hunter_error" table. It breaks on that. I have postgres with "gin_trgm_ops"
CR1AT0RS commented 4 years ago

Commenting out these in schema.rb resolves the issue:

  # create_table "exception_hunter_error_groups", force: :cascade do |t|
  #   t.string "error_class_name", null: false
  #   t.string "message"
  #   t.integer "status", default: 0
  #   t.text "tags", default: [], array: true
  #   t.datetime "created_at", precision: 6, null: false
  #   t.datetime "updated_at", precision: 6, null: false
  #   t.index ["message"], name: "index_exception_hunter_error_groups_on_message", opclass: :gin_trgm_ops, using: :gin
  #   t.index ["status"], name: "index_exception_hunter_error_groups_on_status"
  # end

  # create_table "exception_hunter_errors", force: :cascade do |t|
  #   t.string "class_name", null: false
  #   t.string "message"
  #   t.datetime "occurred_at", null: false
  #   t.json "environment_data"
  #   t.json "custom_data"
  #   t.json "user_data"
  #   t.string "backtrace", default: [], array: true
  #   t.bigint "error_group_id"
  #   t.datetime "created_at", precision: 6, null: false
  #   t.datetime "updated_at", precision: 6, null: false
  #   t.index ["error_group_id"], name: "index_exception_hunter_errors_on_error_group_id"
  # end

 # add_foreign_key "exception_hunter_errors", "exception_hunter_error_groups", column: "error_group_id"
brunvez commented 4 years ago

Hey @CR1AT0RS, thanks for reporting this issue!. It doesn't seem to be related to the gem itself but rather to Postgres. Exception Hunter uses the pg_trgm module from Postgres to quickly index error messages and search them by similarity (kind of like Elasticsearch does).

This module should be installed by default but it may not be present on your system, could you tell me which operating system are you using, Postgres' version, and how did you install it?

You can also check for instructions to enable the module in this issue, it seems you only need to run CREATE EXTENSION pg_trgm; inside a psql session.

CR1AT0RS commented 4 years ago

@brunvez thanks for responding.

I have the extensions enabled. I am using OSX postgres.app which comes precompiled with the extensions. I am on rails 6.0.3 and ruby 2.7.1. Interestingly if I run the migrations manually to create a new schema it works but when I use the default "apartment" based migration creation it faiils.

This works:

      t.index :message, using: :gin

This doesn't work:

      t.index :message, opclass: :gin_trgm_ops, using: :gin

Migration name: 20200716171440_create_exception_hunter_error_groups.rb

class CreateExceptionHunterErrorGroups < ActiveRecord::Migration[6.0]
  def change
    enable_extension :pg_trgm

    create_table :exception_hunter_error_groups do |t|
      t.string :error_class_name, null: false
      t.string :message
      t.integer :status, default: 0
      t.text :tags, array: true, default: []

      t.timestamps

      t.index :message, opclass: :gin_trgm_ops, using: :gin
      t.index :status
    end
  end
end