struct OpenTelemetry::Sampler::TraceIdRatioBased

Overview

This sampler will only record a subset of the total number of traces. It can be initialized with either a decimal ratio or a fraction. Examples:

# Record 10% of the total traces
sampler = OpenTelemetry::Sampler::TraceIdRatioBased.new(0.1)
# Record 50% of the total traces
sampler = OpenTelemetry::Sampler::TraceIdRatioBased.new(0.5)
# Record 1/30th of the total traces
sampler = OpenTelemetry::Sampler::TraceIdRatioBased.new(1, 30)

It uses CRC32 for the hashing/randomization algorithm. CRC32 is dramatically faster than algorithms like MD5 or SHA1, and it produces a more uniform distribution of the bits for trace id input data than does any of the readily available cryptographic hashing algorithms. It is surprisingly good for this purpose.

Defined in:

samplers/trace_id_ratio_based.cr

Constant Summary

BlankId = Slice(UInt8).new(16, 0)

Constructors

Instance Method Summary

Instance methods inherited from struct OpenTelemetry::Sampler

description description, get_description get_description, should_sample(context : SpanContext, name : String = "", trace_id : Slice(UInt8) | Nil = nil, kind : OpenTelemetry::Span::Kind = OpenTelemetry::Span::Kind::Internal, attributes : Hash(String, AnyAttribute) = {} of String => AnyAttribute, links : Nil = nil) : SamplingResult
should_sample(span)
should_sample
, to_s(io) to_s

Constructor methods inherited from struct OpenTelemetry::Sampler

new(arg = nil) new

Constructor Detail

def self.new(numerator : Int, denominator : Int) #

def self.new(ratio : Float | String) #

def self.new(arg = nil) #

Instance Method Detail

def description : String #
Description copied from struct OpenTelemetry::Sampler

This should probably be overridden with a specific, appropriate name.


def description? : String | Nil #

def initialize_impl(ratio : Float64) #