/// <summary> /// Shuts down the Application Insights Logging functionality /// and flushes any pending requests. /// /// This handles start and stop times and the application lifetime /// log entry that logs duration of operation. /// </summary> public static void ShutdownLogging() { if (Configuration.System.SendTelemetry && Telemetry.UseApplicationInsights && AppInsights != null) { var t = AppRunTelemetry.Telemetry; // multi-instance shutdown - ignore if (t.Properties.ContainsKey("usage")) { return; } t.Properties.Add("usage", Configuration.ApplicationUpdates.AccessCount.ToString()); t.Properties.Add("registered", UnlockKey.IsAppRegistered().ToString()); t.Properties.Add("version", GetVersion()); t.Properties.Add("dotnetversion", MarkdownMonster.Utilities.mmWindowsUtils.GetDotnetVersion()); t.Properties.Add("culture", CultureInfo.CurrentUICulture.IetfLanguageTag); t.Stop(); try { AppInsights.StopOperation(AppRunTelemetry); } catch (Exception ex) { LogLocal("Failed to Stop Telemetry Client: " + ex.GetBaseException().Message); } AppInsights.Flush(); AppInsights = null; AppRunTelemetry.Dispose(); } }
private void ReleaseUnmanagedResources() { if (requestOperation != null) { telemetryClient?.StopOperation(requestOperation); requestOperation?.Dispose(); } }
public void StopRunAsyncLoop( ) { DefaultEventSource.Current.StopRunAsyncLoop( _context ); _telemetryClient.StopOperation(_runAsyncLoopOperationHolder); _runAsyncLoopOperationHolder.Dispose(); }
public void Dispose() { telemetry?.StopOperation(operation); operation?.Dispose(); //transactionScope?.Dispose(); transactionProvider.Current.Dispose(); ((ReliableStateManagerTransactionProvider)transactionProvider).Current = null; LifetimeScope?.Dispose(); }
protected override void FinishInternal() { if (Duration.HasValue) // should always be true by this point { _operation.Telemetry.Duration = Duration.Value; } Tracer.Client.StopOperation(_operation); _operation.Dispose(); _operation = null; }
public void StopLoop( ) { DefaultEventSource.Current.StopLoop( _processId, _machineName, _actorId ); _telemetryClient.StopOperation(_loopOperationHolder); _loopOperationHolder.Dispose(); }
public void StopTrackRequest(IOperationHolder <RequestTelemetry> operation, string responseCode) { if (operation == null) { return; } operation.Telemetry.Stop(); operation.Telemetry.ResponseCode = responseCode; _telemetry.StopOperation(operation); operation.Dispose(); internalOperation = null; }
private void Dispose(bool disposing) { if (disposing) { if (requestOperation != null) { telemetry?.StopOperation(requestOperation); requestOperation.Dispose(); } } requestOperation = null; }
/// <summary> /// Stop operation computes the duration of the operation and tracks it using the respective telemetry client. /// </summary> /// <param name="telemetryClient">Telemetry client object.</param> /// <param name="operation">Operation object to compute duration and track.</param> public static void StopOperation <T>(this TelemetryClient telemetryClient, IOperationHolder <T> operation) where T : OperationTelemetry { if (telemetryClient == null) { throw new ArgumentNullException("telemetryClient"); } if (operation == null) { CoreEventSource.Log.OperationIsNullWarning(); return; } operation.Dispose(); }
public void Dispose() { if (_requestOperation != null) { _telemetry.StopOperation(_requestOperation); _requestOperation.Dispose(); _requestOperation = null; } if (_dependencyOperation != null) { _telemetry.StopOperation(_dependencyOperation); _dependencyOperation.Dispose(); _dependencyOperation = null; } }
/*************************************************************************/ public void Dispose() { _client.StopOperation(_op); _op.Dispose(); }
public async Task ProcessMessage(QueueMessage queueMessage, CancellationToken stoppingToken) { if (queueMessage == null) { throw new ArgumentNullException(nameof(queueMessage)); } //Running this as separate task gives the following benefits //1. ExecutionContext isn't overlap between message processors //2. Makes message parallel processing easier await Task.Yield();//makes execution parallel immidiatly for the reasons above var processed = false; MessageDetails? messageDetails = null; IServiceScope? scope = null; IAsyncDisposable?updateVisibilityStopAction = null; IOperationHolder <RequestTelemetry>?operation = null; try { messageDetails = new MessageDetails(queueMessage); operation = _telemetryClient.StartOperation <RequestTelemetry>(_workerOptions.OperationName); operation.Telemetry.Properties["InvocationId"] = queueMessage.MessageId; operation.Telemetry.Properties["MessageId"] = queueMessage.MessageId; operation.Telemetry.Properties["OperationName"] = _workerOptions.OperationName; operation.Telemetry.Properties["TriggerReason"] = $"New queue message detected on '{_workerOptions.QueueName}'."; operation.Telemetry.Properties["QueueName"] = _workerOptions.QueueName; operation.Telemetry.Properties["Processor"] = typeof(TMessageProcessor).Name; updateVisibilityStopAction = await StartKeepMessageInvisibleAsync(_queueClient, messageDetails); scope = _serviceProvider.CreateScope(); var messageProcessor = scope.ServiceProvider.GetRequiredService <TMessageProcessor>(); var lastAttempt = messageDetails.Message.DequeueCount >= _workerOptions.MaxRetryCount; await messageProcessor.ProcessMessage(GetTypedMessage(queueMessage), lastAttempt, stoppingToken); processed = true; _telemetryClient.TrackTrace("Processor finished"); //short cut for now. TOOD:// wrap processing in a separate operation //stoppingToken aren't passed here. We should try to delete message even if cancellation was requested //if operation was done await DeleteMessageAsync(_queueClient, messageDetails, updateVisibilityStopAction); operation.Telemetry.Success = true; operation.Telemetry.ResponseCode = "0"; } catch (OperationCanceledException) { _logger.OperationCancelledExceptionOccurred(); if (operation != null) { operation.Telemetry.Success = false; operation.Telemetry.ResponseCode = "400"; } } catch (Exception ex) { if (!processed && messageDetails != null) { await TryMoveToPoisonAsync(_queueClient, messageDetails, updateVisibilityStopAction); } _logger.UnhandledMessageProcessingExceptionOccurred(ex); await _exceptionHandler.HandleUnhandledExceptionAsync(scope, ex, _workerOptions.ProcessingIssueStopHostCode); if (operation != null) { operation.Telemetry.Success = false; operation.Telemetry.ResponseCode = "500"; } } finally { if (updateVisibilityStopAction != null) { await updateVisibilityStopAction.DisposeAsync(); } scope?.Dispose(); operation?.Dispose(); } }