Exemplo n.º 1
0
        public void OnBeforeAction(object actionDescriptor, HttpContext httpContext)
        {
            // NOTE: This event is the start of the action pipeline. The action has been selected, the route
            //       has been selected but no filters have run and model binding hasn't occured.
            Execute(() =>
            {
                var parent = TraceContext.CurrentSpan;
                if (parent == null)
                {
                    Logger.LogWarning("CurrentSpan not found");
                    return;
                }

                var typedActionDescriptor = ConvertActionDescriptor(actionDescriptor);

                var span = Tracer.BuildSpan(ActionOperationName)
                           .AsChildOf(parent)
                           .WithTag(Tags.Component, Component)
                           .WithTag(ActionTagControllerName, typedActionDescriptor.ControllerName)
                           .WithTag(ActionTagActionName, typedActionDescriptor.ActionName)
                           .Start();

                TraceContext.Push(span);

                // Tells OnAfterAction that a span was created and should be finished.
                httpContext.Items[ActionItemKey] = true;
            });
        }
Exemplo n.º 2
0
        public void OnBeforeActionResult(IActionContext actionContext, object result)
        {
            // NOTE: This event is the start of the result pipeline. The action has been executed, but
            //       we haven't yet determined which view (if any) will handle the request

            Execute(() =>
            {
                var parent = TraceContext.CurrentSpan;
                if (parent == null)
                {
                    Logger.LogWarning("CurrentSpan not found");
                    return;
                }

                string resultType = result.GetType().Name;

                var span = Tracer.BuildSpan(ResultOperationName)
                           .AsChildOf(parent)
                           .WithTag(Tags.Component, Component)
                           .WithTag(ResultTagType, resultType)
                           .Start();

                TraceContext.Push(span);

                // Tells OnAfterActionResult that a span was created and should be finished.
                actionContext.HttpContext.Items[ResultItemKey] = true;
            });
        }
        public void Returns_span_in_sync_method()
        {
            var traceContext = new TraceContext();
            var span         = GetSpan();

            traceContext.Push(span);

            Assert.Same(span, traceContext.CurrentSpan);
        }
        public void Sync_CurrentSpan_for_nested_spans_succeeds_with_pop()
        {
            var traceContext = new TraceContext();
            var span1        = GetSpan();
            var span2        = GetSpan();

            traceContext.Push(span1);
            Assert.Equal(span1, traceContext.CurrentSpan);

            traceContext.Push(span2);
            Assert.Equal(span2, traceContext.CurrentSpan);
            traceContext.TryPop();

            Assert.Equal(span1, traceContext.CurrentSpan);
            traceContext.TryPop();

            Assert.Null(traceContext.CurrentSpan);
        }
        public void CurrentSpan_keeps_span_on_stack()
        {
            var traceContext = new TraceContext();
            var span         = GetSpan();

            traceContext.Push(span);

            Assert.Equal(span, traceContext.CurrentSpan);
            Assert.Equal(1, traceContext.Count);
        }
        public async Task Async_CurrentSpan_for_nested_spans_succeeds_with_using()
        {
            var traceContext = new TraceContext();
            var span1        = GetSpan();
            var span2        = GetSpan();
            var span3        = GetSpan();

            using (traceContext.Push(span1))
            {
                await Delay();

                Assert.Equal(span1, traceContext.CurrentSpan);

                await Delay();

                using (traceContext.Push(span2))
                {
                    await Delay();

                    Assert.Equal(span2, traceContext.CurrentSpan);

                    using (traceContext.Push(span3))
                    {
                        await Delay();

                        Assert.Equal(span3, traceContext.CurrentSpan);
                    }

                    await Delay();

                    Assert.Equal(span2, traceContext.CurrentSpan);
                }

                await Delay();

                Assert.Equal(span1, traceContext.CurrentSpan);
            }

            await Delay();

            Assert.Null(traceContext.CurrentSpan);
        }
        public async Task Returns_span_in_async_call()
        {
            var traceContext = new TraceContext();
            var span         = GetSpan();

            traceContext.Push(span);

            var resultContext = await CallAsync(traceContext);

            Assert.Same(span, resultContext);
        }
        public void Returns_span_in_sync_call()
        {
            var traceContext = new TraceContext();
            var span         = GetSpan();

            traceContext.Push(span);

            var resultContext = CallSync(traceContext);

            Assert.Same(span, resultContext);
        }
        public void Sync_CurrentSpan_for_nested_spans_succeeds_with_using()
        {
            var traceContext = new TraceContext();
            var span1        = GetSpan();
            var span2        = GetSpan();

            using (traceContext.Push(span1))
            {
                Assert.Equal(span1, traceContext.CurrentSpan);

                using (traceContext.Push(span2))
                {
                    Assert.Equal(span2, traceContext.CurrentSpan);
                }

                Assert.Equal(span1, traceContext.CurrentSpan);
            }

            Assert.Null(traceContext.CurrentSpan);
        }
        public void Using_pops_span_from_stack()
        {
            var traceContext = new TraceContext();
            var span         = GetSpan();

            using (traceContext.Push(span))
            {
                Assert.Equal(span, traceContext.CurrentSpan);
            }

            Assert.Null(traceContext.CurrentSpan);
        }
Exemplo n.º 11
0
        public void OnBeginRequest(HttpContext httpContext)
        {
            Execute(() =>
            {
                var extractedSpanContext = TryExtractSpanContext(httpContext.Request);

                ISpan span = StartSpan(extractedSpanContext, httpContext.Request);

                // Push span to stack for in-process propagation.
                TraceContext.Push(span);
            });
        }
        public async Task Async_Using_pops_span_from_stack()
        {
            var traceContext = new TraceContext();
            var span         = GetSpan();

            using (traceContext.Push(span))
            {
                await Delay();

                Assert.Equal(span, traceContext.CurrentSpan);
            }

            await Delay();

            Assert.Null(traceContext.CurrentSpan);
        }
        public void OnRequest_creates_span_if_parent()
        {
            var tracer       = new TestTracer();
            var traceContext = new TraceContext();
            var interceptor  = GetInterceptor(tracer, traceContext);
            var request      = new HttpRequestMessage(HttpMethod.Get, new Uri("http://www.example.com/api/values"));

            // Create parent span
            var parentSpan = tracer.BuildSpan("parent").Start();

            traceContext.Push(parentSpan);

            // Call interceptor
            interceptor.OnRequest(request);

            var newSpan = (TestSpan)request.Properties[PropertySpan];

            Assert.NotSame(parentSpan, newSpan);
        }