public void ContinueContext_should_set_null_traceid_and_contextid_when_not_active() { var traceId = TraceIdGenerator.CreateTraceId(); var contextId = TraceIdGenerator.CreateTraceContextId(); using (var traceContext = Trace.ContinueContext(traceId, contextId, isActive: false, isRoot: false)) { traceContext.TraceId.Should().BeSameAs(string.Empty); traceContext.ContextId.Should().BeSameAs(string.Empty); traceContext.IsActive.Should().Be(false); } }
public void ContinueContext_should_use_trace_and_context_id_from_parameter_when_active() { var traceId = TraceIdGenerator.CreateTraceId(); var contextId = TraceIdGenerator.CreateTraceContextId(); using (var traceContext = Trace.ContinueContext(traceId, contextId, isActive: true, isRoot: false)) { traceContext.TraceId.Should().BeSameAs(traceId); traceContext.ContextId.Should().BeSameAs(contextId); traceContext.IsActive.Should().Be(true); } }
public RemoteTask PopTask() { var task = taskQueue.Count > 0 ? taskQueue.Dequeue() : null; if (task != null) { using (var queueContext = Trace.ContinueContext(task.TraceId, task.QueueContextId, isActive: true, isRoot: false)) { queueContext.RecordTimepoint(Timepoint.Finish); } } return(task); }
public void ContinueContext_should_throw_exception_if_context_is_set_already(bool isActive) { var traceId = TraceIdGenerator.CreateTraceId(); var contextId = TraceIdGenerator.CreateTraceContextId(); using (var traceContext = Trace.CreateRootContext("Test")) { Assert.DoesNotThrow(() => { using (var continueContext = Trace.ContinueContext(traceId, contextId, isActive, isRoot: false)) { } }); } }
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))); }
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); } }
public static void ClientServerCase() { const string url = "http://localhost:12346/"; var listener = new HttpListener(); listener.Prefixes.Add(url); listener.Start(); var serverTask = Task.Factory.StartNew(() => { var context = listener.GetContext(); var request = context.Request; string traceId, contextId; bool?isActive; RequestExtensions.ExtractFromHttpHeaders(request.Headers, out traceId, out contextId, out isActive); using (var serverContext = Trace.ContinueContext(traceId, contextId, isActive ?? false, isRoot: false)) { serverContext.RecordTimepoint(Timepoint.ServerReceive); context.Response.Close(); serverContext.RecordTimepoint(Timepoint.ServerSend); } }); using (var clientContext = Trace.CreateRootContext("Client")) { clientContext.RecordTimepoint(Timepoint.ClientSend); clientContext.RecordAnnotation(Annotation.RequestUrl, url); var clientRequest = (HttpWebRequest)WebRequest.Create(url); clientRequest.SetTracingHeaders(clientContext); clientRequest.GetResponse(); serverTask.Wait(); clientContext.RecordTimepoint(Timepoint.ClientReceive); } listener.Close(); }