Exemple #1
0
        public string Serialize(JsonPacket packet, Formatting formatting)
        {
            stringWriter.GetStringBuilder().Length = 0;
            writer.Formatting = formatting;

            writer.WriteStartObject();
            {
                Write("event_id", packet.EventID);
                Write("project", packet.Project);
                Write("culprit", packet.Culprit);

                writer.WritePropertyName("level");
                writer.WriteValue(packet.Level);

                writer.WritePropertyName("timestamp");
                writer.WriteValue(packet.TimeStamp.ToString("s", CultureInfo.InvariantCulture));

                Write("logger", packet.Logger);
                Write("platform", packet.Platform);
                Write("message", packet.Message);
                Write("tags", packet.Tags);

                Write(packet.Exception);
                Write(packet.StackTrace);
            }
            writer.WriteEndObject();

            return(stringWriter.ToString());
        }
        public void SerializedJsonPacket_WithValidData_IsValid()
        {
            var exception = TestHelper.GetException();

            // TODO: This packet should preferably be "complete", i.e. contain as much information as possible. --asbjornu
            JsonPacket packet = new JsonPacket("https://*****:*****@app.getsentry.com/1337", exception)
            {
                Level = ErrorLevel.Fatal,
                Tags = new Dictionary<string, string>
                {
                    { "key1", "value1" },
                    { "key2", "value2" },
                },
                Request = new SentryRequest
                {
                    QueryString = "?a=b&c=d",
                    Data = new
                    {
                        A = true,
                        B = 1,
                        C = "Hello"
                    }
                }
            };

            JObject jPacket = JObject.Parse(packet.ToString());
            JsonSchema schema = SchemaHelper.GetSchema();

            jPacket.Validate(schema, (s, e) => Console.WriteLine(e.Message));
            Console.WriteLine(jPacket);

            var valid = jPacket.IsValid(schema);

            Assert.That(valid, Is.True);
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Requester"/> class.
        /// </summary>
        /// <param name="packet">The <see cref="JsonPacket"/> to initialize with.</param>
        /// <param name="ravenClient">The <see cref="RavenClient"/> to initialize with.</param>
        public Requester(JsonPacket packet, RavenClient ravenClient)
        {
            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }

            if (ravenClient == null)
            {
                throw new ArgumentNullException("ravenClient");
            }

            this.ravenClient = ravenClient;
            this.packet      = ravenClient.PreparePacket(packet);
            this.data        = new RequestData(this);

            this.webRequest = CreateWebRequest(ravenClient.CurrentDsn.SentryUri);

            if (ravenClient.Compression)
            {
                this.webRequest.Headers.Add(HttpRequestHeader.ContentEncoding, "gzip");
                this.webRequest.AutomaticDecompression = DecompressionMethods.Deflate;
                this.webRequest.ContentType            = "application/octet-stream";
            }

            else
            {
                this.webRequest.ContentType = "application/json; charset=utf-8";
            }
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Requester"/> class.
        /// </summary>
        /// <param name="packet">The <see cref="JsonPacket"/> to initialize with.</param>
        /// <param name="ravenClient">The <see cref="RavenClient"/> to initialize with.</param>
        internal Requester(JsonPacket packet, RavenClient ravenClient)
        {
            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }

            if (ravenClient == null)
            {
                throw new ArgumentNullException("ravenClient");
            }

            this.ravenClient = ravenClient;
            this.packet      = ravenClient.PreparePacket(packet);
            this.data        = new RequestData(this);

            this.webRequest                  = (HttpWebRequest)System.Net.WebRequest.Create(ravenClient.CurrentDsn.SentryUri);
            this.webRequest.Timeout          = (int)ravenClient.Timeout.TotalMilliseconds;
            this.webRequest.ReadWriteTimeout = (int)ravenClient.Timeout.TotalMilliseconds;
            this.webRequest.Method           = "POST";
            this.webRequest.Accept           = "application/json";
            this.webRequest.Headers.Add("X-Sentry-Auth", PacketBuilder.CreateAuthenticationHeader(ravenClient.CurrentDsn));
            this.webRequest.UserAgent = PacketBuilder.UserAgent;

            if (ravenClient.Compression)
            {
                this.webRequest.Headers.Add(HttpRequestHeader.ContentEncoding, "gzip");
                this.webRequest.AutomaticDecompression = DecompressionMethods.Deflate;
                this.webRequest.ContentType            = "application/octet-stream";
            }
            else
            {
                this.webRequest.ContentType = "application/json; charset=utf-8";
            }
        }
        public void Constructor_ProjectAndException_EventIDIsValidGuid()
        {
            var project = Guid.NewGuid().ToString();
            var json = new JsonPacket(project, new Exception("Error"));

            Assert.That(json.EventID, Is.Not.Null.Or.Empty, "EventID");
            Assert.That(Guid.Parse(json.EventID), Is.Not.Null);
        }
        public void Constructor_ProjectAndException_MessageEqualsExceptionMessage()
        {
            var project = Guid.NewGuid().ToString();
            Exception exception = new Exception("Error");
            var json = new JsonPacket(project, exception);

            Assert.That(json.Message, Is.EqualTo(exception.Message));
        }
        /// <summary>
        /// Creates a new instance of  <see cref="JsonPacket" /> for the specified
        /// <paramref name="project" />, with the  given <paramref name="event" />.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="event">The event to capture.</param>
        /// <returns>
        /// A new instance of <see cref="JsonPacket" /> for the specified
        /// <paramref name="project" />, with the given <paramref name="event" />.
        /// </returns>
        public JsonPacket Create(string project, SentryEvent @event)
        {
            var json = new JsonPacket(project, @event)
            {
                Breadcrumbs = @event.Breadcrumbs
            };

            return(OnCreate(json));
        }
        public int CaptureException(Exception e, string[][] tags, object extra = null)
        {
            JsonPacket packet = new JsonPacket(CurrentDSN.ProjectID, e);
            packet.Level = ErrorLevel.error;
            packet.Tags = tags;
            packet.Extra = extra;

            Send(packet, CurrentDSN);

            return 0;
        }
        private static void SimulateHttpRequest(Action<JsonPacket> test)
        {
            using (var simulator = new HttpSimulator())
            {
                simulator.SetFormVariable("Form1", "Value1")
                         .SetCookie("Cookie1", "Value1")
                         .SetHeader("Header1", "Value1")
                         .SetReferer(new Uri("http://getsentry.com/"));

                using (simulator.SimulateRequest())
                {
                    var json = new JsonPacket(Guid.NewGuid().ToString("n"));
                    test.Invoke(json);
                }
            }
        }
        /// <summary>
        /// Called when the <see cref="JsonPacket" /> has been created. Can be overridden to
        /// adjust the values of the <paramref name="jsonPacket" /> before it is sent to Sentry.
        /// </summary>
        /// <param name="jsonPacket">The json packet.</param>
        /// <returns>
        /// The <see cref="JsonPacket" />.
        /// </returns>
        protected override JsonPacket OnCreate(JsonPacket jsonPacket)
        {
            var nancyContext = CallContext.LogicalGetData(NancyConfiguration.NancyContextDataSlot) as NancyContext;

            if (nancyContext == null)
                return jsonPacket;

            var sentryRequest = NancySentryRequest.GetRequest(nancyContext);

            if (sentryRequest == null)
                return jsonPacket;

            jsonPacket.Request = sentryRequest;
            jsonPacket.User = sentryRequest.GetUser();

            return jsonPacket;
        }
        /// <summary>
        /// Creates a new instance of
        /// <see cref="JsonPacket" /> for the specified
        /// <paramref name="project" />.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="message">The message to capture.</param>
        /// <param name="level">The <see cref="ErrorLevel" /> of the captured <paramref name="message" />. Default <see cref="ErrorLevel.Info" />.</param>
        /// <param name="tags">The tags to annotate the captured <paramref name="message" /> with.</param>
        /// <param name="extra">The extra metadata to send with the captured <paramref name="message" />.</param>
        /// <returns>
        /// A new instance of <see cref="JsonPacket" /> for the specified <paramref name="project" />.
        /// </returns>
        public JsonPacket Create(string project,
                                 SentryMessage message,
                                 ErrorLevel level = ErrorLevel.Info,
                                 IDictionary<string, string> tags = null,
                                 object extra = null)
        {
            var json = new JsonPacket(project)
            {
                Message = message != null ? message.ToString() : null,
                MessageObject = message,
                Level = level,
                Tags = tags,
                Extra = extra
            };

            return OnCreate(json);
        }
Exemple #12
0
        /// <summary>
        /// Creates a new instance of
        /// <see cref="JsonPacket" /> for the specified
        /// <paramref name="project" />.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="message">The message to capture.</param>
        /// <param name="level">The <see cref="ErrorLevel" /> of the captured <paramref name="message" />. Default <see cref="ErrorLevel.Info" />.</param>
        /// <param name="tags">The tags to annotate the captured <paramref name="message" /> with.</param>
        /// <param name="extra">The extra metadata to send with the captured <paramref name="message" />.</param>
        /// <returns>
        /// A new instance of <see cref="JsonPacket" /> for the specified <paramref name="project" />.
        /// </returns>
        public JsonPacket Create(string project,
                                 SentryMessage message,
                                 ErrorLevel level = ErrorLevel.Info,
                                 IDictionary <string, string> tags = null,
                                 object extra = null)
        {
            var json = new JsonPacket(project)
            {
                Message = message != null?message.ToString() : null,
                              MessageObject = message,
                              Level         = level,
                              Tags          = tags,
                              Extra         = extra
            };

            return(OnCreate(json));
        }
Exemple #13
0
        /// <summary>
        /// Creates a new instance of
        /// <see cref="JsonPacket" /> for the specified
        /// <paramref name="project" />, with the
        /// given
        /// <paramref name="exception" />.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="exception">The <see cref="Exception" /> to capture.</param>
        /// <param name="message">The optional message to capture. Default: <see cref="Exception.Message" />.</param>
        /// <param name="level">The <see cref="ErrorLevel" /> of the captured <paramref name="exception" />. Default: <see cref="ErrorLevel.Error" />.</param>
        /// <param name="tags">The tags to annotate the captured <paramref name="exception" /> with.</param>
        /// <param name="fingerprint">The custom fingerprint to annotate the captured <paramref name="message" /> with.</param>
        /// <param name="extra">The extra metadata to send with the captured <paramref name="exception" />.</param>
        /// <returns>
        /// A new instance of
        /// <see cref="JsonPacket" /> for the specified
        /// <paramref name="project" />, with the
        /// given
        /// <paramref name="exception" />.
        /// </returns>
        public JsonPacket Create(string project,
                                 Exception exception,
                                 SentryMessage message             = null,
                                 ErrorLevel level                  = ErrorLevel.Error,
                                 IDictionary <string, string> tags = null,
                                 string[] fingerprint              = null,
                                 object extra = null)
        {
            var json = new JsonPacket(project, exception)
            {
                Message = message != null?message.ToString() : exception.Message,
                              MessageObject = message,
                              Level         = level,
                              Tags          = tags,
                              Fingerprint   = fingerprint,
                              Extra         = Merge(extra, exception)
            };

            return(OnCreate(json));
        }
        public JsonPacket Create(string projectId, EventEntry entry,
            ISentryExceptionLocator exceptionLocator)
        {
            var extras = GetExtras(entry);

            var packet = new JsonPacket(projectId)
            {
                Message = entry.FormattedMessage,
                Level = GetLogLevel(entry.Schema.Level),
                Tags = GetTags(entry),
                Extra = extras,
                TimeStamp = entry.Timestamp.UtcDateTime
            };

            if (exceptionLocator != null)
            {
                var exceptions = exceptionLocator.Locate(extras);

                if (exceptions != null)
                    packet.Exceptions = exceptions.ToList();
            }

            return packet;
        }
 protected override JsonPacket OnCreate(JsonPacket jsonPacket)
 {
     jsonPacket.Project = this.project;
     jsonPacket.Release = this.release;
     jsonPacket.Environment = this.environment;
     jsonPacket.Logger = this.logger;
     return base.OnCreate(jsonPacket);
 }
 protected override string Send(JsonPacket packet)
 {
     // TODO(dcramer): this is duped from RavenClient
     packet = PreparePacket(packet);
     LastPacket = packet;
     return packet.Project;
 }
 private static void SimulateHttpRequest(Action<JsonPacket> test)
 {
     using (var simulator = new HttpSimulator())
     {
         using (simulator.SimulateRequest())
         {
             var json = new JsonPacket(Guid.NewGuid().ToString("n"));
             test.Invoke(json);
         }
     }
 }
        public void Constructor_Project_ServerNameEqualsMachineName()
        {
            var project = Guid.NewGuid().ToString();
            var json = new JsonPacket(project);

            Assert.That(json.ServerName, Is.EqualTo(Environment.MachineName));
        }
        public void Constructor_Project_ProjectIsEqual()
        {
            var project = Guid.NewGuid().ToString();
            var json = new JsonPacket(project);

            Assert.That(json.Project, Is.EqualTo(project));
        }
 protected override Task<string> SendAsync(JsonPacket packet)
 {
     packet = PreparePacket(packet);
     LastPacket = packet;
     return Task.FromResult(packet.Project);
 }
 /// <summary>
 /// Called when the <see cref="JsonPacket"/> has been created. Can be overridden to
 /// adjust the values of the <paramref name="jsonPacket"/> before it is sent to Sentry.
 /// </summary>
 /// <param name="jsonPacket">The json packet.</param>
 /// <returns>
 /// The <see cref="JsonPacket"/>.
 /// </returns>
 protected virtual JsonPacket OnCreate(JsonPacket jsonPacket)
 {
     return jsonPacket;
 }
