Пример #1
0
 protected int CalculateProcessSize(ThriftProcess proc)
 {
     try
     {
         return(GetSize(proc));
     }
     catch (Exception ex)
     {
         throw new SenderException("ThriftSender failed writing Process to memory buffer.", ex, 1);
     }
 }
Пример #2
0
        /// <summary>
        /// AppendAsync serializes the passed in span into Jaeger Thrift and passes it off
        /// to the sender which will buffer it to be sent. If the buffer is full enough it
        /// will be flushed and the number of spans sent will be returned. If the buffer is
        /// not full enough, nothing will be done and a 0 will be returned to indicate that 0
        /// spans were sent.
        /// </summary>
        /// <param name="span">The span to serialize into Jaeger Thrift and buffer to be sent</param>
        /// <param name="cancellationToken"></param>
        /// <returns>The number of spans flushed, if any</returns>
        public async Task <int> AppendAsync(IJaegerCoreSpan span, CancellationToken cancellationToken)
        {
            if (_process == null)
            {
                _process = _jaegerThriftSerialization.BuildJaegerProcessThrift(span.Tracer);
            }

            var jaegerSpan = _jaegerThriftSerialization.BuildJaegerThriftSpan(span);

            return(await ProtocolAppendLogicAsync(jaegerSpan, cancellationToken));
        }
Пример #3
0
 protected override async Task SendAsync(ThriftProcess process, List <ThriftSpan> spans, CancellationToken cancellationToken)
 {
     try
     {
         var batch = new ThriftBatch(process, spans);
         await _agentClient.emitBatchAsync(batch, cancellationToken).ConfigureAwait(false);
     }
     catch (Exception ex)
     {
         throw new SenderException($"Could not send {spans.Count} spans", ex, spans.Count);
     }
 }
        protected override async Task SendAsync(ThriftProcess process, List <ThriftSpan> spans, CancellationToken cancellationToken)
        {
            try
            {
                var batch = new ThriftBatch(process, spans);
                await batch.WriteAsync(_protocol, cancellationToken).ConfigureAwait(false);

                await _protocol.Transport.FlushAsync(cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                throw new SenderException($"Could not send {spans.Count} spans", ex, spans.Count);
            }
        }
Пример #5
0
        public async void FlushAsync_ShouldNotCallSendAsyncWhenTheBufferIsEmpty()
        {
            var sender = new TestingSender
            {
                SendAsyncDelegate = Substitute.For <Func <List <JaegerSpan>, CancellationToken, Task <int> > >()
            };
            var process = new JaegerProcess("testingService");
            var cts     = new CancellationTokenSource();
            var token   = cts.Token;


            var sent = await sender.FlushAsync(process, token);

            Assert.Equal(0, sent);
            Assert.Empty(sender.Buffer);
            await sender.SendAsyncDelegate.Received(0)(Arg.Any <List <JaegerSpan> >(), Arg.Any <CancellationToken>());
        }
        public async Task <int> Append(ILetsTraceSpan span)
        {
            if (_process == null)
            {
                _process = BuildJaegerProcessThrift(span.Tracer);
            }
            var jaegerSpan = BuildJaegerThriftSpan(span);

            _buffer.Add(jaegerSpan);

            if (_buffer.Count > _bufferSize)
            {
                return(await Flush());
            }

            return(0);
        }
Пример #7
0
        public async Task <int> AppendAsync(ILetsTraceSpan span, CancellationToken canellationToken)
        {
            if (_process == null)
            {
                _process = _jaegerThriftSerialization.BuildJaegerProcessThrift(span.Tracer);
            }
            var jaegerSpan = _jaegerThriftSerialization.BuildJaegerThriftSpan(span);

            var curBuffCount = _sender.BufferItem(jaegerSpan);

            if (curBuffCount > BufferSize)
            {
                return(await _sender.FlushAsync(_process, canellationToken));
            }

            return(0);
        }
Пример #8
0
        public async Task <int> AppendAsync(Span span, CancellationToken cancellationToken)
        {
            if (_process == null)
            {
                _process          = new ThriftProcess(span.Tracer.ServiceName);
                _process.Tags     = JaegerThriftSpanConverter.BuildTags(span.Tracer.Tags);
                _processBytesSize = CalculateProcessSize(_process);
                _byteBufferSize  += _processBytesSize;
            }

            ThriftSpan thriftSpan = JaegerThriftSpanConverter.ConvertSpan(span);
            int        spanSize   = CalculateSpanSize(thriftSpan);

            if (spanSize > MaxSpanBytes)
            {
                throw new SenderException($"ThriftSender received a span that was too large, size = {spanSize}, max = {MaxSpanBytes}", null, 1);
            }

            _byteBufferSize += spanSize;
            if (_byteBufferSize <= MaxSpanBytes)
            {
                _spanBuffer.Add(thriftSpan);
                if (_byteBufferSize < MaxSpanBytes)
                {
                    return(0);
                }
                return(await FlushAsync(cancellationToken).ConfigureAwait(false));
            }

            int n;

            try
            {
                n = await FlushAsync(cancellationToken).ConfigureAwait(false);
            }
            catch (SenderException ex)
            {
                // +1 for the span not submitted in the buffer above
                throw new SenderException(ex.Message, ex, ex.DroppedSpanCount + 1);
            }

            _spanBuffer.Add(thriftSpan);
            _byteBufferSize = _processBytesSize + spanSize;
            return(n);
        }
Пример #9
0
        public async void FlushAsync_ShouldCallSendAsyncAndReturnCountOfSpansSent()
        {
            var sender = new TestingSender
            {
                SendAsyncDelegate = Substitute.For <Func <List <JaegerSpan>, CancellationToken, Task <int> > >()
            };
            var item    = new JaegerSpan();
            var process = new JaegerProcess("testingService");
            var cts     = new CancellationTokenSource();
            var token   = cts.Token;

            sender.BufferItem(item);
            sender.BufferItem(item);
            sender.BufferItem(item);
            sender.BufferItem(item);

            sender.SendAsyncDelegate(Arg.Is <List <JaegerSpan> >(js => js.Count == 4), Arg.Is(token)).Returns(4);

            var sent = await sender.FlushAsync(process, token);

            Assert.Equal(4, sent);
            Assert.Empty(sender.Buffer);
            await sender.SendAsyncDelegate.Received(1)(Arg.Is <List <JaegerSpan> >(js => js.Count == 4), Arg.Is(token));
        }
Пример #10
0
 public Task <int> FlushAsync(JaegerProcess process, CancellationToken cancellationToken)
 {
     _process = process ?? throw new ArgumentNullException(nameof(process));
     return(FlushAsync(cancellationToken));
 }
Пример #11
0
 protected abstract Task SendAsync(ThriftProcess process, List <ThriftSpan> spans, CancellationToken cancellationToken);