lib/elastic_apm/trace_context/traceparent.rb in elastic-apm-3.15.1 vs lib/elastic_apm/trace_context/traceparent.rb in elastic-apm-4.0.0.beta.1
- old
+ new
@@ -20,26 +20,25 @@
module ElasticAPM
class TraceContext
# @api private
class Traceparent
VERSION = '00'
- HEX_REGEX = /[^[:xdigit:]]/.freeze
+ NON_HEX_REGEX = /[^[:xdigit:]]/.freeze
TRACE_ID_LENGTH = 16
ID_LENGTH = 8
def initialize(
version: VERSION,
trace_id: nil,
- span_id: nil,
+ parent_id: nil,
id: nil,
recorded: true
)
@version = version
@trace_id = trace_id || hex(TRACE_ID_LENGTH)
- # TODO: rename span_id kw arg to parent_id with next major version bump
- @parent_id = span_id
+ @parent_id = parent_id
@id = id || hex(ID_LENGTH)
@recorded = recorded
end
attr_accessor :version, :id, :trace_id, :parent_id, :recorded
@@ -54,11 +53,11 @@
t.version, t.trace_id, t.parent_id, t.flags =
header.split('-').tap do |values|
values[-1] = Util.hex_to_bits(values[-1])
end
- raise_invalid(header) if HEX_REGEX =~ t.trace_id
- raise_invalid(header) if HEX_REGEX =~ t.parent_id
+ raise_invalid(header) if NON_HEX_REGEX.match?(t.trace_id)
+ raise_invalid(header) if NON_HEX_REGEX.match?(t.parent_id)
end
end
class << self
private