gabrake 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: e9086971eceb0388ced5f4d94016d68fa6535cc7
4
+ data.tar.gz: b4e13cafcb4e01d162951d9373701fc70d7d2bce
5
+ SHA512:
6
+ metadata.gz: 029078fd523169306bc11a9cc36a618e48a4925cacea1a60d28653f8903b98c7d507484210574de58afacd9dcdba8fefec875c2b6ba071d8750aafc5871f2304
7
+ data.tar.gz: 1637cd6656d513887115881849508ba53251dda569c5b48d968bdeaf5f9bdc8c2a6c51c15dabd9e1d4f7ed6a1988aa5dac107bc7682e56056fbf5d78df2119a7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gabrake.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Samuel Molnar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # Gabrake — Realtime Error Tracking with Google Analytics
2
+
3
+ Gabrake is a gem built on top of Google Analytics API and provides realtime server-side and client-side error tracking by using custom events. It uses a flexibility of Google Analytics API and handles server-side error server-side, without exposing any of your error messages or backtrace on client.
4
+
5
+ Let's have a look.
6
+
7
+ [Realtime Tracking by category](https://www.dropbox.com/s/k0bhpd1f90hhe6e/gabrake-realtime.png?dl=0)
8
+
9
+ [Overview by error message and location](https://www.dropbox.com/s/hrmyy9cgo1jkclw/gabrake-overview.png?dl=0)
10
+
11
+ [Overview by error message and browser](https://www.dropbox.com/s/q736nd92vzz5r4a/gabrake-overview-by-browser.png?dl=0)
12
+
13
+ Inspired by [garelic](https://github.com/jsuchal/garelic) — gem that tracks app performace by Google Analytics User Timing variables.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'gabrake'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install gabrake
30
+
31
+ ## Usage
32
+
33
+ ### 1. Set it up
34
+
35
+ Create an initializer `config/initializers/gabrake.rb` and add
36
+
37
+ ```ruby
38
+ Gabrake.tracking_id = 'YOUR GA TRACKING ID'
39
+ ```
40
+
41
+ In your javascript do
42
+
43
+ ```coffeecript
44
+ #= require gabrake/analytics # if you haven't required analytics tracking code somewhere else
45
+ #= require gabrake
46
+ ```
47
+
48
+ **Note**: *This library uses new analytics.js code – Universal Google Analytics. If you still have the old `_gaq` library and you use it (for tracking events and stuff), you have to [create a new property](http://stackoverflow.com/a/20690546/1691413) (get second tracking ID and use that one for Gabrake).*
49
+
50
+ ### 2. Track errors
51
+
52
+ Go to Google Analytics page, hit **Real Time** > **Events** and track 'em.
53
+
54
+ **Pro Tip:** *Gabrake errors have two categories – Gabrake (Rails) and Gabrake (JavaScript). Click on one of the category to filter out events and see error message (action) along with error backtrace location (label).*
55
+
56
+ ### 3. Analyze
57
+
58
+ Wait couple minutes.
59
+
60
+ 1. Go to **Behaviour** > **Events** > **Overview**.
61
+ 2. Click on one of the Gabrake categories. On top of table, choose primary dimension as **Event Action**.
62
+ 3. Choose secondary dimension by your taste — *Event Label (backtrace location), Page, Browser,* …
63
+
64
+ **Important**: *Make sure that the overview date includes TODAY! You'll save yourself a headache.*
65
+
66
+ ## Advanced
67
+
68
+ ### Tracking versions
69
+
70
+ If you want to compare errors by app versions, you need create a custom dimension.
71
+
72
+ 1. Go to **Admin** > Under **Property** tab (the big middle one) > hit **Custom Definitions** > **Custom Dimension** > create one.
73
+ 2. Write down the name and the index.
74
+ 3. Set `Gabrake.custom_dimension_index = YOUR_INDEX`.
75
+ 3. Go to **Behaviour** > **Events** > **Overview**. Click category. Choose **Event Action**. Search for secondary dimension, by the name. Choose it.
76
+
77
+
78
+ ## Contributing
79
+
80
+ 1. Fork it
81
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
82
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
83
+ 4. Push to the branch (`git push origin my-new-feature`)
84
+ 5. Create new Pull Request
85
+
86
+ ## License
87
+
88
+ ### This code is free to use under the terms of the MIT license.
89
+
90
+ Copyright (c) 2015 Samuel Molnár
91
+
92
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
93
+
94
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
95
+
96
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'gabrake'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+
15
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/gabrake.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gabrake/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gabrake'
8
+ spec.version = Gabrake::VERSION
9
+ spec.authors = ['Samuel Molnar']
10
+ spec.email = ['molnar.samuel@gmail.com']
11
+
12
+ spec.summary = 'Simple Realtime Error Tracking and Statistics with Google Analytics'
13
+ spec.description = 'Simple Realtime Error Tracking and Statistics with Google Analytics'
14
+ spec.homepage = 'https://github.com/smolnar/gabrake'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'railties', '>= 3.2.0'
23
+ spec.add_dependency 'rails', '>= 3.2.0'
24
+ spec.add_dependency 'httparty', '~> 0.13.5'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.10'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0.0'
29
+ spec.add_development_dependency 'pry'
30
+ end
@@ -0,0 +1,58 @@
1
+ module Gabrake
2
+ class Collector
3
+ URL = 'http://www.google-analytics.com/collect'
4
+
5
+ def self.event_for(exception, context)
6
+ event = Event.new(exception)
7
+
8
+ unless Gabrake.tracking_id
9
+ raise ArgumentError.new('You need to specify Google Analytics Tracking ID in `Gabrake.tracking_id\'')
10
+ end
11
+
12
+ params = {
13
+ v: context[:version],
14
+ dl: CGI::escape(context[:url]),
15
+ cid: context[:client_id],
16
+ tid: Gabrake.tracking_id,
17
+ t: :event,
18
+ ec: event.category,
19
+ ea: event.action,
20
+ el: event.label
21
+ }
22
+
23
+ params[:"cd#{Gabrake.custom_dimension_index}"] = Gabrake.tracked_version if Gabrake.custom_dimension_index
24
+
25
+ "#{URL}?#{params.map { |key, value| "#{key}=#{value}" }.join('&') }"
26
+ end
27
+
28
+ class Event
29
+ def initialize(exception)
30
+ @exception = exception
31
+ end
32
+
33
+ def category
34
+ 'Gabrake (Rails)'
35
+ end
36
+
37
+ def action
38
+ @message ||= "#{@exception.class}: #{@exception.message}"
39
+ end
40
+
41
+ def label
42
+ "#{location.gsub(/\A#{::Rails.root}\//, '')}" if location
43
+ end
44
+
45
+ private
46
+
47
+ def location
48
+ return @location if @location
49
+
50
+ backtrace = @exception.backtrace.try(:first)
51
+
52
+ return unless backtrace
53
+
54
+ _, @location, _ = *backtrace.match(/\A(.+?:\d+):in/)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,17 @@
1
+ module Gabrake
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ begin
9
+ @app.call(env)
10
+ rescue ::Exception => exception
11
+ Gabrake::Notifier.deliver(exception, env: env) unless exception.is_a?(ActionController::RoutingError)
12
+
13
+ raise exception
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ module Gabrake
2
+ class Notifier
3
+ def self.deliver(exception, env:, **options)
4
+ context = Env.extract_context(env)
5
+ event_url = Gabrake::Collector.event_for(exception, context)
6
+
7
+ HTTParty.get(URI.encode(event_url), headers: { 'User-Agent' => env['HTTP_USER_AGENT'] })
8
+ end
9
+
10
+ class Env
11
+ def self.extract_context(env)
12
+ cookies = env['action_dispatch.cookies']
13
+ default_client_id = "GA1.1.#{(rand() * 2147483647).to_i}.#{Time.now.to_i}"
14
+ _, version, client_id = *(cookies['_ga'] || default_client_id).match(/GA(\d+)\..+\.(\d+\.\d+)\z/)
15
+
16
+ {
17
+ version: version,
18
+ client_id: client_id,
19
+ url: env['REQUEST_URI']
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ module Gabrake
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Gabrake
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Gabrake
2
+ VERSION = '0.1.0'
3
+ end
data/lib/gabrake.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'httparty'
2
+ require 'cgi'
3
+ require 'gabrake/version'
4
+ require 'gabrake/rails'
5
+ require 'gabrake/collector'
6
+ require 'gabrake/notifier'
7
+ require 'gabrake/middleware'
8
+ require 'net/http'
9
+
10
+ module Gabrake
11
+ mattr_accessor :tracking_id, :tracked_version, :custom_dimension_index, instance_accessor: false
12
+
13
+ class Railtie < ::Rails::Railtie
14
+ initializer 'gabrake.boot_exception_catching' do |app|
15
+ app.middleware.use Gabrake::Middleware
16
+
17
+ Gabrake.tracked_version = version_from_git || version_from_revision_file
18
+ end
19
+
20
+ def version_from_git
21
+ `git log --pretty=format:"%cd %h" --date=iso -1 2>/dev/null`.strip.presence
22
+ end
23
+
24
+ def version_from_revision_file
25
+ `cat #{::Rails.root}/REVISION 2>/dev/null`.strip.presence
26
+ end
27
+ end
28
+ end
data/vendor/.gitkeep ADDED
File without changes
@@ -0,0 +1,7 @@
1
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
2
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
3
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
4
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
5
+
6
+ ga('create', '<%= Gabrake.tracking_id %>', 'auto');
7
+ ga('send', 'pageview');
@@ -0,0 +1,19 @@
1
+ class window.Gabrake
2
+ @trackedVersion: null
3
+ @customDimensionIndex: null
4
+
5
+ @report: (message, file, line, options) ->
6
+ options = {}
7
+
8
+ if Gabrake.customDimensionIndex
9
+ options["dimension#{Gabrake.customDimensionIndex}"] = Gabrake.trackedVersion
10
+
11
+ ga('send', 'event', 'Gabrake (JavaScript)', message, "#{file}:#{line}", options)
12
+
13
+ @inject: ->
14
+ window.onerror = Gabrake.report
15
+
16
+ Gabrake.trackedVersion = <%= Gabrake.tracked_version ? "'#{Gabrake.tracked_version}'" : 'null' %>
17
+ Gabrake.customDimensionIndex = <%= Gabrake.custom_dimension_index || 'null' %>
18
+
19
+ Gabrake.inject()
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gabrake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Molnar
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.13.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.13.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Simple Realtime Error Tracking and Statistics with Google Analytics
112
+ email:
113
+ - molnar.samuel@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - gabrake.gemspec
128
+ - lib/gabrake.rb
129
+ - lib/gabrake/collector.rb
130
+ - lib/gabrake/middleware.rb
131
+ - lib/gabrake/notifier.rb
132
+ - lib/gabrake/rails.rb
133
+ - lib/gabrake/version.rb
134
+ - vendor/.gitkeep
135
+ - vendor/assets/javascripts/gabrake.js.coffee.erb
136
+ - vendor/assets/javascripts/gabrake/analytics.js.erb
137
+ homepage: https://github.com/smolnar/gabrake
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.2.2
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Simple Realtime Error Tracking and Statistics with Google Analytics
161
+ test_files: []