grpc_newrelic_interceptor 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/Gemfile.lock +5 -5
- data/README.md +16 -1
- data/lib/grpc_newrelic_interceptor.rb +1 -0
- data/lib/grpc_newrelic_interceptor/client_interceptor.rb +79 -0
- data/lib/grpc_newrelic_interceptor/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52a1fa41d6cca5fe25fb6d01fec2e75323725efb6db4c49e1f14539dbcabe690
|
4
|
+
data.tar.gz: fee4b6bc62c403fc9ade21cb0cfa8f280ec1feb6bbe3d0efb20481c2c52a200a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 066d0af34fa9e33a40691169fb3684960f78829e421d6a40d3c12e683f232d274e18be4129d00a02331b3cd0b12a23c23a3b25e3a04490be28959c9a1fb17abf
|
7
|
+
data.tar.gz: 49ba61cd669e60da4b90201fab0f409d66d15ed50ab5c20fc178b6577608ce9918da0f927fb1ed08fae254e720aa198a2c2f70f71516091d6d6b5e1357fa2865
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grpc_newrelic_interceptor (0.0.
|
4
|
+
grpc_newrelic_interceptor (0.0.2)
|
5
5
|
grpc
|
6
6
|
newrelic_rpm (~> 6.0)
|
7
7
|
|
@@ -10,14 +10,14 @@ GEM
|
|
10
10
|
specs:
|
11
11
|
coderay (1.1.2)
|
12
12
|
diff-lcs (1.3)
|
13
|
-
google-protobuf (3.
|
13
|
+
google-protobuf (3.11.3)
|
14
14
|
googleapis-common-protos-types (1.0.4)
|
15
15
|
google-protobuf (~> 3.0)
|
16
|
-
grpc (1.
|
17
|
-
google-protobuf (~> 3.
|
16
|
+
grpc (1.27.0)
|
17
|
+
google-protobuf (~> 3.11)
|
18
18
|
googleapis-common-protos-types (~> 1.0)
|
19
19
|
method_source (0.9.2)
|
20
|
-
newrelic_rpm (6.
|
20
|
+
newrelic_rpm (6.8.0.360)
|
21
21
|
pry (0.12.2)
|
22
22
|
coderay (~> 1.1.0)
|
23
23
|
method_source (~> 0.9.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.
|
@@ -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
|
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.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nao Minami
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- bin/setup
|
142
142
|
- grpc_newrelic_interceptor.gemspec
|
143
143
|
- lib/grpc_newrelic_interceptor.rb
|
144
|
+
- lib/grpc_newrelic_interceptor/client_interceptor.rb
|
144
145
|
- lib/grpc_newrelic_interceptor/server_interceptor.rb
|
145
146
|
- lib/grpc_newrelic_interceptor/version.rb
|
146
147
|
homepage: https://github.com/south37/grpc_newrelic_interceptor
|
@@ -164,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
165
|
- !ruby/object:Gem::Version
|
165
166
|
version: '0'
|
166
167
|
requirements: []
|
167
|
-
rubygems_version: 3.0.
|
168
|
+
rubygems_version: 3.0.6
|
168
169
|
signing_key:
|
169
170
|
specification_version: 4
|
170
171
|
summary: An interceptor for using New Relic with gRPC.
|