log_weasel 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +87 -4
- data/lib/log_weasel/middleware.rb +2 -2
- data/lib/log_weasel/resque.rb +6 -4
- data/lib/log_weasel/version.rb +1 -1
- data/spec/log_weasel/resque_spec.rb +1 -1
- metadata +6 -6
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Log Weasel
|
2
2
|
|
3
|
-
Instrument Rails and Resque with shared transaction IDs so that you trace execution
|
3
|
+
Instrument Rails and Resque with shared transaction IDs so that you trace execution of a unit of work across
|
4
|
+
applications and application instances.
|
5
|
+
This particularly handy if you're using a system like <a href="http://www.splunk.com">Splunk</a> to manage your log
|
6
|
+
files across many applications and application instances.
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -18,7 +21,8 @@ bundle install
|
|
18
21
|
|
19
22
|
## Rack
|
20
23
|
|
21
|
-
Log Weasel provides Rack middleware to create and destroy a transaction for every HTTP request.
|
24
|
+
Log Weasel provides Rack middleware to create and destroy a transaction for every HTTP request. You can use it
|
25
|
+
in a any web framework that supports Rack (Rails, Sinatra,...)
|
22
26
|
|
23
27
|
### Rails 3
|
24
28
|
|
@@ -38,17 +42,96 @@ YourApp::Application.configure do
|
|
38
42
|
end
|
39
43
|
</pre>
|
40
44
|
|
45
|
+
<code>:key</code> is an optional parameter that is useful in an environment where a unit of work may span multiple applications.
|
46
|
+
|
41
47
|
## Resque
|
42
48
|
|
43
49
|
To see Log Weasel transaction IDs in your Resque logs, you need to need to initialize Log Weasel
|
44
50
|
when you configure Resque, for example in a Rails initializer.
|
45
51
|
|
46
52
|
<pre>
|
47
|
-
LogWeasel::Resque.initialize! 'YOUR_APP'
|
53
|
+
LogWeasel::Resque.initialize! :key => 'YOUR_APP'
|
54
|
+
</pre>
|
55
|
+
|
56
|
+
Start your Resque worker with <code>VERBOSE=1</code> and you'll see transaction IDs in your Resque logs.
|
57
|
+
|
58
|
+
## Hoptoad
|
59
|
+
|
60
|
+
If you are using <a href="http://hoptoadapp.com">Hoptoad</a>, Log Weasel will add the parameter <code>log_weasel_id</code>
|
61
|
+
to Hoptoad errors so that you can track execution through your application stack that resulted in the error. No additional
|
62
|
+
configuration required.
|
63
|
+
|
64
|
+
## Example
|
65
|
+
|
66
|
+
In this example we have a Rails app pushing jobs to Resque and a Resque worker that run with the Rails environment loaded.
|
67
|
+
|
68
|
+
### HelloController
|
69
|
+
|
70
|
+
<pre>
|
71
|
+
class HelloController < ApplicationController
|
72
|
+
|
73
|
+
def index
|
74
|
+
Resque.enqueue EchoJob, 'hello from HelloController'
|
75
|
+
Rails.logger.info("HelloController#index: pushed EchoJob")
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
</pre>
|
80
|
+
|
81
|
+
### EchoJob
|
82
|
+
|
83
|
+
<pre>
|
84
|
+
class EchoJob
|
85
|
+
@queue = :default_queue
|
86
|
+
|
87
|
+
def self.perform(args)
|
88
|
+
Rails.logger.info("EchoJob.perform: #{args.inspect}")
|
89
|
+
end
|
90
|
+
end
|
48
91
|
</pre>
|
49
92
|
|
93
|
+
Start Resque with:
|
94
|
+
|
95
|
+
<pre>
|
96
|
+
QUEUE=default_queue rake resque:work VERBOSE=1
|
97
|
+
</pre>
|
98
|
+
|
99
|
+
Requesting <code>http://localhost:3030/hello/index</code>, our development log shows:
|
100
|
+
|
101
|
+
<pre>
|
102
|
+
[2011-02-14 14:37:42] YOUR_APP-WEB-192587b585fa66b19638 48353 INFO
|
103
|
+
|
104
|
+
Started GET "/hello/index" for 127.0.0.1 at 2011-02-14 14:37:42 -0800
|
105
|
+
[2011-02-14 14:37:42] YOUR_APP-WEB-192587b585fa66b19638 48353 INFO Processing by HelloController#index as HTML
|
106
|
+
[2011-02-14 14:37:42] YOUR_APP-WEB-192587b585fa66b19638 48353 INFO HelloController#index: pushed EchoJob
|
107
|
+
[2011-02-14 14:37:42] YOUR_APP-WEB-192587b585fa66b19638 48353 INFO Rendered hello/index.html.erb within layouts/application (1.8ms)
|
108
|
+
[2011-02-14 14:37:42] YOUR_APP-WEB-192587b585fa66b19638 48353 INFO Completed 200 OK in 14ms (Views: 6.4ms | ActiveRecord: 0.0ms)
|
109
|
+
[2011-02-14 14:37:45] YOUR_APP-WEB-192587b585fa66b19638 48461 INFO EchoJob.perform: "hello from HelloController"
|
110
|
+
</pre>
|
111
|
+
|
112
|
+
Fire up a Rails console and push a job directly with:
|
113
|
+
|
114
|
+
<pre>
|
115
|
+
> Resque.enqueue EchoJob, 'hi from Rails console'
|
116
|
+
</pre>
|
117
|
+
|
118
|
+
and our development log shows:
|
119
|
+
|
120
|
+
<pre>
|
121
|
+
[2011-02-14 14:37:10] YOUR_APP-RESQUE-a8e54bfb76718d09f8ed 48453 INFO EchoJob.perform: "hi from Rails console"
|
122
|
+
</pre>
|
123
|
+
|
124
|
+
Units of work initiated from Resque, for example if using a scheduler like
|
125
|
+
<a href="https://github.com/bvandenbos/resque-scheduler">resque-scheduler</a>,
|
126
|
+
will include 'RESQUE' in the transaction ID to indicate that the work started in Resque.
|
127
|
+
|
128
|
+
## Contributing
|
129
|
+
|
130
|
+
If you would like to contribute a fix or integrate Log Weasel transaction tracking into another frameworks
|
131
|
+
please fork the code, add the fix or feature in your local project and then send a pull request on github.
|
132
|
+
Please ensure that you include a test which verifies your changes.
|
50
133
|
|
51
134
|
|
52
135
|
## LICENSE
|
53
136
|
|
54
|
-
|
137
|
+
Copyright (c) 2011 Carbon Five. See LICENSE for details.
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class LogWeasel::Middleware
|
2
2
|
def initialize(app, options = {})
|
3
3
|
@app = app
|
4
|
-
@key = options[:key]
|
4
|
+
@key = options[:key] ? "#{options[:key]}-WEB" : "WEB"
|
5
5
|
end
|
6
6
|
|
7
7
|
def call(env)
|
8
|
-
LogWeasel::Transaction.create
|
8
|
+
LogWeasel::Transaction.create @key
|
9
9
|
@app.call(env)
|
10
10
|
ensure
|
11
11
|
LogWeasel::Transaction.destroy
|
data/lib/log_weasel/resque.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module LogWeasel::Resque
|
2
2
|
|
3
|
-
def self.initialize!(
|
3
|
+
def self.initialize!(options = {})
|
4
4
|
::Resque::Worker.send(:include, LogWeasel::Resque::Worker)
|
5
5
|
::Resque::Job.send(:include, LogWeasel::Resque::Job)
|
6
6
|
::Resque.extend(LogWeasel::Resque::ClassMethods)
|
7
7
|
|
8
|
+
key = options[:key] ? "#{options[:key]}-RESQUE" : "RESQUE"
|
9
|
+
|
8
10
|
::Resque.after_fork do |job|
|
9
11
|
LogWeasel::Resque::Callbacks.after_fork job, key
|
10
12
|
end
|
@@ -19,12 +21,12 @@ module LogWeasel::Resque
|
|
19
21
|
if job.context && job.context.has_key?('log_weasel_id')
|
20
22
|
LogWeasel::Transaction.id = job.context['log_weasel_id']
|
21
23
|
else
|
22
|
-
LogWeasel::Transaction.create
|
24
|
+
LogWeasel::Transaction.create key
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
28
|
def self.before_push(queue, item, key)
|
27
|
-
item['context'] = {'log_weasel_id' => (LogWeasel::Transaction.id || LogWeasel::Transaction.create(
|
29
|
+
item['context'] = {'log_weasel_id' => (LogWeasel::Transaction.id || LogWeasel::Transaction.create(key))}
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
@@ -56,7 +58,7 @@ module LogWeasel::Resque
|
|
56
58
|
|
57
59
|
module Worker
|
58
60
|
def log_with_transaction_id(message)
|
59
|
-
log_without_transaction_id "
|
61
|
+
log_without_transaction_id "#{LogWeasel::Transaction.id} #{message}"
|
60
62
|
end
|
61
63
|
|
62
64
|
def self.included(base)
|
data/lib/log_weasel/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Alon Salant
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-15 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -128,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
hash:
|
131
|
+
hash: -994140046389382350
|
132
132
|
segments:
|
133
133
|
- 0
|
134
134
|
version: "0"
|
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
137
|
requirements:
|
138
138
|
- - ">="
|
139
139
|
- !ruby/object:Gem::Version
|
140
|
-
hash:
|
140
|
+
hash: -994140046389382350
|
141
141
|
segments:
|
142
142
|
- 0
|
143
143
|
version: "0"
|
@@ -147,7 +147,7 @@ rubyforge_project: log_weasel
|
|
147
147
|
rubygems_version: 1.3.7
|
148
148
|
signing_key:
|
149
149
|
specification_version: 3
|
150
|
-
summary: log_weasel-0.0.
|
150
|
+
summary: log_weasel-0.0.5
|
151
151
|
test_files:
|
152
152
|
- spec/log_weasel/buffered_logger_spec.rb
|
153
153
|
- spec/log_weasel/hoptoad_notifier_spec.rb
|