sentry-sidekiq 4.1.0 → 4.2.1

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: 06ff7807f2ed20afd1ddbb25fdefca1d4fa031ed3e7f5a00b0e1070be3b33a46
4
- data.tar.gz: 5653d9635ed8c25f8adf20e7913c12953b4ba8acaf515020cc5859804053abac
3
+ metadata.gz: 383b3c28fc5583dadfc497ae0c3b0dc052e7909f8e71e8d8eca728f68b060aea
4
+ data.tar.gz: b867a8389fbd6e44b06a7256c6dafdc68f04acf2fe4dc2e99c84f647c010e614
5
5
  SHA512:
6
- metadata.gz: ff3cc9abe9105fbfd68b843cc6146d7612e31b96c71bcfcaba346ff0399d3c8e55de2b6e8532a3fb47a7fa41cd4605a83e1b1123678bee8cd3fe0477e20b36bf
7
- data.tar.gz: 900d1648fff07895107620ae91e58ee006de41fc2735a16e8f56e5d5d579f68977c729f84614955f2334ab1a9bb973e65aee7c97fc11f08c36d44989d5033c72
6
+ metadata.gz: 71cd8d00dc973f0521b387ea75b2d2aa52da2078b5bbb7cd1b14533f0db944b1f387dd02a6ed0272ea7958c2fe18981c5350b24121e68e846851ae1c8b3e21d0
7
+ data.tar.gz: c1c3c647df576a8ed592d90a104dd171fe99c4b6cd775ee7364b9f9cbc84489b2614d20d085abf0c7ca1b5c3e71f3f2b50e0bdaf854321fa9b192fb153127b81
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
1
  --format documentation
2
2
  --color
