Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'uninitialized constant GRPC::Interceptor' when with the 'gapic-common' gem #2649

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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