Sha256: ea91ad6e8a1133ddd8249bec3e790f9950c48a1dd14d7fe015cb28d44ef81ed1

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

require 'ddtrace/ext/app_types'
require 'ddtrace/contrib/grpc/ext'

module Datadog
  module Contrib
    module GRPC
      # :nodoc:
      module DatadogInterceptor
        # :nodoc:
        class Base < ::GRPC::Interceptor
          attr_accessor :datadog_pin

          def initialize(options = {})
            add_datadog_pin! { |c| yield(c) if block_given? }
          end

          def request_response(**keywords)
            trace(keywords) { yield }
          end

          def client_streamer(**keywords)
            trace(keywords) { yield }
          end

          def server_streamer(**keywords)
            trace(keywords) { yield }
          end

          def bidi_streamer(**keywords)
            trace(keywords) { yield }
          end

          private

          def add_datadog_pin!
            Pin.new(
              service_name,
              app: Ext::APP,
              app_type: Datadog::Ext::AppTypes::WEB,
              tracer: tracer
            ).tap do |pin|
              yield(pin) if block_given?
              pin.onto(self)
            end
          end

          def datadog_configuration
            Datadog.configuration[:grpc]
          end

          def tracer
            (datadog_pin && datadog_pin.tracer) || datadog_configuration[:tracer]
          end

          def service_name
            (datadog_pin && datadog_pin.service_name) || datadog_configuration[:service_name]
          end
        end

        require_relative 'datadog_interceptor/client'
        require_relative 'datadog_interceptor/server'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ddtrace-0.20.0 lib/ddtrace/contrib/grpc/datadog_interceptor.rb