opentelemetry-instrumentation-grpc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 19942eb457cf16278ba3ab85cbe4f967a720be9bfa4f8e4b407bbea1c8e45087
4
+ data.tar.gz: e92250ae62eb1f6dd610b413cdfd41041402a3154eedf4b56e6473c5a4a4f60a
5
+ SHA512:
6
+ metadata.gz: da0d80f073653ce4d1c224e4f7899e7e92e9d4232cb0f2369f892b5f8f3ac897f1f12e674101ac54ec35f91addb6595bc4cb15c95b3052c86be955ae13270d25
7
+ data.tar.gz: e24cad286c11e2cd20459fcbde4d54ed28d2b08a85558e95d0993de8bdef7860a4da730f034aeb9e78a892ea4a52fa2fecefe8bdfd6ec102a369d0a644dfa102
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-06-18
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at hbachrach@dropbox.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Hazel Bachrach
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,63 @@
1
+ # OpenTelemetry::Instrumentation::Grpc
2
+
3
+ OpenTelemetry instrumentation for users of the `grpc` gem
4
+
5
+ > [!WARNING]
6
+ > Right now, the gem only instruments outbound requests to gRPC services
7
+
8
+ ## Installation
9
+
10
+ Install the gem and add to the application's Gemfile by executing:
11
+
12
+ $ bundle add opentelemetry-instrumentation-grpc
13
+
14
+ If bundler is not being used to manage dependencies, install the gem by executing:
15
+
16
+ $ gem install opentelemetry-instrumentation-grpc
17
+
18
+ ## Usage
19
+
20
+ To use the instrumentation, call `use` with the name of the instrumentation:
21
+
22
+ ```ruby
23
+ OpenTelemetry::SDK.configure do |c|
24
+ c.use 'OpenTelemetry::Instrumentation::Grpc', {
25
+ peer_service: "Example",
26
+ allowed_metadata_headers: [],
27
+ }
28
+ end
29
+ ```
30
+
31
+ Alternatively, you can also call `use_all` to install all the available
32
+ instrumentation.
33
+
34
+ ```ruby
35
+ OpenTelemetry::SDK.configure do |c|
36
+ c.use_all
37
+ end
38
+ ```
39
+
40
+ You *also* need to make sure your stubs are using the interceptor, e.g.
41
+
42
+ ```ruby
43
+ otel = OpenTelemetry::Instrumentation::Grpc.client_interceptor
44
+ SomeService::Stub.new(host, credentials, *args, **kwargs, interceptors: [otel])
45
+ ```
46
+
47
+ ## Development
48
+
49
+ 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.
50
+
51
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hibachrach/opentelemetry-instrumentation-grpc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/opentelemetry-instrumentation-grpc/blob/main/CODE_OF_CONDUCT.md).
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
60
+
61
+ ## Code of Conduct
62
+
63
+ Everyone interacting in the OpenTelemetry::Instrumentation::Grpc project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/opentelemetry-instrumentation-grpc/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenTelemetry
4
+ module Instrumentation
5
+ module Grpc
6
+ # The Instrumentation class contains logic to detect and install the Grpc instrumentation
7
+ class Instrumentation < OpenTelemetry::Instrumentation::Base
8
+ install do |_config|
9
+ require_dependencies
10
+ end
11
+
12
+ option :allowed_metadata_headers, default: [], validate: :array
13
+ option :peer_service, default: nil, validate: :string
14
+
15
+ present do
16
+ defined?(::GRPC)
17
+ end
18
+
19
+ private
20
+
21
+ def require_dependencies
22
+ require_relative "interceptors/client"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenTelemetry
4
+ module Instrumentation
5
+ module Grpc
6
+ module Interceptors
7
+ class Client < ::GRPC::ClientInterceptor
8
+ def request_response(request: nil, call: nil, method: nil, metadata: nil, &blk)
9
+ call(type: "request_response", requests: [request], call: call, method: method, metadata: metadata, &blk)
10
+ end
11
+
12
+ def client_streamer(requests: nil, call: nil, method: nil, metadata: nil, &blk)
13
+ call(type: "client_streamer", requests: requests, call: call, method: method, metadata: metadata, &blk)
14
+ end
15
+
16
+ def server_streamer(request: nil, call: nil, method: nil, metadata: nil, &blk)
17
+ call(type: "server_streamer", requests: [request], call: call, method: method, metadata: metadata, &blk)
18
+ end
19
+
20
+ def bidi_streamer(request: nil, call: nil, method: nil, metadata: nil, &blk)
21
+ call(type: "client_streamer", requests: requests, call: call, method: method, metadata: metadata, &blk)
22
+ end
23
+
24
+ private
25
+
26
+ def call(type:, requests: nil, call: nil, method: nil, metadata: nil)
27
+ return yield if instrumentation_config.empty?
28
+
29
+ method_parts = method.to_s.split("/")
30
+ service = method_parts[1]
31
+ method_name = method_parts.last
32
+
33
+ attributes = {
34
+ OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => "grpc",
35
+ OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => service,
36
+ OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => method_name,
37
+ OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE => instrumentation_config[:peer_service],
38
+ "rpc.type" => type,
39
+ "net.sock.peer.addr" => call.instance_variable_get(:@wrapped)&.peer
40
+ }.compact
41
+
42
+ attributes.merge!(allowed_metadata_headers(metadata.transform_keys(&:to_s)))
43
+
44
+ instrumentation_tracer.in_span(
45
+ method.to_s,
46
+ attributes: attributes,
47
+ kind: OpenTelemetry::Trace::SpanKind::CLIENT
48
+ ) do |span|
49
+ OpenTelemetry.propagation.inject(metadata)
50
+ yield.tap do
51
+ span&.set_attribute(OpenTelemetry::SemanticConventions::Trace::RPC_GRPC_STATUS_CODE, 0)
52
+ end
53
+ rescue => e
54
+ span&.set_attribute(OpenTelemetry::SemanticConventions::Trace::RPC_GRPC_STATUS_CODE, e.code)
55
+ raise e
56
+ end
57
+ end
58
+
59
+ def allowed_metadata_headers(metadata)
60
+ instrumentation_config[:allowed_metadata_headers].each_with_object({}) do |k, h|
61
+ if (v = metadata[k.to_s])
62
+ h["rpc.request.metadata.#{k}"] = v
63
+ end
64
+ end
65
+ end
66
+
67
+ def instrumentation_config
68
+ Grpc::Instrumentation.instance.config
69
+ end
70
+
71
+ def instrumentation_tracer
72
+ Grpc::Instrumentation.instance.tracer
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenTelemetry
4
+ module Instrumentation
5
+ module Grpc
6
+ VERSION = "0.1.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "opentelemetry"
4
+ require "opentelemetry-instrumentation-base"
5
+ require "active_support/inflector"
6
+
7
+ module OpenTelemetry
8
+ module Instrumentation
9
+ # Contains the OpenTelemetry instrumentation for the Gruf gem
10
+ module Grpc
11
+ class Error < StandardError; end
12
+
13
+ module_function
14
+
15
+ def client_interceptor
16
+ Interceptors::Client.new
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ require_relative "grpc/instrumentation"
23
+ require_relative "grpc/version"
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenTelemetry
4
+ module Instrumentation
5
+ end
6
+ end
7
+
8
+ require_relative "instrumentation/grpc"
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "opentelemetry/instrumentation"
@@ -0,0 +1,8 @@
1
+ module OpenTelemetry
2
+ module Instrumentation
3
+ module Grpc
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opentelemetry-instrumentation-grpc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hazel Bachrach
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opentelemetry-instrumentation-base
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.22.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.22.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: opentelemetry-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '4'
55
+ description:
56
+ email:
57
+ - hbachrach@dropbox.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rspec"
63
+ - ".standard.yml"
64
+ - CHANGELOG.md
65
+ - CODE_OF_CONDUCT.md
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/opentelemetry-instrumentation-grpc.rb
70
+ - lib/opentelemetry/instrumentation.rb
71
+ - lib/opentelemetry/instrumentation/grpc.rb
72
+ - lib/opentelemetry/instrumentation/grpc/instrumentation.rb
73
+ - lib/opentelemetry/instrumentation/grpc/interceptors/client.rb
74
+ - lib/opentelemetry/instrumentation/grpc/version.rb
75
+ - sig/opentelemetry/instrumentation/grpc.rbs
76
+ homepage: https://github.com/hibachrach/opentelemetry-instrumentation-grpc
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ homepage_uri: https://github.com/hibachrach/opentelemetry-instrumentation-grpc
81
+ source_code_uri: https://github.com/hibachrach/opentelemetry-instrumentation-grpc
82
+ changelog_uri: https://github.com/hibachrach/opentelemetry-instrumentation-grpc/blob/main/CHANGELOG.md
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 3.0.0
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.3.27
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: OpenTelemetry instrumentation for the Ruby gem `grpc`
102
+ test_files: []