Class: Protobuf::Opentracing::RequestDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/protobuf/opentracing/request_decoder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RequestDecoder

Returns a new instance of RequestDecoder.



6
7
8
# File 'lib/protobuf/opentracing/request_decoder.rb', line 6

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



4
5
6
# File 'lib/protobuf/opentracing/request_decoder.rb', line 4

def app
  @app
end

#envObject (readonly)

Returns the value of attribute env.



4
5
6
# File 'lib/protobuf/opentracing/request_decoder.rb', line 4

def env
  @env
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/protobuf/opentracing/request_decoder.rb', line 10

def call(env)
  operation = "RPC #{env.service_name}##{env.method_name}"
  headers = request_headers(env)
  parent = ::OpenTracing.extract(::OpenTracing::FORMAT_TEXT_MAP, headers)
  options = {}
  options[:child_of] = parent unless parent.nil?
  options[:tags] = {
    "span.kind" => "server",
    "component" => "Protobuf",
  }
  result = nil

  ::OpenTracing.start_active_span(operation, **options) do
    result = app.call(env)
  end

  result
end

#request_headers(env) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/protobuf/opentracing/request_decoder.rb', line 29

def request_headers(env)
  return nil if env.request_wrapper.nil?
  env.request_wrapper.headers.reduce({}) do |ctx, header|
    ctx[header.key] = header.value
    ctx
  end
end