Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HoptoadNotifier logging, Rack middleware
- Loading branch information
Showing
9 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
require 'log_weasel/transaction' | ||
require 'log_weasel/resque' | ||
require 'log_weasel/buffered_logger' | ||
require 'log_weasel/hoptoad_notifier' | ||
require 'log_weasel/middleware' | ||
require 'log_weasel/resque' | ||
|
||
class << ::HoptoadNotifier | ||
include LogWeasel::HoptoadNotifier; | ||
end if defined? ::HoptoadNotifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module LogWeasel::HoptoadNotifier | ||
def notify_with_transaction_id(exception, opts = {}) | ||
add_transaction_id(opts) if LogWeasel::Transaction.id | ||
notify_without_transaction_id exception, opts | ||
end | ||
|
||
def notify_or_ignore_with_transaction_id(exception, opts = {}) | ||
add_transaction_id(opts) if LogWeasel::Transaction.id | ||
notify_or_ignore_without_transaction_id exception, opts | ||
end | ||
|
||
def add_transaction_id(opts) | ||
opts[:parameters] ||= {} | ||
opts[:parameters]['log_weasel_id'] = LogWeasel::Transaction.id | ||
end | ||
|
||
def self.included(base) | ||
base.send :alias_method, :notify_without_transaction_id, :notify | ||
base.send :alias_method, :notify, :notify_with_transaction_id | ||
base.send :alias_method, :notify_or_ignore_without_transaction_id, :notify_or_ignore | ||
base.send :alias_method, :notify_or_ignore, :notify_or_ignore_with_transaction_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class LogWeasel::Middleware | ||
def initialize(app, options = {}) | ||
@app = app | ||
@key = options[:key] || 'RAILS' | ||
end | ||
|
||
def call(env) | ||
LogWeasel::Transaction.create "#{@key}-WEB" | ||
@app.call(env) | ||
ensure | ||
LogWeasel::Transaction.destroy | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
require 'hoptoad_notifier' | ||
require 'log_weasel/hoptoad_notifier' | ||
|
||
describe LogWeasel::HoptoadNotifier do | ||
before do | ||
class << ::HoptoadNotifier | ||
include LogWeasel::HoptoadNotifier; | ||
end if defined? ::HoptoadNotifier | ||
|
||
HoptoadNotifier.configure {} | ||
LogWeasel::Transaction.stubs(:id).returns('123') | ||
end | ||
|
||
it "adds transaction id to parameters with no parameters" do | ||
HoptoadNotifier.expects(:send_notice).with do |notice| | ||
notice.parameters.should have_key('log_weasel_id') | ||
end | ||
HoptoadNotifier.notify(RuntimeError.new('failure')) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters