upfluence-utils 0.11.4 → 0.12.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 +4 -4
- data/lib/upfluence/error_logger/null.rb +1 -1
- data/lib/upfluence/error_logger/sentry.rb +77 -27
- data/lib/upfluence/utils/version.rb +1 -1
- data/rbutils.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2c9dcbd049e1e8c27d2ec9f7075cccacb7f4814d23ea04def031a0f9f00957f
|
4
|
+
data.tar.gz: 1f6b5c5812beaccfbf78123004f503f9135c96aedef1097cede9df3f007c6e92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c9e85e446a91a43b0d71d855a3b5c8c601f84f77582b6f3f32c725eadc96682bed636d6987dbab210b98b64c437a92412df89e6ef4494a6b1b01d49e9aa4a79
|
7
|
+
data.tar.gz: 10f73661eccb80401be50c860b660b0be5707f60b9d864bbe6e49cd1e0e93a91ee1dc1fbcbdf99adb0f59936dcdd2115424657edb76d8345ab46c1dd95811232
|
@@ -1,66 +1,116 @@
|
|
1
|
-
require '
|
1
|
+
require 'sentry-ruby'
|
2
2
|
|
3
3
|
module Upfluence
|
4
4
|
module ErrorLogger
|
5
5
|
class Sentry
|
6
|
-
EXCLUDED_ERRORS = (
|
6
|
+
EXCLUDED_ERRORS = (::Sentry::Configuration::IGNORE_DEFAULT + ['Identity::Thrift::Forbidden'])
|
7
|
+
MAX_TAG_SIZE = 8 * 1024
|
7
8
|
|
8
9
|
def initialize
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
@tag_extractors = []
|
11
|
+
|
12
|
+
::Sentry.init do |config|
|
13
|
+
config.send_default_pii = true
|
14
|
+
config.dsn = ENV.fetch('SENTRY_DSN', nil)
|
15
|
+
config.environment = Upfluence.env
|
12
16
|
config.excluded_exceptions = EXCLUDED_ERRORS
|
13
17
|
config.logger = Upfluence.logger
|
14
|
-
config.release = "#{ENV
|
15
|
-
config.
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
config.release = "#{ENV.fetch('PROJECT_NAME', nil)}-#{ENV.fetch('SEMVER_VERSION', nil)}"
|
19
|
+
config.enable_tracing = false
|
20
|
+
config.auto_session_tracking = false
|
21
|
+
end
|
22
|
+
|
23
|
+
::Sentry.set_tags(
|
24
|
+
{ unit_name: unit_name, unit_type: unit_type }.select { |_, v| v }
|
25
|
+
)
|
26
|
+
|
27
|
+
::Sentry.with_scope do |scope|
|
28
|
+
scope.add_event_processor do |event, hint|
|
29
|
+
tags = @tag_extractors.map(&:extract).compact.reduce({}, &:merge)
|
30
|
+
|
31
|
+
exc = hint[:exception]
|
32
|
+
|
33
|
+
tags.merge!(exc.tags) if exc.respond_to? :tags
|
34
|
+
|
35
|
+
tx_name = transaction_name(tags)
|
36
|
+
|
37
|
+
event.transaction = tx_name if tx_name
|
38
|
+
event.extra.merge!(prepare_extra(tags))
|
39
|
+
|
40
|
+
event
|
41
|
+
end
|
19
42
|
end
|
20
43
|
end
|
21
44
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
)
|
29
|
-
|
30
|
-
|
45
|
+
def append_tag_extractors(klass)
|
46
|
+
@tag_extractors << klass
|
47
|
+
end
|
48
|
+
|
49
|
+
def notify(error, *args)
|
50
|
+
::Sentry.with_scope do |scope|
|
51
|
+
context = args.reduce({}) do |acc, arg|
|
52
|
+
v = if arg.is_a?(Hash)
|
53
|
+
arg
|
54
|
+
else
|
55
|
+
key = acc.empty? ? 'method' : "arg_#{acc.length}"
|
56
|
+
{ key => arg.inspect }
|
57
|
+
end
|
58
|
+
|
59
|
+
acc.merge(v)
|
60
|
+
end
|
61
|
+
|
62
|
+
scope.set_extras(prepare_extra(context))
|
63
|
+
|
64
|
+
::Sentry.capture_exception(error)
|
31
65
|
end
|
66
|
+
rescue ::Sentry::Error => e
|
67
|
+
Upfluence.logger.warning e.message
|
32
68
|
end
|
33
69
|
|
34
70
|
def user=(user)
|
35
|
-
|
71
|
+
::Sentry.set_user(id: user.id, email: user.email)
|
36
72
|
end
|
37
73
|
|
38
74
|
def middleware
|
39
|
-
::
|
75
|
+
::Sentry::Rack::CaptureExceptions
|
40
76
|
end
|
41
77
|
|
42
78
|
def ignore_exception(*klss)
|
43
79
|
klss.each do |kls|
|
44
|
-
puts kls
|
45
80
|
case kls.class
|
46
81
|
when Class
|
47
|
-
|
82
|
+
::Sentry.configuration.excluded_exceptions << kls.name
|
48
83
|
when String
|
49
|
-
|
84
|
+
::Sentry.configuration.excluded_exceptions << kls
|
50
85
|
else
|
51
|
-
Upfluence.logger.warn
|
86
|
+
Upfluence.logger.warn "Unexcepted argument for ignore_exception #{kls}"
|
52
87
|
end
|
53
88
|
end
|
54
89
|
end
|
55
90
|
|
56
91
|
private
|
57
92
|
|
93
|
+
def prepare_extra(tags)
|
94
|
+
tags.select { |_k, v| v.respond_to?(:size) && v.size < MAX_TAG_SIZE }
|
95
|
+
end
|
96
|
+
|
97
|
+
def transaction_name(tags)
|
98
|
+
return tags['transaction'] if tags['transaction']
|
99
|
+
|
100
|
+
svc = tags['thrift.request.service']
|
101
|
+
mth = tags['thrift.request.method']
|
102
|
+
|
103
|
+
return "#{svc}##{mth}" if svc && mth
|
104
|
+
|
105
|
+
nil
|
106
|
+
end
|
107
|
+
|
58
108
|
def unit_name
|
59
|
-
ENV['UNIT_NAME']
|
109
|
+
ENV['UNIT_NAME']&.split('.')&.first
|
60
110
|
end
|
61
111
|
|
62
112
|
def unit_type
|
63
|
-
unit_name
|
113
|
+
unit_name&.split('@')&.first
|
64
114
|
end
|
65
115
|
end
|
66
116
|
end
|
data/rbutils.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency 'upfluence-thrift'
|
24
24
|
spec.add_runtime_dependency 'sinatra'
|
25
25
|
spec.add_runtime_dependency 'redis'
|
26
|
-
spec.add_runtime_dependency 'sentry-
|
26
|
+
spec.add_runtime_dependency 'sentry-ruby'
|
27
27
|
spec.add_runtime_dependency 'sinatra-contrib'
|
28
28
|
spec.add_runtime_dependency 'activesupport'
|
29
29
|
spec.add_runtime_dependency 'puma'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upfluence-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Upfluence
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: sentry-
|
98
|
+
name: sentry-ruby
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|