3
- --require spec_helper
data/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.2.1
4
+
5
+ - Use ::Rails::Railtie for checking Rails definition [#1284](https://github.com/getsentry/sentry-ruby/pull/1284)
6
+ - Fixes [#1276](https://github.com/getsentry/sentry-ruby/issues/1276)
7
+
8
+ ## 4.2.0
9
+
10
+ ### Features
11
+
12
+ - Tag queue name and jid on sidekiq events [#1258](https://github.com/getsentry/sentry-ruby/pull/1258)
13
+ <img width="1234" alt="sidekiq event tagged with queue name and jid" src="https://user-images.githubusercontent.com/5079556/106389900-d0381700-6420-11eb-90b9-a95b0881b696.png">
14
+
15
+ ### Refactorings
16
+
17
+ - Add sidekiq adapter to sentry-rails' ignored adapters list [#1257](https://github.com/getsentry/sentry-ruby/pull/1257)
18
+
19
+ ## 4.1.3
20
+
21
+ - Use sentry-ruby-core as the main SDK dependency [#1245](https://github.com/getsentry/sentry-ruby/pull/1245)
22
+
23
+ ## 4.1.2
24
+
25
+ - Fix sidekiq middleware [#1175](https://github.com/getsentry/sentry-ruby/pull/1175)
26
+ - Fixes [#1173](https://github.com/getsentry/sentry-ruby/issues/1173)
27
+ - Adopt Integrable module [#1177](https://github.com/getsentry/sentry-ruby/pull/1177)
28
+
29
+ ## 4.1.1
30
+
31
+ - Use stricter dependency declaration [#1159](https://github.com/getsentry/sentry-ruby/pull/1159)
32
+
3
33
  ## 4.1.0
4
34
 
5
35
  - Check SDK initialization before running integrations [#1151](https://github.com/getsentry/sentry-ruby/pull/1151)
data/Gemfile CHANGED
@@ -3,13 +3,17 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in sentry-ruby.gemspec
4
4
  gemspec
5
5
 
6
+ # TODO: Remove this if https://github.com/jruby/jruby/issues/6547 is addressed
7
+ gem "i18n", "<= 1.8.7"
8
+
6
9
  gem "rake", "~> 12.0"
7
10
  gem "rspec", "~> 3.0"
8
- gem "codecov"
11
+ gem "codecov", "0.2.12"
9
12
 
10
13
  gem "sidekiq"
11
- gem "activejob"
14
+ gem "rails"
12
15
 
13
16
  gem "sentry-ruby", path: "../sentry-ruby"
17
+ gem "sentry-rails", path: "../sentry-rails"
14
18
 
15
19
  gem "pry"
data/Makefile ADDED
@@ -0,0 +1,3 @@
1
+ build:
2
+ bundle install
3
+ gem build sentry-sidekiq.gemspec
@@ -1,24 +1,32 @@
1
1
  require "sidekiq"
2
2
  require "sentry-ruby"
3
+ require "sentry/integrable"
3
4
  require "sentry/sidekiq/version"
4
5
  require "sentry/sidekiq/error_handler"
5
- require "sentry/sidekiq/cleanup_middleware"
6
- # require "sentry/sidekiq/configuration"
6
+ require "sentry/sidekiq/sentry_context_middleware"
7
7
 
8
8
  module Sentry
9
9
  module Sidekiq
10
- META = { "name" => "sentry.ruby.sidekiq", "version" => Sentry::Sidekiq::VERSION }.freeze
11
- end
10
+ extend Sentry::Integrable
11
+
12
+ register_integration name: "sidekiq", version: Sentry::Sidekiq::VERSION
13
+
14
+ if defined?(::Rails::Railtie)
15
+ class Railtie < ::Rails::Railtie
16
+ config.after_initialize do
17
+ next unless Sentry.initialized?
12
18
 
13
- def self.sdk_meta
14
- Sentry::Sidekiq::META
19
+ Sentry.configuration.rails.skippable_job_adapters << "ActiveJob::QueueAdapters::SidekiqAdapter"
20
+ end
21
+ end
22
+ end
15
23
  end
16
24
  end
17
25
 
18
26
  Sidekiq.configure_server do |config|
19
27
  config.error_handlers << Sentry::Sidekiq::ErrorHandler.new
20
28
  config.server_middleware do |chain|
21
- chain.add Sentry::Sidekiq::CleanupMiddleware
29
+ chain.add Sentry::Sidekiq::SentryContextMiddleware
22
30
  end
23
31
  end
24
32
 
@@ -2,8 +2,12 @@ module Sentry
2
2
  module Sidekiq
3
3
  class ContextFilter
4
4
  ACTIVEJOB_RESERVED_PREFIX_REGEX = /^_aj_/.freeze
5
+ SIDEKIQ_NAME = "Sidekiq".freeze
5
6
 
6
- def initialize
7
+ attr_reader :context
8
+
9
+ def initialize(context)
10
+ @context = context
7
11
  @has_global_id = defined?(GlobalID)
8
12
  end
9
13
 
@@ -13,23 +17,41 @@ module Sentry
13
17
  # The problem is, if this job in turn gets queued back into ActiveJob with
14
18
  # these magic reserved keys, ActiveJob will throw up and error. We want to
15
19
  # capture these and mutate the keys so we can sanely report it.
16
- def filter_context(context)
17
- case context
20
+ def filtered
21
+ filter_context(context)
22
+ end
23
+
24
+ def transaction_name
25
+ class_name = (context["wrapped"] || context["class"] ||
26
+ (context[:job] && (context[:job]["wrapped"] || context[:job]["class"]))
27
+ )
28
+
29
+ if class_name
30
+ "#{SIDEKIQ_NAME}/#{class_name}"
31
+ elsif context[:event]
32
+ "#{SIDEKIQ_NAME}/#{context[:event]}"
33
+ else
34
+ SIDEKIQ_NAME
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def filter_context(hash)
41
+ case hash
18
42
  when Array
19
- context.map { |arg| filter_context(arg) }
43
+ hash.map { |arg| filter_context(arg) }
20
44
  when Hash
21
- Hash[context.map { |key, value| filter_context_hash(key, value) }]
45
+ Hash[hash.map { |key, value| filter_context_hash(key, value) }]
22
46
  else
23
- if has_global_id? && context.is_a?(GlobalID)
24
- context.to_s
47
+ if has_global_id? && hash.is_a?(GlobalID)
48
+ hash.to_s
25
49
  else
26
- context
50
+ hash
27
51
  end
28
52
  end
29
53
  end
30
54
 
31
- private
32
-
33
55
  def filter_context_hash(key, value)
34
56
  key = key.to_s.sub(ACTIVEJOB_RESERVED_PREFIX_REGEX, "") if key.match(ACTIVEJOB_RESERVED_PREFIX_REGEX)
35
57
  [key, filter_context(value)]
@@ -3,37 +3,19 @@ require 'sentry/sidekiq/context_filter'
3
3
  module Sentry
4
4
  module Sidekiq
5
5
  class ErrorHandler
6
- SIDEKIQ_NAME = "Sidekiq".freeze
7
-
8
6
  def call(ex, context)
9
7
  return unless Sentry.initialized?
10
- context = Sentry::Sidekiq::ContextFilter.new.filter_context(context)
11
8
 
12
- Sentry.with_scope do |scope|
13
- scope.set_transaction_name transaction_from_context(context)
14
- Sentry.capture_exception(
15
- ex,
16
- extra: { sidekiq: context },
17
- hint: { background: false }
18
- )
19
- end
20
- end
9
+ context_filter = Sentry::Sidekiq::ContextFilter.new(context)
21
10
 
22
- private
11
+ scope = Sentry.get_current_scope
12
+ scope.set_transaction_name(context_filter.transaction_name) unless scope.transaction_name
23
13
 
24
- # this will change in the future:
25
- # https://github.com/mperham/sidekiq/pull/3161
26
- def transaction_from_context(context)
27
- classname = (context["wrapped"] || context["class"] ||
28
- (context[:job] && (context[:job]["wrapped"] || context[:job]["class"]))
29
- )
30
- if classname
31
- "#{SIDEKIQ_NAME}/#{classname}"
32
- elsif context[:event]
33
- "#{SIDEKIQ_NAME}/#{context[:event]}"
34
- else
35
- SIDEKIQ_NAME
36
- end
14
+ Sentry::Sidekiq.capture_exception(
15
+ ex,
16
+ extra: { sidekiq: context_filter.filtered },
17
+ hint: { background: false }
18
+ )
37
19
  end
38
20
  end
39
21
  end
@@ -0,0 +1,25 @@
1
+ require 'sentry/sidekiq/context_filter'
2
+
3
+ module Sentry
4
+ module Sidekiq
5
+ class SentryContextMiddleware
6
+ def call(_worker, job, queue)
7
+ return yield unless Sentry.initialized?
8
+
9
+ context_filter = Sentry::Sidekiq::ContextFilter.new(job)
10
+
11
+ Sentry.clone_hub_to_current_thread
12
+ scope = Sentry.get_current_scope
13
+ scope.set_tags(queue: queue, jid: job["jid"])
14
+ scope.set_extras(sidekiq: job.merge("queue" => queue))
15
+ scope.set_transaction_name(context_filter.transaction_name)
16
+
17
+ yield
18
+
19
+ # don't need to use ensure here
20
+ # if the job failed, we need to keep the scope for error handler. and the scope will be cleared there
21
+ scope.clear
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Sidekiq
3
- VERSION = "4.1.0"
3
+ VERSION = "4.2.1"
4
4
  end
5
5
  end
@@ -16,11 +16,11 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = spec.homepage
19
- spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
19
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/sentry-sidekiq/CHANGELOG.md"
20
20
 
21
21
  spec.bindir = "exe"
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_dependency "sentry-ruby", ">= 4.1.0"
25
+ spec.add_dependency "sentry-ruby-core", "~> 4.2.0"
26
26
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-18 00:00:00.000000000 Z
11
+ date: 2021-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: sentry-ruby
14
+ name: sentry-ruby-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.0
19
+ version: 4.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 4.1.0
26
+ version: 4.2.0
27
27
  description: A gem that provides Sidekiq integration for the Sentry error logger
28
28
  email: accounts@sentry.io
29
29
  executables: []
@@ -35,11 +35,11 @@ files:
35
35
  - ".craft.yml"
36
36
  - ".gitignore"
37
37
  - ".rspec"
38
- - ".travis.yml"
39
38
  - CHANGELOG.md
40
39
  - CODE_OF_CONDUCT.md
41
40
  - Gemfile
42
41
  - LICENSE.txt
42
+ - Makefile
43
43
  - README.md
44
44
  - Rakefile
45
45
  - bin/console
@@ -49,9 +49,9 @@ files:
49
49
  - example/config/sidekiq.yml
50
50
  - example/error_worker.rb
51
51
  - lib/sentry-sidekiq.rb
52
- - lib/sentry/sidekiq/cleanup_middleware.rb
53
52
  - lib/sentry/sidekiq/context_filter.rb
54
53
  - lib/sentry/sidekiq/error_handler.rb
54
+ - lib/sentry/sidekiq/sentry_context_middleware.rb
55
55
  - lib/sentry/sidekiq/version.rb
56
56
  - sentry-sidekiq.gemspec
57
57
  homepage: https://github.com/getsentry/sentry-ruby
@@ -60,7 +60,7 @@ licenses:
60
60
  metadata:
61
61
  homepage_uri: https://github.com/getsentry/sentry-ruby
62
62
  source_code_uri: https://github.com/getsentry/sentry-ruby
63
- changelog_uri: https://github.com/getsentry/sentry-ruby/blob/master/CHANGELOG.md
63
+ changelog_uri: https://github.com/getsentry/sentry-ruby/blob/master/sentry-sidekiq/CHANGELOG.md
64
64
  post_install_message:
65
65
  rdoc_options: []
66
66
  require_paths:
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.6.5
6
- before_install: gem install bundler -v 2.1.1
@@ -1,21 +0,0 @@
1
- module Sentry
2
- module Sidekiq
3
- class CleanupMiddleware
4
- def call(_worker, job, queue)
5
- return yield unless Sentry.initialized?
6
-
7
- Sentry.clone_hub_to_current_thread
8
- Sentry.with_scope do |scope|
9
- scope.set_extras(sidekiq: job.merge("queue" => queue))
10
- scope.set_transaction_name("Sidekiq/#{job["class"]}")
11
-
12
- begin
13
- yield
14
- rescue => ex
15
- Sentry.capture_exception(ex, hint: { background: false })
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end