Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breadcrumbs: Add Mongo integration #516

Merged
merged 35 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
fde94dd
Breadcrumbs/Rails integration: Initial integration implemenetation
Cawllec Dec 11, 2018
d778468
Merge branch 'breadcrumbs/base' into breadcrumbs/rails-breadcrumbs
Cawllec Dec 12, 2018
a30612f
Breadcrumbs/Rails: Minor fixes
Cawllec Dec 12, 2018
f3b5110
Merge branch 'breadcrumbs/update-reports-class' into breadcrumbs/rail…
Cawllec Dec 12, 2018
82dcd48
Breadcrumbs/Rails: Add initial maze tests
Cawllec Dec 12, 2018
6e1bbbb
Breadcrumbs/Mongo: Initial subscriber implementation
Cawllec Dec 12, 2018
23b7cfb
Breadcrumbs/Rails breadcrumbs: Remove plural event data
Cawllec Dec 12, 2018
0aae277
Breadcrumbs/Rails breadcrumbs: Ammend breadcrumb namespace
Cawllec Dec 13, 2018
ed5e05b
Breadcrumbs/Rails breadcrumbs: Remove event_id from allowed keys, cha…
Cawllec Dec 13, 2018
909d3df
Breadcrumbs/Rails breadcrumbs: Require breadcrumb file when necessary…
Cawllec Dec 13, 2018
1000ced
Breadcrumbs/Mongo integration: Fix module name issue
Cawllec Dec 13, 2018
cd49c7c
Breadcrumbs/Mongo integration: Maintain consistency with ActiveSuppor…
Cawllec Dec 13, 2018
61532e9
Breadcrumbs/Rails breadcrumbs: Fix rubocop issues
Cawllec Dec 13, 2018
537c3f1
Breadcrumbs/Rails breadcrumbs: Clarify namespaces better
Cawllec Dec 14, 2018
c2cbdea
Merge branch 'breadcrumbs/rails-breadcrumbs' into breadcrumbs/mongo-i…
Cawllec Dec 14, 2018
3f043ac
Breadcrumbs/Mongo integration: Add integration tests
Cawllec Dec 14, 2018
6fb099d
Breadcrumbs/Mongo integration: Remove example commits
Cawllec Dec 14, 2018
4dd868f
Breadcrumbs/Rails breadcrumbs: Remove invalid data from captured brea…
Cawllec Dec 17, 2018
9803713
Breadcrumbs/Mongo integration: Rubocop fixes
Cawllec Dec 17, 2018
6a5484f
Merge branch 'breadcrumbs/base' into breadcrumbs/rails-breadcrumbs
Cawllec Dec 17, 2018
1d5dd19
Merge branch 'breadcrumbs/rails-breadcrumbs' into breadcrumbs/mongo-i…
Cawllec Dec 17, 2018
cb53284
Breadcrumbs/Mongo integration: Better doc comments
Cawllec Dec 18, 2018
9e1bcd2
Breadcrumbs/Mongo integration: Improve tests, add 'failure' test
Cawllec Dec 18, 2018
1bd8b99
Breadcrumbs/Mongo integration: Re-add 'success' test
Cawllec Dec 18, 2018
064ecc8
Breadcrumbs/Rails breadcrumbs: Added ActiveJob breadcrumb test
Cawllec Dec 18, 2018
df05870
Breadcrumbs/Rails breadcrumbs: Ammended active_job event id
Cawllec Dec 18, 2018
ddd6e87
Breadcrumbs/Ruby breadcrumbs: Removed complex breadcrumb metadata
Cawllec Dec 18, 2018
2228391
Breadcrumbs/Ruby: Added cache breadcrumb
Cawllec Dec 18, 2018
59d1d58
Breadcrumbs/Ruby breadcrumbs: Fleshed out maze-test expectations wher…
Cawllec Dec 18, 2018
db28a7d
Merge branch 'breadcrumbs/rails-breadcrumbs' into breadcrumbs/mongo-i…
Cawllec Dec 18, 2018
dbdd13c
Breadcrumbs/Mongo integration: Rubocop fixes
Cawllec Dec 18, 2018
b9b13da
Breadcrumbs/Rails breadcrumbs: Fixed broken test fixture, made fixtur…
Cawllec Dec 19, 2018
c2c72f3
Merge branch 'breadcrumbs/rails-breadcrumbs' into breadcrumbs/mongo-i…
Cawllec Dec 19, 2018
dfd5ed9
Breadcrumbs/Mongo integration: Maze fixes
Cawllec Dec 19, 2018
3f90c9d
Merge branch 'breadcrumbs/base' into breadcrumbs/mongo-integration
Cawllec Dec 19, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions features/fixtures/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ services:
redis:
image: redis

