raygun-apm-rails 1.0.12 → 1.0.17
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 +4 -4
- data/lib/raygun/apm/rails.rb +7 -0
- data/lib/raygun/apm/rails/middleware.rb +44 -21
- data/lib/raygun/apm/rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee2d3d33cf58103bfd89b13c63cab3519fdade4b62c2201945296ca0b5ce3ff9
|
4
|
+
data.tar.gz: '0439759d0352745d3a1493eab01f39160a1ead9b82d09ed19ed652c3df1fc88d'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f05e571751ed3bb771041d9d67ba805d556338d56bb6b65c6142f86102e4c9a52938005642381562e461d75f7250ccd7e808927189ced46c3b8882e487750ac
|
7
|
+
data.tar.gz: 6f59d3c5523145e84917412dde20ae1a289a338a97af072cbbf2e2590f8afdf04052a59f409ff882ac959d134a7f13bce70cde005e41f6130352aced3cc681cf
|
data/lib/raygun/apm/rails.rb
CHANGED
@@ -4,7 +4,7 @@ module Raygun
|
|
4
4
|
class Middleware
|
5
5
|
def initialize(app)
|
6
6
|
@app = app
|
7
|
-
@
|
7
|
+
@tracer = nil
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
@@ -13,45 +13,52 @@ module Raygun
|
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
|
+
|
17
|
+
def instrument(env)
|
18
|
+
res = nil
|
19
|
+
# Can be nil if we had a fatal error
|
20
|
+
@tracer ||= init_tracer
|
21
|
+
if @tracer
|
22
|
+
# For the exceptional HTTP IN handler
|
23
|
+
@request_started = @tracer.now
|
24
|
+
Thread.current.thread_variable_set(:_raygun_apm_tracer, @tracer)
|
25
|
+
@tracer.start_trace
|
26
|
+
end
|
27
|
+
res = Ruby_APM_profiler_trace{ @app.call(env) }
|
28
|
+
if (status = res.first) >= 400 && status < 600
|
29
|
+
exceptional_http_in_handler(env, status)
|
30
|
+
end
|
31
|
+
# Can be nil if we had a fatal error
|
32
|
+
@tracer.end_trace if @tracer
|
33
|
+
res
|
34
|
+
rescue Raygun::Apm::FatalError => e
|
35
|
+
raygun_shutdown_handler(e)
|
36
|
+
end
|
16
37
|
|
17
|
-
def
|
38
|
+
def init_tracer
|
39
|
+
return @tracer if @tracer
|
18
40
|
@tracer = Raygun::Apm::Tracer.new
|
19
41
|
@tracer.udp_sink!
|
20
42
|
@tracer.process_started
|
21
43
|
ObjectSpace.define_finalizer(self, self.class.finalize(@tracer))
|
22
|
-
|
44
|
+
|
23
45
|
@http_in_subscriber = ActiveSupport::Notifications.subscribe('process_action.action_controller') do |*args|
|
24
46
|
http_in_handler(args)
|
25
47
|
end
|
48
|
+
|
26
49
|
@sql_subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
|
27
50
|
sql_handler(args)
|
28
51
|
end
|
29
52
|
|
30
53
|
GC.stress = true if ENV['RAYGUN_STRESS_GC']
|
31
|
-
|
54
|
+
@tracer
|
32
55
|
# If any fatal errors on init, shutdown the tracer
|
33
56
|
rescue Raygun::Apm::FatalError => e
|
34
57
|
raygun_shutdown_handler(e)
|
35
58
|
end
|
36
|
-
|
37
|
-
def instrument(env)
|
38
|
-
res = nil
|
39
|
-
@tracer_initialized ||= initialize_tracer
|
40
|
-
# Can be nil if we had a fatal error
|
41
|
-
if @tracer
|
42
|
-
Thread.current.thread_variable_set(:_raygun_apm_tracer, @tracer)
|
43
|
-
@tracer.start_trace
|
44
|
-
end
|
45
|
-
res = Ruby_APM_profiler_trace{ @app.call(env) }
|
46
|
-
# Can be nil if we had a fatal error
|
47
|
-
@tracer.end_trace if @tracer
|
48
|
-
res
|
49
|
-
rescue Raygun::Apm::FatalError => e
|
50
|
-
raygun_shutdown_handler(e)
|
51
|
-
end
|
52
59
|
|
53
60
|
def raygun_shutdown_handler(exception)
|
54
|
-
warn "[Raygun APM] shutting down due to error - #{exception.message}",
|
61
|
+
warn "[Raygun APM] shutting down due to error - #{exception.message} #{exception.backtrace.join("\n")}",
|
55
62
|
# Kill extended event subcriptions
|
56
63
|
ActiveSupport::Notifications.unsubscribe(@http_in_subscriber)
|
57
64
|
ActiveSupport::Notifications.unsubscribe(@sql_subscriber)
|
@@ -83,6 +90,22 @@ module Raygun
|
|
83
90
|
raygun_shutdown_handler(e)
|
84
91
|
end
|
85
92
|
|
93
|
+
# For middleware chain halts that does not trigger 'process_action.action_controller'
|
94
|
+
def exceptional_http_in_handler(env, status)
|
95
|
+
req = Rack::Request.new env
|
96
|
+
event = http_in_event
|
97
|
+
event[:url] = req.url
|
98
|
+
event[:verb] = req.request_method
|
99
|
+
event[:status] = status
|
100
|
+
event[:duration] = @tracer.now - @request_started
|
101
|
+
event[:timestamp] = @tracer.now
|
102
|
+
event[:tid] = @tracer.get_thread_id(Thread.current)
|
103
|
+
@tracer.emit(event)
|
104
|
+
rescue => e
|
105
|
+
warn "[Raygun APM] error reporting exceptional HTTP IN event"
|
106
|
+
raygun_shutdown_handler(e)
|
107
|
+
end
|
108
|
+
|
86
109
|
def http_in_event
|
87
110
|
@http_in_event ||= begin
|
88
111
|
event = Raygun::Apm::Event::HttpIn.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raygun-apm-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raygun
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-03-
|
12
|
+
date: 2020-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: raygun-apm
|
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
|
-
rubygems_version: 3.
|
108
|
+
rubygems_version: 3.1.2
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: Raygun application performance monitoring for Rails
|