Esempio n. 1
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    = await 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.Labels.StackTrace]);
            Assert.Contains(nameof(TraceController.ThrowException), span.Labels[Common.Labels.StackTrace]);
        }
Esempio n. 2
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(await 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(await GetTrace(spanName, startTime));
            Assert.NotNull(await GetTrace(spanNameStack, startTime));
        }
Esempio n. 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    = await 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);
        }
Esempio n. 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(await GetTrace(spanNameLabels, startTime, expectTrace: false));
            Assert.NotNull(await GetTrace(spanNameTrace, startTime));
        }
Esempio n. 5
0
        public async Task Trace_Label()
        {
            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();
                await client.GetAsync($"/Trace/TraceLabels/{testId}");
            }

            var spanName = TraceController.GetMessage(nameof(TraceController.TraceLabels), testId);
            var trace    = await 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);
        }