app_perf_rpm 0.0.4 → 0.0.5

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: a31589cddf1471657ebd6d97b9eb41fedfc86768
4
- data.tar.gz: 306b0b306e9ce951a5f88281aaa28ee2ce33c099
3
+ metadata.gz: 8a066a37d5f3c2f7880ef434988ca092e512e741
4
+ data.tar.gz: a781dcbc4d6c97fe97fd807d6eaa8859450a45a2
5
5
  SHA512:
6
- metadata.gz: efa6827c82f8155be934a5c4130ef8b2f6e6a5967c4c4a45219a5c6498debc38aabbf64fbfe0557766603520343ffa28e329ff5b5a2feb1c37f9bbafd7fcd3d9
7
- data.tar.gz: c7517fd67206b1e8f1bb00f9a75871282638daffd987595a4a2167126bc8468a3d25cf9ad5140e06f965ac4afd2c6b74663ef42ea34cdd26a5fdc4339b374f81
6
+ metadata.gz: d0c35afab0e3d636277c7b308f0c81186ee5a6cfe3f01997c0e559e63b327e5e09103063ee5e6d026f69357c00387e326e013affa98d9de64d0fcf92ea29989c
7
+ data.tar.gz: 1bed1af8e426808af7702eedfc810f7508f8b510acb0c49f621dbbf17c343e5a1bc6a3f47571ba18b4ba3cb3614e4ef1f2c2cd629ee5fb7348310ed0d4f2b6c8
@@ -30,7 +30,7 @@ module AppPerfRpm
30
30
  self.dispatch_interval ||= 60 # In seconds
31
31
  self.agent_disabled ||= default_if_blank(ENV["APP_PERF_AGENT_DISABLED"], false)
