Skip to content

Commit

Permalink
Fix probablility sampler (#299)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Wear <matthew.wear@gmail.com>
  • Loading branch information
fbogsany and mwear authored Jul 20, 2020
1 parent 1765e8b commit 2499c53
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
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

0 comments on commit 2499c53

Please sign in to comment.