raygun-apm-sidekiq 1.0.11 → 1.0.16

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
  SHA256:
3
- metadata.gz: ada58e6aa2ff6b48c268217c38693cac278aa306f682eb2dc69f73edb53b3b2e
4
- data.tar.gz: 379565ec5a6a69f2f1f895bdbe60c7506a6eccd7cc913a773591021bb8a44003
3
+ metadata.gz: e8b45cd686413df0cefdc5546fbf08a31e36060b7393e828bd83c19239ad43c0
4
+ data.tar.gz: 1b3662d09b9d64a04539c9f5fceba35d73c34ec1847c492688170ee66de3ff85
5
5
  SHA512:
6
- metadata.gz: bba188aa02c29dea66a6e8936da18a744328fa583e848aebb7fa37a524a0d79ba726b675106663c707252bf4b2179a288e7ec3f3149ee2426aeee0b65f8b0906
7
- data.tar.gz: e9302fe170f3eb1b848303908399b5e9b507dcd6234cda89157eb0ccd0594ec95fdc7551385cbbb676050c0c32247d50595c781a39f31a7f514a9d0e9bb2877d
6
+ metadata.gz: dce241ad3576c65f8943d666b22db69b715fb1baa898a44f68ea16a03cb8e2ab35615cba1c47b61f5e05072a5a06f9458c871c3cede06683b88c383f51f49677
7
+ data.tar.gz: 2263c613a2deefeab136f326cf5a7cc2500975a587a4be6f9754fdc21688730312fcdece83c66c242cb827c90085539c1e28d502eee4f7cbe35664b73f668b1a
@@ -0,0 +1 @@
1
+ *.gem
@@ -1,5 +1,27 @@
1
1
  = Changelog
2
2
 
3
+ == 1.0.16 (June 8, 2020)
4
+
5
+ * Integrate exception correlation with rayrun4ruby
6
+ * Move raygun4ruby whitelisting and blacklisting out to profiler core
7
+
8
+ == 1.0.15 (May 17, 2020)
9
+
10
+ * Remove the Tracer#process_started callback (set on begin transaction command now)
11
+
12
+ == 1.0.14 (May 15, 2020)
13
+
14
+ * Introduce support for Redis as client adapter
15
+ * Prefer hooking Sidekiq::Processor as Middleware does not wrap enough to intercept the raygun4ruby error handler as an HTTP OUT event
16
+
17
+ == 1.0.13 (April 2, 2020)
18
+
19
+ * Prefer hooking Sidekiq::Processor as Middleware does not wrap enough to intercept the raygun4ruby error handler as an HTTP OUT event
20
+
21
+ == 1.0.12 (March 25, 2020)
22
+
23
+ * Do not cache PID on HTTP OUT and SQL events
24
+
3
25
  == 1.0.11 (March 15, 2020)
4
26
 
5
27
  * Emit the happy path and error state HTTP IN events for Sidekiq jobs WITHIN the entrypoint function for the agent to pick it up
@@ -1,24 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- raygun-apm-rails (0.1.0)
5
- raygun-apm (~> 0.0.8)
4
+ raygun-apm-sidekiq (1.0.16)
5
+ raygun-apm (~> 1.0.15)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  minitest (5.13.0)
11
11
  rake (10.5.0)
12
- raygun-apm (0.0.8-x86-linux)
12
+ raygun-apm (1.0.43-universal-darwin)
13
13
 
14
14
  PLATFORMS
15
15
  ruby
16
16
 
17
17
  DEPENDENCIES
18
- bundler (~> 1.17)
18
+ bundler
19
19
  minitest (~> 5.0)
20
20
  rake (~> 10.0)
21
- raygun-apm-rails!
21
+ raygun-apm-sidekiq!
22
22
 
23
23
  BUNDLED WITH
24
24
  1.17.3
@@ -7,9 +7,9 @@ module Raygun
7
7
 
8
8
  BLACKLIST = %w{
9
9
  Sidekiq
10
- Redis
11
- +Raygun::Apm::Sidekiq::Middleware::Ruby_APM_profiler_trace
10
+ +Raygun::Apm::Sidekiq::Hook::Ruby_APM_profiler_trace
12
11
  }
