Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sentry-delayed_job integration #1273

Merged
merged 7 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Basic setup
  • Loading branch information
st0012 committed Feb 9, 2021
commit 8601a236bdd1692175df5f73b2b138a4aa550c90
19 changes: 19 additions & 0 deletions sentry-delayed_job/.craft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
minVersion: '0.13.2'
github:
owner: getsentry
repo: sentry-ruby
changelogPolicy: simple
preReleaseCommand: ruby ../.scripts/bump-version.rb
releaseBranchPrefix: release-sentry-sidekiq
statusProvider:
name: github
artifactProvider:
name: github
targets:
- name: gem
- name: github
tagPrefix: sentry-sidekiq-v
- name: registry
type: sdk
config:
canonical: 'gem:sentry-sidekiq'
11 changes: 11 additions & 0 deletions sentry-delayed_job/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
.rspec_status
2 changes: 2 additions & 0 deletions sentry-delayed_job/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--format documentation
--color
3 changes: 3 additions & 0 deletions sentry-delayed_job/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

## 0.1.0
74 changes: 74 additions & 0 deletions sentry-delayed_job/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [https://contributor-covenant.org/version/1/4][version]

[homepage]: https://contributor-covenant.org
[version]: https://contributor-covenant.org/version/1/4/
19 changes: 19 additions & 0 deletions sentry-delayed_job/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
source "https://rubygems.org"

# Specify your gem's dependencies in sentry-ruby.gemspec
gemspec

# TODO: Remove this if https://github.com/jruby/jruby/issues/6547 is addressed
gem "i18n", "<= 1.8.7"

gem "rake", "~> 12.0"
gem "rspec", "~> 3.0"
gem "codecov", "0.2.12"

gem "delayed_job"
gem "rails"

gem "sentry-ruby", path: "../sentry-ruby"
gem "sentry-rails", path: "../sentry-rails"

gem "pry"
21 changes: 21 additions & 0 deletions sentry-delayed_job/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 st0012

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
3 changes: 3 additions & 0 deletions sentry-delayed_job/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
bundle install
gem build sentry-delayed_job.gemspec
34 changes: 34 additions & 0 deletions sentry-delayed_job/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<p align="center">
<a href="https://sentry.io" target="_blank" align="center">
<img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
</a>
<br>
</p>

# sentry-delayed_job, the DelayedJob integration for Sentry's Ruby client

---


[![Gem Version](https://img.shields.io/gem/v/sentry-delayed_job.svg)](https://rubygems.org/gems/sentry-delayed_job)
![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-delayed_job%20Test/badge.svg)
[![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master)
[![Gem](https://img.shields.io/gem/dt/sentry-delayed_job.svg)](https://rubygems.org/gems/sentry-delayed_job/)
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=sentry-delayed_job&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sentry-delayed_job&package-manager=bundler&version-scheme=semver)


[Documentation](https://docs.sentry.io/platforms/ruby/guides/delayed_job/) | [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues) | [Forum](https://forum.sentry.io/) | IRC: irc.freenode.net, #sentry

The official Ruby-language client and integration layer for the [Sentry](https://github.com/getsentry/sentry) error reporting API.


## Getting Started

### Install

```ruby
gem "sentry-ruby"
gem "sentry-delayed_job"
```

Then you're all set! `sentry-delayed_job` will automatically insert a custom middleware and error handler to capture exceptions from your workers!
8 changes: 8 additions & 0 deletions sentry-delayed_job/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec).tap do |task|
task.rspec_opts = "--order rand"
end

task :default => :spec
14 changes: 14 additions & 0 deletions sentry-delayed_job/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "sentry/ruby"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require "irb"
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions sentry-delayed_job/bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
22 changes: 22 additions & 0 deletions sentry-delayed_job/lib/sentry-delayed_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require "delayed_job"
require "sentry-ruby"
require "sentry/integrable"
require "sentry/delayed_job/version"

module Sentry
module DelayedJob
extend Sentry::Integrable

register_integration name: "delayed_job", version: Sentry::DelayedJob::VERSION

if defined?(::Rails)
class Railtie < ::Rails::Railtie
config.after_initialize do
next unless Sentry.initialized?

Sentry.configuration.rails.skippable_job_adapters << "ActiveJob::QueueAdapters::DelayedJobAdapter"
end
end
end
end
end
5 changes: 5 additions & 0 deletions sentry-delayed_job/lib/sentry/delayed_job/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Sentry
module DelayedJob
VERSION = "0.1.0"
end
end
26 changes: 26 additions & 0 deletions sentry-delayed_job/sentry-delayed_job.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require_relative "lib/sentry/delayed_job/version"

Gem::Specification.new do |spec|
spec.name = "sentry-delayed_job"
spec.version = Sentry::DelayedJob::VERSION
spec.authors = ["Sentry Team"]
spec.description = spec.summary = "A gem that provides DelayedJob integration for the Sentry error logger"
spec.email = "[email protected]"
spec.license = 'Apache-2.0'
spec.homepage = "https://github.com/getsentry/sentry-ruby"

spec.platform = Gem::Platform::RUBY
spec.required_ruby_version = '>= 2.4'
spec.extra_rdoc_files = ["README.md", "LICENSE.txt"]
spec.files = `git ls-files | grep -Ev '^(spec|benchmarks|examples)'`.split("\n")

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = spec.homepage
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/sentry-delayed_job/CHANGELOG.md"

spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "sentry-ruby-core", "~> 4.2.0"
end
12 changes: 12 additions & 0 deletions sentry-delayed_job/spec/sentry/delayed_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require "spec_helper"

RSpec.describe Sentry::DelayedJob do
before do
perform_basic_setup
end

let(:transport) do
Sentry.get_current_client.transport
end
end

91 changes: 91 additions & 0 deletions sentry-delayed_job/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
require "bundler/setup"
require "pry"

require "sentry-ruby"

require 'simplecov'

SimpleCov.start do
project_name "sentry-delayed_job"
root File.join(__FILE__, "../../../")
coverage_dir File.join(__FILE__, "../../coverage")
end

if ENV["CI"]
require 'codecov'
SimpleCov.formatter = SimpleCov::Formatter::Codecov
end

require "sentry-delayed_job"

DUMMY_DSN = 'http:https://12345:[email protected]/sentry/42'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"

# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!

config.expect_with :rspec do |c|
c.syntax = :expect
end

config.before :each do
# Make sure we reset the env in case something leaks in
ENV.delete('SENTRY_DSN')
ENV.delete('SENTRY_CURRENT_ENV')
ENV.delete('SENTRY_ENVIRONMENT')
ENV.delete('SENTRY_RELEASE')
ENV.delete('RACK_ENV')
end
end

def build_exception
1 / 0
rescue ZeroDivisionError => e
e
end

def build_exception_with_cause(cause = "exception a")
begin
raise cause
rescue
raise "exception b"
end
rescue RuntimeError => e
e
end

def build_exception_with_two_causes
begin
begin
raise "exception a"
rescue
raise "exception b"
end
rescue
raise "exception c"
end
rescue RuntimeError => e
e
end

def build_exception_with_recursive_cause
backtrace = []

exception = double("Exception")
allow(exception).to receive(:cause).and_return(exception)
allow(exception).to receive(:message).and_return("example")
allow(exception).to receive(:backtrace).and_return(backtrace)
exception
end

def perform_basic_setup
Sentry.init do |config|
config.dsn = DUMMY_DSN
config.logger = ::Logger.new(nil)
config.background_worker_threads = 0
config.transport.transport_class = Sentry::DummyTransport
end
end