Пример #1
0
        /// <summary>
        /// Creates an envelope that contains a session update.
        /// </summary>
        public static Envelope FromSession(SessionUpdate sessionUpdate)
        {
            var header = CreateHeader();

            var items = new[]
            {
                EnvelopeItem.FromSession(sessionUpdate)
            };

            return(new Envelope(header, items));
        }
Пример #2
0
        /// <summary>
        /// Creates an envelope that contains a single transaction.
        /// </summary>
        public static Envelope FromTransaction(Transaction transaction)
        {
            var header = CreateHeader(transaction.EventId);

            var items = new[]
            {
                EnvelopeItem.FromTransaction(transaction)
            };

            return(new Envelope(header, items));
        }
Пример #3
0
        /// <summary>
        /// Creates an envelope that contains a single user feedback.
        /// </summary>
        public static Envelope FromUserFeedback(UserFeedback sentryUserFeedback)
        {
            var header = CreateHeader(sentryUserFeedback.EventId);

            var items = new[]
            {
                EnvelopeItem.FromUserFeedback(sentryUserFeedback)
            };

            return(new Envelope(header, items));
        }
Пример #4
0
        /// <summary>
        /// Deserializes envelope from stream.
        /// </summary>
        public static async Task <Envelope> DeserializeAsync(
            Stream stream,
            CancellationToken cancellationToken = default)
        {
            var header = await DeserializeHeaderAsync(stream, cancellationToken).ConfigureAwait(false);

            var items = new List <EnvelopeItem>();

            while (stream.Position < stream.Length)
            {
                var item = await EnvelopeItem.DeserializeAsync(stream, cancellationToken).ConfigureAwait(false);

                items.Add(item);
            }

            return(new Envelope(header, items));
        }
Пример #5
0
        /// <summary>
        /// Creates an envelope that contains a single event.
        /// </summary>
        public static Envelope FromEvent(
            SentryEvent @event,
            IDiagnosticLogger?logger = null,
            IReadOnlyCollection <Attachment>?attachments = null,
            SessionUpdate?sessionUpdate = null)
        {
            var header = CreateHeader(@event.EventId);

            var items = new List <EnvelopeItem>
            {
                EnvelopeItem.FromEvent(@event)
            };

            if (attachments is not null)
            {
                foreach (var attachment in attachments)
                {
                    try
                    {
                        items.Add(EnvelopeItem.FromAttachment(attachment));
                    }
                    catch (Exception exception)
                    {
                        if (logger is null)
                        {
                            throw;
                        }

                        logger.LogError("Failed to add attachment: {0}.", exception, attachment.FileName);
                    }
                }
            }

            if (sessionUpdate is not null)
            {
                items.Add(EnvelopeItem.FromSession(sessionUpdate));
            }

            return(new Envelope(header, items));
        }
Пример #6
0
        /// <summary>
        /// Creates an envelope that contains a single event.
        /// </summary>
        public static Envelope FromEvent(
            SentryEvent @event,
            IReadOnlyCollection <Attachment>?attachments = null,
            SessionUpdate?sessionUpdate = null)
        {
            var header = CreateHeader(@event.EventId);

            var items = new List <EnvelopeItem>
            {
                EnvelopeItem.FromEvent(@event)
            };

            if (attachments is not null)
            {
                items.AddRange(attachments.Select(EnvelopeItem.FromAttachment));
            }

            if (sessionUpdate is not null)
            {
                items.Add(EnvelopeItem.FromSession(sessionUpdate));
            }

            return(new Envelope(header, items));
        }