示例#1
0
        public async Task Trace_Buffer()
        {
            string testId    = Utils.GetTestId();
            var    startTime = Timestamp.FromDateTime(DateTime.UtcNow);

            var spanName = TraceController.GetMessage(nameof(TraceController.Trace), testId);

            var builder = new WebHostBuilder().UseStartup <TraceTestBufferHighQpsApplication>();

            using (var server = new TestServer(builder))
            {
                var client = server.CreateClient();

                // Make a trace with a small span that will not cause the buffer to flush.
                await client.GetAsync($"/Trace/Trace/{testId}");

                Assert.Null(_polling.GetTrace(spanName, startTime, expectTrace: false));

                // Make a large trace that will flush the buffer.
                await client.GetAsync($"/Trace/TraceStackTrace/{testId}");
            }

            var spanNameStack = TraceController.GetMessage(nameof(TraceController.TraceStackTrace), testId);

            Assert.NotNull(_polling.GetTrace(spanName, startTime));
            Assert.NotNull(_polling.GetTrace(spanNameStack, startTime));
        }
示例#2
0
        public async Task Trace_Exception()
        {
            string testId    = Utils.GetTestId();
            var    startTime = Timestamp.FromDateTime(DateTime.UtcNow);

            var builder = new WebHostBuilder().UseStartup <TraceTestNoBufferHighQpsApplication>();

            using (var server = new TestServer(builder))
            {
                var client = server.CreateClient();
                try
                {
                    await client.GetAsync($"/Trace/ThrowException/{testId}");
                }
                catch
                {
                    // This will throw as the task faults.
                }
            }

            var spanName = TraceController.GetMessage(nameof(TraceController.ThrowException), testId);
            var trace    = _polling.GetTrace(spanName, startTime);

            Assert.NotNull(trace);
            var span = trace.Spans.First(s => s.Name.StartsWith("/Trace/ThrowException"));

            Assert.NotEmpty(span.Labels);
            Assert.Contains(nameof(TraceController), span.Labels[Common.TraceLabels.StackTrace]);
            Assert.Contains(nameof(TraceController.ThrowException), span.Labels[Common.TraceLabels.StackTrace]);
        }
示例#3
0
        public async Task Trace_Header()
        {
            string traceId = TraceIdFactory.Create().NextId();
            ulong  spanId  = SpanIdFactory.Create().NextId();

            string testId    = Utils.GetTestId();
            var    startTime = Timestamp.FromDateTime(DateTime.UtcNow);
            var    builder   = new WebHostBuilder().UseStartup <TraceTestNoBufferLowQpsApplication>();

            using (var server = new TestServer(builder))
            {
                var client = server.CreateClient();

                var header = TraceHeaderContext.Create(traceId, spanId, shouldTrace: true);
                client.DefaultRequestHeaders.Add(TraceHeaderContext.TraceHeader, header.ToString());
                await client.GetAsync($"/Trace/Trace/{testId}");
            }

            var spanName = TraceController.GetMessage(nameof(TraceController.Trace), testId);
            var trace    = _polling.GetTrace(spanName, startTime);

            Assert.NotNull(trace);
            Assert.Equal(traceId, trace.TraceId);
            Assert.Equal(2, trace.Spans.Count);
            var span = trace.Spans.First(s => s.Name.StartsWith("/Trace"));

            Assert.Equal(spanId, span.ParentSpanId);
        }
示例#4
0
        public async Task Trace_QPS()
        {
            string testId    = Utils.GetTestId();
            var    startTime = Timestamp.FromDateTime(DateTime.UtcNow);

            var builder = new WebHostBuilder().UseStartup <TraceTestNoBufferApplication>();

            using (var server = new TestServer(builder))
            {
                var client = server.CreateClient();

                // The first request is not traced, sleep long enough
                // for the rate limiter to allow a request, then the second
                // request is traced.
                await client.GetAsync($"/Trace/TraceLabels/{testId}");

                Thread.Sleep(TimeSpan.FromSeconds(2));
                await client.GetAsync($"/Trace/Trace/{testId}");
            }

            var spanNameTrace  = TraceController.GetMessage(nameof(TraceController.Trace), testId);
            var spanNameLabels = TraceController.GetMessage(nameof(TraceController.TraceLabels), testId);

            Assert.Null(_polling.GetTrace(spanNameLabels, startTime, expectTrace: false));
            Assert.NotNull(_polling.GetTrace(spanNameTrace, startTime));
        }
