示例#1
0
        public async Task ShutdownTwice()
        {
            using var spanProcessor = new BatchingSpanProcessor(new TestSpanExporter(null));
            await spanProcessor.ShutdownAsync(CancellationToken.None);

            // does not throw
            await spanProcessor.ShutdownAsync(CancellationToken.None);
        }
        public async Task ShutdownTwice()
        {
            using (var spanProcessor = new BatchingSpanProcessor(new NoopSpanExporter()))
            {
                await spanProcessor.ShutdownAsync(CancellationToken.None);

                // does not throw
                await spanProcessor.ShutdownAsync(CancellationToken.None);
            }
        }
示例#3
0
        public async Task ShutdownOnNotEmptyQueueNotFullFlush()
        {
            const int batchSize         = 2;
            int       exportCalledCount = 0;

            // we'll need about 1.5 sec to export all spans
            // we export 100 spans in batches of 2, each export takes 30ms, in one thread
            var spanExporter = new TestSpanExporter(_ =>
            {
                Interlocked.Increment(ref exportCalledCount);
                Thread.Sleep(30);
            });

            using var spanProcessor =
                      new BatchingSpanProcessor(spanExporter, 128, TimeSpan.FromMilliseconds(100), batchSize);
            var spans = new List <SpanSdk>();

            for (int i = 0; i < 100; i++)
            {
                spans.Add(this.CreateSampledEndedSpan(i.ToString(), spanProcessor));
            }

            Assert.True(spanExporter.ExportedSpans.Length < spans.Count);

            // we won't bs able to export all before cancellation will fire
            using (var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(200)))
            {
                await spanProcessor.ShutdownAsync(cts.Token);
            }

            var exportedCount = spanExporter.ExportedSpans.Length;

            Assert.True(exportedCount < spans.Count);
        }
示例#4
0
        public async Task ShutdownOnNotEmptyQueueFullFlush()
        {
            const int batchSize         = 2;
            int       exportCalledCount = 0;
            var       spanExporter      = new TestSpanExporter(_ => Interlocked.Increment(ref exportCalledCount));

            using var spanProcessor =
                      new BatchingSpanProcessor(spanExporter, 128, TimeSpan.FromMilliseconds(100), batchSize);
            var spans = new List <SpanSdk>();

            for (int i = 0; i < 100; i++)
            {
                spans.Add(this.CreateSampledEndedSpan(i.ToString(), spanProcessor));
            }

            Assert.True(spanExporter.ExportedSpans.Length < spans.Count);
            using (var cts = new CancellationTokenSource(DefaultTimeout))
            {
                await spanProcessor.ShutdownAsync(cts.Token);
            }

            Assert.True(spanExporter.WasShutDown);
            Assert.Equal(spans.Count, spanExporter.ExportedSpans.Length);
            Assert.InRange(exportCalledCount, spans.Count / batchSize, spans.Count);
        }
        public void Dispose()
        {
            using (var cts = new CancellationTokenSource())
            {
                var t = spanProcessor.ShutdownAsync(cts.Token);
                cts.Cancel(true);

                t.ContinueWith(_ => { }).GetAwaiter().GetResult();
            }

            Activity.Current = null;
        }
        public async Task ShutdownWithHugeScheduleDelay()
        {
            spanProcessor = new BatchingSpanProcessor(new NoopSpanExporter(), 128, TimeSpan.FromMinutes(1), 32);

            var sw = Stopwatch.StartNew();

            using (var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)))
            {
                cts.Token.ThrowIfCancellationRequested();
                await spanProcessor.ShutdownAsync(cts.Token).ConfigureAwait(false);
            }
            sw.Stop();
            Assert.InRange(sw.Elapsed, TimeSpan.Zero, TimeSpan.FromMilliseconds(100));
        }