diff --git a/.gitignore b/.gitignore index ea5182ac1..f2086c0a3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ # Appraisals instrumentation/**/*.gemfile.lock + +# Vendored gems +**/vendor/**/* diff --git a/sdk/lib/opentelemetry/sdk/trace/samplers/probability_sampler.rb b/sdk/lib/opentelemetry/sdk/trace/samplers/probability_sampler.rb index 5e1359b1d..1f872b1d3 100644 --- a/sdk/lib/opentelemetry/sdk/trace/samplers/probability_sampler.rb +++ b/sdk/lib/opentelemetry/sdk/trace/samplers/probability_sampler.rb @@ -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 @@ -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 diff --git a/sdk/test/opentelemetry/sdk/trace/samplers_test.rb b/sdk/test/opentelemetry/sdk/trace/samplers_test.rb index f57580ea1..3fc38df4d 100644 --- a/sdk/test/opentelemetry/sdk/trace/samplers_test.rb +++ b/sdk/test/opentelemetry/sdk/trace/samplers_test.rb @@ -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)