Exemple #22
0
 public int CaptureException(Exception e)
 {
     JsonPacket packet = new JsonPacket(CurrentDSN.ProjectID, e);
     Send(packet, CurrentDSN);
     return 0;
 }
        /// <summary>
        /// Captures the message.
        /// </summary>
        /// <param name="message">The message to capture.</param>
        /// <param name="level">The <see cref="ErrorLevel" /> of the captured message.</param>
        /// <param name="tags">The tags to annotate the captured exception with.</param>
        /// <param name="extra">The extra metadata to send with the captured exception.</param>
        /// <returns>
        /// The <see cref="JsonPacket.EventID"/> of the successfully captured message, or <c>null</c> if it fails.
        /// </returns>
        public string CaptureMessage(string message,
            ErrorLevel level = ErrorLevel.Info,
            Dictionary<string, string> tags = null,
            object extra = null)
        {
            JsonPacket packet = new JsonPacket(CurrentDsn.ProjectID)
            {
                Message = message,
                Level = level,
                Tags = tags,
                Extra = extra
            };

            return Send(packet, CurrentDsn);
        }
        public void Constructor_ProjectAndException_ModulesHasCountGreaterThanZero()
        {
            var project = Guid.NewGuid().ToString();
            var json = new JsonPacket(project, new Exception("Error"));

            Assert.That(json.Modules, Has.Count.GreaterThan(0));
        }
