escalate 0.1.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bb743da8ea57e11a7bfa80d653548239e0b760ab
4
+ data.tar.gz: 36555a0ba6f8bca3f821c5b0044739e26762cc23
5
+ SHA512:
6
+ metadata.gz: 7c735aa3214359068d14e0fd981c64c62e14896d73965d467d5b28ebaa3d2bf300ae9037164d3a4a7e5a6b4a77439a8a5137dd5d3b7b51eda27cef0ec7a57a60
7
+ data.tar.gz: a3899dc985f47f6e87d609b5fdf85443b9278ca100b40e5e41e4be641c8aa6116850dc80a4426f779c34e741b5b0893c9032e3c2b59974a9b802da0bcc8629bd
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.4.2
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.6
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -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
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog for `escalate`
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.1.0] - Unreleased
8
+
9
+ [0.1.0]: https://github.com/Invoca/escalate/releases/tag/v0.1.0
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,47 @@
1
+ # Contributing to Escalate
2
+
3
+ This document explains our guidelines and workflows to contributing to an Invoca open source project. Please take care to follow the guidelines, as they exist to help us manage changes in a timely and efficient manner.
4
+
5
+ ## Code of Conduct
6
+ All contributors to this project must adhere to the [Community Code of Conduct](https://github.com/Invoca/escalate/blob/master/code-of-conduct.md)
7
+
8
+ ## Environment Setup
9
+ 1. Install the ruby version specified in the [.ruby-version](https://github.com/Invoca/escalate/blob/master/.ruby-version) file (preferably you're using [rvm](https://rvm.io/) or [rbenv](https://github.com/rbenv/rbenv) to manage ruby versions)
10
+ 2. Make a fork of Escalate, then clone your fork to your machine
11
+ 3. Run `bundle install` in your Escalate directory to install dependencies
12
+
13
+ ## Branching
14
+
15
+ * __Create an issue before starting a branch__
16
+ * For bugs, prefix the branch name with `bug/`
17
+ * For features, prefix the branch name with `feature/`
18
+ * Include the issue number and a short description of the issue
19
+
20
+ Examples
21
+ * `bug/1234_fix_issue_with_formatter_not_formatting`
22
+ * `feature/4321_merge_contexts_together`
23
+
24
+ ## Filing Issues
25
+
26
+ * Use the appropriate template provided
27
+ * Include as much information as possible to help:
28
+ * The person who will be fixing the bug understand the issue
29
+ * The person code reviewing the fix to understand what the original need was
30
+ * Check for open issues before filing your own
31
+
32
+ ## Committing
33
+
34
+ * Break your commits into logical atomic units. Well-segmented commits make it much easier for others to step through your changes.
35
+ * Limit your subject (first) line to 50 characters (GitHub truncates more than 70).
36
+ * Provide a body if you'd like to explain your commit in detail.
37
+ * Capitalize the beginning of your subject line, and do not end the subject line with a period.
38
+ * Your subject line should complete this sentence: `If applied, this commit will [your subject line]`.
39
+ * Don't use [magic GitHub words](https://help.github.com/articles/closing-issues-using-keywords/) in your commits to close issues - do that in the pull request for your code instead.
40
+ * Adapted from [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/#seven-rules).
41
+
42
+ ## Making Pull Requests
43
+
44
+ * Use fill out the template provided
45
+ * Provide a link to the issue being resolved by the PR
46
+ * Make sure to include tests
47
+ * Resolve linting comments from Hound before requesting review
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in escalate.gemspec
6
+ gemspec
7
+
8
+ gem "pry"
9
+ gem "pry-byebug"
10
+
11
+ gem "rake", "~> 13.0"
12
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ escalate (0.1.0.pre.1)
5
+ activesupport
6
+ contextual_logger
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.4.4)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ byebug (11.1.3)
17
+ coderay (1.1.3)
18
+ concurrent-ruby (1.1.8)
19
+ contextual_logger (0.11.0)
20
+ activesupport
21
+ json
22
+ diff-lcs (1.4.4)
23
+ i18n (1.8.7)
24
+ concurrent-ruby (~> 1.0)
25
+ json (2.5.1)
26
+ method_source (1.0.0)
27
+ minitest (5.14.3)
28
+ pry (0.13.1)
29
+ coderay (~> 1.1)
30
+ method_source (~> 1.0)
31
+ pry-byebug (3.9.0)
32
+ byebug (~> 11.0)
33
+ pry (~> 0.13.0)
34
+ rake (13.0.3)
35
+ rspec (3.10.0)
36
+ rspec-core (~> 3.10.0)
37
+ rspec-expectations (~> 3.10.0)
38
+ rspec-mocks (~> 3.10.0)
39
+ rspec-core (3.10.1)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-expectations (3.10.1)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-mocks (3.10.1)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.10.0)
47
+ rspec-support (3.10.1)
48
+ thread_safe (0.3.6)
49
+ tzinfo (1.2.9)
50
+ thread_safe (~> 0.1)
51
+
52
+ PLATFORMS
53
+ x86_64-darwin-19
54
+
55
+ DEPENDENCIES
56
+ escalate!
57
+ pry
58
+ pry-byebug
59
+ rake (~> 13.0)
60
+ rspec (~> 3.0)
61
+
62
+ BUNDLED WITH
63
+ 2.2.6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Invoca Inc.
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Escalate
2
+
3
+ A simple and lightweight gem to help with escalating errors
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'escalate'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install escalate
20
+
21
+ ## Usage
22
+
23
+ ### Adding Escalate to Your Gem
24
+
25
+ All you need to do is extend `Escalate.mixin` within your gem and you're all set.
26
+
27
+ ```ruby
28
+ module SomeGem
29
+ include Escalate.mixin
30
+ end
31
+ ```
32
+
33
+ This will expose the `Escalate#ex_escalate` method within your gem to be used instead
34
+ of using `logger.error`.
35
+
36
+ ```ruby
37
+ module SomeGem
38
+ include Escalate.mixin
39
+
40
+ class << self
41
+ attr_accessor :logger
42
+ end
43
+
44
+ class SomeClass
45
+ def something_dangerous
46
+ # ...
47
+ rescue => ex
48
+ SomeGem.escalate(ex, "I was doing something dangerous and an exception was raised")
49
+ end
50
+ end
51
+ end
52
+ ```
53
+
54
+ When `SomeGem.escalate` above is triggered, it will use the logger returned by `SomeGem.logger` or
55
+ default to a `STDERR` logger and do the following:
56
+
57
+ 1. Log an error containing the exception and any additional information about the current environment that is specified
58
+ 2. Trigger any `escalation_callbacks` configured on the `Escalate` gem
59
+ ## Development
60
+
61
+ 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.
62
+
63
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/invoca/escalate.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "escalate"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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,16 @@
1
+ # Invoca Community Code of Conduct v1.0
2
+
3
+ ## Contributor Code of Conduct
4
+ As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
5
+
6
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
7
+
8
+ Examples of unacceptable behavior by participants include:
9
+ * The use of sexualized language or imagery
10
+ * Personal attacks
11
+ * Trolling or insulting/derogatory comments
12
+ * Public or private harassment
13
+ * Publishing other's private information, such as physical or electronic addresses, without explicit permission
14
+ * Other unethical or unprofessional conduct
15
+
16
+ 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. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
data/escalate.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/escalate/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "escalate"
7
+ spec.version = Escalate::VERSION
8
+ spec.authors = ["Invoca Development", "Octothorp"]
9
+ spec.email = ["development@invoca.com", "octothorp@invoca.com"]
10
+
11
+ spec.summary = "Simple gem for abstracting log escalations"
12
+ spec.description = "Simple gem for abstracting log escalations"
13
+ spec.homepage = "https://github.com/invoca/escalate"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
+
16
+ spec.metadata = {
17
+ "allowed_push_host" => "https://rubygems.org",
18
+ "homepage_uri" => spec.homepage,
19
+ "changelog_uri" => "#{spec.homepage}/blob/main/CHANGELOG.md"
20
+ }
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "activesupport"
31
+ spec.add_dependency "contextual_logger"
32
+ end
data/lib/escalate.rb ADDED
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_support/core_ext"
5
+ require "contextual_logger"
6
+
7
+ require_relative "escalate/version"
8
+ require_relative "escalate/mixin"
9
+
10
+ module Escalate
11
+ class Error < StandardError; end
12
+
13
+ class << self
14
+ # Logs and escalated an exception
15
+ #
16
+ # @param [Exception] exception
17
+ # The exception that was raised and needs to be escalated
18
+ #
19
+ # @param [String] message
20
+ # An additional message about what was happening at the time of the exception
21
+ #
22
+ # @param [Logger] logger
23
+ # The logger object to use when logging the exception
24
+ #
25
+ # @param [Hash] context
26
+ # Any additional context to be tied to the escalation
27
+ def escalate(exception, message, logger, **context)
28
+ error_message = <<~EOS
29
+ [Escalate] #{message} (#{context.inspect})
30
+ #{exception.class.name}: #{exception.message}
31
+ #{exception.backtrace.join("\n")}
32
+ EOS
33
+
34
+ if logger.is_a?(ContextualLogger::LoggerMixin)
35
+ logger.error(error_message, **context)
36
+ else
37
+ logger.error(error_message)
38
+ end
39
+
40
+ on_escalate_blocks.each do |block|
41
+ block.call(exception, message, **context)
42
+ end
43
+ rescue Exception => ex
44
+ STDERR.puts("[ExEscalator] Exception rescued while escalating #{exception.inspect}:" \
45
+ "#{ex.class.name}: #{ex.message}")
46
+ end
47
+
48
+ # Returns a module to be mixed into a class or module exposing
49
+ # the ex_escalate method to be used for escalating and logging
50
+ # exceptions.
51
+ #
52
+ # @param [Proc] logger_block
53
+ # A block to be used to get the logger object that Escalate
54
+ # should be using
55
+ def mixin(&logger_block)
56
+ Thread.current[:escalate_logger_block] = logger_block
57
+
58
+ Module.new do
59
+ def self.included(base)
60
+ base.extend Escalate::Mixin
61
+ base.escalate_logger_block = Thread.current[:escalate_logger_block] || -> { base.try(:logger) }
62
+ end
63
+ end
64
+ end
65
+
66
+ # Registers an escalation callback to be executed when `ex_escalate`
67
+ # is invoked.
68
+ def on_escalate(&block)
69
+ on_escalate_blocks.add(block)
70
+ end
71
+
72
+ private
73
+
74
+ def on_escalate_blocks
75
+ @on_escalate_blocks ||= Set.new
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Escalate
4
+ module Mixin
5
+ class << self
6
+ def included(base)
7
+ raise 'instead of `include ExEscalator::Mixin`, you should `include ExEscalator.mixin`'
8
+ end
9
+ end
10
+
11
+ attr_accessor :escalate_logger_block
12
+
13
+ def ex_escalate(exception, message, **context)
14
+ Escalate.escalate(exception, message, escalate_logger, **context)
15
+ end
16
+
17
+ private
18
+
19
+ def escalate_logger
20
+ escalate_logger_block.try(:call) || default_escalate_logger
21
+ end
22
+
23
+ def default_escalate_logger
24
+ @default_escalate_logger ||= Logger.new(STDERR)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Escalate
4
+ VERSION = "0.1.0.pre.1"
5
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: escalate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre.1
5
+ platform: ruby
6
+ authors:
7
+ - Invoca Development
8
+ - Octothorp
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-02-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: contextual_logger
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: Simple gem for abstracting log escalations
43
+ email:
44
+ - development@invoca.com
45
+ - octothorp@invoca.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".github/workflows/main.yml"
51
+ - ".gitignore"
52
+ - ".rspec"
53
+ - CHANGELOG.md
54
+ - CONTRIBUTING.md
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - bin/console
61
+ - bin/setup
62
+ - code-of-conduct.md
63
+ - escalate.gemspec
64
+ - lib/escalate.rb
65
+ - lib/escalate/mixin.rb
66
+ - lib/escalate/version.rb
67
+ homepage: https://github.com/invoca/escalate
68
+ licenses: []
69
+ metadata:
70
+ allowed_push_host: https://rubygems.org
71
+ homepage_uri: https://github.com/invoca/escalate
72
+ changelog_uri: https://github.com/invoca/escalate/blob/main/CHANGELOG.md
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 2.4.0
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">"
85
+ - !ruby/object:Gem::Version
86
+ version: 1.3.1
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.6.13
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Simple gem for abstracting log escalations
93
+ test_files: []