private Task OnStarting(object state) { var record = ((HttpRequestRecord)state); record.Transferring = TimelineScope.Create("Transferring", TimelineEventCategory.AspNetCoreCommon); return(Task.CompletedTask); }
async Task MogeAsync(int delay) { using (TimelineScope.Create()) { await Task.Delay(delay); } }
public async Task <IActionResult> Timeline() { _loggerLog4Net.Warn("Begin Timeline \r\n(logging via log4net)"); using (TimelineScope.Create("First")) { await Task.Delay(50); using (TimelineScope.Create("Second")) { await Task.Delay(100); var t1 = HogeAsync(12); var t2 = HogeAsync(34); var t3 = HogeAsync(56); await Task.WhenAll(t1, t2, t3); } await Task.Delay(85); var sql = @"SELECT * FROM SugoiTable WHERE Nantoka = 1 AND Kantoka IN (1, 2, 3, 4, 5) ORDER BY Id DESC"; using (TimelineScope.Create("Third", TimelineEventCategory.Data, sql)) { await Task.Delay(120); await MogeAsync(22); await Task.Delay(80); await MogeAsync(33); } } NewThread(); var scope = TimelineScope.Create("Manual", TimelineEventCategory.Data); { var scope2 = TimelineScope.Create("Manual.Inner", TimelineEventCategory.Data); scope2.Complete(); scope2.Duration = TimeSpan.FromMilliseconds(24); } scope.Complete(); scope.Duration = TimeSpan.FromMilliseconds(12); for (var i = 0; i < 30; i++) { var scope2 = TimelineScope.Create("Manual." + i, TimelineEventCategory.Data); scope2.Complete(); scope2.Duration = TimeSpan.FromMilliseconds(24 + i); } return(Content("OK")); }
public void OnNext(KeyValuePair <string, object> value) { if (value.Key == RelationalEventId.CommandExecuted.Name && value.Value is CommandExecutedEventData commandExecutedEventData) { var scope = TimelineScope.Create("CommandExecuted", TimelineEventCategory.Data, commandExecutedEventData.Command.CommandText); scope.Complete(); scope.Timestamp = commandExecutedEventData.StartTime; scope.Duration = commandExecutedEventData.Duration; } }
public async Task InvokeAsync(HttpContext context, RinOptions options) { var request = context.Request; var response = context.Response; if (request.Path.StartsWithSegments(options.Inspector.MountPath) || (options.RequestRecorder.Excludes.Any(x => x.Invoke(request)))) { await _next(context); return; } // Prepare AsyncLocals var timelineRoot = TimelineScope.Prepare(); _recordingFeatureAccessor.SetValue(null); HttpRequestRecord?record = default; try { record = await PreprocessAsync(context, options, timelineRoot); } catch (Exception ex) { _logger.LogError(ex, "Unhandled Exception was thrown until pre-processing"); } try { await _next(context); } catch (Exception ex) { if (record != null) { record.Exception = new ExceptionData(ex); } throw; } finally { try { if (record != null) { await PostprocessAsync(context, options, record); } } catch (Exception ex) { _logger.LogError(ex, "Unhandled Exception was thrown until post-processing"); } } }
void NewThread() { var t = new Thread(() => { using (TimelineScope.Create()) { Thread.Sleep(120); } }); t.Start(); t.Join(); }
private async Task <HttpRequestRecord> PreprocessAsync(HttpContext context, RinOptions options, ITimelineScope timelineRoot) { var request = context.Request; var response = context.Response; var record = new HttpRequestRecord() { Id = Guid.NewGuid().ToString(), IsHttps = request.IsHttps, Host = request.Host.Value, QueryString = request.QueryString.Value, Path = request.Path, Method = request.Method, RequestReceivedAt = DateTimeOffset.Now, RequestHeaders = request.Headers.ToDictionary(k => k.Key, v => v.Value), RemoteIpAddress = request.HttpContext.Connection.RemoteIpAddress, Timeline = timelineRoot, }; // Set Rin recorder feature. var feature = new RinRequestRecordingFeature(record);; _recordingFeatureAccessor.SetValue(feature); context.Features.Set <IRinRequestRecordingFeature>(feature); await _eventBus.PostAsync(new RequestEventMessage(EventSourceName, record, RequestEvent.BeginRequest)); // Set a current Rin request ID to response header. context.Response.Headers.Add("X-Rin-Request-Id", record.Id); if (options.RequestRecorder.EnableBodyCapturing) { context.EnableResponseDataCapturing(); request.EnableBuffering(); } response.OnStarting(OnStarting, record); response.OnCompleted(OnCompleted, record); // Execute pipeline middlewares. record.Processing = TimelineScope.Create("Processing", TimelineEventCategory.AspNetCoreCommon); return(record); }
public void OnBeforeActionResult(Microsoft.AspNetCore.Mvc.ActionContext actionContext, Microsoft.AspNetCore.Mvc.IActionResult result) { _onActionResultScope.Value = TimelineScope.Create("ActionResult", TimelineEventCategory.AspNetCoreMvcResult); }
public void OnBeforeViewPage(IRazorPage page, ViewContext viewContext) { _onViewPageScope.Value = TimelineScope.Create("Page", TimelineEventCategory.AspNetCoreMvcView, page.Path); }
public void OnBeforeActionMethod(Microsoft.AspNetCore.Mvc.ActionContext actionContext, System.Collections.Generic.IDictionary <string, object> actionArguments, object controller) { _onActionMethodScope.Value = TimelineScope.Create("ActionMethod", TimelineEventCategory.AspNetCoreMvcAction, actionContext.ActionDescriptor.DisplayName); }