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

Fix probabilility sampler #299

Merged
merged 2 commits into from
Jul 20, 2020
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@

# Appraisals
instrumentation/**/*.gemfile.lock

# Vendored gems
**/vendor/**/*
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ProbabilitySampler

def initialize(probability, ignore_parent:, apply_to_remote_parent:, apply_to_all_spans:)
@probability = probability
@id_upper_bound = format('%016x', (probability * (2**64 - 1)).ceil)
@id_upper_bound = (probability * (2**64 - 1)).ceil
@use_parent_sampled_flag = !ignore_parent
@apply_to_remote_parent = apply_to_remote_parent
@apply_to_all_spans = apply_to_all_spans
Expand Down Expand Up @@ -55,7 +55,7 @@ def sample_trace_id_for_child?(parent_context, trace_id)
end

def sample_trace_id?(trace_id)
@probability == 1.0 || trace_id[16, 16] < @id_upper_bound
@probability == 1.0 || trace_id[8, 8].unpack1('Q>') < @id_upper_bound
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion sdk/test/opentelemetry/sdk/trace/samplers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@
end

def trace_id(id)
format('%032x', id)
first = id >> 64
second = id & 0xffff_ffff_ffff_ffff
[first, second].pack('Q>Q>')
end

def call_sampler(sampler, trace_id: nil, parent_context: nil, links: nil, name: nil, kind: nil, attributes: nil)
Expand Down