/// <summary> /// Replace <see cref="Sampler"/> with a new instance when parameters are updated. /// </summary> /// <param name="response">Response which contains either a <see cref="ProbabilisticSampler"/> /// or <see cref="RateLimitingSampler"/>.</param> private void UpdateRateLimitingOrProbabilisticSampler(SamplingStrategyResponse response) { ISampler sampler; if (response.ProbabilisticSampling != null) { ProbabilisticSamplingStrategy strategy = response.ProbabilisticSampling; sampler = new ProbabilisticSampler(strategy.SamplingRate); } else if (response.RateLimitingSampling != null) { RateLimitingSamplingStrategy strategy = response.RateLimitingSampling; sampler = new RateLimitingSampler(strategy.MaxTracesPerSecond); } else { _metrics.SamplerParsingFailure.Inc(1); _logger.LogError("No strategy present in response. Not updating sampler."); return; } lock (_lock) { if (!Sampler.Equals(sampler)) { Sampler.Close(); Sampler = sampler; _metrics.SamplerUpdated.Inc(1); } } }
/// <summary> /// Replace <see cref="_sampler"/> with a new instance when parameters are updated. /// </summary> /// <param name="strategy"><see cref="ProbabilisticSamplingStrategy"/></param> internal void UpdateProbabilisticSampler(ProbabilisticSamplingStrategy strategy) { var sampler = _samplerFactory.NewProbabilisticSampler(strategy.SamplingRate); SetSamplerIfNotTheSame(sampler); }