Exemple #25
0
        public int CaptureMessage(string message, ErrorLevel level = ErrorLevel.info, string[][] tags = null, object extra = null)
        {
            JsonPacket packet = new JsonPacket(CurrentDSN.ProjectID);
            packet.Message = message;
            packet.Level = level;
            packet.Tags = tags;
            packet.Extra = extra;

            Send(packet, CurrentDSN);

            return 0;
        }
Exemple #26
0
        public int CaptureUntiyLog(string log, string stack, LogType logType, Dictionary<string, string> tags = null, object extra = null)
        {
            JsonPacket packet = new JsonPacket(CurrentDSN.ProjectID, log, stack, logType);
            packet.Level = ErrorLevel.error;
            packet.Tags = tags;
            packet.Extra = extra;

            Send(packet, CurrentDSN);

            return 0;
        }
Exemple #27
0
        public int CaptureMessage(string message, ErrorLevel level /*= ErrorLevel.info*/, Dictionary<string, string> tags /*= null*/, object extra /*= null*/)
        {
            JsonPacket packet = new JsonPacket(CurrentDSN.ProjectID);
            packet.Message = message;
            packet.Level = level;
            packet.Tags = tags;
            packet.Extra = extra;

            Send(packet, CurrentDSN);

            return 0;
        }
