Skip to content

Commit 07c9cf4

Browse files
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 grpc/grpc#6705 --------- Co-authored-by: Ariel Valentin <[email protected]>
1 parent a25cd4b commit 07c9cf4

File tree

13 files changed

+40
-126
lines changed

13 files changed

+40
-126
lines changed

.github/workflows/ci-instrumentation.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
- faraday
4040
- grape
4141
- graphql
42+
- grpc
4243
- gruf
4344
- http
4445
- http_client
@@ -102,6 +103,7 @@ jobs:
102103
[[ "${{ matrix.gem }}" == "lmdb" ]] && echo "skip=true" >> $GITHUB_OUTPUT
103104
[[ "${{ matrix.gem }}" == "rack" ]] && echo "skip=true" >> $GITHUB_OUTPUT
104105
[[ "${{ matrix.gem }}" == "rails" ]] && echo "skip=true" >> $GITHUB_OUTPUT
106+
[[ "${{ matrix.gem }}" == "grpc" ]] && echo "skip=true" >> $GITHUB_OUTPUT
105107
[[ "${{ matrix.gem }}" == "gruf" ]] && echo "skip=true" >> $GITHUB_OUTPUT
106108
# This is essentially a bash script getting evaluated, so we need to return true or the whole job fails.
107109
true

instrumentation/grpc/.rubocop.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
inherit_from: ../../.rubocop.yml
2+
3+
AllCops:
4+
Exclude:
5+
- 'test/support/proto/*.rb'

instrumentation/grpc/.standard.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

instrumentation/grpc/CODE_OF_CONDUCT.md

Lines changed: 0 additions & 84 deletions
This file was deleted.

instrumentation/grpc/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
source "https://rubygems.org"
7+
source 'https://rubygems.org'
88

99
# Specify your gem's dependencies in opentelemetry-instrumentation-grpc.gemspec
1010
gemspec

instrumentation/grpc/lib/opentelemetry-instrumentation-grpc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
require_relative "opentelemetry/instrumentation"
7+
require_relative 'opentelemetry/instrumentation'

instrumentation/grpc/lib/opentelemetry/instrumentation.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7+
# OpenTelemetry is an open source observability framework, providing a
8+
# general-purpose API, SDK, and related tools required for the instrumentation
9+
# of cloud-native software, frameworks, and libraries.
10+
#
11+
# The OpenTelemetry module provides global accessors for telemetry objects.
12+
# See the documentation for the `opentelemetry-api` gem for details.
713
module OpenTelemetry
14+
# "Instrumentation" are specified by
15+
# https://github.com/open-telemetry/opentelemetry-specification/blob/784635d01d8690c8f5fcd1f55bdbc8a13cf2f4f2/specification/glossary.md#instrumentation-library
16+
#
17+
# Instrumentation should be able to handle the case when the library is not installed on a user's system.
818
module Instrumentation
919
end
1020
end
1121

12-
require_relative "instrumentation/grpc"
22+
require_relative 'instrumentation/grpc'

instrumentation/grpc/lib/opentelemetry/instrumentation/grpc.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
require "opentelemetry"
8-
require "opentelemetry-instrumentation-base"
7+
require 'opentelemetry'
8+
require 'opentelemetry-instrumentation-base'
99

1010
module OpenTelemetry
1111
module Instrumentation
@@ -16,6 +16,6 @@ class Error < StandardError; end
1616
end
1717
end
1818

19-
require_relative "grpc/instrumentation"
20-
require_relative "grpc/version"
19+
require_relative 'grpc/instrumentation'
20+
require_relative 'grpc/version'
2121
require_relative 'grpc/interceptors/client_tracer'

instrumentation/grpc/lib/opentelemetry/instrumentation/grpc/interceptors/client_tracer.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,45 @@ module Interceptors
1111
# ClientTracer is a gRPC client interceptor which instrument gRPC calls with OpenTelemetry tracing
1212
class ClientTracer < ::GRPC::ClientInterceptor
1313
def request_response(request: nil, call: nil, method: nil, metadata: nil, &blk)
14-
call(type: "request_response", requests: [request], call: call, method: method, metadata: metadata, &blk)
14+
call(type: 'request_response', requests: [request], call: call, method: method, metadata: metadata, &blk)
1515
end
1616

1717
def client_streamer(requests: nil, call: nil, method: nil, metadata: nil, &blk)
18-
call(type: "client_streamer", requests: requests, call: call, method: method, metadata: metadata, &blk)
18+
call(type: 'client_streamer', requests: requests, call: call, method: method, metadata: metadata, &blk)
1919
end
2020

2121
def server_streamer(request: nil, call: nil, method: nil, metadata: nil, &blk)
22-
call(type: "server_streamer", requests: [request], call: call, method: method, metadata: metadata, &blk)
22+
call(type: 'server_streamer', requests: [request], call: call, method: method, metadata: metadata, &blk)
2323
end
2424

2525
def bidi_streamer(requests: nil, call: nil, method: nil, metadata: nil, &blk)
26-
call(type: "client_streamer", requests: requests, call: call, method: method, metadata: metadata, &blk)
26+
call(type: 'client_streamer', requests: requests, call: call, method: method, metadata: metadata, &blk)
2727
end
2828

2929
private
3030

3131
def call(type:, requests: nil, call: nil, method: nil, metadata: nil)
3232
return yield if instrumentation_config.empty?
3333

34-
method_parts = method.to_s.split("/")
34+
method_parts = method.to_s.split('/')
3535
service = method_parts[1]
3636
method_name = method_parts.last
3737

3838
attributes = {
39-
OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => "grpc",
39+
OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => 'grpc',
4040
OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => service,
4141
OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => method_name,
4242
OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE => instrumentation_config[:peer_service],
43-
"rpc.type" => type,
44-
"net.sock.peer.addr" => call.instance_variable_get(:@wrapped)&.peer
43+
'rpc.type' => type,
44+
'net.sock.peer.addr' => call.instance_variable_get(:@wrapped)&.peer
4545
}.compact
4646

4747
attributes.merge!(allowed_metadata_headers(metadata.transform_keys(&:to_s)))
4848

4949
instrumentation_tracer.in_span(
5050
# The specification requires there be no leading slash
5151
# https://github.com/open-telemetry/semantic-conventions/blob/5a2836bbea0b6e105b98370f331a7661bcf19540/docs/rpc/rpc-spans.md?plain=1#L63-L69
52-
method.to_s.delete_prefix("/"),
52+
method.to_s.delete_prefix('/'),
5353
attributes: attributes,
5454
kind: OpenTelemetry::Trace::SpanKind::CLIENT
5555
) do |span|

instrumentation/grpc/lib/opentelemetry/instrumentation/grpc/patches/client_stub.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ module Patches
1313
module ClientStub
1414
def initialize(host, creds, **args)
1515
interceptors = args[:interceptors] || []
16-
interceptors.unshift(Interceptors::ClientTracer.new) unless interceptors.any? do |interceptor|
17-
interceptor.is_a?(Interceptors::ClientTracer)
18-
end
16+
interceptors.unshift(Interceptors::ClientTracer.new) unless interceptors.any?(Interceptors::ClientTracer)
1917
args[:interceptors] = interceptors
2018

2119
super

0 commit comments

Comments
 (0)