Ejemplo n.º 1
0
        // ReSharper disable once UnusedMember.Global
        public static ErrorReporter.OnError createSendOnError(
            SentryAPI.SendOnErrorData sendData, Uri reportingUrl, SentryAPI.ApiKeys keys, bool onlySendUniqueErrors
            )
        {
            var sentJsonsOpt = onlySendUniqueErrors.opt(() => new HashSet <string>());

            return(logEvent => {
                var msg = message(
                    keys, sendData.appInfo, logEvent, sendData.addExtraData,
                    sendData.userOpt, sendData.staticTags
                    );
                Action send = () => msg.send(reportingUrl);
                sentJsonsOpt.voidFold(
                    send,
                    sentJsons => {
                    if (sentJsons.Add(msg.jsonWithoutTimestamps))
                    {
                        send();
                    }
                    else if (Log.d.isDebug())
                    {
                        Log.d.debug($"Not sending duplicate Sentry msg: {msg}");
                    }
                }
                    );
            });
        }
Ejemplo n.º 2
0
        public static Message message(
            SentryAPI.ApiKeys keys, ErrorReporter.AppInfo appInfo,
            LogEvent data, SentryAPI.ExtraData extraData, Option <SentryAPI.UserInterface> userOpt,
            IDictionary <string, SentryAPI.Tag> staticTags
            )
        {
            const string logger    = "tlplib-" + nameof(SentryRESTAPI);
            var          eventId   = Guid.NewGuid();
            var          timestamp = DateTime.UtcNow;

            // The list of frames should be ordered by the oldest call first.
            var stacktraceFrames = data.entry.backtrace.map(
                // ReSharper disable once ConvertClosureToMethodGroup - MCS bug
                b => b.elements.a.Select(a => backtraceElemToJson(a)).Reverse().ToList()
                );

            // Beware of the order! Do not mutate static tags!
            var tags =
                SentryAPI.dynamicTags()
                .addAll(staticTags)
                .addAll(SentryAPI.convertTags(data.entry.tags));

            extraData.addTagsToDictionary(tags);

            // Extra contextual data is limited to 4096 characters.
            var extras =
                SentryAPI.dynamicExtras()
                .addAll(SentryAPI.convertExtras(data.entry.extras));

            extraData.addExtrasToDictionary(extras);

            var json = new Dictionary <string, object> {
                { "message", s(data.entry.message) },
                { "level", s(data.level.asSentry(), SentryAPI.LogLevel_.str) },
                { "logger", s(logger) },
                { "platform", s(Application.platform.ToString()) },
                { "release", s(appInfo.bundleVersion) },
                { "tags", tags.toDict(_ => _.Key, _ => _.Value.s) },
                { "extra", extras },
                { "fingerprint", data.entry.toSentryFingerprint() }
            };

            foreach (var stacktrace in stacktraceFrames)
            {
                json.Add("stacktrace", new Dictionary <string, object> {
                    { "frames", stacktrace }
                });
            }
            foreach (var user in userOpt)
            {
                json.Add("user", userInterfaceParametersJson(user));
            }

            return(new Message(keys, eventId, timestamp, json));
        }
Ejemplo n.º 3
0
            public Message(
                SentryAPI.ApiKeys keys, Guid eventId, DateTime timestamp,
                Dictionary <string, object> jsonDict
                )
            {
                this.keys      = keys;
                this.eventId   = eventId;
                this.timestamp = timestamp;
                this.jsonDict  = jsonDict;

                var json = new Dictionary <string, object>(jsonDict)
                {
                    { "event_id", eventId.ToString("N") },
                    { "timestamp", timestamp.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss") }
                };

                this.json = Json.Serialize(json);
            }