mongo:
image: mongo

plain-ruby:
build:
context: plain
Expand Down Expand Up @@ -93,6 +96,8 @@ services:
args:
- RUBY_VERSION
- APP_PATH
depends_on:
- mongo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you don't have any Rails 3 + mongo tests, so this depends_on here is unnecessary.

environment:
- BUGSNAG_API_KEY
- http_proxy
Expand Down Expand Up @@ -128,6 +133,8 @@ services:
args:
- RUBY_VERSION
- APP_PATH
depends_on:
- mongo
environment:
- BUGSNAG_API_KEY
- http_proxy
Expand Down Expand Up @@ -163,6 +170,8 @@ services:
args:
- RUBY_VERSION
- APP_PATH
depends_on:
- mongo
environment:
- BUGSNAG_API_KEY
- http_proxy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class BreadcrumbsController < ActionController::Base
def initialize
@cache = ActiveSupport::Cache::MemoryStore.new
end

def handled
Bugsnag.notify("Request breadcrumb")
render json: {}
end

def sql_breadcrumb
User.take
Bugsnag.notify("SQL breadcrumb")
render json: {}
end

def cache_read
@cache.write('test', true)
@cache.read('test')
Bugsnag.notify("Cache breadcrumb")
render json: {}
end
end
1 change: 1 addition & 0 deletions features/fixtures/rails3/app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
get "/send_code/(:action)", controller: 'send_code'
get "/send_environment/(:action)", controller: 'send_environment'
get "/warden/(:action)", controller: 'warden'
get "/breadcrumbs/(:action)", controller: 'breadcrumbs'
get "/(:action)", controller: 'application'
end
4 changes: 3 additions & 1 deletion features/fixtures/rails4/app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ end
# Added at 2018-03-26 15:02:53 +0100 by amoinet:
gem 'bugsnag', path: '/bugsnag'

gem 'devise'
gem 'devise'

gem "mongoid", '~> 5.4.0'
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class BreadcrumbsController < ActionController::Base
def initialize
@cache = ActiveSupport::Cache::MemoryStore.new
end

def handled
Bugsnag.notify("Request breadcrumb")
render json: {}
end

def sql_breadcrumb
User.take
Bugsnag.notify("SQL breadcrumb")
render json: {}
end

def active_job
ApplicationJob.perform_later
render json: {}
end

def cache_read
@cache.write('test', true)
@cache.read('test')
Bugsnag.notify("Cache breadcrumb")
render json: {}
end
end
17 changes: 17 additions & 0 deletions features/fixtures/rails4/app/app/controllers/mongo_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class MongoController < ActionController
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should inherit from ApplicationController, not ActionController (same with the rails5 app)


def success_crash
doc = MongoModel.create(string_field: "String")
doc.save
"Statement".prepnd("Failing")
end

def failure_crash
begin
Mongoid::Clients.default.database.command(:bogus => 1)
rescue
end

"Statement".prepnd("Failing")
end
end
5 changes: 5 additions & 0 deletions features/fixtures/rails4/app/app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ApplicationJob < ActiveJob::Base
def perform
Bugsnag.notify("Failed")
end
end
5 changes: 5 additions & 0 deletions features/fixtures/rails4/app/app/models/mongo_model.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class MongoModel
include Mongoid::Document

