Skip to content

Commit

Permalink
[distributed_headers] Accept signed integers as IDs.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Sep 10, 2018
1 parent dab4f5b commit 142192f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 8 additions & 6 deletions lib/ddtrace/propagation/distributed_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ def valid?
end

def trace_id
value = header(HTTP_HEADER_TRACE_ID).to_i
return if value <= 0 || value >= Span::MAX_ID
value
id HTTP_HEADER_TRACE_ID
end

def parent_id
value = header(HTTP_HEADER_PARENT_ID).to_i
return if value <= 0 || value >= Span::MAX_ID
value
id HTTP_HEADER_PARENT_ID
end

def sampling_priority
Expand All @@ -44,5 +40,11 @@ def header(name)

@env[rack_header]
end

def id(header)
value = header(header).to_i
return if value == 0 || value >= Span::MAX_ID
value < 0 ? value + 0x1_0000_0000_0000_0000 : value
end
end
end
6 changes: 4 additions & 2 deletions test/propagation/distributed_headers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def test_trace_id
test_cases = {
{ 'HTTP_X_DATADOG_TRACE_ID' => '123' } => 123,
{ 'HTTP_X_DATADOG_TRACE_ID' => '0' } => nil,
{ 'HTTP_X_DATADOG_TRACE_ID' => '-1' } => nil,
{ 'HTTP_X_DATADOG_TRACE_ID' => '-1' } => 18446744073709551615,
{ 'HTTP_X_DATADOG_TRACE_ID' => '-8809075535603237910' } => 9637668538106313706,
{ 'HTTP_X_DATADOG_TRACE_ID' => 'ooops' } => nil,
{ 'HTTP_X_DATADOG_TRACE_TYPO' => '1' } => nil,
{ 'HTTP_X_DATADOG_TRACE_ID' => Datadog::Span::MAX_ID.to_s } => nil,
Expand All @@ -69,7 +70,8 @@ def test_parent_id
test_cases = {
{ 'HTTP_X_DATADOG_PARENT_ID' => '123' } => 123,
{ 'HTTP_X_DATADOG_PARENT_ID' => '0' } => nil,
{ 'HTTP_X_DATADOG_PARENT_ID' => '-1' } => nil,
{ 'HTTP_X_DATADOG_PARENT_ID' => '-1' } => 18446744073709551615,
{ 'HTTP_X_DATADOG_PARENT_ID' => '-8809075535603237910' } => 9637668538106313706,
{ 'HTTP_X_DATADOG_PARENT_ID' => 'ooops' } => nil,
{ 'HTTP_X_DATADOG_PARENT_TYPO' => '1' } => nil,
{ 'HTTP_X_DATADOG_PARENT_ID' => Datadog::Span::MAX_ID.to_s } => nil,
Expand Down

0 comments on commit 142192f

Please sign in to comment.