escalate 0.2.0.pre.2 → 0.2.0.pre.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +28 -2
- data/lib/escalate.rb +13 -12
- data/lib/escalate/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67b615521fd3e15a59bb8401486496175afa19be36a98c415d9eccf52dd0815f
|
4
|
+
data.tar.gz: 951d5afc0052cde73fca383e23dc38aa63e759fce7f4863b2093e9bf9b2463b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7979594ec79d527e123efb08114d602ab11446d8e822a9a716b582150d7e0f4b97840443974270177d861d874fbf4544f7e14eb8bd5e98e66acc86d49b51e19a
|
7
|
+
data.tar.gz: 2ab19d1367350559290fb9603e7af73934fcf1085121bf5a1cebe03059d450d19e53f76dc9947d92fac8a06f2a08fc0bb6ed12d0135a1e09617c87c6835dc158
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -58,8 +58,34 @@ end
|
|
58
58
|
When `SomeGem.escalate` above is triggered, it will use the logger returned by `SomeGem.logger` or
|
59
59
|
default to a `STDERR` logger and do the following:
|
60
60
|
|
61
|
-
1. Log an error containing the exception and
|
62
|
-
2. Trigger any `
|
61
|
+
1. [optional] Log an error containing the exception, location_message, and context hash
|
62
|
+
2. Trigger any `on_escalate_callbacks` configured on the `Escalate` gem
|
63
|
+
|
64
|
+
Step (1) is optional. It will happen if either of these is true:
|
65
|
+
- by default if no `on_escalate_callbacks` have been registered; or
|
66
|
+
- if any of the `on_escalate_callbacks` was registered with `on_escalate(log_first: true)`.
|
67
|
+
|
68
|
+
### Registering an Escalate Callback
|
69
|
+
|
70
|
+
If you are using an error reporting service, you can register an `on_escalate` callback to escalate exceptions.
|
71
|
+
You have the option to handle logging yourself, or to let `escalate` log first, before calling your callback.
|
72
|
+
|
73
|
+
#### Leave the Logging to the Escalate Gem
|
74
|
+
Here is an example that uses the default `log_first: true` so that logging is handled by the `Escalate` gem first:
|
75
|
+
```
|
76
|
+
Escalate.on_escalate do |exception, location_message, **context|
|
77
|
+
# send exception, location_message, **context to the error reporting service here
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
#### Handle the Logging in the `on_escalate` Callback
|
82
|
+
Here is an example that handles logging itself with `log_first: false`:
|
83
|
+
```
|
84
|
+
Escalate.on_escalate(log_first: false) do |exception, location_message, **context|
|
85
|
+
# log here first
|
86
|
+
# send exception, location_message, **context to the error reporting service here
|
87
|
+
end
|
88
|
+
```
|
63
89
|
## Development
|
64
90
|
|
65
91
|
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.
|
data/lib/escalate.rb
CHANGED
@@ -11,7 +11,11 @@ module Escalate
|
|
11
11
|
|
12
12
|
LOG_FIRST_INSTANCE_VARIABLE = :@_escalate_log_first
|
13
13
|
|
14
|
+
@on_escalate_callbacks = Set.new
|
15
|
+
|
14
16
|
class << self
|
17
|
+
attr_reader :on_escalate_callbacks
|
18
|
+
|
15
19
|
# Logs and escalated an exception
|
16
20
|
#
|
17
21
|
# @param [Exception] exception
|
@@ -27,21 +31,22 @@ module Escalate
|
|
27
31
|
# Any additional context to be tied to the escalation
|
28
32
|
def escalate(exception, location_message, logger, **context)
|
29
33
|
ensure_failsafe("Exception rescued while escalating #{exception.inspect}") do
|
30
|
-
if
|
34
|
+
if on_escalate_callbacks.none? || on_escalate_callbacks.any? { |block| block.instance_variable_get(LOG_FIRST_INSTANCE_VARIABLE) }
|
35
|
+
logger_allows_added_context?(logger) or context_string = " (#{context.inspect})"
|
31
36
|
error_message = <<~EOS
|
32
|
-
[Escalate] #{location_message}
|
37
|
+
[Escalate] #{location_message}#{context_string}
|
33
38
|
#{exception.class.name}: #{exception.message}
|
34
39
|
#{exception.backtrace.join("\n")}
|
35
40
|
EOS
|
36
41
|
|
37
|
-
if
|
38
|
-
logger.error(error_message, **context)
|
39
|
-
else
|
42
|
+
if context_string
|
40
43
|
logger.error(error_message)
|
44
|
+
else
|
45
|
+
logger.error(error_message, **context)
|
41
46
|
end
|
42
47
|
end
|
43
48
|
|
44
|
-
|
49
|
+
on_escalate_callbacks.each do |block|
|
45
50
|
ensure_failsafe("Exception rescued while escalating #{exception.inspect} to #{block.inspect}") do
|
46
51
|
block.call(exception, location_message, **context)
|
47
52
|
end
|
@@ -90,11 +95,11 @@ module Escalate
|
|
90
95
|
# whether escalate should log first before escalating, or leave the logging to the escalate block
|
91
96
|
def on_escalate(log_first: true, &block)
|
92
97
|
block.instance_variable_set(LOG_FIRST_INSTANCE_VARIABLE, log_first)
|
93
|
-
|
98
|
+
on_escalate_callbacks.add(block)
|
94
99
|
end
|
95
100
|
|
96
101
|
def clear_on_escalate_callbacks
|
97
|
-
|
102
|
+
on_escalate_callbacks.clear
|
98
103
|
end
|
99
104
|
|
100
105
|
private
|
@@ -109,9 +114,5 @@ module Escalate
|
|
109
114
|
defined?(ContextualLogger::LoggerMixin) &&
|
110
115
|
logger.is_a?(ContextualLogger::LoggerMixin)
|
111
116
|
end
|
112
|
-
|
113
|
-
def on_escalate_blocks
|
114
|
-
@on_escalate_blocks ||= Set.new
|
115
|
-
end
|
116
117
|
end
|
117
118
|
end
|
data/lib/escalate/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: escalate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0.pre.
|
4
|
+
version: 0.2.0.pre.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca Development
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|