12
+
13
13
  end
14
14
  end
15
15
  end
@@ -0,0 +1,135 @@
1
+ require "sidekiq"
2
+ require 'sidekiq/processor'
3
+
4
+ module Raygun
5
+ module Apm
6
+ module Sidekiq
7
+ module Hook
8
+ def self.finalize(tracer)
9
+ proc {tracer.process_ended}
10
+ end
11
+
12
+ def initialize(mgr)
13
+ super
14
+ @tracer = Raygun::Apm::Tracer.instance || init_tracer
15
+ end
16
+
17
+ def process(work)
18
+ job_hash = ::Sidekiq.load_json(work.job)
19
+ queue = work.queue_name
20
+ # Can be nil if we had a fatal error
21
+ if @tracer
22
+ @worker_started = @tracer.now
23
+ @tracer.start_trace
24
+ end
25
+ exception = nil
26
+ Ruby_APM_profiler_trace do
27
+ begin
28
+ super
29
+ fake_http_in_handler(@tracer, @worker_started, job_hash, queue, nil) if @tracer
30
+ rescue => e
31
+ fake_http_in_handler(@tracer, @worker_started, job_hash, queue, e) if @tracer
32
+ exception = e
33
+ end
34
+ end
35
+ # Can be nil if we had a fatal error
36
+ @tracer.end_trace if @tracer
37
+ raise exception if exception
38
+ rescue Raygun::Apm::FatalError => e
39
+ raygun_shutdown_handler(e)
40
+ end
41
+
42
+ private
43
+
44
+ def init_tracer
45
+ tracer = Raygun::Apm::Tracer.new
46
+ tracer.udp_sink!
47
+ ObjectSpace.define_finalizer(self, Hook.finalize(tracer))
48
+
49
+ ActiveSupport::Notifications.unsubscribe(@sql_subscriber) if @sql_subscriber
50
+ @sql_subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
51
+ sql_handler(tracer, args)
52
+ end
53
+
54
+ GC.stress = true if ENV['RAYGUN_STRESS_GC']
55
+ Raygun::Apm::Tracer.instance = tracer
56
+ # If any fatal errors on init, shutdown the tracer
57
+ rescue Raygun::Apm::FatalError => e
58
+ raygun_shutdown_handler(e)
59
+ end
60
+
61
+ def raygun_shutdown_handler(exception)
62
+ warn "[Raygun APM] shutting down due to error - #{exception.message} #{exception.backtrace.join("\n")}"
63
+ # Kill extended event subcriptions
64
+ ActiveSupport::Notifications.unsubscribe(@sql_subscriber)
65
+ warn "[Raygun APM] notification hooks unsubscribed"
66
+ # Let the GC clean up the sink thread through the finalizer below
67
+ @tracer = nil
68
+ Raygun::Apm::Tracer.instance = nil
69
+ raise(exception) unless (Raygun::Apm::FatalError === exception)
70
+ end
71
+
72
+ def fake_http_in_handler(tracer, started, msg, queue, exception)
73
+ ended = tracer.now
74
+ event = http_in_event
75
+ event[:pid] = Process.pid
76
+ event[:url] = "sidekiq://#{queue}/#{msg["class"]}?#{msg["jid"]}"
77
+ event[:status] = exception ? 500 : 200
78
+ event[:duration] = ended - started
79
+ event[:timestamp] = tracer.now
80
+ event[:tid] = tracer.get_thread_id(Thread.current)
81
+ tracer.emit(event)
82
+ rescue => e
83
+ warn "[Raygun APM] error reporting HTTP IN event #{e.class} #{e.backtrace.join("\n")}"
84
+ raygun_shutdown_handler(e)
85
+ end
86
+
87
+ def http_in_event
88
+ @http_in_event ||= begin
89
+ event = Raygun::Apm::Event::HttpIn.new
90
+ event[:verb] = "POST"
91
+ event
92
+ end
93
+ end
94
+
95
+ def sql_handler(tracer, args)
96
+ notification = ActiveSupport::Notifications::Event.new *args
97
+ connection = if notification.payload[:connection]
98
+ notification.payload[:connection]
99
+ else
100
+ ObjectSpace._id2ref(notification.payload[:connection_id])
101
+ end
102
+ event = sql_event
103
+ event[:pid] = Process.pid
104
+ event[:query] = notification.payload[:sql]
105
+
106
+ # XXX this is hacky
107
+ if config = connection.instance_variable_get('@config')
108
+ event[:provider] = config[:adapter]
109
+ event[:host] = config[:host]
110
+ event[:database] = config[:database]
111
+ end
112
+
113
+ # XXX constant milliseconds to microseconds
114
+ event[:duration] = notification.duration * 1000
115
+ event[:timestamp] = notification.time.to_f * 1000000
116
+ event[:tid] = tracer.get_thread_id(Thread.current)
117
+ tracer.emit(event)
118
+ rescue => e
119
+ warn "[Raygun APM] error reporting SQL event"
120
+ raygun_shutdown_handler(e)
121
+ end
122
+
123
+ def sql_event
124
+ @sql_event ||= Raygun::Apm::Event::Sql.new
125
+ end
126
+
127
+ def Ruby_APM_profiler_trace
128
+ yield
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ Sidekiq::Processor.prepend Raygun::Apm::Sidekiq::Hook
@@ -4,18 +4,16 @@ module Raygun
4
4
  class Railtie < ::Rails::Railtie
