Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Only require trace id for distributed tracing headers #708

Merged
merged 6 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ddtrace/propagation/distributed_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def initialize(env)
end

def valid?
# Synthetics sends us `X-Datadog-Parent-Id: 0` which normally we would want
# to filter out, but is ok in this context since there is no parent from Synthetics
return true if origin == 'synthetics' && trace_id

# Sampling priority and origin are optional.
trace_id && parent_id
brettlangdon marked this conversation as resolved.
Show resolved Hide resolved
end
Expand Down
19 changes: 14 additions & 5 deletions test/propagation/distributed_headers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'ddtrace/propagation/distributed_headers'

class DistributedHeadersTest < Minitest::Test
def test_valid_without_sampling_priority
def test_valid_without_sampling_priority # rubocop:disable Metrics/MethodLength
test_cases = {
{ 'HTTP_X_DATADOG_TRACE_ID' => '123',
'HTTP_X_DATADOG_PARENT_ID' => '456' } => true,
Expand All @@ -20,9 +20,6 @@ def test_valid_without_sampling_priority
{ 'HTTP_X_DATADOG_TRACE_ID' => 'a',
'HTTP_X_DATADOG_PARENT_ID' => '456',
'HTTP_X_DATADOG_SAMPLING_PRIORITY' => '0' } => false,
{ 'HTTP_X_DATADOG_TRACE_ID' => '123',
'HTTP_X_DATADOG_PARENT_ID' => 'b',
'HTTP_X_DATADOG_SAMPLING_PRIORITY' => '0' } => false,
{ 'HTTP_X_DATADOG_TRACE_ID' => '123',
'HTTP_X_DATADOG_PARENT_ID' => '456',
'HTTP_X_DATADOG_SAMPLING_PRIORITY' => 'ooops' } => true, # corner case, 0 is valid for a sampling priority
Expand All @@ -31,7 +28,17 @@ def test_valid_without_sampling_priority
{ 'HTTP_X_DATADOG_TRACE_TYPO' => '123',
'HTTP_X_DATADOG_PARENT_ID' => '456' } => false,
{ 'HTTP_X_DATADOG_TRACE_ID' => '123',
'HTTP_X_DATADOG_PARENT_TYPO' => '456' } => false
'HTTP_X_DATADOG_PARENT_ID' => 'b',
'HTTP_X_DATADOG_SAMPLING_PRIORITY' => '0' } => false,
{ 'HTTP_X_DATADOG_TRACE_ID' => '123',
'HTTP_X_DATADOG_PARENT_TYPO' => '456' } => false,
# Parent id is not required when origin is synthetics
{ 'HTTP_X_DATADOG_TRACE_ID' => '123',
'HTTP_X_DATADOG_PARENT_ID' => '0',
'HTTP_X_DATADOG_ORIGIN' => 'not-synthetics' } => false,
{ 'HTTP_X_DATADOG_TRACE_ID' => '123',
'HTTP_X_DATADOG_PARENT_ID' => '0',
'HTTP_X_DATADOG_ORIGIN' => 'synthetics' } => true
}

test_cases.each do |env, expected|
Expand Down Expand Up @@ -70,6 +77,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' => 'a' } => nil,
{ 'HTTP_X_DATADOG_PARENT_ID' => '' } => nil,
{ 'HTTP_X_DATADOG_PARENT_ID' => '-1' } => 18446744073709551615,
{ 'HTTP_X_DATADOG_PARENT_ID' => '-8809075535603237910' } => 9637668538106313706,
{ 'HTTP_X_DATADOG_PARENT_ID' => 'ooops' } => nil,
Expand Down