field :string_field, type: String
end
22 changes: 22 additions & 0 deletions features/fixtures/rails4/app/config/mongoid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
development:
# Configure available database clients. (required)
clients:
# Defines the default client. (required)
default:
# Defines the name of the default database that Mongoid can connect to.
# (required).
database: rails4_development
# Provides the hosts the default client can connect to. Must be an array
# of host:port pairs. (required)
hosts:
- mongo:27017
test:
clients:
default:
database: rails4_test
hosts:
- mongo:27018
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 27017 instead? (although I guess the maze-runner tests don't run test suites themselves, so this is probably doesn't matter)

options:
read:
mode: :primary
max_pool_size: 1
2 changes: 2 additions & 0 deletions features/fixtures/rails4/app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
get "/send_code/(:action)", controller: 'send_code'
get "/send_environment/(:action)", controller: 'send_environment'
get "/devise/(:action)", controller: 'devise'
get "/breadcrumbs/(:action)", controller: 'breadcrumbs'
get "/mongo/(:action)", controller: 'mongo'
end
2 changes: 2 additions & 0 deletions features/fixtures/rails5/app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ gem 'bugsnag', path: '/bugsnag'

# Added at 2018-04-26 10:20:10 +0100 by amoinet:
gem "clearance", "~> 1.16"

gem "mongoid"
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class BreadcrumbsController < ActionController::Base
protect_from_forgery with: :exception

def initialize
@cache = ActiveSupport::Cache::MemoryStore.new
end

def handled
Bugsnag.notify("Request breadcrumb")
render json: {}
end

def sql_breadcrumb
User.take
Bugsnag.notify("SQL breadcrumb")
render json: {}
end

def active_job
ApplicationJob.perform_later
render json: {}
end

def cache_read
@cache.write('test', true)
@cache.read('test')
Bugsnag.notify("Cache breadcrumb")
render json: {}
end

def action_mailer
Bugsnag.notify("Mailer breadcrumb")
render json: {}
end
end
16 changes: 16 additions & 0 deletions features/fixtures/rails5/app/app/controllers/mongo_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class MongoController < ActionController
def success_crash
doc = MongoModel.create(string_field: "String")
doc.save
"Statement".prepnd("Failing")
end

def failure_crash
begin
Mongoid::Clients.default.database.command(:bogus => 1)
rescue
end

"Statement".prepnd("Failing")
end
end
3 changes: 3 additions & 0 deletions features/fixtures/rails5/app/app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class ApplicationJob < ActiveJob::Base
def perform
Bugsnag.notify("Failed")
end
end
5 changes: 5 additions & 0 deletions features/fixtures/rails5/app/app/models/mongo_model.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class MongoModel
include Mongoid::Document

field :string_field, type: String
end
23 changes: 23 additions & 0 deletions features/fixtures/rails5/app/config/mongoid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
development:
# Configure available database clients. (required)
clients:
# Defines the default client. (required)
default:
# Defines the name of the default database that Mongoid can connect to.
# (required).
database: rails5_development
# Provides the hosts the default client can connect to. Must be an array
# of host:port pairs. (required)
hosts:
- mongo:27017

test:
clients:
default:
database: rails5_test
hosts:
- mongo:27017
options:
read:
mode: :primary
max_pool_size: 1
8 changes: 8 additions & 0 deletions features/fixtures/rails5/app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,12 @@
get 'clearance/create', to: 'clearance#create'
get 'clearance/unhandled', to: 'clearance#unhandled'
get 'clearance/handled', to: 'clearance#handled'

get 'breadcrumbs/handled', to: 'breadcrumbs#handled'
get 'breadcrumbs/sql_breadcrumb', to: 'breadcrumbs#sql_breadcrumb'
get 'breadcrumbs/active_job', to: 'breadcrumbs#active_job'
get 'breadcrumbs/cache_read', to: 'breadcrumbs#cache_read'

