From 07c9cf4ba92fac8936e12119f91b7d7fa96b120a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ka=C5=BAmierczak?= Date: Thu, 16 Jan 2025 02:30:12 +0100 Subject: [PATCH] feat: migrate gRPC instrumentation from standardrb to Rubocop (#1341) * fix: migrate grpc instrumentation from standardrb to rubocop * remove standardrb * fix: remove conflicting CODE_OF_CONDUCT * fix: remove rbs * include the gRPC instrumentation in the general CI * fix(grpc instrumentation): skip JRuby tests since gRPC is not compatible with JRuby reference https://github.com/grpc/grpc/issues/6705 --------- Co-authored-by: Ariel Valentin --- .github/workflows/ci-instrumentation.yml | 2 + instrumentation/grpc/.rubocop.yml | 5 ++ instrumentation/grpc/.standard.yml | 3 - instrumentation/grpc/CODE_OF_CONDUCT.md | 84 ------------------- instrumentation/grpc/Gemfile | 2 +- .../lib/opentelemetry-instrumentation-grpc.rb | 2 +- .../grpc/lib/opentelemetry/instrumentation.rb | 12 ++- .../lib/opentelemetry/instrumentation/grpc.rb | 8 +- .../grpc/interceptors/client_tracer.rb | 18 ++-- .../grpc/patches/client_stub.rb | 4 +- ...opentelemetry-instrumentation-grpc.gemspec | 10 +-- .../opentelemetry/instrumentation/grpc.rbs | 14 ---- .../grpc/test/support/grpc_server_runner.rb | 2 +- 13 files changed, 40 insertions(+), 126 deletions(-) create mode 100644 instrumentation/grpc/.rubocop.yml delete mode 100644 instrumentation/grpc/.standard.yml delete mode 100644 instrumentation/grpc/CODE_OF_CONDUCT.md delete mode 100644 instrumentation/grpc/sig/opentelemetry/instrumentation/grpc.rbs diff --git a/.github/workflows/ci-instrumentation.yml b/.github/workflows/ci-instrumentation.yml index cf938e48f..f4fc1465a 100644 --- a/.github/workflows/ci-instrumentation.yml +++ b/.github/workflows/ci-instrumentation.yml @@ -39,6 +39,7 @@ jobs: - faraday - grape - graphql + - grpc - gruf - http - http_client @@ -102,6 +103,7 @@ jobs: [[ "${{ matrix.gem }}" == "lmdb" ]] && echo "skip=true" >> $GITHUB_OUTPUT [[ "${{ matrix.gem }}" == "rack" ]] && echo "skip=true" >> $GITHUB_OUTPUT [[ "${{ matrix.gem }}" == "rails" ]] && echo "skip=true" >> $GITHUB_OUTPUT + [[ "${{ matrix.gem }}" == "grpc" ]] && echo "skip=true" >> $GITHUB_OUTPUT [[ "${{ matrix.gem }}" == "gruf" ]] && echo "skip=true" >> $GITHUB_OUTPUT # This is essentially a bash script getting evaluated, so we need to return true or the whole job fails. true diff --git a/instrumentation/grpc/.rubocop.yml b/instrumentation/grpc/.rubocop.yml new file mode 100644 index 000000000..3dad77a56 --- /dev/null +++ b/instrumentation/grpc/.rubocop.yml @@ -0,0 +1,5 @@ +inherit_from: ../../.rubocop.yml + +AllCops: + Exclude: + - 'test/support/proto/*.rb' diff --git a/instrumentation/grpc/.standard.yml b/instrumentation/grpc/.standard.yml deleted file mode 100644 index 6d67c99eb..000000000 --- a/instrumentation/grpc/.standard.yml +++ /dev/null @@ -1,3 +0,0 @@ -# For available configuration options, see: -# https://github.com/standardrb/standard -ruby_version: 3.0 diff --git a/instrumentation/grpc/CODE_OF_CONDUCT.md b/instrumentation/grpc/CODE_OF_CONDUCT.md deleted file mode 100644 index e478f902c..000000000 --- a/instrumentation/grpc/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,84 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -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. - -We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. - -## Our Standards - -Examples of behavior that contributes to a positive environment for our community include: - -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience -* Focusing on what is best not just for us as individuals, but for the overall community - -Examples of unacceptable behavior include: - -* The use of sexualized language or imagery, and sexual attention or - advances of any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or email - address, without their explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Enforcement Responsibilities - -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. - -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. - -## Scope - -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. - -## Enforcement - -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. - -All community leaders are obligated to respect the privacy and security of the reporter of any incident. - -## Enforcement Guidelines - -Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: - -### 1. Correction - -**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. - -**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. - -### 2. Warning - -**Community Impact**: A violation through a single incident or series of actions. - -**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. - -### 3. Temporary Ban - -**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. - -**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. - -### 4. Permanent Ban - -**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. - -**Consequence**: A permanent ban from any sort of public interaction within the community. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, -available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. - -Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). - -[homepage]: https://www.contributor-covenant.org - -For answers to common questions about this code of conduct, see the FAQ at -https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. diff --git a/instrumentation/grpc/Gemfile b/instrumentation/grpc/Gemfile index 2834fc34b..68f476d47 100644 --- a/instrumentation/grpc/Gemfile +++ b/instrumentation/grpc/Gemfile @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: Apache-2.0 -source "https://rubygems.org" +source 'https://rubygems.org' # Specify your gem's dependencies in opentelemetry-instrumentation-grpc.gemspec gemspec diff --git a/instrumentation/grpc/lib/opentelemetry-instrumentation-grpc.rb b/instrumentation/grpc/lib/opentelemetry-instrumentation-grpc.rb index c6f1e5014..c034f140f 100644 --- a/instrumentation/grpc/lib/opentelemetry-instrumentation-grpc.rb +++ b/instrumentation/grpc/lib/opentelemetry-instrumentation-grpc.rb @@ -4,4 +4,4 @@ # # SPDX-License-Identifier: Apache-2.0 -require_relative "opentelemetry/instrumentation" +require_relative 'opentelemetry/instrumentation' diff --git a/instrumentation/grpc/lib/opentelemetry/instrumentation.rb b/instrumentation/grpc/lib/opentelemetry/instrumentation.rb index e036eea9d..d1785c1c4 100644 --- a/instrumentation/grpc/lib/opentelemetry/instrumentation.rb +++ b/instrumentation/grpc/lib/opentelemetry/instrumentation.rb @@ -4,9 +4,19 @@ # # SPDX-License-Identifier: Apache-2.0 +# OpenTelemetry is an open source observability framework, providing a +# general-purpose API, SDK, and related tools required for the instrumentation +# of cloud-native software, frameworks, and libraries. +# +# The OpenTelemetry module provides global accessors for telemetry objects. +# See the documentation for the `opentelemetry-api` gem for details. module OpenTelemetry + # "Instrumentation" are specified by + # https://github.com/open-telemetry/opentelemetry-specification/blob/784635d01d8690c8f5fcd1f55bdbc8a13cf2f4f2/specification/glossary.md#instrumentation-library + # + # Instrumentation should be able to handle the case when the library is not installed on a user's system. module Instrumentation end end -require_relative "instrumentation/grpc" +require_relative 'instrumentation/grpc' diff --git a/instrumentation/grpc/lib/opentelemetry/instrumentation/grpc.rb b/instrumentation/grpc/lib/opentelemetry/instrumentation/grpc.rb index ed7f5afe9..e47e42bfa 100644 --- a/instrumentation/grpc/lib/opentelemetry/instrumentation/grpc.rb +++ b/instrumentation/grpc/lib/opentelemetry/instrumentation/grpc.rb @@ -4,8 +4,8 @@ # # SPDX-License-Identifier: Apache-2.0 -require "opentelemetry" -require "opentelemetry-instrumentation-base" +require 'opentelemetry' +require 'opentelemetry-instrumentation-base' module OpenTelemetry module Instrumentation @@ -16,6 +16,6 @@ class Error < StandardError; end end end -require_relative "grpc/instrumentation" -require_relative "grpc/version" +require_relative 'grpc/instrumentation' +require_relative 'grpc/version' require_relative 'grpc/interceptors/client_tracer' diff --git a/instrumentation/grpc/lib/opentelemetry/instrumentation/grpc/interceptors/client_tracer.rb b/instrumentation/grpc/lib/opentelemetry/instrumentation/grpc/interceptors/client_tracer.rb index d1ffeb3b6..288a3a0d8 100644 --- a/instrumentation/grpc/lib/opentelemetry/instrumentation/grpc/interceptors/client_tracer.rb +++ b/instrumentation/grpc/lib/opentelemetry/instrumentation/grpc/interceptors/client_tracer.rb @@ -11,19 +11,19 @@ module Interceptors # ClientTracer is a gRPC client interceptor which instrument gRPC calls with OpenTelemetry tracing class ClientTracer < ::GRPC::ClientInterceptor def request_response(request: nil, call: nil, method: nil, metadata: nil, &blk) - call(type: "request_response", requests: [request], call: call, method: method, metadata: metadata, &blk) + call(type: 'request_response', requests: [request], call: call, method: method, metadata: metadata, &blk) end def client_streamer(requests: nil, call: nil, method: nil, metadata: nil, &blk) - call(type: "client_streamer", requests: requests, call: call, method: method, metadata: metadata, &blk) + call(type: 'client_streamer', requests: requests, call: call, method: method, metadata: metadata, &blk) end def server_streamer(request: nil, call: nil, method: nil, metadata: nil, &blk) - call(type: "server_streamer", requests: [request], call: call, method: method, metadata: metadata, &blk) + call(type: 'server_streamer', requests: [request], call: call, method: method, metadata: metadata, &blk) end def bidi_streamer(requests: nil, call: nil, method: nil, metadata: nil, &blk) - call(type: "client_streamer", requests: requests, call: call, method: method, metadata: metadata, &blk) + call(type: 'client_streamer', requests: requests, call: call, method: method, metadata: metadata, &blk) end private @@ -31,17 +31,17 @@ def bidi_streamer(requests: nil, call: nil, method: nil, metadata: nil, &blk) def call(type:, requests: nil, call: nil, method: nil, metadata: nil) return yield if instrumentation_config.empty? - method_parts = method.to_s.split("/") + method_parts = method.to_s.split('/') service = method_parts[1] method_name = method_parts.last attributes = { - OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => "grpc", + OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => 'grpc', OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => service, OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => method_name, OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE => instrumentation_config[:peer_service], - "rpc.type" => type, - "net.sock.peer.addr" => call.instance_variable_get(:@wrapped)&.peer + 'rpc.type' => type, + 'net.sock.peer.addr' => call.instance_variable_get(:@wrapped)&.peer }.compact attributes.merge!(allowed_metadata_headers(metadata.transform_keys(&:to_s))) @@ -49,7 +49,7 @@ def call(type:, requests: nil, call: nil, method: nil, metadata: nil) instrumentation_tracer.in_span( # The specification requires there be no leading slash # https://github.com/open-telemetry/semantic-conventions/blob/5a2836bbea0b6e105b98370f331a7661bcf19540/docs/rpc/rpc-spans.md?plain=1#L63-L69 - method.to_s.delete_prefix("/"), + method.to_s.delete_prefix('/'), attributes: attributes, kind: OpenTelemetry::Trace::SpanKind::CLIENT ) do |span| diff --git a/instrumentation/grpc/lib/opentelemetry/instrumentation/grpc/patches/client_stub.rb b/instrumentation/grpc/lib/opentelemetry/instrumentation/grpc/patches/client_stub.rb index 5d9367eaf..c6706510d 100644 --- a/instrumentation/grpc/lib/opentelemetry/instrumentation/grpc/patches/client_stub.rb +++ b/instrumentation/grpc/lib/opentelemetry/instrumentation/grpc/patches/client_stub.rb @@ -13,9 +13,7 @@ module Patches module ClientStub def initialize(host, creds, **args) interceptors = args[:interceptors] || [] - interceptors.unshift(Interceptors::ClientTracer.new) unless interceptors.any? do |interceptor| - interceptor.is_a?(Interceptors::ClientTracer) - end + interceptors.unshift(Interceptors::ClientTracer.new) unless interceptors.any?(Interceptors::ClientTracer) args[:interceptors] = interceptors super diff --git a/instrumentation/grpc/opentelemetry-instrumentation-grpc.gemspec b/instrumentation/grpc/opentelemetry-instrumentation-grpc.gemspec index 9cb74cf8a..810c7f1ce 100644 --- a/instrumentation/grpc/opentelemetry-instrumentation-grpc.gemspec +++ b/instrumentation/grpc/opentelemetry-instrumentation-grpc.gemspec @@ -4,10 +4,10 @@ # # SPDX-License-Identifier: Apache-2.0 -require_relative "lib/opentelemetry/instrumentation/grpc/version" +require_relative 'lib/opentelemetry/instrumentation/grpc/version' Gem::Specification.new do |spec| - spec.name = "opentelemetry-instrumentation-grpc" + spec.name = 'opentelemetry-instrumentation-grpc' spec.version = OpenTelemetry::Instrumentation::Grpc::VERSION spec.authors = ['OpenTelemetry Authors'] spec.email = ['cncf-opentelemetry-contributors@lists.cncf.io'] @@ -17,7 +17,7 @@ Gem::Specification.new do |spec| spec.homepage = 'https://github.com/open-telemetry/opentelemetry-ruby-contrib' spec.license = 'Apache-2.0' - spec.required_ruby_version = ">= 3.0.0" + spec.required_ruby_version = '>= 3.0.0' # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. @@ -28,9 +28,9 @@ Gem::Specification.new do |spec| f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile]) end end - spec.bindir = "exe" + spec.bindir = 'exe' spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] # Uncomment to register a new dependency of your gem spec.add_dependency 'opentelemetry-api', '~> 1.2' diff --git a/instrumentation/grpc/sig/opentelemetry/instrumentation/grpc.rbs b/instrumentation/grpc/sig/opentelemetry/instrumentation/grpc.rbs deleted file mode 100644 index 03f8245de..000000000 --- a/instrumentation/grpc/sig/opentelemetry/instrumentation/grpc.rbs +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -module OpenTelemetry - module Instrumentation - module Grpc - VERSION: String - # See the writing guide of rbs: https://github.com/ruby/rbs#guides - end - end -end diff --git a/instrumentation/grpc/test/support/grpc_server_runner.rb b/instrumentation/grpc/test/support/grpc_server_runner.rb index 0659b294e..84ae09d25 100644 --- a/instrumentation/grpc/test/support/grpc_server_runner.rb +++ b/instrumentation/grpc/test/support/grpc_server_runner.rb @@ -6,7 +6,7 @@ # inspired by https://github.com/grpc/grpc/blob/master/src/ruby/spec/support/helpers.rb -require_relative './ping_server_impl' +require_relative 'ping_server_impl' module Support class GrpcServerRunner