Sha256: 71481dfd6d56dda0a9603d772f53752dfa803bf28bff46d9dd5b2a4ffe91b7e1
Contents?: true
Size: 1.22 KB
Versions: 2
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true # Copyright The OpenTelemetry Authors # # SPDX-License-Identifier: Apache-2.0 module OpenTelemetry module SDK module Trace module Samplers # @api private # # Implements sampling based on a probability. class TraceIdRatioBased attr_reader :description def initialize(probability) @probability = probability @id_upper_bound = (probability * (2**64 - 1)).ceil @description = format('TraceIdRatioBased{%.6f}', probability) end # @api private # # See {Samplers}. def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) tracestate = OpenTelemetry::Trace.current_span(parent_context).context.tracestate if sample?(trace_id) Result.new(decision: Decision::RECORD_AND_SAMPLE, tracestate: tracestate) else Result.new(decision: Decision::DROP, tracestate: tracestate) end end private def sample?(trace_id) @probability == 1.0 || trace_id[8, 8].unpack1('Q>') < @id_upper_bound end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
opentelemetry-sdk-0.11.1 | lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb |
opentelemetry-sdk-0.11.0 | lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb |