lib/instana/instrumentation/rack.rb in instana-1.11.6-java vs lib/instana/instrumentation/rack.rb in instana-1.11.7

- old
+ new

@@ -6,12 +6,13 @@ class Rack def initialize(app) @app = app end - def call(env) - kvs = { :http => {} } + def collect_kvs(env) + kvs = {} + kvs[:http] = {} kvs[:http][:method] = env['REQUEST_METHOD'] kvs[:http][:url] = ::CGI.unescape(env['PATH_INFO']) if env.key?('HTTP_HOST') kvs[:http][:host] = env['HTTP_HOST'] @@ -35,19 +36,31 @@ end kvs[:http][:header][custom_header.to_sym] = env[rack_header] end } end + return kvs + end + def call(env) # Check incoming context incoming_context = {} if env.key?('HTTP_X_INSTANA_T') incoming_context[:trace_id] = ::Instana::Util.header_to_id(env['HTTP_X_INSTANA_T']) incoming_context[:span_id] = ::Instana::Util.header_to_id(env['HTTP_X_INSTANA_S']) if env.key?('HTTP_X_INSTANA_S') incoming_context[:level] = env['HTTP_X_INSTANA_L'] if env.key?('HTTP_X_INSTANA_L') + + # Honor X-Instana-L + if incoming_context[:level] and incoming_context[:level].length > 0 + if incoming_context[:level][0] == "0" + return @app.call(env) + end + end end + kvs = collect_kvs(env) + ::Instana.tracer.log_start_or_continue(:rack, {}, incoming_context) status, headers, response = @app.call(env) if ::Instana.tracer.tracing? @@ -76,10 +89,12 @@ ensure if headers && ::Instana.tracer.tracing? # Set reponse headers; encode as hex string headers['X-Instana-T'] = ::Instana::Util.id_to_header(trace_id) headers['X-Instana-S'] = ::Instana::Util.id_to_header(span_id) + headers['X-Instana-L'] = '1' + headers['Server-Timing'] = "intid;desc=#{::Instana::Util.id_to_header(trace_id)}" + ::Instana.tracer.log_end(:rack, kvs) end - ::Instana.tracer.log_end(:rack, kvs) end end end