public static void RootCase() { using (var rootContext = Trace.CreateRootContext("Root")) { rootContext.RecordTimepoint(Timepoint.Start); rootContext.RecordTimepoint(Timepoint.Finish); } }
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); }
public void CreateRootContext_should_throw_exception_if_context_name_is_null_or_empty(string contextName) { Assert.Throws <InvalidOperationException>(() => { using (var traceContext = Trace.CreateRootContext(contextName)) { } }); }
public void CreateRootContext_should_throw_exception_if_context_is_set_already() { using (var rootContext = Trace.CreateRootContext("Test")) { Assert.DoesNotThrow(() => { using (var newRootContext = Trace.CreateRootContext("NewRoot")) { } }); } }
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); } }
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); } }
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); } }
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)) { } }); } }
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 void SendMessage(string message) { try { using (var clientContext = Trace.CreateRootContext("Client-Server")) { Console.WriteLine(clientContext.TraceId); clientContext.RecordAnnotation(Annotation.RequestUrl, url); clientContext.RecordTimepoint(Timepoint.ClientSend); var bytes = Encoding.ASCII.GetBytes(message); var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = bytes.Length; request.Timeout = (int)TimeSpan.FromSeconds(2).TotalMilliseconds; request.SetTracingHeaders(clientContext); var stream = request.GetRequestStream(); stream.Write(bytes, 0, bytes.Length); stream.Close(); var response = request.GetResponse(); clientContext.RecordTimepoint(Timepoint.ClientReceive); synchronizer.ServerEndProcessQuerySignal.Wait(); } } catch (Exception e) { Console.Out.WriteLine("Unhandled client exception: {0}", e); } finally { synchronizer.ClientEndQuerySignal.Set(); } }
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(); }
public void CreateRootContext_should_return_real_context_when_current_context_is_sampled() { using (var traceContext = Trace.CreateRootContext("Test")) traceContext.Should().NotBeSameAs(NoOpTraceContext.Instance); }
public void CreateRootContext_should_return_NoOp_instance_when_current_context_is_not_sampled() { using (var traceContext = Trace.CreateRootContext("Test", activate: false)) traceContext.Should().BeSameAs(NoOpTraceContext.Instance); }
public void CreateRootContext_should_be_empty_after_stop() { Trace.Stop(); Trace.CreateRootContext("Test").Should().BeSameAs(NoOpTraceContext.Instance); }
public void CreateContext_should_initialize_if_needed_with_disabled_config() { Trace.Stop(); using (var context = Trace.CreateRootContext("Test")) context.Should().BeSameAs(NoOpTraceContext.Instance); }
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(); }