コード例 #1
0
ファイル: CommonTraceCases.cs プロジェクト: tvilkov/csharp
        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);
            }
        }
コード例 #2
0
ファイル: Trace_UnitTests.cs プロジェクト: tvilkov/csharp
        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);
        }
コード例 #3
0
ファイル: Trace_UnitTests.cs プロジェクト: tvilkov/csharp
 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))
             {
             }
         });
     }
 }
コード例 #4
0
ファイル: Trace_UnitTests.cs プロジェクト: tvilkov/csharp
        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();
            }
        }
コード例 #5
0
ファイル: Trace_UnitTests.cs プロジェクト: tvilkov/csharp
        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);
            }
        }
コード例 #6
0
ファイル: Trace_UnitTests.cs プロジェクト: tvilkov/csharp
        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);
            }
        }
コード例 #7
0
ファイル: CommonTraceCases.cs プロジェクト: tvilkov/csharp
 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);
     }
 }
コード例 #8
0
ファイル: RemoteTaskQueue.cs プロジェクト: tvilkov/csharp
        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);
                }
            }
        }
コード例 #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)));
 }
コード例 #10
0
ファイル: CommonTraceCases.cs プロジェクト: tvilkov/csharp
        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);
            }
        }
コード例 #11
0
ファイル: Trace_UnitTests.cs プロジェクト: tvilkov/csharp
 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();
 }
コード例 #12
0
ファイル: Trace_UnitTests.cs プロジェクト: tvilkov/csharp
 public void CreateChildContext_should_return_NoOp_instance_if_current_context_is_null()
 {
     using (var childContext = Trace.CreateChildContext("Test"))
         childContext.Should().BeSameAs(NoOpTraceContext.Instance);
 }