-
Notifications
You must be signed in to change notification settings - Fork 174
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
Changes from 31 commits
fde94dd
d778468
a30612f
f3b5110
82dcd48
6e1bbbb
23b7cfb
0aae277
ed5e05b
909d3df
1000ced
cd49c7c
61532e9
537c3f1
c2cbdea
3f043ac
6fb099d
4dd868f
9803713
6a5484f
1d5dd19
cb53284
9e1bcd2
1bd8b99
064ecc8
df05870
ddd6e87
2228391
59d1d58
db28a7d
dbdd13c
b9b13da
c2c72f3
dfd5ed9
3f90c9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class MongoController < ActionController | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should inherit from |
||
|
||
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 |
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 |
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 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 |
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 |
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 |
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 |
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 |
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 | |
There was a problem hiding this comment.
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.