gl_exception_notifier 1.0.0
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 +7 -0
- data/lib/gl_exception_notifier.rb +85 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0140b506d32bf3272bb2c400553c538e5cd50e7bba93a1b4992d089185ffcf75
|
4
|
+
data.tar.gz: 32a19cd04ad7b6c4e15080efbd906167f478bb3e9946e51695534532dbc7f45c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f9a91f405b558c288f801ec4c11e47ca0deb898420930a98cb6de4349f79205cdeac46ff9d0f6f5c7adb7718a6960b286f1eed62b671d8b0cbb7106ec54be1d
|
7
|
+
data.tar.gz: 5d7291d7e040efd25363bd69f5ca0f7d782b24b8a594294a1b7c4aaa1891236c9d942f836db1112adce78ff1660f6c5e20cca4bc154ccf72420c053b756843ec
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GLExceptionNotifier
|
4
|
+
CONTEXT_TYPES = %i[extra_context tags_context user_context].freeze
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def call(*args)
|
8
|
+
if exceptionable?(args.first)
|
9
|
+
capture_exception(args)
|
10
|
+
else
|
11
|
+
capture_message(args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def capture_exception(args)
|
16
|
+
error_client.capture_exception(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def capture_message(args)
|
20
|
+
if args.first.is_a?(String)
|
21
|
+
message = args.first
|
22
|
+
extra = args.length == 2 && args.last.is_a?(Hash) ? args.last : { parameters: args.drop(1) }
|
23
|
+
else
|
24
|
+
message_info = if args.first.is_a?(Hash)
|
25
|
+
'called with kwargs, should have been positional'
|
26
|
+
else
|
27
|
+
'Unknown parameter set'
|
28
|
+
end
|
29
|
+
message = "GLExceptionNotifier: #{message_info}"
|
30
|
+
extra = { parameters: args }
|
31
|
+
end
|
32
|
+
|
33
|
+
error_client.capture_message(message, extra:)
|
34
|
+
end
|
35
|
+
|
36
|
+
def exceptionable?(obj)
|
37
|
+
obj.is_a?(Exception) ||
|
38
|
+
(obj.respond_to?(:ancestors) && obj.ancestors.include?(Exception))
|
39
|
+
end
|
40
|
+
|
41
|
+
# @parmas type [Symbol] the type of context to add, either `:tags_context`, `:user_context`, or `:extra_context`
|
42
|
+
# @params context [Hash] the key values to add as context
|
43
|
+
def add_context(type, context)
|
44
|
+
unless CONTEXT_TYPES.include?(type)
|
45
|
+
raise ArgumentError,
|
46
|
+
'type paramater must be one of: :extra_context, :tags_context, :user_context'
|
47
|
+
end
|
48
|
+
raise ArgumentError, 'contexts must be a hash' unless context.is_a?(Hash)
|
49
|
+
|
50
|
+
case type
|
51
|
+
when :user_context
|
52
|
+
error_client.set_user(context)
|
53
|
+
when :tags_context
|
54
|
+
error_client.set_tags(context)
|
55
|
+
when :extra_context
|
56
|
+
error_client.set_extras(context)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# @params data [Hash] the key values to add to the breadcrumb
|
61
|
+
# @params message [String] the message string to add to the breadcrumb
|
62
|
+
def breadcrumbs(data:, message: nil)
|
63
|
+
raise ArgumentError, 'data must be a hash' unless data.is_a?(Hash)
|
64
|
+
raise ArgumentError, 'when providing a message, it must be a string' if message && !message.is_a?(String)
|
65
|
+
|
66
|
+
crumb = breadcrumb.new(message:, data:)
|
67
|
+
error_client.add_breadcrumb(crumb)
|
68
|
+
crumb
|
69
|
+
end
|
70
|
+
|
71
|
+
def last_breadcrumb
|
72
|
+
error_client.get_current_scope&.breadcrumbs&.peek
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def error_client
|
78
|
+
Sentry
|
79
|
+
end
|
80
|
+
|
81
|
+
def breadcrumb
|
82
|
+
error_client::Breadcrumb
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gl_exception_notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Give Lively
|
8
|
+
- Tim Lawrenz
|
9
|
+
- Joe Anzalone
|
10
|
+
- Dave Urban
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2024-05-29 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: sentry-rails
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sentry-ruby
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: sentry-sidekiq
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
description: |-
|
59
|
+
To avoid having to update exception notifiers in all the different repositories,
|
60
|
+
we pull out commonalities and wrap them into gems
|
61
|
+
email: tim@givelively.org
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- lib/gl_exception_notifier.rb
|
67
|
+
homepage: https://github.com/givelively/gl_exception_notifier/
|
68
|
+
licenses:
|
69
|
+
- Apache
|
70
|
+
metadata:
|
71
|
+
rubygems_mfa_required: 'true'
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '3.1'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubygems_version: 3.4.19
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: A wrapper for GiveLively's exception notifier
|
91
|
+
test_files: []
|