Exemplo n.º 1
0
 private static string GetFieldName(FieldsPositions pos)
 {
     // We are using position number before fields name.
     // This will help us to arrange fields position correctly (view on website)
     // (Sentry is sorting them in alphabetical order)
     return($"[{((int)pos).ToString("00")}] {pos}");
 }
Exemplo n.º 2
0
        /// <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
            }
        }