app_perf_rpm 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a066a37d5f3c2f7880ef434988ca092e512e741
|
4
|
+
data.tar.gz: a781dcbc4d6c97fe97fd807d6eaa8859450a45a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =>
|
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
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
16
|
+
status, headers, body = @app.call env
|
17
|
+
end
|
23
18
|
else
|
24
|
-
AppPerfRpm::Tracer.start_trace("rack"
|
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"] =
|
23
|
+
span.options["class"] = @app.class.name
|
29
24
|
|
30
|
-
|
25
|
+
status, headers, body = @app.call env
|
31
26
|
end
|
32
27
|
end
|
33
28
|
|
34
|
-
[
|
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
|
38
|
-
|
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
|
data/lib/app_perf_rpm/rails.rb
CHANGED
@@ -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
|
data/lib/app_perf_rpm/railtie.rb
CHANGED
@@ -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
|
+
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
|