Ejemplo n.º 1
0
        public static void RootChildContinueFinishCase()
        {
            string traceId        = null;
            string childContextId = null;

            using (var rootContext = Trace.CreateRootContext("Root"))
            {
                rootContext.RecordTimepoint(Timepoint.Start);
                using (var childContext = Trace.CreateChildContext("Child"))
                {
                    childContext.RecordTimepoint(Timepoint.Start);
                    childContext.RecordTimepoint(Timepoint.Finish);
                }

                using (var childContext = Trace.CreateChildContext("ChildWithContinue"))
                {
                    childContext.RecordTimepoint(Timepoint.Start);
                    traceId        = childContext.TraceId;
                    childContextId = childContext.ContextId;
                }

                var disposeChildContext = Trace.CreateChildContext("ChildWithFinish");
                disposeChildContext.RecordTimepoint(Timepoint.Start);
                disposeChildContext.RecordTimepoint(Timepoint.Finish);
                Trace.FinishCurrentContext();
                rootContext.RecordTimepoint(Timepoint.Finish);
            }
            using (var childContext = Trace.ContinueContext(traceId, childContextId, isActive: true, isRoot: false))
            {
                childContext.RecordTimepoint(Timepoint.Finish);
            }
        }
Ejemplo n.º 2
0
        public void CreateChildContext_should_set_context_id()
        {
            var contextId = TraceIdGenerator.CreateTraceContextId();

            using (var rootContext = Trace.CreateRootContext("Test"))
                using (var childContext = Trace.CreateChildContext("Child", contextId))
                    childContext.ContextId.Should().BeSameAs(contextId);
        }
Ejemplo n.º 3
0
 public void CreateChildContext_should_throw_exception_if_context_name_is_null_or_empty(string contextName)
 {
     using (var rootContext = Trace.CreateRootContext("Test"))
     {
         Assert.Throws <InvalidOperationException>(() =>
         {
             using (var childContext = Trace.CreateChildContext(contextName))
             {
             }
         });
     }
 }
Ejemplo n.º 4
0
        public void CreateChildContext_with_fixed_parent()
        {
            var traceId         = TraceIdGenerator.CreateTraceId();
            var parentContextId = TraceIdGenerator.CreateTraceContextId();

            using (var childContext = Trace.CreateChildContext("Child", traceId, parentContextId))
            {
                childContext.Should().NotBeSameAs(NoOpTraceContext.Instance);
                childContext.TraceId.Should().BeSameAs(traceId);
                childContext.IsActive.Should().BeTrue();
            }
        }
Ejemplo n.º 5
0
        public void FinishContext_should_pop_context()
        {
            using (var rootContext = Trace.CreateRootContext("Test"))
            {
                var originalContext = TraceContext.Current;

                var childContext = Trace.CreateChildContext("Child");
                Trace.FinishCurrentContext();

                TraceContext.Current.Should().BeSameAs(originalContext);
            }
        }
Ejemplo n.º 6
0
        public void CreateChildContext_should_update_context_and_pop_after_dispose()
        {
            using (var rootContext = Trace.CreateRootContext("Test"))
            {
                var originalContext = TraceContext.Current;

                using (var childContext = Trace.CreateChildContext("Child"))
                    childContext.TraceId.Should().BeSameAs(rootContext.TraceId);

                TraceContext.Current.Should().BeSameAs(originalContext);
            }
        }
Ejemplo n.º 7
0
 public static void RootChildCase()
 {
     using (var rootContext = Trace.CreateRootContext("Root"))
     {
         rootContext.RecordTimepoint(Timepoint.Start);
         using (var childContext = Trace.CreateChildContext("Child"))
         {
             childContext.RecordTimepoint(Timepoint.Start);
             childContext.RecordTimepoint(Timepoint.Finish);
         }
         rootContext.RecordTimepoint(Timepoint.Finish);
     }
 }
Ejemplo n.º 8
0
        public void PushTask(RemoteTask task)
        {
            using (var taskContext = Trace.CreateChildContext("TaskLife", task.TaskId))
            {
                taskContext.RecordTimepoint(Timepoint.Start);
                task.TraceId = taskContext.TraceId;

                using (var queueContext = Trace.CreateChildContext("Queue"))
                {
                    task.QueueContextId = queueContext.ContextId;

                    queueContext.RecordTimepoint(Timepoint.Start);
                    taskQueue.Enqueue(task);
                }
            }
        }
Ejemplo n.º 9
0
 private void Process()
 {
     synchronizer.ClientEndQuerySignal.Wait();
     do
     {
         var task = taskQueue.PopTask();
         if (task != null)
         {
             using (var taskContext = Trace.ContinueContext(task.TraceId, task.TaskId, isActive: true, isRoot: false))
             {
                 using (var handleContext = Trace.CreateChildContext("Handling"))
                 {
                     handleContext.RecordTimepoint(Timepoint.Start);
                     handler.Handle(task);
                     handleContext.RecordTimepoint(Timepoint.Finish);
                 }
                 taskContext.RecordTimepoint(Timepoint.Finish);
             }
         }
     } while (!stopSignal.Wait(TimeSpan.FromSeconds(1)));
 }
Ejemplo n.º 10
0
        public static void RootChildContinueCase()
        {
            string traceId       = null;
            string rootContextId = null;

            using (var rootContext = Trace.CreateRootContext("Root"))
            {
                rootContext.RecordTimepoint(Timepoint.Start);
                traceId       = rootContext.TraceId;
                rootContextId = rootContext.ContextId;

                using (var childContext = Trace.CreateChildContext("Child"))
                {
                    childContext.RecordTimepoint(Timepoint.Start);
                    childContext.RecordTimepoint(Timepoint.Finish);
                }
            }

            using (var rootContext = Trace.ContinueContext(traceId, rootContextId, isActive: true, isRoot: false))
            {
                rootContext.RecordTimepoint(Timepoint.Finish);
            }
        }
Ejemplo n.º 11
0
 public void CreateChildContext_should_generate_context_id(string contextId)
 {
     using (var rootContext = Trace.CreateRootContext("Test"))
         using (var childContext = Trace.CreateChildContext("Child", contextId))
             childContext.TraceId.Should().NotBeNullOrEmpty();
 }
Ejemplo n.º 12
0
 public void CreateChildContext_should_return_NoOp_instance_if_current_context_is_null()
 {
     using (var childContext = Trace.CreateChildContext("Test"))
         childContext.Should().BeSameAs(NoOpTraceContext.Instance);
 }