private SamplingPriority GetSamplingPriority(Span span, float rate, bool withRateLimiter) { var sample = ((span.TraceId * KnuthFactor) % TracerConstants.MaxTraceId) <= (rate * TracerConstants.MaxTraceId); var priority = SamplingPriority.AutoReject; if (sample) { if (withRateLimiter) { // Ensure all allowed traces adhere to the global rate limit if (_limiter.Allowed(span.TraceId)) { priority = SamplingPriority.AutoKeep; } // Always set the sample rate metric whether it was allowed or not // DEV: Setting this allows us to properly compute metrics and debug the // various sample rates that are getting applied to this span span.SetMetric(Metrics.SamplingLimitDecision, _limiter.GetEffectiveRate()); } else { priority = SamplingPriority.AutoKeep; } } return(priority); }
private SamplingPriority GetSamplingPriority(Span span, float rate, bool agentSampling) { var sample = (((ulong)span.TraceId.Lower * KnuthFactor) % TracerConstants.MaxTraceId) <= (rate * TracerConstants.MaxTraceId); var priority = SamplingPriority.AutoReject; if (sample && (agentSampling || _limiter.Allowed(span))) { priority = SamplingPriority.AutoKeep; } return(priority); }
private int GetSamplingPriority(Span span, float rate, bool agentSampling) { // make a sampling decision as a function of traceId and sampling rate var sample = (((ulong)span.TraceId.Lower * KnuthFactor) % TracerConstants.MaxTraceId) <= (rate * TracerConstants.MaxTraceId); // legacy sampling based on data from agent if (agentSampling) { return(sample ? SamplingPriorityValues.AutoKeep : SamplingPriorityValues.AutoReject); } // rules-based sampling + rate limiter // NOTE: all tracers are changing this from AutoKeep/AutoReject to UserKeep/UserReject // to prevent the agent from overriding user configuration return(sample && _limiter.Allowed(span) ? SamplingPriorityValues.UserKeep : SamplingPriorityValues.UserReject); }
private SamplingPriority GetSamplingPriority(Span span, float rate) { var sample = ((span.TraceId * KnuthFactor) % TracerConstants.MaxTraceId) <= (rate * TracerConstants.MaxTraceId); var priority = SamplingPriority.AutoReject; if (sample) { if (_tracingWithoutLimitsEnabled) { if (_limiter.Allowed(span)) { priority = SamplingPriority.AutoKeep; } } else { priority = SamplingPriority.AutoKeep; } } return(priority); }