sentry-sidekiq 4.1.3 → 4.2.0

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: a5ba9a7bc48974dbb919d2859fc58f2db605e1cffcddaa3058a7e0d8ee924832
4
- data.tar.gz: fd590a815c902b52205fc2121b3e093439f9681fe66900809c2440f95af1594f
3
+ metadata.gz: 4e64171c6948ecde7494476fe2eeba1337b4c1c18d14a91400e832056e708580
4
+ data.tar.gz: e9987c3bbcd421ff6ec99e87aeaaec2e3fdfd8caa0ef5225aac07307f7f8734f
5
5
  SHA512:
6
- metadata.gz: 02b0bbab55d0a6fd6d01cc51bc51999e7ba5b81e13da199ebef25ebdec96bf9ed7a417936d9e26263db17dea462d9fa6b4fbcacc5035a6d34e8f9f8dd00828b8
7
- data.tar.gz: 8e8aa01a87c52d657b38a674a9e892ce8d474b89c164ea27c67ed4ce9baba9bcfeb450efb465347792a5acaf881834cd7711f56db8fcc93823c98ea0f4946823
6
+ metadata.gz: 0fc42090e8c82189caf48365f0a160f2cd7cacf38b2b340502c643880ff1b83671f51e89de96f8de4f2a5545ae7aace914653c7000be8eaf00c646da64dc8532
7
+ data.tar.gz: fdf44b2862507f127e9326fb76470cb122c085353b4009fec3a0e6dc844d3fc4a8edd31956ca6e4b6d249eea6f3bb23e591756c83de75fc64bbc4ecc51f06a39
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,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.2.0
4
+
5
+ ### Features
6
+
7
+ - Tag queue name and jid on sidekiq events [#1258](https://github.com/getsentry/sentry-ruby/pull/1258)
8
+ <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">
9
+
10
+ ### Refactorings
11
+
12
+ - Add sidekiq adapter to sentry-rails' ignored adapters list [#1257](https://github.com/getsentry/sentry-ruby/pull/1257)
13
+
3
14
  ## 4.1.3
4
15
 
5
16
  - Use sentry-ruby-core as the main SDK dependency [#1245](https://github.com/getsentry/sentry-ruby/pull/1245)
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
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"
@@ -4,13 +4,22 @@ require "sentry/integrable"
4
4
  require "sentry/sidekiq/version"
5
5
  require "sentry/sidekiq/error_handler"
6
6
  require "sentry/sidekiq/sentry_context_middleware"
7
- # require "sentry/sidekiq/configuration"
8
7
 
9
8
  module Sentry
10
9
  module Sidekiq
11
10
  extend Sentry::Integrable
12
11
 
13
12
  register_integration name: "sidekiq", version: Sentry::Sidekiq::VERSION
13
+
14
+ if defined?(::Rails)
15
+ class Railtie < ::Rails::Railtie
16
+ config.after_initialize do
17
+ next unless Sentry.initialized?
18
+
19
+ Sentry.configuration.rails.skippable_job_adapters << "ActiveJob::QueueAdapters::SidekiqAdapter"
20
+ end
21
+ end
22
+ end
14
23
  end
15
24
  end
16
25
 
@@ -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,20 @@ 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)
8
+
9
+ context_filter = Sentry::Sidekiq::ContextFilter.new(context)
10
+
11
11
  scope = Sentry.get_current_scope
12
- scope.set_transaction_name(transaction_from_context(context)) unless scope.transaction_name
12
+ scope.set_transaction_name(context_filter.transaction_name) unless scope.transaction_name
13
13
 
14
14
  Sentry::Sidekiq.capture_exception(
15
15
  ex,
16
- extra: { sidekiq: context },
16
+ extra: { sidekiq: context_filter.filtered },
17
17
  hint: { background: false }
18
18
  )
19
19
  end
20
-
21
- private
22
-
23
- # this will change in the future:
24
- # https://github.com/mperham/sidekiq/pull/3161
25
- def transaction_from_context(context)
26
- classname = (context["wrapped"] || context["class"] ||
27
- (context[:job] && (context[:job]["wrapped"] || context[:job]["class"]))
28
- )
29
- if classname
30
- "#{SIDEKIQ_NAME}/#{classname}"
31
- elsif context[:event]
32
- "#{SIDEKIQ_NAME}/#{context[:event]}"
33
- else
34
- SIDEKIQ_NAME
35
- end
36
- end
37
20
  end
38
21
  end
39
22
  end
@@ -1,13 +1,18 @@
1
+ require 'sentry/sidekiq/context_filter'
2
+
1
3
  module Sentry
2
4
  module Sidekiq
3
5
  class SentryContextMiddleware
4
6
  def call(_worker, job, queue)
5
7
  return yield unless Sentry.initialized?
6
8
 
9
+ context_filter = Sentry::Sidekiq::ContextFilter.new(job)
10
+
7
11
  Sentry.clone_hub_to_current_thread
8
12
  scope = Sentry.get_current_scope
13
+ scope.set_tags(queue: queue, jid: job["jid"])
9
14
  scope.set_extras(sidekiq: job.merge("queue" => queue))
10
- scope.set_transaction_name("Sidekiq/#{job["class"]}")
15
+ scope.set_transaction_name(context_filter.transaction_name)
11
16
 
12
17
  yield
13
18
 
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Sidekiq
3
- VERSION = "4.1.3"
3
+ VERSION = "4.2.0"
4
4
  end
5
5
  end
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
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-core", "~> 4.1.2"
25
+ spec.add_dependency "sentry-ruby-core", "~> 4.2.0"
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.3
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-28 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sentry-ruby-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.2
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.2
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: []
@@ -49,7 +49,6 @@ 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
55
54
  - lib/sentry/sidekiq/sentry_context_middleware.rb
@@ -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::Sidekiq.capture_exception(ex, hint: { background: false })
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end