package traces

import (
	
	
)

// SamplingParams contains the start-time inputs to a [Sampler].
type SamplingParams struct {
	// Parent is the parent span reference, or zero for root spans.
	Parent SpanRef
	// TraceID is the trace identifier assigned to the new span.
	TraceID TraceID
	// Name is the initial span name.
	Name string
	// Kind is the span kind.
	Kind SpanKind
	// Attrs holds the start-time attributes on the span.
	Attrs []Attr
	// Scope is the instrumentation scope of the [Tracer].
	Scope string
}

// Sampler decides at span start whether a span should be recorded and marked
// sampled.
type Sampler func(ctx context.Context, p SamplingParams) bool

// AlwaysSample is a [Sampler] that samples every span.
func (context.Context, SamplingParams) bool {
	return true
}

// NeverSample is a [Sampler] that samples no spans.
func (context.Context, SamplingParams) bool {
	return false
}

// ParentBased returns a [Sampler] that follows the parent’s Sampled flag when
// a valid parent is present, and delegates to root for root spans.
func ( Sampler) Sampler {
	return func( context.Context,  SamplingParams) bool {
		if .Parent.IsValid() {
			return .Parent.Sampled
		}
		return (, )
	}
}

// Ratio returns a [Sampler] that deterministically samples fraction (in [0, 1])
// of traces based on the rightmost 56 bits of the trace ID.
func ( float64) Sampler {
	const  = 1 << 56
	if  <= 0 {
		return NeverSample
	}
	if  >= 1 {
		return AlwaysSample
	}
	 := uint64( * )
	return func( context.Context,  SamplingParams) bool {
		return binary.BigEndian.Uint64(.TraceID[8:])&(-1) < 
	}
}