5
5
  initializer "raygun.apm.sidekiq" do |app|
6
6
  require "raygun/apm"
7
- require "raygun/apm/sidekiq/middleware"
8
- require "sidekiq"
7
+ require "raygun/apm/sidekiq/hook"
9
8
  Raygun::Apm::Blacklist.extend_with Raygun::Apm::Sidekiq::BLACKLIST
10
-
11
- ::Sidekiq.configure_server do |config|
12
- config.server_middleware do |chain|
13
- chain.prepend Raygun::Apm::Sidekiq::Middleware
14
- end
15
- end
16
-
17
9
  # Explictly enable instrumenting HTTP until a good control API is figured out
18
10
  require "raygun/apm/hooks/net_http"
11
+ require "raygun/apm/hooks/redis" if defined?(Redis::Client)
12
+ # Attempt to explicitly require the raygun4ruby sidekiq integration
13
+ begin
14
+ require "raygun/sidekiq"
15
+ rescue LoadError
16
+ end
19
17
  end
20
18
  end
21
19
  end
@@ -1,7 +1,7 @@
1
1
  module Raygun
2
2
  module Apm
3
3
  module Sidekiq
4
- VERSION = "1.0.11"
4
+ VERSION = "1.0.16"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raygun-apm-sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.16
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-15 00:00:00.000000000 Z
12
+ date: 2020-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: raygun-apm
@@ -75,6 +75,7 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
+ - ".gitignore"
78
79
  - CHANGELOG.rdoc
79
80
  - Gemfile
80
81
  - Gemfile.lock
@@ -83,10 +84,9 @@ files:
83
84
  - bin/console
84
85
  - bin/setup
85
86
  - lib/raygun/apm/sidekiq.rb
86
- - lib/raygun/apm/sidekiq/middleware.rb
87
+ - lib/raygun/apm/sidekiq/hook.rb
87
88
  - lib/raygun/apm/sidekiq/railtie.rb
88
89
  - lib/raygun/apm/sidekiq/version.rb
89
- - raygun-apm-sidekiq-1.0.0.gem
90
90
  - raygun-apm-sidekiq.gemspec
91
91
  homepage: https://raygun.com/platform/apm
92
92
  licenses: []
