public void EmitEvent(HttpEvent httpEvent) { string trackingId = httpEvent.TrackingId.ToString(("d")); string serializedEvent = JsonConvert.SerializeObject(httpEvent); _log.EmitEvent(trackingId, serializedEvent); _log.EmitRequest(trackingId, httpEvent.Request); _log.EmitResponse(trackingId, httpEvent.Response); }
public void EmitEvent(HttpEvent httpEvent) { var eventAsJson = Newtonsoft.Json.JsonConvert.SerializeObject(httpEvent); System.Diagnostics.Trace.WriteLine(eventAsJson); System.Diagnostics.Trace.WriteLine(httpEvent.Request); System.Diagnostics.Trace.WriteLine(httpEvent.Response); }
public override async Task Invoke(IOwinContext context) { var request = context.Request; var response = context.Response; var requestBuffer = new MemoryStream((int)MaxRequestSize); var requestStream = new LoggingStream(requestBuffer, request.Body, MaxRequestSize); request.Body = requestStream; var responseBuffer = new MemoryStream((int)MaxResponseSize); var responseStream = new LoggingStream(responseBuffer, response.Body, MaxResponseSize); response.Body = responseStream; var httpEvent = new HttpEvent(); context.Response.OnSendingHeaders(state => { var resp = ((IOwinContext)state).Response; resp.Headers.Add(TrackingHeader, new[] { httpEvent.TrackingId.ToString("d"), }); }, context); await Next.Invoke(context); SetEventRequestHeaders(request, httpEvent); httpEvent.RequestLength = requestStream.LogContentLength; var reqBytes = await requestStream.ReadLogAsync(); if (httpEvent.RequestHeaders.ContainsKey(ContentTypeHeader) && HttpEvent.IsText(httpEvent.RequestHeaders[ContentTypeHeader])) { httpEvent.Request = Encoding.UTF8.GetString(reqBytes); } else { httpEvent.Request = Convert.ToBase64String(reqBytes); } SetEventResponseHeaders(response, httpEvent); httpEvent.ResponseLength = responseStream.LogContentLength; var respBytes = await responseStream.ReadLogAsync(); if (httpEvent.ResponseHeaders.ContainsKey(ContentTypeHeader) && HttpEvent.IsText(httpEvent.ResponseHeaders[ContentTypeHeader])) { httpEvent.Response = Encoding.UTF8.GetString(respBytes); } else { httpEvent.Response = Convert.ToBase64String(respBytes); } _tracker.EmitEvent(httpEvent); }
private static void SetEventResponseHeaders(IOwinResponse response, HttpEvent record) { record.Status = response.StatusCode; record.ResponseHeaders = response.Headers; }
private static void SetEventRequestHeaders(IOwinRequest request, HttpEvent record) { record.Verb = request.Method; record.Uri = request.Uri.ToString(); record.RequestHeaders = request.Headers; }