public AdaptiveSampler(int targetSamplesPerInterval = DefaultTargetSamplesPerInterval, int targetSamplingIntervalInSeconds = DefaultTargetSamplingIntervalInSeconds, int?seed = null) { if (targetSamplesPerInterval < MinTargetSamplesPerInterval) { throw new ArgumentException( $"invalid value provided for parameter; it must be at least {MinTargetSamplesPerInterval}", nameof(targetSamplesPerInterval)); } var rand = (seed.HasValue) ? new Random(seed.Value) : new Random(); //This .ctor does not trigger the start of the sampling interval timer _state = new AdaptiveSamplerState(targetSamplesPerInterval, TimeSpan.FromSeconds(targetSamplingIntervalInSeconds), rand); }
protected override void OnConfigurationUpdated(ConfigurationUpdateSource configurationUpdateSource) { if (configurationUpdateSource != ConfigurationUpdateSource.Server || !_configuration.DistributedTracingEnabled || !_configuration.SamplingTarget.HasValue) { return; } var samplingTarget = _configuration.SamplingTarget.Value; if (samplingTarget < MinTargetSamplesPerInterval) { Log.Error( $"invalid value specified in new server configuration; sampling_target must be at least {MinTargetSamplesPerInterval} but was {samplingTarget}. (defaulting to {DefaultTargetSamplesPerInterval})"); samplingTarget = DefaultTargetSamplesPerInterval; } var samplingInterval = TimeSpan.FromSeconds(_configuration.SamplingTargetPeriodInSeconds ?? DefaultTargetSamplingIntervalInSeconds); //This .ctor will force the start of the sampling interval timer if it wasn't started previously _state = new AdaptiveSamplerState(samplingTarget, samplingInterval, _state); }
public AdaptiveSamplerState(int targetSamplesPerInterval, TimeSpan targetSamplesInterval, AdaptiveSamplerState state) : this(targetSamplesPerInterval, targetSamplesInterval, state._rand) { _candidatesSeenCurrentInterval = state._candidatesSeenCurrentInterval; _candidatesSeenLastInterval = state._candidatesSeenLastInterval; _candidatesSampledCurrentInterval = state._candidatesSampledCurrentInterval; _nextIntervalStartTime = DateTimeOffset.UtcNow + TargetSamplesInterval; }