grpc_newrelic_interceptor 0.0.1 → 0.0.5

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: 4f48d560a64c635ca1a2a5766cdfeca630f653750b42e75155c05f96440ad15e
4
- data.tar.gz: 6a3760be8b5e0d6f3661f5ff39b40e8980e91cccf2d24eb976000b9c1629fccc
3
+ metadata.gz: 6f762f4530a5289380b3d015ee4071a2ff8e083a9e803fb791c79e54ac2c410c
4
+ data.tar.gz: 89cd8daa94234ab1e7c5c4730d184e196e3142a53bba1136ee6288cddd00e031
5
5
  SHA512:
6
- metadata.gz: e211b44a114ae8f521c8168e48fec436b88fdc8295befc29f8b26b72f239332fcbad2f7ca4e3e65dfc98513ff3840b137a6a582a11caa3cd4f8011a48a11ca4c
7
- data.tar.gz: 46ebb1247039200b02bb35a6d39d5282cca0a4f2f14e74b26c317382e1b155ed4b46e9337e69a92a1e7dec4faed9226f6284cf34b5f8749dbf1142f06d11068a
6
+ metadata.gz: cda2787034a018697c5bcce58811fa9fd2420ee50d9b36a0007c2db476a93044c6a5e343163d4457e994c7f265d4a258f85bc610d09ab6b87f47479741982a24
7
+ data.tar.gz: 4d2c6d53e87600fa3294716df62ff56139cc268d516e0c2146cb10487698bcfb87dbd24a7d20755d54a41a6cd3c8d5259717bc57916d9af8eaf8dd23f356caf2
@@ -0,0 +1,10 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ - package-ecosystem: github-actions
8
+ directory: "/"
9
+ schedule:
10
+ interval: daily
@@ -0,0 +1,28 @@
1
+ name: test
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+
9
+ strategy:
10
+ matrix:
11
+ ruby: ["2.5", "2.6", "2.7", "3.0"]
12
+ gemfile: ['Gemfile']
13
+ include:
14
+ - ruby: "3.0"
15
+ gemfile: "gemfiles/newrelic-6.gemfile"
16
+ - ruby: "3.0"
17
+ gemfile: "gemfiles/newrelic-7.gemfile"
18
+
19
+ env:
20
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
21
+
22
+ steps:
23
+ - uses: actions/checkout@v2.4.0
24
+ - uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby }}
27
+ - run: bundle install
28
+ - run: bundle exec rspec
data/.gitignore CHANGED
@@ -1,8 +1,57 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
4
  /coverage/
5
- /doc/
5
+ /InstalledFiles
6
6
  /pkg/
7
7
  /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
8
11
  /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ Gemfile.lock
49
+ *.gemfile.lock
50
+ .ruby-version
51
+ .ruby-gemset
52
+
53
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
54
+ .rvmrc
55
+
56
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
57
+ # .rubocop-https?--*
data/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ ## 0.0.5
2
+
3
+ - Fixed
4
+ - Support Ruby 3.0 keyword arguments https://github.com/wantedly/grpc_newrelic_interceptor/pull/15
5
+ - Misc
6
+ - Bump actions/checkout from 2.3.5 to 2.4.0 https://github.com/wantedly/grpc_newrelic_interceptor/pull/14
7
+
8
+ ## 0.0.4
9
+
10
+ - Added
11
+ - Allow newrelic_rpm 7.x and 8.x https://github.com/wantedly/grpc_newrelic_interceptor/pull/11
12
+ - Misc
13
+ - Migrate to GitHub Actions https://github.com/wantedly/grpc_newrelic_interceptor/pull/10
14
+ - Set up dependabot https://github.com/wantedly/grpc_newrelic_interceptor/pull/12
15
+
16
+ ## 0.0.3
17
+
18
+ - Fixed
19
+ - Fix server interceptor with overridden methods https://github.com/wantedly/grpc_newrelic_interceptor/pull/8
20
+ - Misc
21
+ - Bump rake https://github.com/wantedly/grpc_newrelic_interceptor/pull/5
22
+
23
+ ## 0.0.2
24
+
25
+ - Added
26
+ - Add client interceptor https://github.com/wantedly/grpc_newrelic_interceptor/pull/1
27
+ - Misc
28
+ - Activate Travis CI https://github.com/wantedly/grpc_newrelic_interceptor/pull/2
29
+ - Update README https://github.com/wantedly/grpc_newrelic_interceptor/pull/3
30
+
31
+ ## 0.0.1
32
+
33
+ Initial release.
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in grpc_newrelic_interceptor.gemspec
4
4
  gemspec
