sentry-sidekiq 0.1.1

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: 3dcbdbb06dfb5f66f6f2c0eaf94d16acd55b5a977908c39ea2623df6185a9304
4
+ data.tar.gz: edf38d17f4163966a3173c25440acff488c5aaf155926843526458bf7f8ee2cd
5
+ SHA512:
6
+ metadata.gz: b39e448dd3cb7178a23b6df2ac22c548d465178b6a2303235aa43c868adc69dbcc37b50b0e1cd290d35802d4d9f1c5d4ac9d8fb24786120f93843743c036d476
7
+ data.tar.gz: '0840c9eb5f8dd8c0a0f90b4a511b3713aba46c6c6aa4e7c5cfa9d44ef5fe463ac0f2f535880e0addc77e63d283f90d55aae143f9ec281ffdad0f7a9623131465'
@@ -0,0 +1,19 @@
1
+ minVersion: '0.13.2'
2
+ github:
3
+ owner: getsentry
4
+ repo: sentry-ruby
5
+ changelogPolicy: simple
6
+ preReleaseCommand: ruby ../.scripts/bump-version.rb
7
+ releaseBranchPrefix: release-sentry-sidekiq
8
+ statusProvider:
9
+ name: github
10
+ artifactProvider:
11
+ name: github
12
+ targets:
13
+ - name: gem
14
+ - name: github
15
+ tagPrefix: sentry-sidekiq
16
+ - name: registry
17
+ type: sdk
18
+ config:
19
+ canonical: 'gem:sentry-sidekiq'
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.1
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## 0.1.1
4
+
5
+ Release test
6
+
7
+ ## 0.1.0
8
+
9
+ First version
10
+
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at stan001212@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sentry-ruby.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "codecov"
9
+
10
+ gem "sidekiq"
11
+ gem "activejob"
12
+
13
+ gem "sentry-ruby", path: "../sentry-ruby"
14
+
15
+ gem "pry"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 st0012
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # sentry-sidekiq
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'sentry-sidekiq'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ ## Usage
16
+
17
+ See `sentry-ruby` for how to configure the Sentry client.
18
+
19
+ You can also see the example under the `/example` folder.
20
+
21
+
22
+ ## Development
23
+
24
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+
26
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sentry-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/sentry-ruby/blob/master/CODE_OF_CONDUCT.md).
31
+
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the Sentry::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sentry-ruby/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sentry/ruby"
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,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "sidekiq"
4
+ gem "sentry-sidekiq", path: "../"
5
+ gem "sentry-ruby", path: "../../sentry-ruby"
6
+
7
+ gem "pry"
@@ -0,0 +1,8 @@
1
+ # sentry-sidekiq example
2
+
3
+ ## Usage
4
+
5
+ 1. run `bundle install`
6
+ 2. change the `dsn` inside `error_worker.rb`
7
+ 3. run `bundle exec sidekiq -r ./error_worker.rb`
8
+ 4. you should see the event from your Sentry dashboard
@@ -0,0 +1,8 @@
1
+ ---
2
+ :verbose: false
3
+ :concurrency: 10
4
+ :timeout: 25
5
+
6
+ :queues:
7
+ - default
8
+
@@ -0,0 +1,18 @@
1
+ require "sidekiq"
2
+ require "sentry/sidekiq"
3
+
4
+ Sentry.init do |config|
5
+ config.breadcrumbs_logger = [:sentry_logger]
6
+ # replace it with your sentry dsn
7
+ config.dsn = 'https://2fb45f003d054a7ea47feb45898f7649@o447951.ingest.sentry.io/5434472'
8
+ end
9
+
10
+ class ErrorWorker
11
+ include Sidekiq::Worker
12
+
13
+ def perform
14
+ 1 / 0
15
+ end
16
+ end
17
+
18
+ ErrorWorker.perform_async
@@ -0,0 +1,23 @@
1
+ require "sidekiq"
2
+ require "sentry"
3
+ require "sentry/sidekiq/error_handler"
4
+ require "sentry/sidekiq/cleanup_middleware"
5
+ # require "sentry/sidekiq/configuration"
6
+
7
+ module Sentry
8
+ module Sidekiq
9
+ META = { "name" => "sentry.ruby.sidekiq", "version" => Sentry::Sidekiq::VERSION }.freeze
10
+ end
11
+
12
+ def self.sdk_meta
13
+ Sentry::Sidekiq::META
14
+ end
15
+ end
16
+
17
+ Sidekiq.configure_server do |config|
18
+ config.error_handlers << Sentry::Sidekiq::ErrorHandler.new
19
+ config.server_middleware do |chain|
20
+ chain.add Sentry::Sidekiq::CleanupMiddleware
21
+ end
22
+ end
23
+
@@ -0,0 +1,19 @@
1
+ module Sentry
2
+ module Sidekiq
3
+ class CleanupMiddleware
4
+ def call(_worker, job, queue)
5
+ Sentry.clone_hub_to_current_thread
6
+ Sentry.with_scope do |scope|
7
+ scope.set_extras(sidekiq: job.merge("queue" => queue))
8
+ scope.set_transaction_name("Sidekiq/#{job["class"]}")
9
+
10
+ begin
11
+ yield
12
+ rescue => ex
13
+ Sentry.capture_exception(ex)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ module Sentry
2
+ module Sidekiq
3
+ class ContextFilter
4
+ ACTIVEJOB_RESERVED_PREFIX_REGEX = /^_aj_/.freeze
5
+
6
+ def initialize
7
+ @has_global_id = defined?(GlobalID)
8
+ end
9
+
10
+ # Once an ActiveJob is queued, ActiveRecord references get serialized into
11
+ # some internal reserved keys, such as _aj_globalid.
12
+ #
13
+ # The problem is, if this job in turn gets queued back into ActiveJob with
14
+ # these magic reserved keys, ActiveJob will throw up and error. We want to
15
+ # capture these and mutate the keys so we can sanely report it.
16
+ def filter_context(context)
17
+ case context
18
+ when Array
19
+ context.map { |arg| filter_context(arg) }
20
+ when Hash
21
+ Hash[context.map { |key, value| filter_context_hash(key, value) }]
22
+ else
23
+ if has_global_id? && context.is_a?(GlobalID)
24
+ context.to_s
25
+ else
26
+ context
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def filter_context_hash(key, value)
34
+ key = key.to_s.sub(ACTIVEJOB_RESERVED_PREFIX_REGEX, "") if key.match(ACTIVEJOB_RESERVED_PREFIX_REGEX)
35
+ [key, filter_context(value)]
36
+ end
37
+
38
+ def has_global_id?
39
+ @has_global_id
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,38 @@
1
+ require 'sentry/sidekiq/context_filter'
2
+
3
+ module Sentry
4
+ module Sidekiq
5
+ class ErrorHandler
6
+ SIDEKIQ_NAME = "Sidekiq".freeze
7
+
8
+ def call(ex, context)
9
+ context = Sentry::Sidekiq::ContextFilter.new.filter_context(context)
10
+
11
+ Sentry.with_scope do |scope|
12
+ scope.set_transaction_name transaction_from_context(context)
13
+ Sentry.capture_exception(
14
+ ex,
15
+ extra: { sidekiq: context }
16
+ )
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ # this will change in the future:
23
+ # https://github.com/mperham/sidekiq/pull/3161
24
+ def transaction_from_context(context)
25
+ classname = (context["wrapped"] || context["class"] ||
26
+ (context[:job] && (context[:job]["wrapped"] || context[:job]["class"]))
27
+ )
28
+ if classname
29
+ "#{SIDEKIQ_NAME}/#{classname}"
30
+ elsif context[:event]
31
+ "#{SIDEKIQ_NAME}/#{context[:event]}"
32
+ else
33
+ SIDEKIQ_NAME
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ module Sentry
2
+ module Sidekiq
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require_relative "lib/sentry/sidekiq/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "sentry-sidekiq"
5
+ spec.version = Sentry::Sidekiq::VERSION
6
+ spec.authors = ["Sentry Team"]
7
+ spec.description = spec.summary = "A gem that provides Sidekiq integration for the Sentry error logger"
8
+ spec.email = "accounts@sentry.io"
9
+ spec.license = 'Apache-2.0'
10
+ spec.homepage = "https://github.com/getsentry/sentry-ruby"
11
+
12
+ spec.platform = Gem::Platform::RUBY
13
+ spec.required_ruby_version = '>= 2.4'
14
+ spec.extra_rdoc_files = ["README.md", "LICENSE.txt"]
15
+ spec.files = `git ls-files | grep -Ev '^(spec|benchmarks|examples)'`.split("\n")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
20
+
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "sentry-ruby"
26
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sentry-sidekiq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Sentry Team
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sentry-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A gem that provides Sidekiq integration for the Sentry error logger
28
+ email: accounts@sentry.io
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files:
32
+ - README.md
33
+ - LICENSE.txt
34
+ files:
35
+ - ".craft.yml"
36
+ - ".gitignore"
37
+ - ".rspec"
38
+ - ".travis.yml"
39
+ - CHANGELOG.md
40
+ - CODE_OF_CONDUCT.md
41
+ - Gemfile
42
+ - LICENSE.txt
43
+ - README.md
44
+ - Rakefile
45
+ - bin/console
46
+ - bin/setup
47
+ - example/Gemfile
48
+ - example/README.md
49
+ - example/config/sidekiq.yml
50
+ - example/error_worker.rb
51
+ - lib/sentry/sidekiq.rb
52
+ - lib/sentry/sidekiq/cleanup_middleware.rb
53
+ - lib/sentry/sidekiq/context_filter.rb
54
+ - lib/sentry/sidekiq/error_handler.rb
55
+ - lib/sentry/sidekiq/version.rb
56
+ - sentry-sidekiq.gemspec
57
+ homepage: https://github.com/getsentry/sentry-ruby
58
+ licenses:
59
+ - Apache-2.0
60
+ metadata:
61
+ homepage_uri: https://github.com/getsentry/sentry-ruby
62
+ source_code_uri: https://github.com/getsentry/sentry-ruby
63
+ changelog_uri: https://github.com/getsentry/sentry-ruby/blob/master/CHANGELOG.md
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '2.4'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 3.0.3
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: A gem that provides Sidekiq integration for the Sentry error logger
83
+ test_files: []