staccato-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +24 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +92 -0
- data/Rakefile +6 -0
- data/lib/staccato/exception_tracking.rb +20 -0
- data/lib/staccato/railtie.rb +33 -0
- data/lib/staccato/session_tracking.rb +23 -0
- data/lib/staccato/subscribers/page.rb +47 -0
- data/lib/staccato/subscribers/timing.rb +44 -0
- data/lib/staccato-rails/version.rb +4 -0
- data/lib/staccato-rails.rb +8 -0
- data/log/development.log +0 -0
- data/spec/fixtures/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/fixtures/dummy/app/controllers/posts_controller.rb +11 -0
- data/spec/fixtures/dummy/config/application.rb +12 -0
- data/spec/fixtures/dummy/config/environments/development.rb +9 -0
- data/spec/fixtures/dummy/config/routes.rb +2 -0
- data/spec/integration/posts_controller_spec.rb +55 -0
- data/spec/lib/staccato/subscribers/page_spec.rb +71 -0
- data/spec/lib/staccato/subscribers/timing_spec.rb +56 -0
- data/spec/spec_helper.rb +27 -0
- data/staccato-rails.gemspec +30 -0
- metadata +193 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 79453c5e3437d648aabe2a13cd116db0ba2073ea
|
4
|
+
data.tar.gz: c163d245693375382faf05e44dee976c1bafc013
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c221d044d4d9656d4be4b0ac6500b691533a2c9c8ee177ef4717737ac4f0358a5a0709c586d51a7eaa9e847ea277ddcfd999005c8b382ea63c57535d57f4ed29
|
7
|
+
data.tar.gz: abb48affccf27c06d39982439de6ad5ef9e42686a6f3cfaeaf1bdb1be78f95512f9c514fb655c721cbdf29c0de6548b982f1fa27c435c836b61c00a30ce5e0a0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.0
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include:
|
8
|
+
|
9
|
+
* The use of sexualized language or imagery
|
10
|
+
* Personal attacks
|
11
|
+
* Trolling or insulting/derogatory comments
|
12
|
+
* Public or private harassment
|
13
|
+
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
|
14
|
+
* Other unethical or unprofessional conduct
|
15
|
+
|
16
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
17
|
+
|
18
|
+
By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
|
19
|
+
|
20
|
+
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
|
21
|
+
|
22
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project maintainer at [INSERT EMAIL ADDRESS]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident.
|
23
|
+
|
24
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.3.0, available at [http://contributor-covenant.org/version/1/3/0/](http://contributor-covenant.org/version/1/3/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Tony Pitale
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# Staccato::Rails
|
2
|
+
|
3
|
+
Provides seamless integration with basic tracking of rails (timing and pageviews) into the Google Analytics Measurement API.
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/tpitale/staccato-rails.png?branch=master)](https://travis-ci.org/tpitale/staccato-rails)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/tpitale/staccato-rails.png)](https://codeclimate.com/github/tpitale/staccato-rails)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'staccato-rails'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install staccato-rails
|
21
|
+
|
22
|
+
## Provides
|
23
|
+
|
24
|
+
* Timing from instrumentation (total duration, db_runtime, view_runtime)
|
25
|
+
* Pageview tracking on GETs
|
26
|
+
* Event tracking hooks in controllers, models that use the request session client id
|
27
|
+
* Exception tracking (tracks only the exception name)
|
28
|
+
|
29
|
+
Session UUID for the `client_id` is handled for you. Can be overridden easily, see [Overriding the client_id](#overriding-the-client_id).
|
30
|
+
|
31
|
+
## Usage ##
|
32
|
+
|
33
|
+
### Configuration ###
|
34
|
+
|
35
|
+
In **environments/production.rb** (leave blank in development/test to not track):
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
config.staccato.tracker_id = 'UA-XXXX-Y'
|
39
|
+
config.staccato.hostname = 'domain.com' # optional, but recommended
|
40
|
+
```
|
41
|
+
|
42
|
+
**Note:** Because this is a Rails-specific gem, we leverage Rails' method of configuration. As such configuration should be placed in the appropriate environment file, specifically `production.rb`. It is _ill-advised_ to configure in Development or Test environments as that may cause false tracking during local work.
|
43
|
+
|
44
|
+
### Tracking ###
|
45
|
+
|
46
|
+
In controllers, `tracker` is made available to you:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
tracker.event(category: 'video', action: 'play', label: 'cars', value: 1)
|
50
|
+
```
|
51
|
+
|
52
|
+
## Overriding the client_id ##
|
53
|
+
|
54
|
+
A method is added to your controller called `staccato_client_id`. By default, it's implementation looks like:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
session['staccato.client_id'] ||= Staccato.build_client_id
|
58
|
+
```
|
59
|
+
|
60
|
+
If you wish to not store the `client_id` in session, or you wish to use another UUID value, you may override the method `staccato_client_id` as you see fit. Make sure that the `client_id` you generate fits with Google Analytics requirements. It _must_ remain the same `client_id` for an individual user's "session" (by GA standards) if you wish to track a user as they move through your application.
|
61
|
+
|
62
|
+
## Setting a pageview prefix ##
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
config.staccato.pageview_prefix = '/staccato'
|
66
|
+
```
|
67
|
+
|
68
|
+
## Tracking exceptions ##
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
config.staccato.exceptions = true
|
72
|
+
```
|
73
|
+
|
74
|
+
Tracking exceptions happens by adding to `ActionController::Base` a `rescue_from` for Exception. Because of this, it will only rescue exceptions that have not already been rescued from in your own code. If you wish to track those exceptions, as well, you can call `track_exception_with_staccato(exception)` to your own `rescue_from` methods.
|
75
|
+
|
76
|
+
## Disable some, or all, tracking
|
77
|
+
|
78
|
+
Inside of your `environment` files, as appropriate
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
config.staccato.timing = false
|
82
|
+
config.staccato.pageviews = false
|
83
|
+
config.staccato.exceptions = false # default
|
84
|
+
```
|
85
|
+
|
86
|
+
## Contributing
|
87
|
+
|
88
|
+
1. Fork it
|
89
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
90
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
91
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
92
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Staccato
|
2
|
+
module ExceptionTracking
|
3
|
+
|
4
|
+
def self.included(controller)
|
5
|
+
controller.rescue_from ::Exception,
|
6
|
+
with: :track_exception_with_staccato_and_raise
|
7
|
+
end
|
8
|
+
|
9
|
+
def track_exception_with_staccato(exception)
|
10
|
+
tracker.exception(description: exception.class.name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def track_exception_with_staccato_and_raise(exception)
|
14
|
+
track_exception_with_staccato(exception)
|
15
|
+
|
16
|
+
# re-raise the exception as normal
|
17
|
+
raise exception
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Staccato
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
config.before_configuration do |app|
|
4
|
+
app.config.staccato = ActiveSupport::OrderedOptions.new
|
5
|
+
|
6
|
+
# set defaults
|
7
|
+
app.config.staccato.timing = true
|
8
|
+
app.config.staccato.pageviews = true
|
9
|
+
app.config.staccato.pageview_prefix = ""
|
10
|
+
app.config.staccato.exceptions = false
|
11
|
+
end
|
12
|
+
|
13
|
+
initializer "staccato.controller_extension" do
|
14
|
+
track_exceptions = config.staccato.exceptions
|
15
|
+
|
16
|
+
ActiveSupport.on_load(:action_controller) do
|
17
|
+
include Staccato::SessionTracking
|
18
|
+
|
19
|
+
include Staccato::ExceptionTracking if track_exceptions
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
initializer "staccato.configure_subscribers" do
|
24
|
+
if config.staccato.timing
|
25
|
+
ActiveSupport::Notifications.subscribe('process_action.action_controller', Staccato::Subscribers::Timing)
|
26
|
+
end
|
27
|
+
|
28
|
+
if config.staccato.pageviews
|
29
|
+
ActiveSupport::Notifications.subscribe('process_action.action_controller', Staccato::Subscribers::Page)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Staccato
|
2
|
+
module SessionTracking
|
3
|
+
def tracker
|
4
|
+
@tracker ||= Staccato.tracker(staccato_tracker_id, staccato_client_id)
|
5
|
+
end
|
6
|
+
|
7
|
+
# pull tracker id from config
|
8
|
+
def staccato_tracker_id
|
9
|
+
Rails.configuration.staccato.tracker_id
|
10
|
+
end
|
11
|
+
|
12
|
+
# load or set new uuid in session
|
13
|
+
def staccato_client_id
|
14
|
+
session['staccato.client_id'] ||= Staccato.build_client_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def append_info_to_payload(payload)
|
18
|
+
super
|
19
|
+
|
20
|
+
payload["staccato.tracker"] = tracker
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Staccato
|
2
|
+
module Subscribers
|
3
|
+
class Page
|
4
|
+
def self.call(*args)
|
5
|
+
new(args).track!
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(args)
|
9
|
+
@args = args
|
10
|
+
end
|
11
|
+
|
12
|
+
def get?
|
13
|
+
payload[:method] == "GET"
|
14
|
+
end
|
15
|
+
|
16
|
+
def path
|
17
|
+
path_prefix + payload[:path]
|
18
|
+
end
|
19
|
+
|
20
|
+
def hostname
|
21
|
+
Rails.configuration.staccato.hostname
|
22
|
+
end
|
23
|
+
|
24
|
+
def track!
|
25
|
+
return unless get?
|
26
|
+
tracker.pageview(path: path, hostname: hostname)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def event
|
31
|
+
@event ||= ActiveSupport::Notifications::Event.new(*@args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def payload
|
35
|
+
@payload ||= event.payload
|
36
|
+
end
|
37
|
+
|
38
|
+
def tracker
|
39
|
+
@tracker ||= payload['staccato.tracker']
|
40
|
+
end
|
41
|
+
|
42
|
+
def path_prefix
|
43
|
+
Rails.application.config.staccato.pageview_prefix.to_s
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Staccato
|
2
|
+
module Subscribers
|
3
|
+
class Timing
|
4
|
+
def self.call(*args)
|
5
|
+
new(args).track!
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(args)
|
9
|
+
@args = args
|
10
|
+
end
|
11
|
+
|
12
|
+
def total_runtime
|
13
|
+
@total_runtime ||= event.duration
|
14
|
+
end
|
15
|
+
|
16
|
+
def db_runtime
|
17
|
+
@db_runtime ||= payload[:db_runtime]
|
18
|
+
end
|
19
|
+
|
20
|
+
def view_runtime
|
21
|
+
@view_runtime ||= payload[:view_runtime]
|
22
|
+
end
|
23
|
+
|
24
|
+
def track!
|
25
|
+
tracker.timing(category: :rails, variable: :runtime, label: :total, time: total_runtime)
|
26
|
+
tracker.timing(category: :rails, variable: :runtime, label: :db, time: db_runtime)
|
27
|
+
tracker.timing(category: :rails, variable: :runtime, label: :view, time: view_runtime)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def event
|
32
|
+
@event ||= ActiveSupport::Notifications::Event.new(*@args)
|
33
|
+
end
|
34
|
+
|
35
|
+
def payload
|
36
|
+
@payload ||= event.payload
|
37
|
+
end
|
38
|
+
|
39
|
+
def tracker
|
40
|
+
@tracker ||= payload['staccato.tracker']
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/log/development.log
ADDED
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "action_controller/railtie"
|
2
|
+
|
3
|
+
# Load Staccato Rails
|
4
|
+
require File.expand_path('../../../../../lib/staccato-rails', __FILE__)
|
5
|
+
|
6
|
+
module Dummy
|
7
|
+
class Application < Rails::Application
|
8
|
+
config.root = File.expand_path('../../', __FILE__)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Dummy::Application.initialize!
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
config.cache_classes = true
|
3
|
+
config.eager_load = true
|
4
|
+
|
5
|
+
# Staccato configuration
|
6
|
+
config.staccato.tracker_id = 'UA-1234-5'
|
7
|
+
config.staccato.hostname = 'domain.com' # optional, but recommended
|
8
|
+
config.staccato.exceptions = true
|
9
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PostsController do
|
4
|
+
let(:controller) {PostsController.new}
|
5
|
+
let(:session) {{}}
|
6
|
+
|
7
|
+
describe '#tracker' do
|
8
|
+
before(:each) do
|
9
|
+
SecureRandom.stubs(:uuid).returns('54321')
|
10
|
+
|
11
|
+
controller.stubs(:session).returns(session)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'builds a new tracker' do
|
15
|
+
tracker = controller.tracker
|
16
|
+
|
17
|
+
expect(tracker.id).to eq('UA-1234-5')
|
18
|
+
expect(tracker.client_id).to eq('54321')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'appends tracker to the notification payload' do
|
22
|
+
payload = {}
|
23
|
+
|
24
|
+
controller.append_info_to_payload(payload)
|
25
|
+
|
26
|
+
expect(payload["staccato.tracker"]).to eq(controller.tracker)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "tracking exceptions" do
|
31
|
+
let(:tracker) {stub(:exception)}
|
32
|
+
|
33
|
+
before(:each) do
|
34
|
+
controller.stubs(:tracker).returns(tracker)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'still raises the error' do
|
38
|
+
expect { controller.destroy }.to raise_exception(NotImplementedError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'tracks the error' do
|
42
|
+
controller.track_exception_with_staccato(NotImplementedError.new)
|
43
|
+
|
44
|
+
expect(tracker).to have_received(:exception).with(description: 'NotImplementedError')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'tracks the error and raises' do
|
48
|
+
expect {
|
49
|
+
controller.track_exception_with_staccato_and_raise(NotImplementedError.new)
|
50
|
+
}.to raise_exception(NotImplementedError)
|
51
|
+
|
52
|
+
expect(tracker).to have_received(:exception).with(description: 'NotImplementedError')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Staccato::Subscribers::Page do
|
4
|
+
|
5
|
+
let(:tracker) { Staccato.tracker(nil) }
|
6
|
+
let(:now) {Time.now.to_i}
|
7
|
+
let(:duration) {49}
|
8
|
+
|
9
|
+
let(:payload) {
|
10
|
+
# args example from:
|
11
|
+
# http://edgeguides.rubyonrails.org/active_support_instrumentation.html#process-action-action-controller
|
12
|
+
{
|
13
|
+
controller: "PostsController",
|
14
|
+
action: "index",
|
15
|
+
params: {"action" => "index", "controller" => "posts"},
|
16
|
+
format: :html,
|
17
|
+
path: "/posts",
|
18
|
+
status: 200,
|
19
|
+
view_runtime: 46.848,
|
20
|
+
db_runtime: 0.157,
|
21
|
+
'staccato.tracker' => tracker
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
context "on a GET request" do
|
26
|
+
let(:args) {
|
27
|
+
[
|
28
|
+
"process_action.action_controller", # name
|
29
|
+
now - duration, # starting
|
30
|
+
now, # ending
|
31
|
+
SecureRandom.uuid, # transaction_id
|
32
|
+
payload.merge(method: "GET")
|
33
|
+
]
|
34
|
+
}
|
35
|
+
|
36
|
+
let(:page) {Staccato::Subscribers::Page.new(args)}
|
37
|
+
|
38
|
+
before(:each) do
|
39
|
+
tracker.stubs(:pageview)
|
40
|
+
page.track!
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'tracks a pageview to google analytics' do
|
44
|
+
expect(tracker).to have_received(:pageview).with(path: '/posts', hostname: 'domain.com')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "on a non-GET request" do
|
49
|
+
let(:args) {
|
50
|
+
[
|
51
|
+
"process_action.action_controller", # name
|
52
|
+
now - duration, # starting
|
53
|
+
now, # ending
|
54
|
+
SecureRandom.uuid, # transaction_id
|
55
|
+
payload.merge(method: "POST")
|
56
|
+
]
|
57
|
+
}
|
58
|
+
|
59
|
+
let(:page) {Staccato::Subscribers::Page.new(args)}
|
60
|
+
|
61
|
+
before(:each) do
|
62
|
+
tracker.stubs(:pageview)
|
63
|
+
page.track!
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'tracks no pageviews to google analytics' do
|
67
|
+
expect(tracker).to have_received(:pageview).never
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Staccato::Subscribers::Timing do
|
4
|
+
|
5
|
+
let(:tracker) { Staccato.tracker(nil) }
|
6
|
+
let(:now) {Time.now.to_i}
|
7
|
+
let(:duration) {49} # in seconds
|
8
|
+
|
9
|
+
let(:payload) {
|
10
|
+
# args example from:
|
11
|
+
# http://edgeguides.rubyonrails.org/active_support_instrumentation.html#process-action-action-controller
|
12
|
+
{
|
13
|
+
controller: "PostsController",
|
14
|
+
action: "index",
|
15
|
+
params: {"action" => "index", "controller" => "posts"},
|
16
|
+
format: :html,
|
17
|
+
path: "/posts",
|
18
|
+
method: "GET",
|
19
|
+
status: 200,
|
20
|
+
view_runtime: 46.848, # milliseconds
|
21
|
+
db_runtime: 0.157, # milliseconds
|
22
|
+
'staccato.tracker' => tracker
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
let(:args) {
|
27
|
+
[
|
28
|
+
"process_action.action_controller", # name
|
29
|
+
now - duration, # starting
|
30
|
+
now, # ending
|
31
|
+
SecureRandom.uuid, # transaction_id
|
32
|
+
payload
|
33
|
+
]
|
34
|
+
}
|
35
|
+
|
36
|
+
let(:timing) {Staccato::Subscribers::Timing.new(args)}
|
37
|
+
|
38
|
+
before(:each) do
|
39
|
+
tracker.stubs(:timing)
|
40
|
+
timing.track!
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'tracks total run time' do
|
44
|
+
# convert duration time to milliseconds
|
45
|
+
total_runtime = duration.to_f*1000
|
46
|
+
expect(tracker).to have_received(:timing).with(category: :rails, variable: :runtime, label: :total, time: total_runtime)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'tracks db run time' do
|
50
|
+
expect(tracker).to have_received(:timing).with(category: :rails, variable: :runtime, label: :db, time: 0.157)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'tracks view rendering run time' do
|
54
|
+
expect(tracker).to have_received(:timing).with(category: :rails, variable: :runtime, label: :view, time: 46.848)
|
55
|
+
end
|
56
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
ENV["RAILS_ENV"] = "development"
|
5
|
+
|
6
|
+
require 'bundler/setup'
|
7
|
+
|
8
|
+
require 'rspec'
|
9
|
+
require 'mocha/api'
|
10
|
+
require 'bourne'
|
11
|
+
|
12
|
+
# Load Rails
|
13
|
+
require File.expand_path('../fixtures/dummy/config/application.rb', __FILE__)
|
14
|
+
|
15
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.mock_with :mocha
|
18
|
+
|
19
|
+
config.run_all_when_everything_filtered = true
|
20
|
+
config.filter_run :focus
|
21
|
+
|
22
|
+
# Run specs in random order to surface order dependencies. If you find an
|
23
|
+
# order dependency and want to debug it, you can fix the order by providing
|
24
|
+
# the seed, which is printed after each run.
|
25
|
+
# --seed 1234
|
26
|
+
config.order = 'random'
|
27
|
+
end
|
@@ -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 'staccato-rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "staccato-rails"
|
8
|
+
spec.version = StaccatoRails::VERSION
|
9
|
+
spec.authors = ["Tony Pitale"]
|
10
|
+
spec.email = ["tpitale@gmail.com"]
|
11
|
+
spec.description = "Rails integration with Staccato for Google Analytics measurement."
|
12
|
+
spec.summary = "Rails integration with Staccato for Google Analytics measurement."
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "mocha"
|
25
|
+
spec.add_development_dependency "bourne"
|
26
|
+
spec.add_development_dependency "simplecov"
|
27
|
+
spec.add_development_dependency "rails", ">= 3.0"
|
28
|
+
|
29
|
+
spec.add_runtime_dependency "staccato", ">= 0.0.2"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: staccato-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tony Pitale
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mocha
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bourne
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: staccato
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.0.2
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.0.2
|
125
|
+
description: Rails integration with Staccato for Google Analytics measurement.
|
126
|
+
email:
|
127
|
+
- tpitale@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".ruby-version"
|
135
|
+
- ".travis.yml"
|
136
|
+
- CHANGELOG.md
|
137
|
+
- CODE_OF_CONDUCT.md
|
138
|
+
- Gemfile
|
139
|
+
- LICENSE.txt
|
140
|
+
- README.md
|
141
|
+
- Rakefile
|
142
|
+
- lib/staccato-rails.rb
|
143
|
+
- lib/staccato-rails/version.rb
|
144
|
+
- lib/staccato/exception_tracking.rb
|
145
|
+
- lib/staccato/railtie.rb
|
146
|
+
- lib/staccato/session_tracking.rb
|
147
|
+
- lib/staccato/subscribers/page.rb
|
148
|
+
- lib/staccato/subscribers/timing.rb
|
149
|
+
- log/development.log
|
150
|
+
- spec/fixtures/dummy/app/controllers/application_controller.rb
|
151
|
+
- spec/fixtures/dummy/app/controllers/posts_controller.rb
|
152
|
+
- spec/fixtures/dummy/config/application.rb
|
153
|
+
- spec/fixtures/dummy/config/environments/development.rb
|
154
|
+
- spec/fixtures/dummy/config/routes.rb
|
155
|
+
- spec/integration/posts_controller_spec.rb
|
156
|
+
- spec/lib/staccato/subscribers/page_spec.rb
|
157
|
+
- spec/lib/staccato/subscribers/timing_spec.rb
|
158
|
+
- spec/spec_helper.rb
|
159
|
+
- staccato-rails.gemspec
|
160
|
+
homepage: ''
|
161
|
+
licenses:
|
162
|
+
- MIT
|
163
|
+
metadata: {}
|
164
|
+
post_install_message:
|
165
|
+
rdoc_options: []
|
166
|
+
require_paths:
|
167
|
+
- lib
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
requirements: []
|
179
|
+
rubyforge_project:
|
180
|
+
rubygems_version: 2.5.1
|
181
|
+
signing_key:
|
182
|
+
specification_version: 4
|
183
|
+
summary: Rails integration with Staccato for Google Analytics measurement.
|
184
|
+
test_files:
|
185
|
+
- spec/fixtures/dummy/app/controllers/application_controller.rb
|
186
|
+
- spec/fixtures/dummy/app/controllers/posts_controller.rb
|
187
|
+
- spec/fixtures/dummy/config/application.rb
|
188
|
+
- spec/fixtures/dummy/config/environments/development.rb
|
189
|
+
- spec/fixtures/dummy/config/routes.rb
|
190
|
+
- spec/integration/posts_controller_spec.rb
|
191
|
+
- spec/lib/staccato/subscribers/page_spec.rb
|
192
|
+
- spec/lib/staccato/subscribers/timing_spec.rb
|
193
|
+
- spec/spec_helper.rb
|