Sha256: 4be9fb71fcc546f70a1038c587dab4c8d37d3f122fafae0ee4c6f09d69b9e20e

Contents?: true

Size: 1.61 KB

Versions: 15

Compression:

Stored size: 1.61 KB

Contents

require 'ddtrace/ext/http'
require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/grpc/ext'

module Datadog
  module Contrib
    module GRPC
      module DatadogInterceptor
        # The DatadogInterceptor::Client implements the tracing strategy
        # for gRPC client-side endpoitns. This middleware compoent will
        # inject trace context information into gRPC metadata prior to
        # sending the request to the server.
        class Client < Base
          def trace(keywords)
            keywords[:metadata] ||= {}

            options = {
              span_type: Datadog::Ext::HTTP::TYPE_OUTBOUND,
              service: service_name,
              resource: format_resource(keywords[:method])
            }

            tracer.trace(Ext::SPAN_CLIENT, options) do |span|
              annotate!(span, keywords[:metadata])

              yield
            end
          end

          private

          def annotate!(span, metadata)
            metadata.each do |header, value|
              span.set_tag(header, value)
            end

            # Set analytics sample rate
            Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) if analytics_enabled?

            Datadog::GRPCPropagator
              .inject!(span.context, metadata)
          rescue StandardError => e
            Datadog::Tracer.log.debug("GRPC client trace failed: #{e}")
          end

          def format_resource(proto_method)
            proto_method.downcase
                        .split('/')
                        .reject(&:empty?)
                        .join('.')
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
ls-trace-0.1.2 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ddtrace-0.30.1 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ddtrace-0.30.0 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ddtrace-0.29.1 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ddtrace-0.26.1 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ls-trace-0.1.1 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ddtrace-0.29.0 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ddtrace-0.28.0 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ddtrace-0.27.0 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ddtrace-0.26.0 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ddtrace-0.25.1 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ddtrace-0.25.0 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ddtrace-0.24.0 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ddtrace-0.23.3 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb
ddtrace-0.23.2 lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb