Class: Datadog::Tracing::Contrib::GRPC::DatadogInterceptor::Server

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

Overview

The DatadogInterceptor::Server implements the tracing strategy for gRPC server-side endpoints. When the datadog fields have been added to the gRPC call metadata, this middleware component will extract any client-side tracing information, attempting to associate its tracing context with a parent client-side context

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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb', line 22

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

  options = {
    type: Tracing::Metadata::Ext::HTTP::TYPE_INBOUND,
    service: service_name, # TODO: Remove server-side service name configuration
    resource: formatter.resource_name,
    on_error: on_error
  }
   = keywords[:call].

  set_distributed_context!()

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

    begin
      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
    else
      span.set_tag(Contrib::Ext::RPC::GRPC::TAG_STATUS_CODE, ::GRPC::Core::StatusCodes::OK)
    end
  end
end