alexb-raygun-apm-sidekiq 1.0.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1c4ae18213fc0abb4d5575d6191c0a266ce11088e68961b33fde10bfeb9a6c89
4
+ data.tar.gz: 0335266a8f195d5fb22682a255150a2a7493aca5a76b145fbee1ab1610e4194a
5
+ SHA512:
6
+ metadata.gz: 2fd5a03970df814e925190eb25588cfe9a36a4c0db6f47b67594c0ece6dabb8160eb4cfed50f32d7f78b4ddc4896b5d3ac6c322f0ad6bb4383a8dfb88154a0fc
7
+ data.tar.gz: 31dc61ac4bb79c0d802b62e65a23876051a4bb03efc83d0e5179b11b1a9febcbdc672567531379c5f5497327981d4e6e00cc5ceb28c28888aad323c286ab144b
@@ -0,0 +1,82 @@
1
+ = Raygun Application Performance Monitoring
2
+
3
+ {Sidekiq}[https://github.com/mperham/sidekiq] for {Raygun Application Performance Monitoring}[https://raygun.com/platform/apm].
4
+
5
+ Distributed as a Rails and Sidekiq wrapper to inject the precompiled native profiler gem into Sidekiq jobs.
6
+
7
+ == Supported platforms
8
+ * x86-mingw32
9
+ * x64-mingw32
10
+ * x86-linux
11
+ * x86_64-linux
12
+ * universal-darwin
13
+
14
+ {Contact us}[https://raygun.com/about/contact] to support other platforms.
15
+
16
+ == Supported Ruby versions
17
+
18
+ The profiler only supports CRuby, also known as Matz's Ruby Interpreter (MRI).
19
+
20
+ * 2.5.x
21
+ * 2.6.x
22
+ * 2.7.x
23
+
24
+ {Contact us}[https://raygun.com/about/contact] to support other Ruby versions.
25
+
26
+ == Supported Rails versions
27
+
28
+ Rails 4 and up.
29
+
30
+ * Rails 4.x
31
+ * Rails 5.x
32
+ * Rails 6.x
33
+
34
+ {Contact us}[https://raygun.com/about/contact] to support other Rails versions.
35
+
36
+ == Agent Setup
37
+
38
+ The Profiler needs to be able to access the Raygun Agent over UDP.
39
+
40
+ The <code>RAYGUN_AGENT_TOKEN</code> needs to be supplied as an argument and is available under "Application Settings" at the {Raygun Application Performance Monitoring}[https://raygun.com/platform/apm] UI
41
+
42
+ To launch Raygun Agent using docker
43
+ docker pull raygunowner/raygun-apm
44
+ docker run -v raygun-agent:/usr/share/Raygun -e "RAYGUN_AGENT_TOKEN=<token>" -p 2790:2790 -p 2788:2788 -p 2799:2799/udp -it raygunowner/raygun-apm:latest
45
+
46
+ == Profiler Setup
47
+
48
+ Include the gem in your Gemfile and enable it for all environments:
49
+
50
+ gem 'raygun-apm-sidekiq'
51
+
52
+ Preferably this profiler should only be enabled for your production environment:
53
+
54
+ group :production do
55
+ gem 'raygun-apm-sidekiq'
56
+ end
57
+
58
+ It is intended to work best alongside the {raygun-apm-rails}[https://rubygems.org/gems/raygun-apm-rails] gem to profile both inline Web and async job work.
59
+
60
+
61
+ group :production do
62
+ gem 'raygun-apm-rails'
63
+ gem 'raygun-apm-sidekiq'
64
+ end
65
+
66
+
67
+ Run <code>bundle</code> to install the gem.
68
+
69
+ Alternatively install using rubygems <code>gem install raygun-apm-sidekiq</code>.
70
+
71
+ == Rails workloads supported
72
+
73
+ Currently we only hook into the framework with Rack middleware and thus only
74
+ instrument HTTP request / response workloads.
75
+
76
+ The following extended events are captured:
77
+
78
+ * HTTP inbound - the request URI, HTTP verb and other details of the current job
79
+ * HTTP outbound - the URI, HTTP verb and time taken (typically external APIs)
80
+ * Database queries - SQL statement, provider, database etc.
81
+
82
+ {Contact us}[https://raygun.com/about/contact] to support other specific background processing frameworks.
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "raygun/apm/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ require "raygun/apm/sidekiq/version"
2
+
3
+ module Raygun
4
+ module Apm
5
+ module Sidekiq
6
+ class Error < StandardError; end
7
+
8
+ BLACKLIST = %w{
9
+ Sidekiq
10
+ +Raygun::Apm::Sidekiq::Hook#Ruby_APM_profiler_trace
11
+ }
12
+
13
+ end
14
+ end
15
+ end
16
+
17
+ if defined?(::Rails) && !ENV['RAYGUN_SKIP_MIDDLEWARE']
18
+ require "raygun/apm/sidekiq/railtie"
19
+ 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
@@ -0,0 +1,21 @@
1
+ module Raygun
2
+ module Apm
3
+ module Sidekiq
4
+ class Railtie < ::Rails::Railtie
5
+ initializer "raygun.apm.sidekiq" do |app|
6
+ require "raygun/apm"
7
+ require "raygun/apm/sidekiq/hook"
8
+ Raygun::Apm::Blacklist.extend_with Raygun::Apm::Sidekiq::BLACKLIST
9
+ # Explictly enable instrumenting HTTP until a good control API is figured out
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
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ module Raygun
2
+ module Apm
3
+ module Sidekiq
4
+ VERSION = "1.0.21"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "raygun/apm/sidekiq/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alexb-raygun-apm-sidekiq"
8
+ spec.version = Raygun::Apm::Sidekiq::VERSION
9
+ spec.authors = ["Raygun", "Erkki Eilonen"]
10
+ spec.email = ["support@raygun.com", "info@bearmetal.eu"]
11
+
12
+ spec.summary = %q{Raygun application performance monitoring for Sidekiq}
13
+ spec.homepage = "https://raygun.com/platform/apm"
14
+ #spec.license = "MIT"
15
+
16
+ spec.files = Dir['README.rdoc', 'raygun-apm-sidekiq.gemspec', 'lib/**/*', 'bin/**/*']
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "raygun-apm", "~> 1.0.44"
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alexb-raygun-apm-sidekiq
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.21
5
+ platform: ruby
6
+ authors:
7
+ - Raygun
8
+ - Erkki Eilonen
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2020-08-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: raygun-apm
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 1.0.44
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 1.0.44
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: minitest
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '5.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '5.0'
70
+ description:
71
+ email:
72
+ - support@raygun.com
73
+ - info@bearmetal.eu
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - README.rdoc
79
+ - bin/console
80
+ - bin/setup
81
+ - lib/raygun/apm/sidekiq.rb
82
+ - lib/raygun/apm/sidekiq/hook.rb
83
+ - lib/raygun/apm/sidekiq/railtie.rb
84
+ - lib/raygun/apm/sidekiq/version.rb
85
+ - raygun-apm-sidekiq.gemspec
86
+ homepage: https://raygun.com/platform/apm
87
+ licenses: []
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubygems_version: 3.1.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Raygun application performance monitoring for Sidekiq
108
+ test_files: []