griffin-interceptors 0.1.5 → 0.1.10

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
- SHA1:
3
- metadata.gz: eaf4ab1433928865a32bd22d19c1283f826ea526
4
- data.tar.gz: 43d9b6c7f9a636fa79ae6e4adf8800c0c5326952
2
+ SHA256:
3
+ metadata.gz: 577b6e15c3329e7de3161208786195c3c294b0cd2b049dbac28cd65760ac69aa
4
+ data.tar.gz: 4b2b4735f2ddcaec02fd0edc7a7008383fc16d21153124b97c0ebe751a6b5039
5
5
  SHA512:
6
- metadata.gz: 57917963336f2b3ba83d84da9c3c59d2c2ac3b3352317375307facadd00b55edc8d415c72c3015bfc4d70295fc1bb06211d4f0c17b382666dc3bd323514f0e6f
7
- data.tar.gz: 6f198f8b51e9a9afd723cc6d285307685e226941af9ed51f67a465a9e193c4853a1c21fbd3bf834db08f7bd8a1682cc96cae0e21cc74643728c8e6cf4fd5ae6e
6
+ metadata.gz: 78ed7afe5b35e0f2d501993c627a063a76d843430e4a96855dc7495048c8dc8633b96d1c3cd009b2734168740f00b100aeaaf0e983d8ba437a80816507afcc76
7
+ data.tar.gz: 69ed67e1d0ae800429004c3d732b95ac582fac407b0c5dba5d360bae2d50ec0df2b27d313599b0b42b65f61d913327b5c2abdb9e7fca87714cbcab129a08cfbe
@@ -2,8 +2,8 @@
2
2
 
3
3
  require 'griffin/interceptors/server/payload_interceptor'
4
4
 
5
- # Check actionpack exists to use ActionDispatch::Http::ParameterFilter
6
- gem 'actionpack'
5
+ # Check actionpack exists to use ActionDispatch::Http::ParameterFilter if needed
6
+ gem 'actionpack' unless defined?(ActiveSupport::ParameterFilter)
7
7
 
8
8
  module Griffin
9
9
  module Interceptors
@@ -19,7 +19,13 @@ module Griffin
19
19
  end
20
20
  end
21
21
 
22
- @parameter_filter = ActionDispatch::Http::ParameterFilter.new(@filters)
22
+ # ActionDispatch::Http::ParameterFilter is deprecated and will be removed from Rails 6.1.
23
+ parameter_filter_klass = if defined?(ActiveSupport::ParameterFilter)
24
+ ActiveSupport::ParameterFilter
25
+ else
26
+ ActionDispatch::Http::ParameterFilter
27
+ end
28
+ @parameter_filter = parameter_filter_klass.new(@filters)
23
29
  end
24
30
 
25
31
  def server_streamer(call: nil, **)
@@ -45,7 +45,7 @@ module Griffin
45
45
  'grpc.code' => '0', # OK
46
46
  }
47
47
 
48
- if call.metadata['x-requst-id']
48
+ if call.metadata['x-request-id']
49
49
  log['grpc.x_request_id'] = call.metadata['x-request-id']
50
50
  end
51
51
 
@@ -19,26 +19,14 @@ module Griffin
19
19
 
20
20
  return yield if @ignored_services.include?(service_name)
21
21
 
22
- transaction_name = build_transaction_name(service_name, method.name)
23
- state = NewRelic::Agent::TransactionState.tl_get
24
-
25
22
  # gRPC's HTTP method is fixed. https://github.com/grpc/grpc/blob/af89e8c00e796f3398b09b7daed693df2b14da56/doc/PROTOCOL-HTTP2.md
26
- req = Request.new("/#{transaction_name}", call.metadata['user-agent'], 'POST')
27
- # ":controller" is not correct category name for gRPC, But since we want to categorized this transaction as web transactions.
28
- # https://docs.newrelic.com/docs/apm/transactions/key-transactions/introduction-key-transactions
29
- NewRelic::Agent::Transaction.start(state, :controller, transaction_name: "Controller/#{transaction_name}", request: req)
30
-
31
- begin
32
- resp = yield
33
- # gRPC alway returns HTTP status code 200
34
- state.current_transaction.http_response_code = '200'
35
-
36
- resp
37
- rescue => e
38
- NewRelic::Agent::Transaction.notice_error(e)
39
- raise e
40
- ensure
41
- NewRelic::Agent::Transaction.stop(state)
23
+ request = Request.new("/#{service_name}/#{method.name}", call.metadata['user-agent'], 'POST')
24
+
25
+ in_transaction("#{service_name}/#{method.name}", request) do |txn|
26
+ yield.tap do
27
+ # gRPC always returns HTTP status code 200.
28
+ txn.http_response_code = '200'
29
+ end
42
30
  end
43
31
  end
44
32
 
@@ -46,8 +34,21 @@ module Griffin
46
34
 
47
35
  private
48
36
 
49
- def build_transaction_name(service, mthd)
50
- "#{service}/#{mthd}"
37
+ if Gem::Version.new(NewRelic::VERSION::STRING) >= Gem::Version.new('6.0.0')
38
+ def in_transaction(partial_name, request)
39
+ NewRelic::Agent::Tracer.in_transaction(partial_name: partial_name, category: :web, options: { request: request }) do
40
+ yield NewRelic::Agent::Tracer.current_transaction
41
+ end
42
+ end
43
+ else
44
+ def in_transaction(partial_name, request)
45
+ state = NewRelic::Agent::TransactionState.tl_get
46
+ # Specify the controller category so that the transaction gets categorized as a web transaction.
47
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/5.7.0.350/lib/new_relic/agent/transaction.rb#L39.
48
+ NewRelic::Agent::Transaction.wrap(state, "Controller/#{partial_name}", :controller, request: request) do
49
+ yield state.current_transaction
50
+ end
51
+ end
51
52
  end
52
53
  end
53
54
  end
@@ -6,7 +6,11 @@ module Griffin
6
6
  module Interceptors
7
7
  module Server
8
8
  class RavenInterceptor < GRPC::ServerInterceptor
9
- def request_response(*)
9
+ def request_response(call: nil, **)
10
+ if call.metadata['x-request-id']
11
+ Raven.tags_context(request_id: call.metadata['x-request-id'])
12
+ end
13
+
10
14
  begin
11
15
  yield
12
16
  rescue => e
@@ -17,6 +21,9 @@ module Griffin
17
21
 
18
22
  raise GRPC::Unknown.new('Internal server error')
19
23
  end
24
+ ensure
25
+ Raven::Context.clear!
26
+ Raven::BreadcrumbBuffer.clear!
20
27
  end
21
28
 
22
29
  alias_method :server_streamer, :request_response
@@ -1,5 +1,5 @@
1
1
  module Griffin
2
2
  module Interceptors
3
- VERSION = '0.1.5'.freeze
3
+ VERSION = '0.1.10'.freeze
4
4
  end
5
5
  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.1.5
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuta Iwama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-12 00:00:00.000000000 Z
11
+ date: 2020-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: get_process_mem
@@ -148,8 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
150
  requirements: []
151
- rubyforge_project:
152
- rubygems_version: 2.6.14.1
151
+ rubygems_version: 3.1.4
153
152
  signing_key:
154
153
  specification_version: 4
155
154
  summary: A collection of interceptors for griffin