5
+
6
+ gem "newrelic_rpm", "~> 8.0"
data/README.md CHANGED
@@ -19,6 +19,8 @@ Or install it yourself as:
19
19
 
20
20
  ## Usage
21
21
 
22
+ ### Server
23
+
22
24
  ```ruby
23
25
  require 'grpc'
24
26
  require 'grpc_newrelic_interceptor'
@@ -27,13 +29,26 @@ NewRelic::Agent.manual_start # start newrelic agent
27
29
 
28
30
  server = GRPC::RpcServer.new(
29
31
  interceptors: [
30
- GrpcNewrelicInterceptor.new,
32
+ GrpcNewrelicInterceptor::ServerInterceptor.new,
31
33
  ]
32
34
  )
33
35
  server.handle(MyHandler.new)
34
36
  server.run_till_terminated_or_interrupted(['SIGINT'])
35
37
  ```
36
38
 
39
+ ### Client
40
+
41
+ ```ruby
42
+ require 'grpc'
43
+ require 'grpc_newrelic_interceptor'
44
+
45
+ url = "dns:test-service:80"
46
+ stub = TestService::Stub.new(url, :this_channel_is_insecure, interceptors: [
47
+ GrpcNewrelicInterceptor::ClientInterceptor.new,
48
+ ])
49
+ stub.hello_rpc
50
+ ```
51
+
37
52
  ## Development
38
53
 
39
54
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -42,7 +57,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
42
57
 
43
58
  ## Contributing
44
59
 
45
- Bug reports and pull requests are welcome on GitHub at https://github.com/south37/grpc_newrelic_interceptor.
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wantedly/grpc_newrelic_interceptor.
46
61
 
47
62
  ## License
48
63
 
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in grpc_newrelic_interceptor.gemspec
4
+ gemspec path: ".."
5
+
6
+ gem "newrelic_rpm", "~> 6.0"
7
+
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in grpc_newrelic_interceptor.gemspec
4
+ gemspec path: ".."
5
+
6
+ gem "newrelic_rpm", "~> 7.0"
7
+
@@ -10,11 +10,11 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = %q{An interceptor for using New Relic with gRPC.}
12
12
  spec.description = %q{An interceptor for using New Relic with gRPC.}
13
- spec.homepage = "https://github.com/south37/grpc_newrelic_interceptor"
13
+ spec.homepage = "https://github.com/wantedly/grpc_newrelic_interceptor"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/south37/grpc_newrelic_interceptor"
17
+ spec.metadata["source_code_uri"] = "https://github.com/wantedly/grpc_newrelic_interceptor"
18
18
 
19
19
  # Specify which files should be added to the gem when it is released.
20
20
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -26,11 +26,11 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ["lib"]
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 2.0"
29
- spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rake", "~> 13.0"
30
30
  spec.add_development_dependency "rspec"
31
31
  spec.add_development_dependency "pry"
32
32
  spec.add_development_dependency "pry-doc"
33
33
  spec.add_development_dependency "google-protobuf"
34
- spec.add_dependency "newrelic_rpm", "~> 6.0"
34
+ spec.add_dependency "newrelic_rpm", ">= 6.0", "< 9.0"
35
35
  spec.add_dependency "grpc"
36
36
  end
