private void InitializeEventToSend() { if (__EventToSend != null) { return; } __EventToSend = ErrorReporter.PrepareEventToSend(__Exception, App.Settings, GetIVPNLog(), GetIVPNLog0(), null, null, __IsServiceException); }
public static ErrorReporterEvent PrepareEventToSend(Exception ex, AppSettings appSettings, string ivpnLog, string ivpnLogOld, string vpnProtocolLog, string vpnProtocolLogOld, bool?isServiceError = null) { if (ex == null) { return(null); } IDictionary <string, string> parameters = InitializeParameters(appSettings); foreach (var item in parameters) { ex.Data.Add(item.Key, item.Value); } if (!string.IsNullOrEmpty(ivpnLog)) { ex.Data.Add(GetFieldName(FieldsPositions.ivpnLog), ivpnLog); } if (!string.IsNullOrEmpty(ivpnLogOld)) { ex.Data.Add(GetFieldName(FieldsPositions.ivpnLogOld), ivpnLogOld); } if (!string.IsNullOrEmpty(vpnProtocolLog)) { ex.Data.Add(GetFieldName(FieldsPositions.vpnProtocolLog), vpnProtocolLog); } if (!string.IsNullOrEmpty(vpnProtocolLogOld)) { ex.Data.Add(GetFieldName(FieldsPositions.vpnProtocolLogOld), vpnProtocolLogOld); } var logEvt = new SharpRaven.Data.SentryEvent(ex); logEvt.Tags = InitializeTags(appSettings); if (isServiceError != null) { ex.Data.Add(GetFieldName(FieldsPositions.IsService), ((bool)isServiceError).ToString()); logEvt.Tags.Add($"{FieldsPositions.IsService}", isServiceError.ToString()); } logEvt.Message = ex.Message; logEvt.Contexts.Device.Name = ""; // do not send real device name ErrorReporterEvent ret = new ErrorReporterEvent(logEvt); //DivideBigParameters(ret); return(ret); }
public static ErrorReporterEvent PrepareDiagReportToSend(AppSettings appSettings, string environmentLog, string ivpnLog, string ivpnLogOld, string vpnProtocolLog, string vpnProtocolLogOld) { var diagReport = new DiagnosticReport(); diagReport.Data.Add(GetFieldName(FieldsPositions.Environment), environmentLog); diagReport.Data.Add(GetFieldName(FieldsPositions.IsDiagnosticReport), "True"); ErrorReporterEvent evt = PrepareEventToSend(diagReport, appSettings, ivpnLog, ivpnLogOld, vpnProtocolLog, vpnProtocolLogOld); evt.Event.Tags.Add($"{FieldsPositions.IsDiagnosticReport}", "True"); evt.Event.Level = ErrorLevel.Debug; //DivideBigParameters(evt); return(evt); }
/// <summary> /// Sentry limits message size to 100Kb /// Here we are trimming parameters size (if their common size is too big) /// </summary> /// <param name="evt"></param> private static void DivideBigParameters(ErrorReporterEvent evt) { try { DivideParameter(evt, FieldsPositions.vpnProtocolLogOld, MaxParameterSize, 2); DivideParameter(evt, FieldsPositions.vpnProtocolLog, MaxParameterSize, 3); DivideParameter(evt, FieldsPositions.ivpnLogOld, MaxParameterSize, 2); DivideParameter(evt, FieldsPositions.Environment, MaxParameterSize, 2); DivideParameter(evt, FieldsPositions.ivpnLog, MaxParameterSize, 6); } catch { // ignore } }
public static void SendReport(ErrorReporterEvent evt, string userComments = null) { if (evt?.Event == null) { return; } if (!string.IsNullOrEmpty(userComments)) { AddParameter(evt.Event.Exception.Data, GetFieldName(FieldsPositions.UserComments), userComments); evt.Event.Message = userComments; } DivideBigParameters(evt); Exception sendError = null; void OnError(Exception ex) { sendError = ex; Logging.Info($"[ERROR]: Unbale to send report-log to server {ex}"); } if (__RavenClient == null) { throw new Exception("Unable to send diagnostic report. Report sender not initialized (RavenClient)."); } __RavenClient.ErrorOnCapture += OnError; try { string eventId = __RavenClient.Capture(evt.Event); if (!string.IsNullOrEmpty(eventId)) { Logging.Info($"Sent report. ID:{eventId}"); } if (sendError != null) { throw sendError; } } finally { __RavenClient.ErrorOnCapture -= OnError; } }
private string UpdateExceptionMessage() { if (__EventToSend != null) { return(__EventToSend.ToString()); } __EventToSend = ErrorReporter.PrepareEventToSend(__Exception, AppDelegate.GetAppSettings(), GetLogFileData(Platform.ServiceLogFilePath), GetLogFileData(Platform.ServiceLogFilePath + ".0"), null, null, __IsServiceException ); return(__EventToSend.ToString()); }
/// <summary> /// Sentry have limit of parameter size - 16KB. So, here we dividing one big parameter to multiple /// </summary> private static void DivideParameter(ErrorReporterEvent evt, FieldsPositions param, int toSize, int maxItemsCount = 0) { string fieldName = GetFieldName(param); if (!evt.Event.Exception.Data.Contains(fieldName)) { return; } string value = (string)evt.Event.Exception.Data[fieldName]; if (value.Length <= toSize) { return; } int processedBytes = 0; int item = 0; List <string> items = new List <string>(); try { while (processedBytes < value.Length) { string newItem; if (toSize * item + toSize >= value.Length) { newItem = value.Substring(toSize * item++); } else { newItem = value.Substring(toSize * item++, toSize); } processedBytes += newItem.Length; newItem = newItem.Trim(); if (newItem.Length > 0) { items.Add(newItem); } } int nameIdxOffset = 0; if (maxItemsCount > 0 && items.Count > maxItemsCount) { nameIdxOffset = items.Count - maxItemsCount; } for (int i = items.Count - 1; i >= 0; i--) { evt.Event.Exception.Data.Add(fieldName + $" {i- nameIdxOffset}", items[i]); if (maxItemsCount > 0 && items.Count - i >= maxItemsCount) { break; } } // remove old big parameter evt.Event.Exception.Data.Remove(fieldName); } catch { // ignore } }