raygun-apm-sidekiq 1.0.12 → 1.0.17

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
  SHA256:
3
- metadata.gz: 9d7f0de52da00010cd3d499c15ceecf7f687983fd5a03b938768ec997e70a966
4
- data.tar.gz: 3dd1bbf9171539d4ec427cef365d712ccb02b54d02ba748e7d3882a7a13b1cd7
3
+ metadata.gz: 849fd2aaca44d53e5d5387365898898e08476a1d7da0d04cfde9ef5f99de8ea2
4
+ data.tar.gz: d6832067056044c52a85c804f399075253c1707f773d9fe6f2b3b31ea4a66249
5
5
  SHA512:
6
- metadata.gz: d38d374b6b8c4e29d015abbbca69b513cb934e4e5c942bfba619f9d23bcd85bb84c392080245ee578e0aa95ab74e04ff175732fedbf27503ecd4838afd25c9ee
7
- data.tar.gz: 42f5e127cdc0f3be52f953b3b73807a6fdd2097f77bde16b8663bce030e122073e6f266a7500072e927dcb238111e6ffbb6dc9b1a4689a3e530765e4caeaefea
6
+ metadata.gz: 30b050b41a163c363f9b30c6a5a2e615c9933c06d6c358c8b081587a55b6bf47b0b6d66236bf8af5b5401844bb5c638207b28d5bee6d43eebfd908d8cc198577
7
+ data.tar.gz: 19c8201d2bff549a23990e1851b819ee6e88e76aaed3cb609a8e0757dc3b49c3bea2981b10f25cd0aad4e08b22c10fbae43319658a25b2024f561fe68bc5bafe
@@ -0,0 +1 @@
1
+ *.gem
@@ -1,5 +1,27 @@
1
1
  = Changelog
2
2
 
3
+ == 1.0.17 (June 17, 2020)
4
+
5
+ * Align with rubyesque blacklist syntax support from profiler version 1.0.44
6
+
7
+ == 1.0.16 (June 8, 2020)
8
+
9
+ * Integrate exception correlation with rayrun4ruby
10
+ * Move raygun4ruby whitelisting and blacklisting out to profiler core
11
+
12
+ == 1.0.15 (May 17, 2020)
13
+
14
+ * Remove the Tracer#process_started callback (set on begin transaction command now)
15
+
16
+ == 1.0.14 (May 15, 2020)
17
+
18
+ * Introduce support for Redis as client adapter
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.13 (April 2, 2020)
22
+
23
+ * Prefer hooking Sidekiq::Processor as Middleware does not wrap enough to intercept the raygun4ruby error handler as an HTTP OUT event
24
+
3
25
  == 1.0.12 (March 25, 2020)
4
26
 
5
27
  * Do not cache PID on HTTP OUT and SQL events
@@ -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.17)
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.44-x86-linux)
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.12"
4
+ VERSION = "1.0.17"
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.12
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-25 00:00:00.000000000 Z
12
+ date: 2020-06-17 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,124 +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[:pid] = Process.pid
62
- event[:url] = "sidekiq://#{queue}/#{msg["class"]}?#{msg["jid"]}"
63
- event[:status] = exception ? 500 : 200
64
- event[:duration] = ended - started
65
- event[:timestamp] = tracer.now
66
- event[:tid] = tracer.get_thread_id(Thread.current)
67
- tracer.emit(event)
68
- raise(exception) if exception
69
- rescue => e
70
- warn "[Raygun APM] error reporting HTTP IN event"
71
- raygun_shutdown_handler(e)
72
- end
73
-
74
- def self.http_in_event
75
- @http_in_event ||= begin
76
- event = Raygun::Apm::Event::HttpIn.new
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[:pid] = Process.pid
91
- event[:query] = notification.payload[:sql]
92
-
93
- # XXX this is hacky
94
- if config = connection.instance_variable_get('@config')
95
- event[:provider] = config[:adapter]
96
- event[:host] = config[:host]
97
- event[:database] = config[:database]
98
- end
99
-
100
- # XXX constant milliseconds to microseconds
101
- event[:duration] = notification.duration * 1000
102
- event[:timestamp] = notification.time.to_f * 1000000
103
- event[:tid] = tracer.get_thread_id(Thread.current)
104
- tracer.emit(event)
105
- rescue => e
106
- warn "[Raygun APM] error reporting SQL event"
107
- raygun_shutdown_handler(e)
108
- end
109
-
110
- def self.sql_event
111
- @sql_event ||= Raygun::Apm::Event::Sql.new
112
- end
113
-
114
- def Ruby_APM_profiler_trace
115
- yield
116
- end
117
-
118
- def self.finalize(tracer)
119
- proc {tracer.process_ended}
120
- end
121
- end
122
- end
123
- end
124
- end
Binary file