Skip to content

Commit

Permalink
Fix 'uninitialized constant GRPC::Interceptor' when with the 'gapic-c…
Browse files Browse the repository at this point in the history
…ommon' gem
  • Loading branch information
marcotc committed Feb 27, 2023
1 parent d76de94 commit 06c3a67
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/datadog/tracing/contrib/grpc/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ def self.version
end

def self.loaded?
!defined?(::GRPC).nil?
!defined?(::GRPC).nil? &&
# When using the Google "Calendar User Availability API"
# (https://developers.google.com/calendar/api/user-availability/reference/rest), though the gem
# `google-cloud-calendar-useravailability-v1alpha` (currently in private preview),
# it's possible to load `GRPC` without loading the rest of the `grpc` gem. See:
# https://github.com/googleapis/gapic-generator-ruby/blob/f1c2e73219453e497b6ec2dc807a907e939e1342/gapic-common/lib/gapic/common.rb#L15-L16
# When this happens, there are no gRPC components of interest to instrument.
!defined?(::GRPC::Interceptor).nil? && !defined?(::GRPC::InterceptionContext).nil?
end

def self.compatible?
Expand Down
21 changes: 20 additions & 1 deletion spec/datadog/tracing/contrib/grpc/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,26 @@
context 'when GRPC is defined' do
before { stub_const('GRPC', Class.new) }

it { is_expected.to be true }
context 'when GRPC::Interceptor is defined' do
before { stub_const('GRPC::Interceptor', Class.new) }

context 'when GRPC::InterceptionContext is defined' do
before { stub_const('GRPC::InterceptionContext', Class.new) }
it { is_expected.to be true }
end

context 'when GRPC::InterceptionContext is not defined' do
before { hide_const('GRPC::InterceptionContext') }

it { is_expected.to be false }
end
end

context 'when GRPC::Interceptor is not defined' do
before { hide_const('GRPC::Interceptor') }

it { is_expected.to be false }
end
end

context 'when GRPC is not defined' do
Expand Down

0 comments on commit 06c3a67

Please sign in to comment.