copperegg-apm 1.0.0.pre10 → 1.0.0.pre11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb34a133475c1607e01bf772b6a90ebd39ca7af2
4
- data.tar.gz: 686545748d0be3430df149329e23a19765c7a816
3
+ metadata.gz: 0e3868f8c2d86ea09b507987e52a6c29eac450bf
4
+ data.tar.gz: bf9a9ab59c8476e7714967f29119ff8a4516fbe6
5
5
  SHA512:
6
- metadata.gz: ce7c65610e6d29cb2e678ed10109d493c3bde1a98aed47d385cc2b52177a08911f7acfdc7a78aa30026e8dc592824284936463cf683ced416542ca453657aaff
7
- data.tar.gz: 333dc247db68184c21beef81afa6d059e904627ae015e0b497146fb90205c447ea997b738da1c3a988a69bbb39d0b9f7cbdad1e7591d7de1b84b5ef4014e2881
6
+ metadata.gz: 9964cf7f797aec7b2bf30ad20edcbe6e38babcce34d058a087c67b9bbacc20dc39598ae5f71dd7337d59659f5f9ebcb0cd39312a364e82da1d9c5b46215f9232
7
+ data.tar.gz: 216c2890bc3ea494d43979a9d4eacade6914d65c33274e236d11627fafb709c6d2d1ba47cce0ed34e64b9867c8d88ecf245fc1a48833dd5d2e89595cd2a5ea62
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- copperegg-apm (1.0.0.pre10)
4
+ copperegg-apm (1.0.0.pre11)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
Binary file
data/lib/copperegg/apm.rb CHANGED
@@ -1,5 +1,8 @@
1
+ # encoding: utf-8
2
+
1
3
  at_exit do
2
4
  begin
5
+ CopperEgg::APM.capture_exception($!) if !$!.nil? && CopperEgg::APM::Configuration.benchmark_exceptions?
3
6
  CopperEgg::APM.send_payload_cache
4
7
  rescue
5
8
  end
@@ -10,8 +13,8 @@ end
10
13
  active_record/connection_adapters/abstract_adapter
11
14
  configuration
12
15
  errors
16
+ exception_capturer
13
17
  ethon/easy/operations
14
- kernel
15
18
  mysql
16
19
  mysql2/client
17
20
  net/http