示例#5
0
        public async Task Trace_QPS()
        {
            string testId    = Utils.GetTestId();
            var    startTime = Timestamp.FromDateTime(DateTime.UtcNow);

            var builder = new WebHostBuilder().UseStartup <TraceTestNoBufferApplication>();

            using (var server = new TestServer(builder))
            {
                var client = server.CreateClient();

                // Wait for 4 seconds to ensure the next time we make a request it will be
                // traced.  Then make two request, one of the two should be traced.
                Thread.Sleep(TimeSpan.FromSeconds(4));
                var   traceTask       = client.GetAsync($"/Trace/Trace/{testId}");
                var   traceLabelsTask = client.GetAsync($"/Trace/TraceLabels/{testId}");
                await traceTask;
                await traceLabelsTask;

                var spanNameTrace  = TraceController.GetMessage(nameof(TraceController.Trace), testId);
                var spanNameLabels = TraceController.GetMessage(nameof(TraceController.TraceLabels), testId);
                var trace          = _polling.GetTrace(spanNameLabels, startTime);
                var traceLabel     = _polling.GetTrace(spanNameTrace, startTime);
                Assert.True((trace == null && traceLabel != null) || (trace != null && traceLabel == null));
            }
        }
示例#6
0
        public async Task Trace_Exception()
        {
            string testId    = Utils.GetTestId();
            var    startTime = Timestamp.FromDateTime(DateTime.UtcNow);

            var client = _noBufferHighQps.CreateClient();

            try
            {
                await client.GetAsync($"/Trace/ThrowException/{testId}");
            }
            catch
            {
                // This will throw as the task faults.
            }

            var spanName = TraceController.GetMessage(nameof(TraceController.ThrowException), testId);
            var trace    = _polling.GetTrace(spanName, startTime);

            Assert.NotNull(trace);
            var span = trace.Spans.First(s => s.Name.StartsWith("/Trace/ThrowException"));

            Assert.NotEmpty(span.Labels);
            Assert.Contains(nameof(TraceController), span.Labels[TraceLabels.StackTrace]);
            Assert.Contains(nameof(TraceController.ThrowException), span.Labels[TraceLabels.StackTrace]);
        }
示例#7
0
        public async Task Trace_Header()
        {
            string traceId = TraceIdFactory.Create().NextId();
            ulong  spanId  = SpanIdFactory.Create().NextId();

            string testId    = Utils.GetTestId();
            var    startTime = Timestamp.FromDateTime(DateTime.UtcNow);

            var client = _noBufferLowQps.CreateClient();

            var header = TraceHeaderContext.Create(traceId, spanId, shouldTrace: true);

            client.DefaultRequestHeaders.Add(TraceHeaderContext.TraceHeader, header.ToString());
            var response = await client.GetAsync($"/Trace/Trace/{testId}");

            var spanName = TraceController.GetMessage(nameof(TraceController.Trace), testId);
            var trace    = _polling.GetTrace(spanName, startTime);

            Assert.NotNull(trace);
            Assert.Equal(traceId, trace.TraceId);
            Assert.Equal(2, trace.Spans.Count);
            var span = trace.Spans.First(s => s.Name.StartsWith("/Trace"));

            Assert.Equal(spanId, span.ParentSpanId);

            Assert.True(response.Headers.Contains(TraceHeaderContext.TraceHeader));
            var returnedHeader = response.Headers.GetValues(TraceHeaderContext.TraceHeader).Single();
            var headerContext  = TraceHeaderContext.FromHeader(returnedHeader);

            Assert.Equal(traceId, headerContext.TraceId);
            Assert.Equal(spanId, headerContext.SpanId);
            Assert.True(headerContext.ShouldTrace);
        }
示例#8
0
        public async Task Trace_Label()
        {
            string testId    = Utils.GetTestId();
            var    startTime = Timestamp.FromDateTime(DateTime.UtcNow);

            var client = _noBufferHighQps.CreateClient();
            await client.GetAsync($"/Trace/TraceLabels/{testId}");

            var spanName = TraceController.GetMessage(nameof(TraceController.TraceLabels), testId);
            var trace    = _polling.GetTrace(spanName, startTime);

            Assert.NotNull(trace);
            Assert.Equal(2, trace.Spans.Count);
            var span = trace.Spans.First(s => s.Name.StartsWith("Trace"));

            Assert.Single(span.Labels);
            Assert.Equal(span.Labels[TraceController.Label], TraceController.LabelValue);
        }
示例#9
0
        private static async Task TestTrace(string testId, DateTime startTime, HttpClient client)
        {
            var response = await client.GetAsync($"/Trace/Trace/{testId}");

            var spanName = TraceController.GetMessage(nameof(TraceController.Trace), testId);

            var polling = new TraceEntryPolling();
            var trace   = polling.GetTrace(spanName, Timestamp.FromDateTime(startTime));

            Assert.NotNull(trace);
            Assert.Equal(2, trace.Spans.Count);
            var span = trace.Spans.First(s => s.Name.StartsWith("/Trace/Trace/"));

            Assert.NotEmpty(span.Labels);
            Assert.Equal("GET", span.Labels[TraceLabels.HttpMethod]);
            Assert.Equal("200", span.Labels[TraceLabels.HttpStatusCode]);

            Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader));
        }