@@ -0,0 +1,79 @@
1
+ require "newrelic_rpm"
2
+ require "grpc"
3
+
4
+ module GrpcNewrelicInterceptor
5
+ class ClientInterceptor < GRPC::ClientInterceptor
6
+ ##
7
+ # Intercept a unary request response call
8
+ #
9
+ # @param [Object] request
10
+ # @param [GRPC::ActiveCall] call
11
+ # @param [String] method
12
+ # @param [Hash] metadata
13
+ #
14
+ def request_response(request:, call:, method:, metadata:)
15
+ return yield if !newrelic_enabled?
16
+
17
+ segment = NewRelic::Agent::Tracer.start_external_request_segment(
18
+ library: "gRPC".freeze,
19
+ uri: dummy_uri(method),
20
+ procedure: get_method_name(method),
21
+ )
22
+
23
+ begin
24
+ response = nil
25
+
26
+ # TODO(south37) Set metadta as reqeust headers
27
+ # segment.add_request_headers something
28
+
29
+ # RUBY-1244 Disable further tracing in request to avoid double
30
+ # counting if connection wasn't started (which calls request again).
31
+ NewRelic::Agent.disable_all_tracing do
32
+ response = yield
33
+ end
34
+
35
+ # NOTE: Here, we can not get metadata of response.
36
+ # TODO(south37) Improve ClientInterceptor to get metadata and set it as
37
+ # response headers
38
+ # segment.read_response_headers something
39
+
40
+ response
41
+ ensure
42
+ segment.finish
43
+ end
44
+ end
45
+
46
+ # NOTE: For now, we don't support server_streamer, client_streamer and bidi_streamer
47
+
48
+ private
49
+
50
+ # @param [String] method
51
+ # @return [URI]
52
+ def dummy_uri(method)
53
+ # Here, we use service_name as domain name.
54
+ service_name = get_service_name(method)
55
+ ::NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url("http://#{service_name}")
56
+ end
57
+
58
+ # @param [String] method
59
+ # @return [String]
60
+ def get_service_name(method)
61
+ # Here, method is a string which represents a full path of gRPC method.
62
+ # e.g. "/wantedly.users.UserService/GetUser"
63
+ method.split('/')[1]
64
+ end
65
+
66
+ # @param [String] method
67
+ # @return [String]
68
+ def get_method_name(method)
69
+ # Here, method is a string which represents a full path of gRPC method.
70
+ # e.g. "/wantedly.users.UserService/GetUser"
71
+ method.split('/')[2]
72
+ end
73
+
74
+ # @return [bool]
75
+ def newrelic_enabled?
76
+ NewRelic::Agent.instance.started?
77
+ end
78
+ end
79
+ end
@@ -37,7 +37,7 @@ module GrpcNewrelicInterceptor
37
37
  filtered_params: filter(request.to_h),
38
38
  }
39
39
  }
40
- NewRelic::Agent::Tracer.in_transaction(transaction_options) do
40
+ NewRelic::Agent::Tracer.in_transaction(**transaction_options) do
41
41
  yield
42
42
  end
43
43
  end
@@ -49,13 +49,13 @@ module GrpcNewrelicInterceptor
49
49
  # @param [Method] method
50
50
  # @return [String]
51
51
  def get_service_name(method)
52
- method.owner.service_name
52
+ method.receiver.class.service_name
53
53
  end
54
54
 
55
55
  # @param [Method] method
56
56
  # @return [String]
57
57
  def get_partial_name(method)
58
- "#{method.owner.name}/#{method.name}"
58
+ "#{method.receiver.class.name}/#{method.name}"
59
59
  end
60
60
 
61
61
  # @param [Method] method
@@ -1,3 +1,3 @@
1
1
  module GrpcNewrelicInterceptor
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,3 +1,4 @@
1
+ require "grpc_newrelic_interceptor/client_interceptor"
1
2
  require "grpc_newrelic_interceptor/server_interceptor"
2
3
  require "grpc_newrelic_interceptor/version"
3
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grpc_newrelic_interceptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nao Minami
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-28 00:00:00.000000000 Z
11
+ date: 2021-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -98,16 +98,22 @@ dependencies:
98
98
  name: newrelic_rpm
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '6.0'
104
+ - - "<"
105
+ - !ruby/object:Gem::Version
106
+ version: '9.0'
104
107
  type: :runtime
105
108
  prerelease: false
106
109
  version_requirements: !ruby/object:Gem::Requirement
107
110
  requirements:
108
- - - "~>"
111
+ - - ">="
109
112
  - !ruby/object:Gem::Version
110
113
  version: '6.0'
