/// <summary>
        /// Instantiate a rate limited IZipkinSender which use an underlying IZipkinSender to send data.
        /// The average sending rate is given by maxSendRequest / duration, instantaneous rate can be much higher.
        /// </summary>
        /// <param name="sender">The underlying IZipkinSender</param>
        /// <param name="maxSendRequest">The maximum send requests per duration aka the bucket size</param>
        /// <param name="duration">TimeSpan necessary to refill the bucket</param>
        public RateLimiterZipkinSender(IZipkinSender sender, int maxSendRequest = 15, TimeSpan?duration = null)
        {
            _underlyingSender = sender;
            MaxSendRequests   = maxSendRequest;
            Duration          = duration ?? TimeSpan.FromSeconds(1);

            _logPeriod         = TimeSpan.FromTicks(Duration.Ticks * 10);
            _requestsReceived  = 0;
            _throttledRequests = 0;
            _currentLogPeriod  = new Stopwatch();

            _bucket = MaxSendRequests;
            _timeSinceLastRequest = Stopwatch.StartNew();
            Rate = MaxSendRequests / Duration.TotalMilliseconds;
        }
Exemple #2
0
        public ZipkinTracer(IZipkinSender sender, ISpanSerializer spanSerializer, IStatistics statistics = null)
        {
            if (sender == null)
            {
                throw new ArgumentNullException("sender", "You have to specify a non-null sender for Zipkin tracer.");
            }
            Statistics  = statistics ?? new Statistics();
            _spanSender = sender;

            if (spanSerializer == null)
            {
                throw new ArgumentNullException("spanSerializer", "You have to specify a non-null span serializer for Zipkin tracer.");
            }
            _spanSerializer = spanSerializer;

            _flushTimer = new Timer(_ => FlushOldSpans(TimeUtils.UtcNow), null, TimeToLive, TimeToLive);
        }
Exemple #3
0
        internal ZipkinTracerReporter(IZipkinSender sender, ISpanSerializer spanSerializer, IStatistics statistics)
        {
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(sender),
                                                "You have to specify a non-null sender.");
            }

            if (spanSerializer == null)
            {
                throw new ArgumentNullException(nameof(spanSerializer),
                                                "You have to specify a non-null span serializer.");
            }

            if (statistics == null)
            {
                throw new ArgumentNullException(nameof(statistics),
                                                "You have to specify a non-null statistics.");
            }
            _sender         = sender;
            _spanSerializer = spanSerializer;
            _statistics     = statistics;
        }
Exemple #4
0
 public ZipkinTracer(IZipkinSender sender, ISpanSerializer spanSerializer, IStatistics statistics)
     : this(new ZipkinTracerReporter(sender, spanSerializer, statistics), statistics)
 {
 }
Exemple #5
0
 public ZipkinTracer(IZipkinSender sender, ISpanSerializer spanSerializer)
     : this(sender, spanSerializer, new Statistics())
 {
 }
Exemple #6
0
        public void ShouldThrowWithNullSender()
        {
            IZipkinSender sender = null;

            Assert.Throws <ArgumentNullException>(() => { var tracer = new ZipkinTracer(sender, Mock.Of <ISpanSerializer>()); });
        }
Exemple #7
0
 public ZipkinTracer(IZipkinSender sender, IStatistics statistics = null) : this(sender, new ThriftSpanSerializer(), statistics)
 {
 }