示例#10
0
        public async Task Trace_Label()
        {
            string testId    = Utils.GetTestId();
            var    startTime = Timestamp.FromDateTime(DateTime.UtcNow);

            using (var server = new TestServer(new WebHostBuilder().UseStartup <TraceTestNoBufferHighQpsApplication>()))
                using (var client = server.CreateClient())
                {
                    await client.GetAsync($"/Trace/TraceLabels/{testId}");

                    var spanName = TraceController.GetMessage(nameof(TraceController.TraceLabels), testId);
                    var trace    = _polling.GetTrace(spanName, startTime);

                    Assert.NotNull(trace);
                    Assert.Equal(2, trace.Spans.Count);
                    var span = trace.Spans.First(s => s.Name.StartsWith("Trace"));
                    Assert.Single(span.Labels);
                    Assert.Equal(span.Labels[TraceController.Label], TraceController.LabelValue);
                }
        }
示例#11
0
        public void Trace_QPS()
        {
            string testId    = Utils.GetTestId();
            var    startTime = Timestamp.FromDateTime(DateTime.UtcNow);

            using (var server = new TestServer(new WebHostBuilder().UseStartup <TraceTestNoBufferApplication>()))
                using (var client = server.CreateClient())
                {
                    // Make two request, one of the two should be traced as they both occur at nearly the same time.
                    var traceTask       = client.GetAsync($"/Trace/Trace/{testId}");
                    var traceLabelsTask = client.GetAsync($"/Trace/TraceLabels/{testId}");
                    Task.WaitAll(traceTask, traceLabelsTask);

                    var spanNameTrace  = TraceController.GetMessage(nameof(TraceController.Trace), testId);
                    var spanNameLabels = TraceController.GetMessage(nameof(TraceController.TraceLabels), testId);
                    var trace          = _polling.GetTrace(spanNameLabels, startTime);
                    var traceLabel     = _polling.GetTrace(spanNameTrace, startTime);
                    Assert.True((trace == null && traceLabel != null) || (trace != null && traceLabel == null));
                }
        }
示例#12
0
        public async Task Trace()
        {
            string testId    = Utils.GetTestId();
            var    startTime = Timestamp.FromDateTime(DateTime.UtcNow);

            var client   = _noBufferHighQps.CreateClient();
            var response = await client.GetAsync($"/Trace/Trace/{testId}");

            var spanName = TraceController.GetMessage(nameof(TraceController.Trace), testId);
            var trace    = _polling.GetTrace(spanName, startTime);

            Assert.NotNull(trace);
            Assert.Equal(2, trace.Spans.Count);
            var span = trace.Spans.First(s => s.Name.StartsWith("/Trace/Trace/"));

            Assert.NotEmpty(span.Labels);
            Assert.Equal(span.Labels[TraceLabels.HttpMethod], "GET");
            Assert.Equal(span.Labels[TraceLabels.HttpStatusCode], "200");

            Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader));
        }
        private static async Task TestTrace(string testId, DateTime startTime, HttpClient client)
        {
            var response = await client.GetAsync($"/Trace/Trace/{testId}");

            var spanName = TraceController.GetMessage(nameof(TraceController.Trace), testId);

            // Give the polling a little extra time to find the trace as
            // trace processing can sometimes take time and the default buffer is a
            // timed buffer.
            var polling = new TraceEntryPolling(TimeSpan.FromSeconds(20));
            var trace   = polling.GetTrace(spanName, Timestamp.FromDateTime(startTime));

            Assert.NotNull(trace);
            Assert.Equal(2, trace.Spans.Count);
            var span = trace.Spans.First(s => s.Name.StartsWith("/Trace/Trace/"));

            Assert.NotEmpty(span.Labels);
            Assert.Equal("GET", span.Labels[TraceLabels.HttpMethod]);
            Assert.Equal("200", span.Labels[TraceLabels.HttpStatusCode]);

            Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader));
        }
示例#14
0
        public async Task Trace()
        {
            string testId    = Utils.GetTestId();
            var    startTime = Timestamp.FromDateTime(DateTime.UtcNow);

            using (var server = new TestServer(new WebHostBuilder().UseStartup <TraceTestNoBufferHighQpsApplication>()))
                using (var client = server.CreateClient())
                {
                    var response = await client.GetAsync($"/Trace/Trace/{testId}");

                    var spanName = TraceController.GetMessage(nameof(TraceController.Trace), testId);
                    var trace    = _polling.GetTrace(spanName, startTime);

                    Assert.NotNull(trace);
                    Assert.Equal(2, trace.Spans.Count);
                    var span = trace.Spans.First(s => s.Name.StartsWith("/Trace/Trace/"));
                    Assert.NotEmpty(span.Labels);
                    Assert.Equal("GET", span.Labels[TraceLabels.HttpMethod]);
                    Assert.Equal("200", span.Labels[TraceLabels.HttpStatusCode]);

                    Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader));
                }
        }