kaeruera 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f10a4c75cdcc7a510f985a61bc48182c27071f89
4
+ data.tar.gz: 623fd3a7f3f5e74b468b539c57740303e2d41418
5
+ SHA512:
6
+ metadata.gz: 8212e3adfe8d95d3264bdd53422fed401a09782bf62212e0612c73453e778989d2fbf26a8b6dcd218bf4d7a83f099213631a19c6ed98f7a1713c821be0507eae
7
+ data.tar.gz: 4e6fee570e76659f25fa767bd190bfdad0669eb95914cef3f4a9bf8c99a0fcb0b5087ca697cdf04ea63e3e7e992dae21b6b20d96e2bd4ed73cfc143860a3cd70
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ === 0.1.0
2
+
3
+ * Initial Public Release
data/MIT-LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2013 Jeremy Evans
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,296 @@
1
+ = KaeruEra
2
+
3
+ KaeruEra is a bare-bones error tracking application for ruby, tracking
4
+ errors that occur in other ruby applications.
5
+
6
+ It is similar to Errbit[1] but with a much smaller feature set. The
7
+ only advantages that KaeruEra has over Errbit are more advanced
8
+ search features, fewer dependencies, and a smaller footprint. There
9
+ are no notification features, source control integration, issue tracker
10
+ integration, user information tracking, deploy tracking, or GitHub/LDAP
11
+ authentication. You are responsible for manually integrating the error
12
+ reporter into the applications that will be reporting errors.
13
+
14
+ As another example of the simplicity, KaeruEra does not do error
15
+ aggregation. Instead, for each error, it offers the ability to easily
16
+ search for errors with the same class, message, backtrace line, etc..
17
+ Any results of that search can be manipulated as a unit.
18
+
19
+ KaeruEra is not designed to replace an existing error tracking
20
+ application. It's designed to supplement an email notification
21
+ about the error.
22
+
23
+ 1. (https://github.com/errbit/errbit)
24
+
25
+ == Demo
26
+
27
+ * URL: http://kaeruera.herokuapp.com
28
+ * Login Email: demo
29
+ * Login Password: demo
30
+
31
+ == Source Control/Issue Tracker
32
+
33
+ https://github.com/jeremyevans/kaeruera
34
+
35
+ == License
36
+
37
+ KaeruEra is licensed under the MIT License.
38
+
39
+ == Design
40
+
41
+ The KaeruEra database and web server have a fairly simple design.
42
+ There are only three tables in the database, users, applications,
43
+ and errors. Each user can have multiple applications, and each
44
+ application multiple errors.
45
+
46
+ In the database, each error is stored is a single row, document
47
+ style. This uses PostgreSQL's advanced types, storing the
48
+ backtrace for the error as an array of text fields (text[]),
49
+ the environment as an hstore (string key/string value hash table),
50
+ and the params and session information as json (since they often
51
+ contain nested data). All of the error columns are indexed for
52
+ easy searching.
53
+
54
+ The web site has a very basic bootstrap design, with only 4 main
55
+ pages:
56
+
57
+ * Front page (choose an application)
58
+ * Search page (options for each search field)
59
+ * Error List page (see open errors for applications/search results)
60
+ * Error page (see all information about a particular error,
61
+ with links to perform searches for similar errors)
62
+
63
+ === Error Information Tracked
64
+
65
+ * Exception Class
66
+ * Exception Message
67
+ * Exception Backtrace
68
+ * Params
69
+ * Environment Variables
70
+ * Session Variables
71
+
72
+ The exception class, message, and backtrace are required and are
73
+ taken from the underlying ruby exception.
74
+
75
+ The params, environment, and session information are optional, and
76
+ you have to configure the reporting code to include the
77
+ information.
78
+
79
+ === Updating Errors
80
+
81
+ Most information for errors is immutable. The two exceptions are that each error has a notes
82
+ field and an open/closed flag. As long as the error is open, the notes flag can be updated and
83
+ it can be closed. Once it is closed, the error is completely immutable.
84
+
85
+ == Reporting Errors
86
+
87
+ KaeruEra is not airbrake compatible. Instead, it offers separate
88
+ libraries for reporting errors. All libraries are shipped in the
89
+ kaeruera gem, installable via:
90
+
91
+ gem install kaeruera
92
+
93
+ === KaeruEra::DatabaseReporter
94
+
95
+ This library assumes you can have a direct connection to the
96
+ database, and inserts the error directly into the database.
97
+
98
+ require 'kaeruera/database_reporter'
99
+ REPORTER = KaeruEra::DatabaseReporter.new('postgres://db_user:pass@host:port/database', 'email@example.com', 'app_name')
100
+
101
+ Here db_user is the PostgreSQL user name for the connection, email
102
+ is the email address for the user account in the KaeruEra application,
103
+ and app_name is the application name in KaeruEra.
104
+
105
+ === KaeruEra::Reporter
106
+
107
+ This library uploads the error information to a server
108
+ running the web application, via json.
109
+
110
+ require 'kaeruera/reporter'
111
+ REPORTER = KaeruEra::Reporter.new('http://host:port/report_error', application_id, 'application_token')
112
+
113
+ You can use the "Reporter Info" page in the web application to get a line that will work for the given
114
+ application.
115
+
116
+ === KaeruEra::AsyncReporter
117
+
118
+ This library is the same as the KaeruEra::Reporter library,
119
+ except it runs asynchronously, useful if the application does
120
+ not have a fast connection to the KaeruEra server. The downside
121
+ is you don't get the id of the error, and are not notified
122
+ if there was a problem reporting the error.
123
+
124
+ require 'kaeruera/async_reporter'
125
+ REPORTER = KaeruEra::AsyncReporter.new('http://host:port/report_error', application_id, 'application_token')
126
+
127
+ === Usage
128
+
129
+ All three libraries for reporting errors have the same API:
130
+
131
+ REPORTER.report
132
+
133
+ If called without arguments, it assumes that $! is the error to report. This makes it easy to use
134
+ in a rescue block:
135
+
136
+ begin
137
+ #code
138
+ rescue
139
+ REPORTER.report
140
+ end
141
+
142
+ If the error you want to report is not in $!, you can pass it via the :error option:
143
+
144
+ begin
145
+ #code
146
+ rescue => e
147
+ begin
148
+ #more code
149
+ rescue
150
+ REPORTER.report(:error => e)
151
+ end
152
+ end
153
+
154
+ The params, session, and environment variables are all passed as options :params, :session, and :env.
155
+ In each case the values for those options should be hashes.
156
+
157
+ As reporters are designed to be used in rescue blocks, they swallow any errors raised internally,
158
+ since the assumption is that it is better to raise the original error in that case.
159
+
160
+ The return value of the reporting methods is one of the following:
161
+
162
+ Integer :: The id of the error, indicating the error was successfully reported.
163
+ false :: There was no error detected (:error option was not set and $! did not indicate an active error)
164
+ true :: The async reporter received a valid error (it cannot tell whether the error was successfully reported).
165
+ StandardError :: an exception occurred when trying to report the error, the return value is the exception.
166
+
167
+ === Sinatra
168
+
169
+ If the application reporting errors is running sinatra, you can probably put this in your error block
170
+ to report errors to KaeruEra:
171
+
172
+ REPORTER.report(:params=>params, :env=>env, :session=>session, :error=>request.env['sinatra.error'])
173
+
174
+ == Runtime Dependencies
175
+
176
+ === KaeruEra::App (web server)
177
+
178
+ * PostgreSQL 9.2+
179
+ * pg
180
+ * sinatra
181
+ * sinatra-flash
182
+ * sequel
183
+ * bcrypt-ruby
184
+ * forme
185
+ * json
186
+ * rack_csrf
187
+ * rack-compatible web server
188
+
189
+ === KaeruEra::DatabaseReporter
190
+
191
+ * pg
192
+ * sequel
193
+
194
+ === KaeruEra::Reporter / KaeruEra::AsyncReporter
195
+
196
+ * rest-client
197
+ * json
198
+
199
+ == Heroku Setup
200
+
201
+ heroku create
202
+ heroku addons:add heroku-postgresql:dev
203
+ heroku pg:promote HEROKU_POSTGRESQL_COLOR_URL
204
+ git push heroku master
205
+ echo 'CREATE EXTENSION hstore' | heroku pg:psql
206
+ heroku run rake production_up
207
+ heroku config:set KAERUERA_SECRET=`ruby -rsecurerandom -e 'puts SecureRandom.hex(30)'`
208
+ heroku run irb -r ./models
209
+ irb> User.create(:email=>'foo', :password=>'bar')
210
+
211
+ == Manual Setup
212
+
213
+ === Database Setup
214
+
215
+ First, copy the example database configuration file:
216
+
217
+ cp db_config.rb.example db_config.rb
218
+
219
+ The rest of the instructions assume you are not modifying the
220
+ default database configuration, and that the database super user
221
+ for your PostgreSQL database cluster is postgres. If those
222
+ assumptions are inaccurate, you should substitute the appropriate
223
+ values. Also, the examples below do not use a password for the
224
+ accounts, so they will only work if localhost is trusted in PostgreSQL.
225
+
226
+ Create a user for the application:
227
+
228
+ createuser -U postgres kaeruera
229
+
230
+ Then, create databases for the application with that user:
231
+
232
+ createdb -U postgres -O kaeruera kaeruera_development
233
+ createdb -U postgres -O kaeruera kaeruera_test
234
+ createdb -U postgres -O kaeruera kaeruera_production
235
+
236
+ If you don't have hstore as a default extension in your PostgreSQL
237
+ template database, you'll have to add it:
238
+
239
+ echo 'CREATE EXTENSION hstore' | psql -U postgres kaeruera_development
240
+ echo 'CREATE EXTENSION hstore' | psql -U postgres kaeruera_test
241
+ echo 'CREATE EXTENSION hstore' | psql -U postgres kaeruera_production
242
+
243
+ Then, you can migrate the database:
244
+
245
+ rake dev_up
246
+ rake test_up
247
+ rake production_up
248
+
249
+ === User Account Setup
250
+
251
+ In development mode, the first time the server is started, if you haven't
252
+ set up any users manually, a kaeruera user account (login/password kaeruera)
253
+ and application named KaeruEraApp will automatically be created for you.
254
+ It's recommended that you change the password for this user after logging
255
+ in for the first time in development mode.
256
+
257
+ In all other cases, you have to setup your user accounts manually:
258
+
259
+ $ irb -r ./models
260
+ User.create(:email=>'foo', :password=>'bar')
261
+
262
+ It's recommended that you have a kaeruera user and KaeruEraApp application
263
+ for that user, as that is where the web application will log any internal
264
+ errors.
265
+
266
+ === Session Secret Setup
267
+
268
+ Create the session secret file:
269
+
270
+ ruby -rsecurerandom -e 'puts SecureRandom.hex(30)' > kaeruera.secret
271
+
272
+ == Testing
273
+
274
+ To run all tests, use rake's default task:
275
+
276
+ rake
277
+
278
+ This assumes you have already created the test database and migrated the
279
+ test database to the latest version. The following are additional
280
+ requirements when running tests:
281
+
282
+ * Rspec 1
283
+ * Unicorn
284
+ * Capybara
285
+
286
+ == Naming
287
+
288
+ KaeruEra is a transliteration of the Japanese words for frog (kaeru)
289
+ and error (era). One of the first popular error reporting apps for
290
+ ruby was named Hoptoad (later renamed to Airbrake), and Errbit I'm
291
+ guessing was chosen for its similarity to ribbit (the sound a frog
292
+ makes) so this is in keeping with the frog theme.
293
+
294
+ == Author
295
+
296
+ Jeremy Evans <code@jeremyevans.net>
@@ -0,0 +1,35 @@
1
+ require 'kaeruera/reporter'
2
+ require 'thread'
3
+
4
+ module KaeruEra
5
+ # AsyncReporter reports the error to a KaeruEra
6
+ # application via HTTP, but does it asynchronously.
7
+ class AsyncReporter
8
+ # Accepts the same arguments as Reporter.
9
+ def initialize(url, application_id, token)
10
+ reporter = Reporter.new(url, application_id, token)
11
+ @queue = Queue.new
12
+ Thread.new do
13
+ loop{reporter.report(@queue.pop) rescue nil}
14
+ end
15
+ end
16
+
17
+ # If an error cannot be determined, returns false.
18
+ # Otherwise, adds the error to the queue of errors
19
+ # to handle asynchronously and returns true. If
20
+ # an exception would be raised by this code, returns
21
+ # the exception instead of raising it.
22
+ #
23
+ # Supports the same options as Reporter#report.
24
+ def report(opts={})
25
+ unless opts[:error]
26
+ return false unless $!
27
+ opts = opts.merge(:error=>$!)
28
+ end
29
+ @queue.push(opts)
30
+ true
31
+ rescue => e
32
+ e
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,58 @@
1
+ require 'sequel'
2
+
3
+ module KaeruEra
4
+ # Reporter class that inserts the error information directly
5
+ # into the database instead of reporting it to a web server via
6
+ # HTTP.
7
+ class DatabaseReporter
8
+ # Exception raised when no matching application is found in the
9
+ # database (i.e. not matching email and application).
10
+ class Error < StandardError; end
11
+
12
+ # Arguments:
13
+ # uri :: Either a Sequel::Database instance or a String treated as a URI.
14
+ # If a Sequel::Database instance is given, uses given database,
15
+ # otherwise, connects to the database specified by the URI via Sequel.
16
+ # email :: The KaeruEra email/login for the application.
17
+ # application :: The KaeruEra application name
18
+ def initialize(uri, email, application)
19
+ @db = uri.is_a?(Sequel::Database) ? uri : Sequel.connect(uri, :keep_reference=>false)
20
+ @db.extension :pg_array, :pg_hstore, :pg_json
21
+ @application_id, @user_id = @db[:applications].where(:user_id=>@db[:users].where(:email=>email).get(:id), :name=>application).get([:id, :user_id])
22
+ raise(Error, "No matching application in database for #{email}/#{application}") unless @application_id
23
+ end
24
+
25
+ # If an error cannot be determined, returns false.
26
+ # Otherwise, inserts the error directly into the
27
+ # database.
28
+ # If an exception would be raised by this code, returns
29
+ # the exception instead of raising it.
30
+ #
31
+ # Supports the same options as Reporter#report.
32
+ def report(opts={})
33
+ return false unless error = opts[:error] || $!
34
+
35
+ h = {
36
+ :user_id=>@user_id,
37
+ :application_id=>@application_id,
38
+ :error_class=>error.class.name,
39
+ :message=>error.message.to_s,
40
+ :backtrace=>Sequel.pg_array(error.backtrace)
41
+ }
42
+
43
+ if v = opts[:params]
44
+ h[:params] = Sequel.pg_json(v.to_hash)
45
+ end
46
+ if v = opts[:session]
47
+ h[:session] = Sequel.pg_json(v.to_hash)
48
+ end
49
+ if v = opts[:env]
50
+ h[:env] = Sequel.hstore(v.to_hash)
51
+ end
52
+
53
+ @db[:errors].insert(h)
54
+ rescue => e
55
+ e
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,59 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ module KaeruEra
5
+ # The standard Reporter class reports errors via HTTP requests
6
+ # to a KaeruEra web server.
7
+ class Reporter
8
+ # Arguments:
9
+ # url :: The url to use to report the error.
10
+ # application_id :: The id for the application on the KaeruEra server.
11
+ # token :: The application's token on the KaeruEra server.
12
+ #
13
+ # You can get this information from looking at the "Reporter Info"
14
+ # page on the KaeruEra server.
15
+ def initialize(url, application_id, token)
16
+ @url = url
17
+ @application_id = application_id
18
+ @token = token
19
+ end
20
+
21
+ # If an error cannot be determined, returns false.
22
+ # Otherwise, reports the error to the KaeruEra server via HTTP.
23
+ # If an exception would be raised by this code, returns
24
+ # the exception instead of raising it.
25
+ #
26
+ # Options:
27
+ # :error :: The exception to report
28
+ # :env :: The environment variables related to this exception.
29
+ # For a web application, generally the HTTP request
30
+ # environment variables.
31
+ # :params :: The params related to the exception. For a web
32
+ # application, generally the GET/POST parameters.
33
+ # :session :: Any session information to the exception.
34
+ def report(opts={})
35
+ return false unless error = opts[:error] || $!
36
+
37
+ h = {
38
+ :error_class=>error.class.name,
39
+ :message=>error.message.to_s,
40
+ :backtrace=>error.backtrace
41
+ }
42
+
43
+ if v = opts[:params]
44
+ h[:params] = v
45
+ end
46
+ if v = opts[:session]
47
+ h[:session] = v
48
+ end
49
+ if v = opts[:env]
50
+ h[:env] = v
51
+ end
52
+
53
+ res = RestClient.post @url, {:data=>h, :id=>@application_id, :token=>@token}.to_json, :content_type => :json, :accept => :json
54
+ JSON.parse(res)['error_id']
55
+ rescue => e
56
+ e
57
+ end
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kaeruera
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Evans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ KaeruEra is a simple error tracking application. This
15
+ gem includes 3 separate reporter libaries that can be
16
+ used to submit errors to KaeruEra.
17
+ email: code@jeremyevans.net
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files:
21
+ - README.rdoc
22
+ - CHANGELOG
23
+ - MIT-LICENSE
24
+ files:
25
+ - MIT-LICENSE
26
+ - CHANGELOG
27
+ - README.rdoc
28
+ - lib/kaeruera/reporter.rb
29
+ - lib/kaeruera/async_reporter.rb
30
+ - lib/kaeruera/database_reporter.rb
31
+ homepage: http://github.com/jeremyevans/kaeruera
32
+ licenses: []
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options:
36
+ - --quiet
37
+ - --line-numbers
38
+ - --inline-source
39
+ - --title
40
+ - Reporter Libraries for KaeruEra
41
+ - --main
42
+ - README.rdoc
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: 1.8.7
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.0.3
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Faster SELECTs when using Sequel with pg
61
+ test_files: []