Class: OpenTracing::Instrumentation::Rack::HttpTagger

Inherits:
Object
  • Object
show all
Defined in:
lib/opentracing/instrumentation/rack/http_tagger.rb

Overview

HttpTagger create addition tags on span

Constant Summary collapse

DEFAULT_TAG_REQUEST_HEADERS =
{
  connection: 'Connection',
  content_type: 'Content-Type',
  user_agent: 'User-Agent',
}.freeze
DEFAULT_TAG_RESPONSE_HEADERS =
{
  connection: 'Connection',
  content_type: 'Content-Type',
  keep_alive: 'Keep-Alive',
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(tag_request_headers: DEFAULT_TAG_REQUEST_HEADERS, tag_response_headers: DEFAULT_TAG_RESPONSE_HEADERS) ⇒ HttpTagger

Returns a new instance of HttpTagger.



22
23
24
25
26
27
28
29
30
# File 'lib/opentracing/instrumentation/rack/http_tagger.rb', line 22

def initialize(
  tag_request_headers: DEFAULT_TAG_REQUEST_HEADERS,
  tag_response_headers: DEFAULT_TAG_RESPONSE_HEADERS
)
  @tag_request_headers =
    prepare_request_mapping(tag_request_headers)
  @tag_response_headers =
    prepare_response_mapping(tag_response_headers)
end

Instance Method Details

#request_tags(env) ⇒ Object



32
33
34
35
36
# File 'lib/opentracing/instrumentation/rack/http_tagger.rb', line 32

def request_tags(env)
  @tag_request_headers
    .transform_values { |header_name| env[header_name] }
    .compact
end

#response_tags(headers) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/opentracing/instrumentation/rack/http_tagger.rb', line 38

def response_tags(headers)
  header_mapper = lambda do |header_regexp|
    headers.find do |(header, _value)|
      header_regexp.match?(header)
    end&.dig(1)
  end
  @tag_response_headers
    .transform_values(&header_mapper)
    .compact
end