get 'mongo/success_crash', to: 'mongo#success_crash'
get 'mongo/failure_crash', to: 'mongo#failure_crash'
end
106 changes: 106 additions & 0 deletions features/rails_features/breadcrumbs.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
Feature: Rails automatic breadcrumbs

Background:
Given I set environment variable "BUGSNAG_API_KEY" to "a35a2a72bd230ac0aa0f52715bbdc6aa"
And I set environment variable "APP_PATH" to "/usr/src"
And I configure the bugsnag endpoint

Scenario Outline: Request breadcrumb
Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
And I start the service "rails<rails_version>"
And I wait for the app to respond on port "6128<rails_version>"
When I navigate to the route "/breadcrumbs/handled" on port "6128<rails_version>"
Then I should receive a request
And the request is a valid for the error reporting API
And the request used the "Ruby Bugsnag Notifier" notifier
And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event has a "request" breadcrumb named "Controller started processing"
And the event "breadcrumbs.0.timestamp" is a timestamp
And the event "breadcrumbs.0.metaData.controller" equals "BreadcrumbsController"
And the event "breadcrumbs.0.metaData.action" equals "handled"
And the event "breadcrumbs.0.metaData.method" equals "GET"
And the event "breadcrumbs.0.metaData.path" equals "/breadcrumbs/handled"
And the event "breadcrumbs.0.metaData.event_name" equals "start_processing.action_controller"

Examples:
| ruby_version | rails_version |
| 2.0 | 3 |
| 2.1 | 3 |
| 2.2 | 3 |
| 2.2 | 4 |
| 2.2 | 5 |
| 2.3 | 3 |
| 2.3 | 4 |
| 2.3 | 5 |
| 2.4 | 3 |
| 2.4 | 5 |
| 2.5 | 3 |
| 2.5 | 5 |

Scenario Outline: SQL Breadcrumb
Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
And I start the service "rails<rails_version>"
And I wait for the app to respond on port "6128<rails_version>"
When I navigate to the route "/breadcrumbs/sql_breadcrumb" on port "6128<rails_version>"
Then I should receive a request
And the request is a valid for the error reporting API
And the request used the "Ruby Bugsnag Notifier" notifier
And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event has a "process" breadcrumb named "ActiveRecord SQL query"

Examples:
| ruby_version | rails_version |
| 2.0 | 3 |
| 2.1 | 3 |
| 2.2 | 3 |
| 2.2 | 4 |
| 2.2 | 5 |
| 2.3 | 3 |
| 2.3 | 4 |
| 2.3 | 5 |
| 2.4 | 3 |
| 2.4 | 5 |
| 2.5 | 3 |
| 2.5 | 5 |

Scenario Outline: Active job breadcrumb
Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
And I start the service "rails<rails_version>"
And I wait for the app to respond on port "6128<rails_version>"
When I navigate to the route "/breadcrumbs/active_job" on port "6128<rails_version>"
Then I should receive a request
And the request is a valid for the error reporting API
And the request used the "Ruby Bugsnag Notifier" notifier
And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event has a "process" breadcrumb named "Start perform ActiveJob"
And the event "breadcrumbs.0.timestamp" is a timestamp
And the event "breadcrumbs.0.metaData.event_name" equals "perform_start.active_job"

Examples:
| ruby_version | rails_version |
| 2.2 | 4 |
| 2.2 | 5 |
| 2.3 | 4 |
| 2.3 | 5 |
| 2.4 | 5 |
| 2.5 | 5 |

Scenario Outline: Cache read
Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
And I start the service "rails<rails_version>"
And I wait for the app to respond on port "6128<rails_version>"
When I navigate to the route "/breadcrumbs/cache_read" on port "6128<rails_version>"
Then I should receive a request
And the request is a valid for the error reporting API
And the request used the "Ruby Bugsnag Notifier" notifier
And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event has a "process" breadcrumb named "Read cache"

Examples:
| ruby_version | rails_version |
| 2.2 | 4 |
| 2.2 | 5 |
| 2.3 | 4 |
| 2.3 | 5 |
| 2.4 | 5 |
| 2.5 | 5 |
Loading