public void record_headers_from_http_request() { var dict = new Dictionary <string, object>(); dict.Add("owin.RequestHeaders", 1); dict.Add("owin.RequestMethod", 2); dict.Add("owin.RequestPath", 3); dict.Add("owin.RequestPathBase", 4); dict.Add("owin.RequestProtocol", 5); dict.Add("owin.RequestQueryString", 6); dict.Add("owin.RequestScheme", 7); dict.Add("owin.ResponseHeaders", 8); dict.Add("owin.ResponseStatusCode", 9); dict.Add("owin.ResponseReasonPhrase", 10); var log = new ChainExecutionLog(); log.RecordHeaders(dict); log.Request["owin.RequestHeaders"].ShouldBe(1); log.Request["owin.RequestMethod"].ShouldBe(2); log.Request["owin.RequestPath"].ShouldBe(3); log.Request["owin.RequestPathBase"].ShouldBe(4); log.Request["owin.RequestProtocol"].ShouldBe(5); log.Request["owin.RequestQueryString"].ShouldBe(6); log.Request["owin.RequestScheme"].ShouldBe(7); log.Request["owin.ResponseHeaders"].ShouldBe(8); log.Request["owin.ResponseStatusCode"].ShouldBe(9); log.Request["owin.ResponseReasonPhrase"].ShouldBe(10); }
public Func <IDictionary <string, object>, Task> WrapAppFunc(FubuRuntime runtime, Func <IDictionary <string, object>, Task> inner) { if (TraceLevel == TraceLevel.None) { return(inner); } var logger = runtime.Get <IExecutionLogger>(); return(env => { var log = new ChainExecutionLog(); env.Log(log); return inner(env).ContinueWith(t => { if (t.IsFaulted) { t.Exception.Flatten().InnerExceptions.Each(log.LogException); } log.MarkFinished(); if (log.RootChain != null && ApplyTracing.ShouldApply(log.RootChain)) { logger.Record(log, env); } }); }); }
public void map_from_execution_when_the_request_was_redirected() { var log = new ChainExecutionLog(); log.Request.Add(OwinConstants.ResponseStatusCodeKey, 302); log.Request.ResponseHeaders().Add(HttpResponseHeaders.ContentType, new[] { "text/plain" }); log.Request.ResponseHeaders().Add(HttpResponseHeaders.Location, new[] { "/new/place" }); var request = new OwinHttpRequest(log.Request); request.HttpMethod("GET"); request.FullUrl("http://server/foo"); log.MarkFinished(); var summary = new HttpRequestSummary(log); summary.id.ShouldBe(log.Id.ToString()); summary.time.ShouldBe(log.Time.ToHttpDateString()); summary.url.ShouldBe("/foo"); summary.method.ShouldBe("GET"); summary.status.ShouldBe(302); summary.contentType.ShouldBe("text/plain"); summary.duration.ShouldBe(log.ExecutionTime); summary.description.ShouldBe("/new/place"); }
public ProductionDiagnosticEnvelopeContext(ILogger logger, ISystemTime systemTime, IChainInvoker invoker, IOutgoingSender outgoing, IHandlerPipeline pipeline, Envelope envelope, IExecutionLogger executionLogger) : base(logger, systemTime, invoker, outgoing, pipeline) { _envelope = envelope; _executionLogger = executionLogger; _log = new ChainExecutionLog(); _envelope.Log = _log; }
public void read_stores_the_last_execution() { var history = new PerformanceHistory(); var log1 = new ChainExecutionLog(); var log2 = new ChainExecutionLog(); history.Read(log1); history.LastExecution.ShouldBeTheSameAs(log1); history.Read(log2); history.LastExecution.ShouldBeTheSameAs(log2); }
public void record_envelope_headers() { var envelope = new Envelope(); envelope.Headers["foo"] = "bar"; var log = new ChainExecutionLog(); log.RecordHeaders(envelope); log.Request["headers"].As <IDictionary <string, string> >()["foo"] .ShouldBe("bar"); }
public void set_the_chain_execution_log() { var source = new Dictionary <string, object>(); source.Log().ShouldBeNull(); var log = new ChainExecutionLog(); source.Log(log); source.RequestId().ShouldBe(log.Id.ToString()); source.Log().ShouldBeSameAs(log); }
public void register_the_execution_log_if_it_exists() { var log = new ChainExecutionLog(); var environment = new Dictionary <string, object>(); environment.Log(log); var routeData = new RouteData(); var arguments = new OwinServiceArguments(routeData, environment); arguments.Get <IChainExecutionLog>() .ShouldBeSameAs(log); }
public Dictionary <string, object> get_request_Id(ChainExecutionLog query) { var log = _history.Find(query.Id); var dict = new Dictionary <string, object>(); if (log != null) { dict.Add("log", log.ToDictionary()); if (log.RootChain != null) { dict.Add("type", log.RootChain.GetType().Name); } } return(dict); }
public HttpRequestSummary(ChainExecutionLog log) : this() { var request = new OwinHttpRequest(log.Request); var response = new OwinHttpResponse(log.Request); id = log.Id.ToString(); time = log.Time.ToHttpDateString(); url = request.RawUrl(); method = request.HttpMethod(); status = response.StatusCode; description = response.StatusDescription; if (status == 302) { // TODO -- write a helper for location description = response.HeaderValueFor(HttpResponseHeaders.Location).SingleOrDefault(); } contentType = response.ContentType(); duration = log.ExecutionTime; }
public void map_from_execution_log_happy_path() { var log = new ChainExecutionLog(); log.Request.Add(OwinConstants.ResponseStatusCodeKey, 200); log.Request.ResponseHeaders().Add(HttpResponseHeaders.ContentType, new [] { "text/plain" }); var request = new OwinHttpRequest(log.Request); request.HttpMethod("POST"); request.FullUrl("http://server/foo"); log.MarkFinished(); var summary = new HttpRequestSummary(log); summary.id.ShouldBe(log.Id.ToString()); summary.time.ShouldBe(log.Time.ToHttpDateString()); summary.url.ShouldBe("/foo"); summary.method.ShouldBe("POST"); summary.status.ShouldBe(200); summary.contentType.ShouldBe("text/plain"); summary.duration.ShouldBe(log.ExecutionTime); }
public static void Bootstrap(FubuRegistry registry) { Runtime = registry.ToRuntime(); var settings = Runtime.Get <DiagnosticsSettings>(); if (settings.TraceLevel == TraceLevel.None) { return; } var executionLogger = Runtime.Get <IExecutionLogger>(); var logger = Runtime.Get <ILogger>(); _startRequest = () => { try { if (!HttpContext.Current.Items.Contains("owin.Environment")) { HttpContext.Current.Items.Add("owin.Environment", new Dictionary <string, object>()); } var log = new ChainExecutionLog(); HttpContext.Current.Response.AppendHeader(HttpRequestExtensions.REQUEST_ID, log.Id.ToString()); HttpContext.Current.Items.Add(AspNetServiceArguments.CHAIN_EXECUTION_LOG, log); } catch (Exception e) { try { logger.Error("Error in request logging", e); } catch (Exception exception) { Console.WriteLine(exception); Console.WriteLine(e); } } }; _endRequest = () => { try { if (!HttpContext.Current.Items.Contains(AspNetServiceArguments.CHAIN_EXECUTION_LOG)) { return; } var log = HttpContext.Current.Items[AspNetServiceArguments.CHAIN_EXECUTION_LOG].As <ChainExecutionLog>(); log.MarkFinished(); executionLogger.Record(log, new AspNetDictionary()); } catch (Exception e) { try { logger.Error("Error in request logging", e); } catch (Exception exception) { Console.WriteLine(exception); Console.WriteLine(e); } } }; }