32
32
  self.instrumentation = {
33
- :rack => { :enabled => true, :backtrace => false, :trace_middleware => false },
33
+ :rack => { :enabled => true, :backtrace => false, :trace_middleware => true },
34
34
  :active_record => { :enabled => true, :backtrace => false },
35
35
  :active_record_import => { :enabled => true, :backtrace => false },
36
36
  :action_view => { :enabled => true, :backtrace => false },
@@ -1,41 +1,76 @@
1
1
  module AppPerfRpm
2
2
  module Instruments
3
- class Rack
4
- attr_reader :app
5
-
6
- def initialize(app)
7
- @app = app
8
- end
9
-
3
+ module RackModule
10
4
  def call(env)
11
5
  req = ::Rack::Request.new(env)
6
+ status, headers, body = nil, nil, nil
12
7
 
13
- incoming_trace = env["HTTP_X_APP_PERF_TRACE"]
14
- incoming_trace_id = env["HTTP_X_APP_PERF_TRACE_ID"]
15
-
16
- opts = {}
17
- if incoming_trace.to_s.eql?("1")
18
- opts.merge!("trace_id" => incoming_trace_id)
19
- end
8
+ if ::AppPerfRpm::Tracer.in_trace? &&
9
+ ::AppPerfRpm.configuration.instrumentation[:rack][:trace_middleware]
10
+ AppPerfRpm::Tracer.trace("rack-middleware") do |span|
11
+ span.type = "web"
12
+ span.domain = req.host
13
+ span.url = req.path
14
+ span.options["class"] = @app.class.name
20
15
 
21
- if ignore_path?(req.path)
22
- @status, @headers, @response = @app.call(env)
16
+ status, headers, body = @app.call env
17
+ end
23
18
  else
24
- AppPerfRpm::Tracer.start_trace("rack", opts) do |span|
19
+ AppPerfRpm::Tracer.start_trace("rack") do |span|
25
20
  span.type = "web"
26
21
  span.domain = req.host
27
22
  span.url = req.path
28
- span.options["class"] = self.class.name
23
+ span.options["class"] = @app.class.name
29
24
 
30
- @status, @headers, @response = @app.call(env)
25
+ status, headers, body = @app.call env
31
26
  end
32
27
  end
33
28
 
34
- [@status, @headers, @response]
29
+ [status, headers, body]
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ if ::AppPerfRpm.configuration.instrumentation[:rack][:enabled]
36
+ ::AppPerfRpm.logger.info "Initializing rack tracer."
37
+
38
+ if ::AppPerfRpm.configuration.instrumentation[:rack][:trace_middleware]
39
+ ::AppPerfRpm.logger.info "Initializing rack-middleware tracer."
40
+ end
41
+
42
+ module AppPerfRpm
43
+ module Instruments
44
+ class Rack
45
+ include AppPerfRpm::Instruments::RackModule
46
+
47
+ def initialize(app)
48
+ @app = app
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ module ActionDispatch
55
+ class MiddlewareStack
56
+ class AppPerfRack
57
+ include AppPerfRpm::Instruments::RackModule
58
+
59
+ def initialize(app)
60
+ @app = app
61
+ end
62
+ end
63
+
64
+ class Middleware
65
+ def build(app)
66
+ AppPerfRack.new(klass.new(app, *args, &block))
67
+ end
35
68
  end
36
69
 
37
- def ignore_path?(path)
38
- path.to_s =~ /\/assets/
70
+ def build(app = nil, &block)
71
+ app ||= block
72
+ raise "AppPerfRack#build requires an app" unless app
73
+ middlewares.reverse.inject(AppPerfRack.new(app)) {|a, e| e.build(a)}
39
74
  end
40
75
  end
41
76
  end
@@ -6,8 +6,6 @@ if defined?(::Rails)
6
6
  unless AppPerfRpm.disable_agent?
7
7
  AppPerfRpm.load
8
8
  Rails.configuration.middleware.use AppPerfRpm::Middleware
9
- AppPerfRpm.logger.info "Initializing rack middleware tracer."
10
- Rails.configuration.middleware.insert 0, AppPerfRpm::Instruments::Rack
11
9
  end
12
10
  end
13
11
  end
@@ -1,22 +1,10 @@
1
1
  module AppPerfRpm
2
2
  class Railtie < ::Rails::Railtie
3
- require 'app_perf_rpm/instruments/rack'
4
-
5
3
  # TODO: Why this isn't working with the initializer?
6
4
  initializer "app_perf.initialize" do |app|
7
5
  unless AppPerfRpm.disable_agent?
6
+ require 'app_perf_rpm/instruments/rack'
8
7
  app.middleware.use AppPerfRpm::Middleware
9
-
10
- if ::AppPerfRpm.configuration.instrumentation[:rack][:enabled]
11
- AppPerfRpm.logger.info "Initializing rack tracer."
12
- app.middleware.insert 0, AppPerfRpm::Instruments::Rack
13
-
14
- if AppPerfRpm.configuration.instrumentation[:rack][:trace_middleware]
15
- AppPerfRpm.logger.info "Initializing rack middleware tracer."
16
- require 'app_perf_rpm/instruments/rack_middleware'
17
- app.middleware.insert 1, AppPerfRpm::Instruments::RackMiddleware
18
- end
19
- end
20
8
  end
21
9
 
22
10
  config.after_initialize do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_perf_rpm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Randy Girard
@@ -103,7 +103,6 @@ files:
103
103
  - lib/app_perf_rpm/instruments/faraday.rb
104
104
  - lib/app_perf_rpm/instruments/net_http.rb
105
105
  - lib/app_perf_rpm/instruments/rack.rb
106
- - lib/app_perf_rpm/instruments/rack_middleware.rb
107
106
  - lib/app_perf_rpm/instruments/redis.rb
108
107
  - lib/app_perf_rpm/instruments/sequel.rb
109
108
  - lib/app_perf_rpm/instruments/sidekiq.rb
@@ -1,69 +0,0 @@
1
- module AppPerfRpm
2
- module Instruments
3
- class RackMiddleware
4
- attr_reader :app
5
-
6
- def initialize(app)
7
- @app = app
8
- self.extend(AppPerfRpmRack)
9
- end
10
-
11
- def call(env)
12
- @app.call(env)
13
- end
14
-
15
- module AppPerfRpmRack
16
- def self.extended(object)
17
- object.singleton_class.class_eval do
18
- alias_method :call_without_tracing, :call
19
- alias_method :call, :call_with_tracing
20
- public :call
21
- end
22
-
23
- object.instance_eval do
24
- recursive_app_perf
25
- end
26
- end
27
-
28
- private
29
-
30
- def recursive_app_perf
31
- return if @app.nil?
32
- return unless @app.respond_to?(:call)
33
- @app.extend(AppPerfRpmRack)
34
- end
35
-
36
- def call_with_tracing(env)
37
- req = ::Rack::Request.new(env)
38
-
39
- incoming_trace = env["HTTP_X_APP_PERF_TRACE"]
40
- incoming_trace_id = env["HTTP_X_APP_PERF_TRACE_ID"]
41
-
42
- opts = {}
43
- if incoming_trace.to_s.eql?("1")
44
- opts.merge!("trace_id" => incoming_trace_id)
45
- end
46
-
47
- if !::AppPerfRpm::Tracer.tracing? || ignore_path?(req.path)
48
- @status, @headers, @response = @app.call_without_tracing(env)
49
- else
50
- AppPerfRpm::Tracer.trace("rack-middleware", opts) do |span|
51
- span.type = "web"
52
- span.domain = req.host
53
- span.url = req.path
54
- span.options["class"] = self.class.name
55
-
56
- @status, @headers, @response = @app.call_without_tracing(env)
57
- end
58
- end
59
-
60
- [@status, @headers, @response]
61
- end
62
-
63
- def ignore_path?(path)
64
- path.to_s =~ /\/assets/
65
- end
66
- end
67
- end
68
- end
69
- end