Class: Datadog::Tracing::Contrib::GRPC::DatadogInterceptor::Client

Inherits:
Base
  • Object
show all
Defined in:
lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb

Overview

The DatadogInterceptor::Client implements the tracing strategy for gRPC client-side endpoints. This middleware component will inject trace context information into gRPC metadata prior to sending the request to the server.

Instance Method Summary collapse

Methods inherited from Base

#bidi_streamer, #client_streamer, #initialize, #request_response, #server_streamer

Constructor Details

This class inherits a constructor from Datadog::Tracing::Contrib::GRPC::DatadogInterceptor::Base

Instance Method Details

#trace(keywords) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb', line 19

def trace(keywords)
  formatter = GRPC::Formatting::FullMethodStringFormatter.new(keywords[:method])

  options = {
    span_type: Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND,
    service: service_name, # Maintain client-side service name configuration
    resource: formatter.resource_name,
    on_error: error_handler
  }

  Tracing.trace(Ext::SPAN_CLIENT, **options) do |span, trace|
    annotate!(trace, span, keywords, formatter)

    begin
      result = yield
    rescue StandardError => e
      code = e.is_a?(::GRPC::BadStatus) ? e.code : ::GRPC::Core::StatusCodes::UNKNOWN
      span.set_tag(Contrib::Ext::RPC::GRPC::TAG_STATUS_CODE, code)

      raise
    end
    span.set_tag(Contrib::Ext::RPC::GRPC::TAG_STATUS_CODE, ::GRPC::Core::StatusCodes::OK)
    result
  end
end