114
+ - - "<"
115
+ - !ruby/object:Gem::Version
116
+ version: '9.0'
111
117
  - !ruby/object:Gem::Dependency
112
118
  name: grpc
113
119
  requirement: !ruby/object:Gem::Requirement
@@ -129,27 +135,31 @@ executables: []
129
135
  extensions: []
130
136
  extra_rdoc_files: []
131
137
  files:
138
+ - ".github/dependabot.yml"
139
+ - ".github/workflows/test.yml"
132
140
  - ".gitignore"
133
141
  - ".rspec"
134
- - ".travis.yml"
142
+ - CHANGELOG.md
135
143
  - Gemfile
136
- - Gemfile.lock
137
144
  - LICENSE.txt
138
145
  - README.md
139
146
  - Rakefile
140
147
  - bin/console
141
148
  - bin/setup
149
+ - gemfiles/newrelic-6.gemfile
150
+ - gemfiles/newrelic-7.gemfile
142
151
  - grpc_newrelic_interceptor.gemspec
143
152
  - lib/grpc_newrelic_interceptor.rb
153
+ - lib/grpc_newrelic_interceptor/client_interceptor.rb
144
154
  - lib/grpc_newrelic_interceptor/server_interceptor.rb
145
155
  - lib/grpc_newrelic_interceptor/version.rb
146
- homepage: https://github.com/south37/grpc_newrelic_interceptor
156
+ homepage: https://github.com/wantedly/grpc_newrelic_interceptor
147
157
  licenses:
148
158
  - MIT
149
159
  metadata:
150
- homepage_uri: https://github.com/south37/grpc_newrelic_interceptor
151
- source_code_uri: https://github.com/south37/grpc_newrelic_interceptor
152
- post_install_message:
160
+ homepage_uri: https://github.com/wantedly/grpc_newrelic_interceptor
161
+ source_code_uri: https://github.com/wantedly/grpc_newrelic_interceptor
162
+ post_install_message:
153
163
  rdoc_options: []
154
164
  require_paths:
155
165
  - lib
@@ -164,8 +174,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
174
  - !ruby/object:Gem::Version
165
175
  version: '0'
166
176
  requirements: []
167
- rubygems_version: 3.0.3
168
- signing_key:
177
+ rubygems_version: 3.2.22
178
+ signing_key:
169
179
  specification_version: 4
170
180
  summary: An interceptor for using New Relic with gRPC.
171
181
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.2
7
- before_install: gem install bundler -v 2.0.2
data/Gemfile.lock DELETED
@@ -1,56 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- grpc_newrelic_interceptor (0.0.1)
5
- grpc
6
- newrelic_rpm (~> 6.0)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- coderay (1.1.2)
12
- diff-lcs (1.3)
13
- google-protobuf (3.10.0-universal-darwin)
14
- googleapis-common-protos-types (1.0.4)
15
- google-protobuf (~> 3.0)
16
- grpc (1.24.0)
17
- google-protobuf (~> 3.8)
18
- googleapis-common-protos-types (~> 1.0)
19
- method_source (0.9.2)
20
- newrelic_rpm (6.7.0.359)
21
- pry (0.12.2)
22
- coderay (~> 1.1.0)
23
- method_source (~> 0.9.0)
24
- pry-doc (1.0.0)
25
- pry (~> 0.11)
26
- yard (~> 0.9.11)
27
- rake (10.5.0)
28
- rspec (3.9.0)
29
- rspec-core (~> 3.9.0)
30
- rspec-expectations (~> 3.9.0)
31
- rspec-mocks (~> 3.9.0)
32
- rspec-core (3.9.0)
33
- rspec-support (~> 3.9.0)
34
- rspec-expectations (3.9.0)
35
- diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.9.0)
37
- rspec-mocks (3.9.0)
38
- diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.9.0)
40
- rspec-support (3.9.0)
41
- yard (0.9.20)
42
-
43
- PLATFORMS
44
- ruby
45
-
46
- DEPENDENCIES
47
- bundler (~> 2.0)
48
- google-protobuf
49
- grpc_newrelic_interceptor!
50
- pry
51
- pry-doc
52
- rake (~> 10.0)
53
- rspec
54
-
55
- BUNDLED WITH
56
- 2.0.2