Exemple #28
0
 /// <summary>
 /// Performs <see cref="JsonPacket"/> post-processing prior to being sent to Sentry.
 /// </summary>
 /// <param name="packet">The prepared <see cref="JsonPacket"/> which has cleared the creation pipeline.</param>
 /// <returns>The <see cref="JsonPacket"/> which should be sent to Sentry.</returns>
 protected virtual JsonPacket PreparePacket(JsonPacket packet)
 {
     packet.Logger = String.IsNullOrWhiteSpace(packet.Logger)
                     || (packet.Logger == "root" && !String.IsNullOrWhiteSpace(Logger))
         ? Logger
         : packet.Logger;
     packet.User = packet.User ?? this.sentryUserFactory.Create();
     packet.Request = packet.Request ?? this.sentryRequestFactory.Create();
     packet.Release = String.IsNullOrWhiteSpace(packet.Release) ? Release : packet.Release;
     packet.Environment = String.IsNullOrWhiteSpace(packet.Environment) ? Environment : packet.Environment;
     return packet;
 }
Exemple #29
0
        /// <summary>Sends the specified packet to Sentry.</summary>
        /// <param name="packet">The packet to send.</param>
        /// <returns>
        /// The <see cref="JsonPacket.EventID" /> of the successfully captured JSON packet, or <c>null</c> if it fails.
        /// </returns>
        protected virtual string Send(JsonPacket packet)
        {
            try
            {
                // TODO(dcramer): moving this out of Send makes it easier to test the final
                // generated packet
                packet = PreparePacket(packet);

                var request = (HttpWebRequest)WebRequest.Create(this.currentDsn.SentryUri);
                request.Timeout = (int)Timeout.TotalMilliseconds;
                request.ReadWriteTimeout = (int)Timeout.TotalMilliseconds;
                request.Method = "POST";
                request.Accept = "application/json";
                request.Headers.Add("X-Sentry-Auth", PacketBuilder.CreateAuthenticationHeader(this.currentDsn));
                request.UserAgent = PacketBuilder.UserAgent;

                if (Compression)
                {
                    request.Headers.Add(HttpRequestHeader.ContentEncoding, "gzip");
                    request.AutomaticDecompression = DecompressionMethods.Deflate;
                    request.ContentType = "application/octet-stream";
                }
                else
                    request.ContentType = "application/json; charset=utf-8";

                /*string data = packet.ToString(Formatting.Indented);
                    Console.WriteLine(data);*/

                var data = packet.ToString(Formatting.None);

                if (LogScrubber != null)
                    data = LogScrubber.Scrub(data);

                // Write the messagebody.
                using (var s = request.GetRequestStream())
                {
                    if (Compression)
                        GzipUtil.Write(data, s);
                    else
                    {
                        using (var sw = new StreamWriter(s))
                        {
                            sw.Write(data);
                        }
                    }
                }

                using (var wr = (HttpWebResponse)request.GetResponse())
                {
                    using (var responseStream = wr.GetResponseStream())
                    {
                        if (responseStream == null)
                            return null;

                        using (var sr = new StreamReader(responseStream))
                        {
                            var content = sr.ReadToEnd();
                            var response = JsonConvert.DeserializeObject<dynamic>(content);
                            return response.id;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return HandleException(ex);
            }
        }
        public void Constructor_ProjectAndException_ProjectIsEqual()
        {
            var project = Guid.NewGuid().ToString();
            var json = new JsonPacket(project, new Exception("Error"));

            Assert.That(json.Project, Is.EqualTo(project));
        }
 /// <summary>
 /// Gets a <see cref="System.String"/> representation of the <see cref="RequestData"/>.
 /// </summary>
 /// <returns>
 /// A <see cref="System.String"/> representation of the <see cref="RequestData"/>.
 /// </returns>
 public override string ToString()
 {
     return(this.formatted = this.formatted ?? JsonPacket.ToString(Formatting.Indented));
 }
Exemple #32
0
        public bool Send(JsonPacket jp, DSN dsn)
        {
            try {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(dsn.SentryURI);
                request.Method = "POST";
                request.Accept = "application/json";
                request.ContentType = "application/json; charset=utf-8";
                request.Headers.Add("X-Sentry-Auth", PacketBuilder.CreateAuthenticationHeader(dsn));
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

                request.UserAgent = "RavenSharp/1.0";

                Console.WriteLine("Header: " + PacketBuilder.CreateAuthenticationHeader(dsn));
                Console.WriteLine("Packet: " + jp.Serialize());

                // Write the messagebody.
                using (Stream s = request.GetRequestStream()) {
                    using (StreamWriter sw = new StreamWriter(s)) {
                        // Compress and encode.
                        //string data = Utilities.GzipUtil.CompressEncode(jp.Serialize());
                        //Console.WriteLine("Writing: " + data);
                        // Write to the JSON script when ready.
                        sw.Write(jp.Serialize());
                        // Close streams.
                        sw.Flush();
                        sw.Close();
                    }
                    s.Flush();
                    s.Close();
                }

                HttpWebResponse wr = (HttpWebResponse)request.GetResponse();
            } catch (WebException e) {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("[ERROR] ");
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine(e.Message);

                string messageBody = String.Empty;
                using (StreamReader sw = new StreamReader(e.Response.GetResponseStream())) {
                    messageBody = sw.ReadToEnd();
                }
                Console.WriteLine("[MESSAGE BODY] " + messageBody);

                return false;
            }

            return true;
        }
 protected override JsonPacket OnCreate(JsonPacket jsonPacket)
 {
     jsonPacket.Project = this.project;
     return base.OnCreate(jsonPacket);
 }
Exemple #34
0
 /// <summary>
 /// Called when the <see cref="JsonPacket"/> has been created. Can be overridden to
 /// adjust the values of the <paramref name="jsonPacket"/> before it is sent to Sentry.
 /// </summary>
 /// <param name="jsonPacket">The json packet.</param>
 /// <returns>
 /// The <see cref="JsonPacket"/>.
 /// </returns>
 protected virtual JsonPacket OnCreate(JsonPacket jsonPacket)
 {
     return(jsonPacket);
 }
Exemple #35
0
        public bool Send(JsonPacket jp, DSN dsn)
        {
            //try
            {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(dsn.SentryURI);
                request.Method = "POST";
                request.Accept = "application/json";
                request.ContentType = "application/json; charset=utf-8";
                request.Headers.Add("X-Sentry-Auth", PacketBuilder.CreateAuthenticationHeader(dsn));
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
                request.UserAgent = "RavenSharp/1.0";
                request.Timeout = 2000;

                //Console.WriteLine("Header: " + PacketBuilder.CreateAuthenticationHeader(dsn));
                //Console.WriteLine("Packet: " + jp.Serialize());

                // Write the messagebody.
                using (Stream s = request.GetRequestStream())
                {
                    string data = jp.Serialize();
                    if (LogScrubber != null)
                        data = LogScrubber.Scrub(data);
                    byte[] byteArray = Encoding.UTF8.GetBytes(data);

                    s.Write(byteArray, 0, byteArray.Length);
                }

                using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
                {
                }

            }/*
            catch (WebException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("[ERROR] ");
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine(e.Message);

                if (e.Response != null)
                {
                    string messageBody = String.Empty;
                    using (StreamReader sw = new StreamReader(e.Response.GetResponseStream()))
                    {
                        messageBody = sw.ReadToEnd();
                    }
                    Console.WriteLine("[MESSAGE BODY] " + messageBody);
                }

                return false;
            }*/

            return true;
        }
        /// <summary>
        /// Captures the exception.
        /// </summary>
        /// <param name="e">The <see cref="Exception" /> to capture.</param>
        /// <param name="tags">The tags to annotate the captured exception with.</param>
        /// <param name="extra">The extra metadata to send with the captured exception.</param>
        /// <returns>
        /// The <see cref="JsonPacket.EventID"/> of the successfully captured <see cref="Exception"/>, or <c>null</c> if it fails.
        /// </returns>
        public string CaptureException(Exception e, IDictionary<string, string> tags = null, object extra = null)
        {
            JsonPacket packet = new JsonPacket(CurrentDsn.ProjectID, e)
            {
                Level = ErrorLevel.Error,
                Tags = tags,
                Extra = extra
            };

            return Send(packet, CurrentDsn);
        }
 protected override string Send(JsonPacket packet, Dsn dsn)
 {
     return packet.Project;
 }
        /// <summary>
        /// Sends the specified packet to Sentry.
        /// </summary>
        /// <param name="packet">The packet to send.</param>
        /// <param name="dsn">The Data Source Name in Sentry.</param>
        /// <returns>
        /// The <see cref="JsonPacket.EventID"/> of the successfully captured JSON packet, or <c>null</c> if it fails.
        /// </returns>
        private string Send(JsonPacket packet, Dsn dsn)
        {
            packet.Logger = Logger;

            try
            {
                HttpWebRequest request = (HttpWebRequest) WebRequest.Create(dsn.SentryUri);
                request.Method = "POST";
                request.Accept = "application/json";
                request.ContentType = "application/json; charset=utf-8";
                request.Headers.Add("X-Sentry-Auth", PacketBuilder.CreateAuthenticationHeader(dsn));
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
                request.UserAgent = PacketBuilder.UserAgent;

                // Write the messagebody.
                using (Stream s = request.GetRequestStream())
                {
                    using (StreamWriter sw = new StreamWriter(s))
                    {
                        // Compress and encode.
                        //string data = Utilities.GzipUtil.CompressEncode(packet.Serialize());
                        //Console.WriteLine("Writing: " + data);
                        // Write to the JSON script when ready.
                        string data = packet.ToString();
                        if (LogScrubber != null)
                            data = LogScrubber.Scrub(data);

                        sw.Write(data);
                    }
                }

                using (HttpWebResponse wr = (HttpWebResponse) request.GetResponse())
                {
                    using (Stream responseStream = wr.GetResponseStream())
                    {
                        if (responseStream == null)
                            return null;

                        using (StreamReader sr = new StreamReader(responseStream))
                        {
                            string content = sr.ReadToEnd();
                            var response = JsonConvert.DeserializeObject<dynamic>(content);
                            return response.id;
                        }
                    }
                }
            }
            catch (WebException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("[ERROR] ");
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine(e);

                if (e.Response != null)
                {
                    string messageBody;
                    using (Stream stream = e.Response.GetResponseStream())
                    {
                        if (stream == null)
                            return null;

                        using (StreamReader sw = new StreamReader(stream))
                        {
                            messageBody = sw.ReadToEnd();
                        }
                    }

                    Console.WriteLine("[MESSAGE BODY] " + messageBody);
                }

                return null;
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("[ERROR] ");
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine(e);

                return null;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RequestData"/> class.
 /// </summary>
 /// <param name="packet">The JsonPacket to send with the request</param>
 /// <param name="logScrubber">The log scrubber to use, if any.</param>
 internal RequestData(JsonPacket packet, IScrubber logScrubber)
 {
     JsonPacket  = packet ?? throw new ArgumentNullException(nameof(packet));
     LogScrubber = logScrubber;
 }