Class: Protobuf::Opentracing::RequestDecoder
- Inherits:
-
Object
- Object
- Protobuf::Opentracing::RequestDecoder
- Defined in:
- lib/protobuf/opentracing/request_decoder.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RequestDecoder
constructor
A new instance of RequestDecoder.
- #request_headers(env) ⇒ Object
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
#app ⇒ Object (readonly)
Returns the value of attribute app.
4 5 6 |
# File 'lib/protobuf/opentracing/request_decoder.rb', line 4 def app @app end |
#env ⇒ Object (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) = {} [:child_of] = parent unless parent.nil? [:tags] = { "span.kind" => "server", "component" => "Protobuf", } result = nil ::OpenTracing.start_active_span(operation, **) 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 |