griffin-interceptors 0.1.11 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffed86abcb2abcde04f6c18a0eca28277125f9828d83c4366d39b3e906fe226d
|
4
|
+
data.tar.gz: a02c68e604410540cf6637f0500b01966c8cf3338fe1d81138a71b3efbe8d8f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d200ccd31a654190d80adf6f5549bc70cf817e5e20859e10c9eca395148a7b85bfbfb2288d2aaf5d485a5865f9a0602c903676d400c32e6009e79dfca7bc31f
|
7
|
+
data.tar.gz: '091fd8f580cea51fe2f8f85c4f18bf913f2c9b85f63fbf17247433223d48b21a82085917b6596dba2347775b8a05b0194fa188ca5fb437a2c514c2a2e00a808a'
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
gem 'sentry-raven'
|
4
|
-
|
5
3
|
module Griffin
|
6
4
|
module Interceptors
|
7
5
|
module Server
|
@@ -10,13 +8,13 @@ module Griffin
|
|
10
8
|
begin
|
11
9
|
yield
|
12
10
|
rescue ActiveRecord::RecordNotFound => e
|
13
|
-
|
11
|
+
capture_exception_if_defined(e)
|
14
12
|
raise GRPC::NotFound.new(e.message)
|
15
13
|
rescue ActiveRecord::StaleObjectError => e
|
16
|
-
|
14
|
+
capture_exception_if_defined(e)
|
17
15
|
raise GRPC::Aborted.new(e.message)
|
18
16
|
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => e
|
19
|
-
|
17
|
+
capture_exception_if_defined(e)
|
20
18
|
raise GRPC::FailedPrecondition.new(e.message)
|
21
19
|
end
|
22
20
|
end
|
@@ -24,6 +22,16 @@ module Griffin
|
|
24
22
|
alias_method :server_streamer, :request_response
|
25
23
|
alias_method :client_streamer, :request_response
|
26
24
|
alias_method :bidi_streamer, :request_response
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def capture_exception_if_defined(e)
|
29
|
+
if defined?(Sentry)
|
30
|
+
Sentry.capture_exception(e)
|
31
|
+
elsif defined?(Raven)
|
32
|
+
Raven.capture_exception(e)
|
33
|
+
end
|
34
|
+
end
|
27
35
|
end
|
28
36
|
end
|
29
37
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
gem "sentry-ruby"
|
4
|
+
|
5
|
+
module Griffin
|
6
|
+
module Interceptors
|
7
|
+
module Server
|
8
|
+
class SentryInterceptor < GRPC::ServerInterceptor
|
9
|
+
TRANSACTION_OP = "griffin"
|
10
|
+
|
11
|
+
def request_response(request: nil, call: nil, method: nil)
|
12
|
+
return yield unless Sentry.initialized?
|
13
|
+
|
14
|
+
Sentry.clone_hub_to_current_thread
|
15
|
+
|
16
|
+
Sentry.with_scope do |scope|
|
17
|
+
Sentry.with_session_tracking do
|
18
|
+
scope.clear_breadcrumbs
|
19
|
+
|
20
|
+
service_name = call.service_name
|
21
|
+
method_name = method.name
|
22
|
+
scope.set_transaction_name("#{service_name}/#{method_name}")
|
23
|
+
|
24
|
+
transaction = start_transaction(call.metadata, scope)
|
25
|
+
scope.set_span(transaction) if transaction
|
26
|
+
|
27
|
+
if call.metadata["x-request-id"]
|
28
|
+
scope.set_tags(request_id: call.metadata["x-request-id"])
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
response = yield
|
33
|
+
rescue GRPC::BadStatus => e
|
34
|
+
finish_transaction(transaction, e.code)
|
35
|
+
raise e
|
36
|
+
rescue => e
|
37
|
+
GRPC.logger.error("Internal server error: #{e}")
|
38
|
+
finish_transaction(transaction, GrpcKit::StatusCodes::INTERNAL)
|
39
|
+
Sentry.capture_exception(e)
|
40
|
+
|
41
|
+
raise GRPC::Unknown.new("Internal server error")
|
42
|
+
end
|
43
|
+
|
44
|
+
finish_transaction(transaction, GrpcKit::StatusCodes::OK)
|
45
|
+
|
46
|
+
response
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
alias_method :server_streamer, :request_response
|
52
|
+
alias_method :client_streamer, :request_response
|
53
|
+
alias_method :bidi_streamer, :request_response
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def start_transaction(metadata, scope)
|
58
|
+
sentry_trace = metadata["grpc-sentry-trace"]
|
59
|
+
options = { name: scope.transaction_name, op: TRANSACTION_OP }
|
60
|
+
transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, **options) if sentry_trace
|
61
|
+
Sentry.start_transaction(transaction: transaction, custom_sampling_context: { metadata: metadata }, **options)
|
62
|
+
end
|
63
|
+
|
64
|
+
def finish_transaction(transaction, status_code)
|
65
|
+
return unless transaction
|
66
|
+
|
67
|
+
transaction.set_http_status(status_code)
|
68
|
+
transaction.finish
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: griffin-interceptors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuta Iwama
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: get_process_mem
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/griffin/interceptors/server/rails_exception_interceptor.rb
|
127
127
|
- lib/griffin/interceptors/server/raven_interceptor.rb
|
128
128
|
- lib/griffin/interceptors/server/scout_apm_interceptor.rb
|
129
|
+
- lib/griffin/interceptors/server/sentry_interceptor.rb
|
129
130
|
- lib/griffin/interceptors/server/timeout_interceptor.rb
|
130
131
|
- lib/griffin/interceptors/server/worker_killer_interceptor.rb
|
131
132
|
- lib/griffin/interceptors/server/x_request_id_interceptor.rb
|
@@ -149,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
150
|
- !ruby/object:Gem::Version
|
150
151
|
version: '0'
|
151
152
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
153
|
+
rubygems_version: 3.2.32
|
153
154
|
signing_key:
|
154
155
|
specification_version: 4
|
155
156
|
summary: A collection of interceptors for griffin
|