grpc_opencensus_interceptor 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +55 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/grpc_opencensus_interceptor.gemspec +35 -0
- data/lib/grpc_opencensus_interceptor.rb +10 -0
- data/lib/grpc_opencensus_interceptor/server_interceptor.rb +171 -0
- data/lib/grpc_opencensus_interceptor/server_interceptor/span_modifier.rb +16 -0
- data/lib/grpc_opencensus_interceptor/version.rb +3 -0
- metadata +159 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c84957ff2c9d44336456778af7145cc38d1bbd74e54375d1a5bb3c1d56c323be
|
|
4
|
+
data.tar.gz: bccd9a4397ce695db700d6b0893d5abd6144bb9d4c288a20d94d1a8daae63aaa
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ba6e5cb703795e1c5f755dba71010b7df80ad3bc4a0c4afc31779a8315099949695ab847382338ac106d1208b15fa81311465e1c81ab514af37b16521f55d85f
|
|
7
|
+
data.tar.gz: '08e725b44a73ac30b62c5751563bb9ca3c2d58ba3e6f60118e64bfda711bdda3b87e346d8222827c14dc8e242ed64b522611a07486945255c39667dc6b27d302'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at south37777@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
grpc_opencensus_interceptor (0.0.1)
|
|
5
|
+
grpc
|
|
6
|
+
opencensus
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
coderay (1.1.2)
|
|
12
|
+
diff-lcs (1.3)
|
|
13
|
+
google-protobuf (3.11.2)
|
|
14
|
+
googleapis-common-protos-types (1.0.4)
|
|
15
|
+
google-protobuf (~> 3.0)
|
|
16
|
+
grpc (1.26.0)
|
|
17
|
+
google-protobuf (~> 3.8)
|
|
18
|
+
googleapis-common-protos-types (~> 1.0)
|
|
19
|
+
method_source (0.9.2)
|
|
20
|
+
opencensus (0.5.0)
|
|
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.1)
|
|
33
|
+
rspec-support (~> 3.9.1)
|
|
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.1)
|
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
39
|
+
rspec-support (~> 3.9.0)
|
|
40
|
+
rspec-support (3.9.2)
|
|
41
|
+
yard (0.9.24)
|
|
42
|
+
|
|
43
|
+
PLATFORMS
|
|
44
|
+
ruby
|
|
45
|
+
|
|
46
|
+
DEPENDENCIES
|
|
47
|
+
bundler (~> 2.0)
|
|
48
|
+
grpc_opencensus_interceptor!
|
|
49
|
+
pry
|
|
50
|
+
pry-doc
|
|
51
|
+
rake (~> 10.0)
|
|
52
|
+
rspec (~> 3.0)
|
|
53
|
+
|
|
54
|
+
BUNDLED WITH
|
|
55
|
+
2.0.2
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nao Minami
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# GrpcOpencensusInterceptor
|
|
2
|
+
An interceptor for using [OpenCensus](https://opencensus.io/) with gRPC.
|
|
3
|
+
|
|
4
|
+
## Installation
|
|
5
|
+
|
|
6
|
+
Add this line to your application's Gemfile:
|
|
7
|
+
|
|
8
|
+
```ruby
|
|
9
|
+
gem 'grpc_opencensus_interceptor'
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
And then execute:
|
|
13
|
+
|
|
14
|
+
$ bundle
|
|
15
|
+
|
|
16
|
+
Or install it yourself as:
|
|
17
|
+
|
|
18
|
+
$ gem install grpc_opencensus_interceptor
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
Please set a `GrpcOpencensusInterceptor` as an interceptor of your gRPC application.
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
require 'grpc'
|
|
26
|
+
require 'grpc_opencensus_interceptor'
|
|
27
|
+
|
|
28
|
+
server = GRPC::RpcServer.new(
|
|
29
|
+
interceptors: [
|
|
30
|
+
GrpcOpencensusInterceptor.new,
|
|
31
|
+
]
|
|
32
|
+
)
|
|
33
|
+
server.handle(MyHandler.new)
|
|
34
|
+
server.run_till_terminated_or_interrupted(['SIGINT'])
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Development
|
|
38
|
+
|
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
40
|
+
|
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
42
|
+
|
|
43
|
+
## Contributing
|
|
44
|
+
|
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/south37/grpc_opencensus_interceptor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
50
|
+
|
|
51
|
+
## Code of Conduct
|
|
52
|
+
|
|
53
|
+
Everyone interacting in the GrpcOpencensusInterceptor project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/south37/grpc_opencensus_interceptor/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "grpc_opencensus_interceptor"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
require "pry"
|
|
10
|
+
Pry.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "grpc_opencensus_interceptor/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "grpc_opencensus_interceptor"
|
|
7
|
+
spec.version = GrpcOpencensusInterceptor::VERSION
|
|
8
|
+
spec.authors = ["Nao Minami"]
|
|
9
|
+
spec.email = ["south37777@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = %q{An interceptor for using OpenCensus with gRPC.}
|
|
12
|
+
spec.description = %q{An interceptor for using OpenCensus with gRPC.}
|
|
13
|
+
spec.homepage = "https://github.com/south37/grpc_opencensus_interceptor"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/south37/grpc_opencensus_interceptor"
|
|
18
|
+
|
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
23
|
+
end
|
|
24
|
+
spec.bindir = "exe"
|
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
26
|
+
spec.require_paths = ["lib"]
|
|
27
|
+
|
|
28
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
31
|
+
spec.add_development_dependency "pry"
|
|
32
|
+
spec.add_development_dependency "pry-doc"
|
|
33
|
+
spec.add_dependency "grpc"
|
|
34
|
+
spec.add_dependency "opencensus"
|
|
35
|
+
end
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
require "opencensus"
|
|
2
|
+
require "grpc"
|
|
3
|
+
require "grpc_opencensus_interceptor/server_interceptor/span_modifier"
|
|
4
|
+
|
|
5
|
+
module GrpcOpencensusInterceptor
|
|
6
|
+
class ServerInterceptor < GRPC::ServerInterceptor
|
|
7
|
+
OPENCENSUS_TRACE_BIN_KEY = "grpc-trace-bin".freeze
|
|
8
|
+
|
|
9
|
+
# @param [#export] exporter The exported used to export captured spans
|
|
10
|
+
# at the end of the request. Optional: If omitted, uses the exporter
|
|
11
|
+
# in the current config.
|
|
12
|
+
# @param [SpanModifier, call] span_modifier Modify span if necessary. It
|
|
13
|
+
# takes span, request, call, method as its parameters.
|
|
14
|
+
#
|
|
15
|
+
def initialize(exporter: nil, span_modifier: nil)
|
|
16
|
+
@exporter = exporter || OpenCensus::Trace.config.exporter
|
|
17
|
+
@span_modifier = span_modifier
|
|
18
|
+
@deserializer = OpenCensus::Trace::Formatters::Binary.new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
##
|
|
22
|
+
# Intercept a unary request response call.
|
|
23
|
+
#
|
|
24
|
+
# @param [Object] request
|
|
25
|
+
# @param [GRPC::ActiveCall::SingleReqView] call
|
|
26
|
+
# @param [Method] method
|
|
27
|
+
#
|
|
28
|
+
def request_response(request:, call:, method:)
|
|
29
|
+
context_bin = call.metadata[OPENCENSUS_TRACE_BIN_KEY]
|
|
30
|
+
if context_bin
|
|
31
|
+
context = deserialize(context_bin)
|
|
32
|
+
else
|
|
33
|
+
cojntext = nil
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
OpenCensus::Trace.start_request_trace(
|
|
37
|
+
trace_context: context,
|
|
38
|
+
same_process_as_parent: false) do |span_context|
|
|
39
|
+
begin
|
|
40
|
+
OpenCensus::Trace.in_span get_name(method) do |span|
|
|
41
|
+
modify_span(span, request, call, method)
|
|
42
|
+
|
|
43
|
+
start_request(span, call, method)
|
|
44
|
+
begin
|
|
45
|
+
grpc_ex = GRPC::Ok.new
|
|
46
|
+
yield
|
|
47
|
+
rescue StandardError => e
|
|
48
|
+
grpc_ex = to_grpc_ex(e)
|
|
49
|
+
raise e
|
|
50
|
+
ensure
|
|
51
|
+
finish_request(span, grpc_ex)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
ensure
|
|
55
|
+
@exporter.export span_context.build_contained_spans
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# NOTE: For now, we don't support server_streamer, client_streamer and bidi_streamer
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
# @param [String] context_bin OpenCensus span context in binary format
|
|
65
|
+
# @return [OpenCensus::Trace::TraceContextData, nil]
|
|
66
|
+
def deserialize(context_bin)
|
|
67
|
+
@deserializer.deserialize(context_bin)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Span name is represented as $package.$service/$method
|
|
71
|
+
# cf. https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/gRPC.md#spans
|
|
72
|
+
#
|
|
73
|
+
# @param [Method] method
|
|
74
|
+
# @return [String]
|
|
75
|
+
def get_name(method)
|
|
76
|
+
"#{method.owner.service_name}/#{camelize(method.name.to_s)}"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# @param [Method] method
|
|
80
|
+
# @return [String]
|
|
81
|
+
def get_path(method)
|
|
82
|
+
"/" + get_name(method)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# @param [String] term
|
|
86
|
+
# @return [String]
|
|
87
|
+
def camelize(term)
|
|
88
|
+
term.split("_").map(&:capitalize).join
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Modify span by custom span modifier
|
|
92
|
+
#
|
|
93
|
+
# @param [OpenCensus::Trace::SpanBuilder] span
|
|
94
|
+
# @param [Object] request
|
|
95
|
+
# @param [GRPC::ActiveCall::SingleReqView] call
|
|
96
|
+
# @param [Method] method
|
|
97
|
+
def modify_span(span, request, call, method)
|
|
98
|
+
@span_modifier.call(span, request, call, method) if @span_modifier
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# @param [OpenCensus::Trace::SpanBuilder] span
|
|
102
|
+
# @param [GRPC::ActiveCall::SingleReqView] call
|
|
103
|
+
# @param [Method] method
|
|
104
|
+
def start_request(span, call, method)
|
|
105
|
+
span.kind = OpenCensus::Trace::SpanBuilder::SERVER
|
|
106
|
+
span.put_attribute "http.path", get_path(method)
|
|
107
|
+
span.put_attribute "http.method", "POST" # gRPC always uses "POST"
|
|
108
|
+
if call.metadata['user-agent']
|
|
109
|
+
span.put_attribute "http.user_agent", call.metadata['user-agent']
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# @param [OpenCensus::Trace::SpanBuilder] span
|
|
114
|
+
# @param [GRPC::BadStatus] exception
|
|
115
|
+
def finish_request(span, exception)
|
|
116
|
+
# Set gRPC server status
|
|
117
|
+
# https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/gRPC.md#spans
|
|
118
|
+
span.set_status exception.code
|
|
119
|
+
span.put_attribute "http.status_code", to_http_status(exception)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# cf. https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md
|
|
123
|
+
# cf. https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/HTTP.md#mapping-from-http-status-codes-to-trace-status-codes
|
|
124
|
+
#
|
|
125
|
+
# @param [GRPC::BadStatus] exception
|
|
126
|
+
# @return [Integer]
|
|
127
|
+
def to_http_status(exception)
|
|
128
|
+
case exception
|
|
129
|
+
when GRPC::Ok
|
|
130
|
+
200
|
|
131
|
+
when GRPC::InvalidArgument
|
|
132
|
+
400
|
|
133
|
+
when GRPC::DeadlineExceeded
|
|
134
|
+
504
|
|
135
|
+
when GRPC::NotFound
|
|
136
|
+
404
|
|
137
|
+
when GRPC::PermissionDenied
|
|
138
|
+
403
|
|
139
|
+
when GRPC::Unauthenticated
|
|
140
|
+
401
|
|
141
|
+
when GRPC::Aborted
|
|
142
|
+
# For GRPC::Aborted, grpc-gateway uses 409. We do the same.
|
|
143
|
+
# cf. https://github.com/grpc-ecosystem/grpc-gateway/blob/e8db07a3923d3f5c77dbcea96656afe43a2757a8/runtime/errors.go#L17-L58
|
|
144
|
+
409
|
|
145
|
+
when GRPC::ResourceExhausted
|
|
146
|
+
429
|
|
147
|
+
when GRPC::Unimplemented
|
|
148
|
+
501
|
|
149
|
+
when GRPC::Unavailable
|
|
150
|
+
503
|
|
151
|
+
when GRPC::Unknown
|
|
152
|
+
# NOTE: This is not same with the correct mapping
|
|
153
|
+
500
|
|
154
|
+
else
|
|
155
|
+
# NOTE: Here, we use 500 temporarily.
|
|
156
|
+
500
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# @param [Exception] e
|
|
161
|
+
# @return [GRPC::BadStatus] e
|
|
162
|
+
def to_grpc_ex(e)
|
|
163
|
+
case e
|
|
164
|
+
when GRPC::BadStatus
|
|
165
|
+
e
|
|
166
|
+
else
|
|
167
|
+
GRPC::Unknown.new(e.message)
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module GrpcOpencensusInterceptor
|
|
2
|
+
class ServerInterceptor < GRPC::ServerInterceptor
|
|
3
|
+
##
|
|
4
|
+
# Modify span by request, call, method if necessary
|
|
5
|
+
#
|
|
6
|
+
class SpanModifier
|
|
7
|
+
# @param [OpenCensus::Trace::SpanBuilder] span
|
|
8
|
+
# @param [Object] request
|
|
9
|
+
# @param [GRPC::ActiveCall::SingleReqView] call
|
|
10
|
+
# @param [Method] method
|
|
11
|
+
def call(span, request, call, method)
|
|
12
|
+
# Do something necessary
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: grpc_opencensus_interceptor
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nao Minami
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-01-16 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: pry
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: pry-doc
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: grpc
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: opencensus
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :runtime
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
description: An interceptor for using OpenCensus with gRPC.
|
|
112
|
+
email:
|
|
113
|
+
- south37777@gmail.com
|
|
114
|
+
executables: []
|
|
115
|
+
extensions: []
|
|
116
|
+
extra_rdoc_files: []
|
|
117
|
+
files:
|
|
118
|
+
- ".gitignore"
|
|
119
|
+
- ".rspec"
|
|
120
|
+
- ".travis.yml"
|
|
121
|
+
- CODE_OF_CONDUCT.md
|
|
122
|
+
- Gemfile
|
|
123
|
+
- Gemfile.lock
|
|
124
|
+
- LICENSE.txt
|
|
125
|
+
- README.md
|
|
126
|
+
- Rakefile
|
|
127
|
+
- bin/console
|
|
128
|
+
- bin/setup
|
|
129
|
+
- grpc_opencensus_interceptor.gemspec
|
|
130
|
+
- lib/grpc_opencensus_interceptor.rb
|
|
131
|
+
- lib/grpc_opencensus_interceptor/server_interceptor.rb
|
|
132
|
+
- lib/grpc_opencensus_interceptor/server_interceptor/span_modifier.rb
|
|
133
|
+
- lib/grpc_opencensus_interceptor/version.rb
|
|
134
|
+
homepage: https://github.com/south37/grpc_opencensus_interceptor
|
|
135
|
+
licenses:
|
|
136
|
+
- MIT
|
|
137
|
+
metadata:
|
|
138
|
+
homepage_uri: https://github.com/south37/grpc_opencensus_interceptor
|
|
139
|
+
source_code_uri: https://github.com/south37/grpc_opencensus_interceptor
|
|
140
|
+
post_install_message:
|
|
141
|
+
rdoc_options: []
|
|
142
|
+
require_paths:
|
|
143
|
+
- lib
|
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
|
+
requirements:
|
|
146
|
+
- - ">="
|
|
147
|
+
- !ruby/object:Gem::Version
|
|
148
|
+
version: '0'
|
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
|
+
requirements:
|
|
151
|
+
- - ">="
|
|
152
|
+
- !ruby/object:Gem::Version
|
|
153
|
+
version: '0'
|
|
154
|
+
requirements: []
|
|
155
|
+
rubygems_version: 3.0.6
|
|
156
|
+
signing_key:
|
|
157
|
+
specification_version: 4
|
|
158
|
+
summary: An interceptor for using OpenCensus with gRPC.
|
|
159
|
+
test_files: []
|