Esempio n. 1
0
        public void ProcessEvent_IgnoresUnprocessableEvents()
        {
            var option = new TraceEndpointOptions();

            var obs = new TraceDiagnosticObserver(option);

            // No current activity, event ignored
            obs.ProcessEvent("foobar", null);

            var current = new Activity("barfoo");

            current.Start();

            // Activity current, but no value provided, event ignored
            obs.ProcessEvent("foobar", null);

            // Activity current, value provided, event not stop event, event is ignored
            obs.ProcessEvent("foobar", new object());

            // Activity current, event is stop event, no context in event value, event it ignored
            obs.ProcessEvent("Microsoft.AspNetCore.Hosting.HttpRequestIn.Stop", new object());

            Assert.Empty(obs._queue);
            current.Stop();
        }
Esempio n. 2
0
        public void ProcessEvent_HonorsCapacity()
        {
            var option = new TraceEndpointOptions();

            var obs     = new TraceDiagnosticObserver(option);
            var current = new Activity("Microsoft.AspNetCore.Hosting.HttpRequestIn");

            current.Start();

            for (var i = 0; i < 200; i++)
            {
                var context = CreateRequest();
                obs.ProcessEvent("Microsoft.AspNetCore.Hosting.HttpRequestIn.Stop", new { HttpContext = context });
            }

            Assert.Equal(option.Capacity, obs._queue.Count);
        }
Esempio n. 3
0
        public void ProcessEvent_AddsToQueue()
        {
            var option = new TraceEndpointOptions();

            var obs = new TraceDiagnosticObserver(option);

            var current = new Activity("Microsoft.AspNetCore.Hosting.HttpRequestIn");

            current.Start();

            var context = CreateRequest();

            obs.ProcessEvent("Microsoft.AspNetCore.Hosting.HttpRequestIn.Stop", new { HttpContext = context });

            Assert.Single(obs._queue);

            Assert.True(obs._queue.TryPeek(out var result));
            Assert.NotNull(result.Info);
            Assert.NotEqual(0, result.TimeStamp);
            Assert.True(result.Info.ContainsKey("method"));
            Assert.True(result.Info.ContainsKey("path"));
            Assert.True(result.Info.ContainsKey("headers"));
            Assert.True(result.Info.ContainsKey("timeTaken"));
            Assert.Equal("GET", result.Info["method"]);
            Assert.Equal("/myPath", result.Info["path"]);
            var headers = result.Info["headers"] as Dictionary <string, object>;

            Assert.NotNull(headers);
            Assert.True(headers.ContainsKey("request"));
            Assert.True(headers.ContainsKey("response"));
            var timeTaken = result.Info["timeTaken"] as string;

            Assert.NotNull(timeTaken);
            Assert.Equal("0", timeTaken); // 0 because activity not stopped

            current.Stop();
        }
Esempio n. 4
0
        public void GetTraces_ReturnsTraces()
        {
            var listener = new DiagnosticListener("test");
            var option   = new TraceEndpointOptions();

            var obs     = new TraceDiagnosticObserver(option);
            var current = new Activity("Microsoft.AspNetCore.Hosting.HttpRequestIn");

            current.Start();

            for (var i = 0; i < 200; i++)
            {
                var context = CreateRequest();
                obs.ProcessEvent("Microsoft.AspNetCore.Hosting.HttpRequestIn.Stop", new { HttpContext = context });
            }

            Assert.Equal(option.Capacity, obs._queue.Count);
            var traces = obs.GetTraces();

            Assert.Equal(option.Capacity, traces.Count);
            Assert.Equal(option.Capacity, obs._queue.Count);

            listener.Dispose();
        }