11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/griffin/interceptors/server/sentry_interceptor.rb', line 11
def request_response(request: nil, call: nil, method: nil)
return yield unless Sentry.initialized?
Sentry.clone_hub_to_current_thread
Sentry.with_scope do |scope|
Sentry.with_session_tracking do
scope.clear_breadcrumbs
service_name = call.service_name
method_name = method.name
scope.set_transaction_name("#{service_name}/#{method_name}")
transaction = start_transaction(call.metadata, scope)
scope.set_span(transaction) if transaction
if call.metadata["x-request-id"]
scope.set_tags(request_id: call.metadata["x-request-id"])
end
begin
response = yield
rescue GRPC::BadStatus => e
finish_transaction(transaction, e.code)
raise e
rescue => e
GRPC.logger.error("Internal server error: #{e}")
finish_transaction(transaction, GrpcKit::StatusCodes::INTERNAL)
Sentry.capture_exception(e)
raise GRPC::Unknown.new("Internal server error")
end
finish_transaction(transaction, GrpcKit::StatusCodes::OK)
response
end
end
end
|