@@ -1,127 +0,0 @@
1
- module Raygun
2
- module Apm
3
- module Sidekiq
4
- class Middleware
5
- def initialize
6
- @tracer = Raygun::Apm::Tracer.instance || self.class.init_tracer
7
- end
8
-
9
- def call(worker_instance, msg, queue)
10
- # Can be nil if we had a fatal error
11
- if @tracer
12
- started = @tracer.now
13
- @tracer.start_trace
14
- end
15
- exception = nil
16
- Ruby_APM_profiler_trace do
17
- yield
18
- self.class.fake_http_in_handler(@tracer, started, worker_instance, msg, queue, nil) if @tracer
19
- rescue => e
20
- self.class.fake_http_in_handler(@tracer, started, worker_instance, msg, queue, exception) if @tracer
21
- end
22
- # Can be nil if we had a fatal error
23
- @tracer.end_trace if @tracer
24
- rescue Raygun::Apm::FatalError => e
25
- self.class.raygun_shutdown_handler(e)
26
- end
27
-
28
- private
29
-
30
- def self.init_tracer
31
- tracer = Raygun::Apm::Tracer.new
32
- tracer.udp_sink!
33
- tracer.process_started
34
- ObjectSpace.define_finalizer(self, self.finalize(tracer))
35
-
36
- @sql_subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
37
- sql_handler(tracer, args)
38
- end
39
-
40
- GC.stress = true if ENV['RAYGUN_STRESS_GC']
41
- Raygun::Apm::Tracer.instance = tracer
42
- # If any fatal errors on init, shutdown the tracer
43
- rescue Raygun::Apm::FatalError => e
44
- raygun_shutdown_handler(e)
45
- end
46
-
47
- def self.raygun_shutdown_handler(exception)
48
- warn "Raygun APM shutting down due to error - %s", exception.message
49
- # Kill extended event subcriptions
50
- ActiveSupport::Notifications.unsubscribe(@sql_subscriber)
51
- warn "[Raygun APM] notification hooks unsubscribed"
52
- # Let the GC clean up the sink thread through the finalizer below
53
- @tracer = nil
54
- Raygun::Apm::Tracer.instance = nil
55
- raise(exception) unless (Raygun::Apm::FatalError === exception)
56
- end
57
-
58
- def self.fake_http_in_handler(tracer, started, worker_instance, msg, queue, exception)
59
- ended = tracer.now
60
- event = http_in_event
61
- event[:url] = "sidekiq://#{queue}/#{msg["class"]}?#{msg["jid"]}"
62
- event[:status] = exception ? 500 : 200
63
- event[:duration] = ended - started
64
- event[:timestamp] = tracer.now
65
- event[:tid] = tracer.get_thread_id(Thread.current)
66
- tracer.emit(event)
67
- raise(exception) if exception
68
- rescue => e
69
- warn "[Raygun APM] error reporting HTTP IN event"
70
- raygun_shutdown_handler(e)
71
- end
72
-
73
- def self.http_in_event
74
- @http_in_event ||= begin
75
- event = Raygun::Apm::Event::HttpIn.new
76
- event[:pid] = Process.pid
77
- event[:verb] = "POST"
78
- event
79
- end
80
- end
81
-
82
- def self.sql_handler(tracer, args)
83
- notification = ActiveSupport::Notifications::Event.new *args
84
- connection = if notification.payload[:connection]
85
- notification.payload[:connection]
86
- else
87
- ObjectSpace._id2ref(notification.payload[:connection_id])
88
- end
89
- event = sql_event
90
- event[:query] = notification.payload[:sql]
91
-
92
- # XXX this is hacky
93
- if config = connection.instance_variable_get('@config')
94
- event[:provider] = config[:adapter]
95
- event[:host] = config[:host]
96
- event[:database] = config[:database]
97
- end
98
-
99
- # XXX constant milliseconds to microseconds
100
- event[:duration] = notification.duration * 1000
101
- event[:timestamp] = notification.time.to_f * 1000000
102
- event[:tid] = tracer.get_thread_id(Thread.current)
103
- tracer.emit(event)
104
- rescue => e
105
- warn "[Raygun APM] error reporting SQL event"
106
- raygun_shutdown_handler(e)
107
- end
108
-
109
- def self.sql_event
110
- @sql_event ||= begin
111
- event = Raygun::Apm::Event::Sql.new
112
- event[:pid] = Process.pid
113
- event
114
- end
115
- end
116
-
117
- def Ruby_APM_profiler_trace
118
- yield
119
- end
120
-
121
- def self.finalize(tracer)
122
- proc {tracer.process_ended}
123
- end
124
- end
125
- end
126
- end
127
- end
Binary file