module Datadog::Contrib::GRPC::InterceptWithDatadog

The `#intercept!` method is implemented in gRPC; this module will be prepended to the original class, effectively injecting our tracing middleware into the head of the call chain.

Public Instance Methods

intercept!(type, args = {}) click to toggle source
Calls superclass method
# File lib/ddtrace/contrib/grpc/intercept_with_datadog.rb, line 12
def intercept!(type, args = {})
  if should_prepend?
    datadog_interceptor = choose_datadog_interceptor(args)

    @interceptors.unshift(datadog_interceptor.new) if datadog_interceptor

    @trace_started = true
  end

  super
end

Private Instance Methods

already_prepended?() click to toggle source
# File lib/ddtrace/contrib/grpc/intercept_with_datadog.rb, line 34
def already_prepended?
  @interceptors.any? do |interceptor|
    interceptor.class.ancestors.include?(Datadog::Contrib::GRPC::DatadogInterceptor::Base)
  end
end
choose_datadog_interceptor(args) click to toggle source
# File lib/ddtrace/contrib/grpc/intercept_with_datadog.rb, line 40
def choose_datadog_interceptor(args)
  if args.key?(:metadata)
    Datadog::Contrib::GRPC::DatadogInterceptor::Client
  elsif args.key?(:call)
    Datadog::Contrib::GRPC::DatadogInterceptor::Server
  end
end
should_prepend?() click to toggle source
# File lib/ddtrace/contrib/grpc/intercept_with_datadog.rb, line 26
def should_prepend?
  !trace_started? && !already_prepended?
end
trace_started?() click to toggle source
# File lib/ddtrace/contrib/grpc/intercept_with_datadog.rb, line 30
def trace_started?
  defined?(@trace_started) && @trace_started
end