lib/instana/instrumentation/instrumented_request.rb in instana-1.209.6 vs lib/instana/instrumentation/instrumented_request.rb in instana-1.209.7

- old
+ new

@@ -7,11 +7,11 @@ require 'cgi' require 'rack/request' module Instana class InstrumentedRequest < Rack::Request - W3_TRACE_PARENT_FORMAT = /00-(?<trace>[0-9a-f]+)-(?<parent>[0-9a-f]+)-(?<flags>[0-9a-f]+)/.freeze + W3C_TRACE_PARENT_FORMAT = /[0-9a-f][0-9a-e]-(?<trace>[0-9a-f]{32})-(?<parent>[0-9a-f]{16})-(?<flags>[0-9a-f]{2})/.freeze INSTANA_TRACE_STATE = /in=(?<trace>[0-9a-f]+);(?<span>[0-9a-f]+)/.freeze def skip_trace? # Honor X-Instana-L @env.has_key?('HTTP_X_INSTANA_L') && @env['HTTP_X_INSTANA_L'].start_with?('0') @@ -30,20 +30,20 @@ {} end context[:level] = @env['HTTP_X_INSTANA_L'][0] if @env['HTTP_X_INSTANA_L'] - unless ::Instana.config[:w3_trace_correlation] + unless ::Instana.config[:w3c_trace_correlation] trace_state = parse_trace_state - if context[:from_w3] && trace_state.empty? + if context[:from_w3c] && trace_state.empty? context.delete(:span_id) - context[:from_w3] = false - elsif context[:from_w3] && !trace_state.empty? + context[:from_w3c] = false + elsif context[:from_w3c] && !trace_state.empty? context[:trace_id] = trace_state[:t] context[:span_id] = trace_state[:p] - context[:from_w3] = false + context[:from_w3c] = false end end context end @@ -84,11 +84,11 @@ def instana_ancestor @instana_ancestor ||= parse_trace_state end def continuing_from_trace_parent? - incoming_context[:from_w3] + incoming_context[:from_w3c] end def synthetic? @env.has_key?('HTTP_X_INSTANA_SYNTHETIC') && @env['HTTP_X_INSTANA_SYNTHETIC'].eql?('1') end @@ -120,17 +120,17 @@ span_id: sanitized_s, trace_id: long_instana_id? ? sanitized_t[16..-1] : sanitized_t, # rubocop:disable Style/SlicingWithRange, Lint/RedundantCopDisableDirective long_instana_id: long_instana_id? ? sanitized_t : nil, external_trace_id: external_trace_id, external_state: @env['HTTP_TRACESTATE'], - from_w3: false + from_w3c: false }.reject { |_, v| v.nil? } end def context_from_trace_parent return {} unless @env.has_key?('HTTP_TRACEPARENT') - matches = @env['HTTP_TRACEPARENT'].match(W3_TRACE_PARENT_FORMAT) + matches = @env['HTTP_TRACEPARENT'].match(W3C_TRACE_PARENT_FORMAT) return {} unless matches return {} if matches_is_invalid(matches) trace_id = ::Instana::Util.header_to_id(matches['trace'][16..-1]) # rubocop:disable Style/SlicingWithRange, Lint/RedundantCopDisableDirective span_id = ::Instana::Util.header_to_id(matches['parent']) @@ -138,11 +138,11 @@ { external_trace_id: matches['trace'], external_state: @env['HTTP_TRACESTATE'], trace_id: trace_id, span_id: span_id, - from_w3: true + from_w3c: true } end def matches_is_invalid(matches) matches['trace'].match(/\A0+\z/) || matches['parent'].match(/\A0+\z/) @@ -152,10 +152,10 @@ state = parse_trace_state { trace_id: state[:t], span_id: state[:p], - from_w3: false + from_w3c: false }.reject { |_, v| v.nil? } end def parse_trace_state return {} unless @env.has_key?('HTTP_TRACESTATE')