@@ -197,15 +197,8 @@ module CopperEgg
197
197
  caller[1] =~ /`([^']*)'/ and $1
198
198
  end
199
199
 
200
- def capture_exception(*args)
201
- exception = if args.size == 0
202
- $!.nil? ? RuntimeError.new : $!
203
- elsif args.size == 1
204
- args.first.is_a?(String) ? RuntimeError.exception(args.first) : args.first.exception
205
- elsif args.size <= 3
206
- args.first.exception(args[1])
207
- end
208
- stacktrace = trim_stacktrace(caller)
200
+ def capture_exception(exception)
201
+ stacktrace = trim_stacktrace(exception.backtrace)
209
202
  return if stacktrace.length == 0
210
203
  parameters = {:error => "#{exception.class}|#{stacktrace.first}", :stacktrace => "#{exception.message}\n#{stacktrace.join("\n")}", :ts => Time.now.to_i}
211
204
  send_payload(parameters)
@@ -195,6 +195,10 @@ module CopperEgg
195
195
  if @@benchmark_browser && defined?(::Rails) && ::Rails.respond_to?(:configuration) && ::Rails.configuration.respond_to?(:middleware) && ::Rails.configuration.middleware.respond_to?(:use)
196
196
  ::Rails.configuration.middleware.use CopperEgg::APM::RUMBlender
197
197
  end
198
+
199
+ if @@benchmark_exceptions && defined?(::Rails) && ::Rails.respond_to?(:configuration) && ::Rails.configuration.respond_to?(:middleware) && ::Rails.configuration.middleware.respond_to?(:use)
200
+ ::Rails.configuration.middleware.use CopperEgg::APM::ExceptionCapturer
201
+ end
198
202
  end
199
203
  end
200
204
 
@@ -0,0 +1,21 @@
1
+ require 'rack'
2
+
3
+ module CopperEgg
4
+ module APM
5
+ class ExceptionCapturer
6
+
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ begin
13
+ @app.call(env)
14
+ rescue Exception => e
15
+ CopperEgg::APM.capture_exception(e)
16
+ raise e
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  module CopperEgg
2
2
  module APM
3
- GEM_VERSION = '1.0.0.pre10' unless defined? GEM_VERSION
3
+ GEM_VERSION = '1.0.0.pre11' unless defined? GEM_VERSION
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copperegg-apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre10
4
+ version: 1.0.0.pre11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Bradford
@@ -197,11 +197,10 @@ files:
197
197
  - ./lib/copperegg/apm/active_record/connection_adapters/abstract_adapter.rb
198
198
  - ./lib/copperegg/apm/benchmark.rb
199
199
  - ./lib/copperegg/apm/benchmark_methods_table.rb
200
- - ./lib/copperegg/apm/benchmark_middleware.rb
201
200
  - ./lib/copperegg/apm/configuration.rb
202
201
  - ./lib/copperegg/apm/errors.rb
203
202
  - ./lib/copperegg/apm/ethon/easy/operations.rb
204
- - ./lib/copperegg/apm/kernel.rb
203
+ - ./lib/copperegg/apm/exception_capturer.rb
205
204
  - ./lib/copperegg/apm/mysql.rb
206
205
  - ./lib/copperegg/apm/mysql2/client.rb
207
206
  - ./lib/copperegg/apm/net/http.rb
@@ -223,7 +222,6 @@ files:
223
222
  - ./README.md
224
223
  - ./screenshot01.png
225
224
  - ./screenshot02.png
226
- - ./spec/action_controller_spec.rb
227
225
  - ./spec/apm_spec.rb
228
226
  - ./spec/ethon_spec.rb
229
227
  - ./spec/helpers/mysql2_setup.rb
@@ -231,7 +229,6 @@ files:
231
229
  - ./spec/helpers/pg_setup.rb
232
230
  - ./spec/helpers/rails.rb
233
231
  - ./spec/helpers/sqlite3_setup.rb
234
- - ./spec/kernel_spec.rb
235
232
  - ./spec/mysql2_spec.rb
236
233
  - ./spec/mysql_spec.rb
237
234
  - ./spec/net_http_spec.rb
@@ -244,7 +241,6 @@ files:
244
241
  - README.md
245
242
  - Rakefile
246
243
  - copperegg-apm.gemspec
247
- - spec/action_controller_spec.rb
248
244
  - spec/apm_spec.rb
249
245
  - spec/ethon_spec.rb
250
246
  - spec/helpers/mysql2_setup.rb
@@ -252,7 +248,6 @@ files:
252
248
  - spec/helpers/pg_setup.rb
253
249
  - spec/helpers/rails.rb
254
250
  - spec/helpers/sqlite3_setup.rb
255
- - spec/kernel_spec.rb
256
251
  - spec/mysql2_spec.rb
257
252
  - spec/mysql_spec.rb
258
253
  - spec/net_http_spec.rb
@@ -293,9 +288,8 @@ rubyforge_project:
293
288
  rubygems_version: 2.0.3
294
289
  signing_key:
295
290
  specification_version: 4
296
- summary: copperegg-apm-1.0.0.pre10
291
+ summary: copperegg-apm-1.0.0.pre11
297
292
  test_files:
298
- - spec/action_controller_spec.rb
299
293
  - spec/apm_spec.rb
300
294
  - spec/ethon_spec.rb
301
295
  - spec/helpers/mysql2_setup.rb
@@ -303,7 +297,6 @@ test_files:
303
297
  - spec/helpers/pg_setup.rb
304
298
  - spec/helpers/rails.rb
305
299
  - spec/helpers/sqlite3_setup.rb
306
- - spec/kernel_spec.rb
307
300
  - spec/mysql2_spec.rb
308
301
  - spec/mysql_spec.rb
309
302
  - spec/net_http_spec.rb
@@ -1,20 +0,0 @@
1
- module CopperEgg
2
- module APM
3
- class BenchmarkMiddleware
4
- def initialize(app)
5
- @app = app
6
- end
7
-
8
- def call(env)
9
- CopperEgg::APM.benchmark(:url => env['REQUEST_URI'].gsub(/\/\/[^:]+:[^@]@/,"//").gsub(/\?.*/,"")) do
10
- @status, @headers, @response = @app.call(env)
11
- end
12
- [@status, @headers, self]
13
- end
14
-
15
- def each(&block)
16
- @response.each(&block)
17
- end
18
- end
19
- end
20
- end
@@ -1,19 +0,0 @@
1
- module CopperEgg
2
- module APM
3
- module Kernel
4
- def raise(*args)
5
- CopperEgg::APM.capture_exception(*args) if CopperEgg::APM::Configuration.benchmark_exceptions?
6
- super
7
- end
8
-
9
- def fail(*args)
10
- CopperEgg::APM.capture_exception(*args) if CopperEgg::APM::Configuration.benchmark_exceptions?
11
- super
12
- end
13
- end
14
- end
15
- end
16
-
17
- Object.class_eval do
18
- include CopperEgg::APM::Kernel
19
- end
@@ -1,37 +0,0 @@
1
- # Props to @relishapp (http://www.relishapp.com/rspec/rspec-rails/docs/controller-specs/anonymous-controller) and
2
- # @AlexandrZaytsev (http://say26.com/rspec-testing-controllers-outside-of-a-rails-application) for their helpful blog posts
3
- require File.dirname(__FILE__) + '/helpers/rails'
4
- require 'spec_helper'
5
-
6
- RSpec.configure do |c|
7
- c.infer_base_class_for_anonymous_controllers = true
8
- end
9
-
10
- class ApplicationController < ActionController::Base
11
- include Rails.application.routes.url_helpers
12
- end
13
-
14
- class ExceptionController < ApplicationController; end
15
-
16
- describe ExceptionController, :type => :controller do
17
- controller(ExceptionController) do
18
- def index
19
- @count = 1/0
20
- end
21
- end
22
-
23
- it "should instrument all exceptions not rescued" do
24
- expect { get :index, {:id => 1, :sort => "name"} }.to raise_error
25
-
26
- last_payload = CopperEgg::APM.send(:class_variable_get, :@@payload_cache).split("\x00").select {|i| i.size > 2}.map {|i| i.sub(/^[^\{]+/,'')}.last
27
- hash = JSON.parse last_payload
28
-
29
- expect(hash.keys.sort).to eq ["excp", "id"]
30
- expect(hash["id"]).to match(/\A[0-1a-z]{16}\z/i)
31
- expect(hash["excp"].keys.sort).to eq ["error", "stacktrace", "ts"]
32
- expect(hash["excp"]["error"]).to match(/\AZeroDivisionError\|/)
33
- expect(hash["excp"]["error"]).to match(/\{Ruby\}\Z/)
34
- expect(hash["excp"]["stacktrace"]).to match(/\Adivided by 0\n/)
35
- expect(hash["excp"]["ts"]).to be_an_instance_of(Fixnum)
36
- end
37
- end
data/spec/kernel_spec.rb DELETED
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Kernel do
4
- describe "#raise" do
5
- it "should instrument any exception" do
6
- expect { raise "the roof" }.to raise_error(RuntimeError)
7
- print "."
8
-
9
- last_payload = CopperEgg::APM.send(:class_variable_get, :@@payload_cache).split("\x00").select {|i| i.size > 2}.map {|i| i.sub(/^[^\{]+/,'')}.last
10
- hash = JSON.parse last_payload
11
-
12
- expect(hash.keys.sort).to eq ["excp", "id"]
13
- expect(hash["id"]).to match(/\A[0-1a-z]{16}\z/i)
14
- expect(hash["excp"].keys.sort).to eq ["error", "stacktrace", "ts"]
15
- expect(hash["excp"]["error"]).to match(/RuntimeError\|/)
16
- expect(hash["excp"]["stacktrace"]).to match(/\Athe roof\n/)
17
- expect(hash["excp"]["ts"]).to be_an_instance_of(Fixnum)
18
- end
19
- end
20
-
21
- describe "#fail" do
22
- it "should instrument any exception" do
23
- expect { fail "epically" }.to raise_error(RuntimeError)
24
- print "."
25
-
26
- last_payload = CopperEgg::APM.send(:class_variable_get, :@@payload_cache).split("\x00").select {|i| i.size > 2}.map {|i| i.sub(/^[^\{]+/,'')}.last
27
- hash = JSON.parse last_payload
28
-
29
- expect(hash.keys.sort).to eq ["excp", "id"]
30
- expect(hash["id"]).to match(/\A[0-1a-z]{16}\z/i)
31
- expect(hash["excp"].keys.sort).to eq ["error", "stacktrace", "ts"]
32
- expect(hash["excp"]["error"]).to match(/RuntimeError\|/)
33
- expect(hash["excp"]["stacktrace"]).to match(/\Aepically\n/)
34
- expect(hash["excp"]["ts"]).to be_an_instance_of(Fixnum)
35
- end
36
- end
37
- end