Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RavenClient"/> class.
        /// </summary>
        /// <param name="dsn">The Data Source Name in Sentry.</param>
        public RavenClient(Dsn dsn)
        {
            if (dsn == null)
                throw new ArgumentNullException("dsn");

            this.currentDsn = dsn;
            Logger = "root";
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RavenClient" /> class.
        /// </summary>
        /// <param name="dsn">The Data Source Name in Sentry.</param>
        /// <param name="jsonPacketFactory">The optional factory that will be used to create the <see cref="JsonPacket" /> that will be sent to Sentry.</param>
        /// <exception cref="System.ArgumentNullException">dsn</exception>
        public RavenClient(Dsn dsn, IJsonPacketFactory jsonPacketFactory = null)
        {
            if (dsn == null)
                throw new ArgumentNullException("dsn");

            this.currentDsn = dsn;
            this.jsonPacketFactory = jsonPacketFactory ?? new JsonPacketFactory();
            Logger = "root";
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SharpRaven.RavenClient" /> class.
 /// </summary>
 /// <param name="dsn">The Data Source Name in Sentry.</param>
 /// <param name="backgroundSending">Whether to send events in the background or not.</param>
 /// <param name="jsonPacketFactory">The optional factory that will be used to create the <see cref="T:SharpRaven.Data.JsonPacket" /> that will be sent to Sentry.</param>
 /// <param name="sentryRequestFactory">The optional factory that will be used to create the <see cref="T:SharpRaven.Data.SentryRequest" /> that will be sent to Sentry.</param>
 /// <param name="sentryUserFactory">The optional factory that will be used to create the <see cref="T:SharpRaven.Data.SentryUser" /> that will be sent to Sentry.</param>
 /// <inheritdoc />
 public RavenClient(Dsn dsn,
                    bool backgroundSending,
                    IJsonPacketFactory jsonPacketFactory       = null,
                    ISentryRequestFactory sentryRequestFactory = null,
                    ISentryUserFactory sentryUserFactory       = null)
     : this(
         dsn,
         jsonPacketFactory,
         sentryRequestFactory,
         sentryUserFactory,
         backgroundSending
             ? new BackgroundRequesterFactory(new HttpRequesterFactory())
             : new HttpRequesterFactory() as IRequesterFactory)
 {
     // Lifetime of RequesterFactory owned by this instance, make sure to dispose it.
     this.disposeRequesterFactory = backgroundSending;
 }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RavenClient" /> class.
        /// </summary>
        /// <param name="dsn">The Data Source Name in Sentry.</param>
        /// <param name="jsonPacketFactory">The optional factory that will be used to create the <see cref="JsonPacket" /> that will be sent to Sentry.</param>
        /// <param name="sentryRequestFactory">The optional factory that will be used to create the <see cref="SentryRequest"/> that will be sent to Sentry.</param>
        /// <param name="sentryUserFactory">The optional factory that will be used to create the <see cref="SentryUser"/> that will be sent to Sentry.</param>
        /// <exception cref="System.ArgumentNullException">dsn</exception>
        public RavenClient(Dsn dsn,
                           IJsonPacketFactory jsonPacketFactory       = null,
                           ISentryRequestFactory sentryRequestFactory = null,
                           ISentryUserFactory sentryUserFactory       = null)
        {
            if (dsn == null)
            {
                throw new ArgumentNullException("dsn");
            }

            this.currentDsn           = dsn;
            this.jsonPacketFactory    = jsonPacketFactory ?? new JsonPacketFactory();
            this.sentryRequestFactory = sentryRequestFactory ?? new SentryRequestFactory();
            this.sentryUserFactory    = sentryUserFactory ?? new SentryUserFactory();

            Logger           = "root";
            Timeout          = TimeSpan.FromSeconds(5);
            this.defaultTags = new Dictionary <string, string>();
        }
Beispiel #5
0
        private IEnumerator SendAsync(Dsn dsn, string data, string[] headers)
        {
            var www = _wwwPool.Take();

            www.InitWWW(dsn.SentryURI, _encoding.GetBytes(data), headers);

            while (!www.isDone)
            {
                yield return(null);
            }

//            if (!string.IsNullOrEmpty(www.error)) {
//                Debug.LogError("Failed to send error to Sentry: " + www.error);
//            }
//            else {
//                Debug.Log("Sentry response: " + www.text);
//            }

            _wwwPool.Return(www);
        }
Beispiel #6
0
        /// <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;
            }
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NoOpRavenClient" /> class.
 /// </summary>
 public NoOpRavenClient()
 {
     currentDsn  = new Dsn("http://sentry-dsn.invalid");
     defaultTags = new Dictionary <string, string>();
 }
Beispiel #8
0
        /// <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>
        protected virtual 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.Headers.Add("X-Sentry-Auth", PacketBuilder.CreateAuthenticationHeader(dsn));
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

                // Added to disable self signed certificate
                ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);

                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);*/

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

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

                // Write the messagebody.
                using (Stream s = request.GetRequestStream())
                {
                    if (Compression)
                    {
                        GzipUtil.Write(data, s);
                    }
                    else
                    {
                        using (StreamWriter sw = new StreamWriter(s))
                            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 (Exception exception)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("[ERROR] ");
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine(exception);

                WebException webException = exception as WebException;
                if (webException != null && webException.Response != null)
                {
                    string messageBody;
                    using (Stream stream = webException.Response.GetResponseStream())
                    {
                        if (stream == null)
                        {
                            return(null);
                        }

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

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

            return(null);
        }
Beispiel #9
0
        /// <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>
        protected virtual string Send(JsonPacket packet, Dsn dsn)
        {
            packet.Logger = Logger;

            var request = (HttpWebRequest)WebRequest.Create(dsn.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(dsn));
            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);*/

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

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

            // Write the messagebody.
            using (Stream s = request.GetRequestStream())
            {
                if (Compression)
                {
                    GzipUtil.Write(data, s);
                }
                else
                {
                    using (StreamWriter sw = new StreamWriter(s))
                        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);
                    }
                }
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RavenClient" /> class.
        /// </summary>
        /// <param name="dsn">The Data Source Name in Sentry.</param>
        /// <param name="jsonPacketFactory">The optional factory that will be used to create the <see cref="JsonPacket" /> that will be sent to Sentry.</param>
        /// <param name="sentryRequestFactory">The optional factory that will be used to create the <see cref="SentryRequest"/> that will be sent to Sentry.</param>
        /// <param name="sentryUserFactory">The optional factory that will be used to create the <see cref="SentryUser"/> that will be sent to Sentry.</param>
        /// <exception cref="System.ArgumentNullException">dsn</exception>
        public RavenClient(Dsn dsn,
            IJsonPacketFactory jsonPacketFactory = null,
            ISentryRequestFactory sentryRequestFactory = null,
            ISentryUserFactory sentryUserFactory = null)
        {
            if (dsn == null)
                throw new ArgumentNullException("dsn");

            this.currentDsn = dsn;
            this.jsonPacketFactory = jsonPacketFactory ?? new JsonPacketFactory();
            this.sentryRequestFactory = sentryRequestFactory ?? new SentryRequestFactory();
            this.sentryUserFactory = sentryUserFactory ?? new SentryUserFactory();

            Logger = "root";
            Timeout = TimeSpan.FromSeconds(5);
            this.defaultTags = new Dictionary<string, string>();
        }
Beispiel #11
0
        /// <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>
        protected virtual 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.Headers.Add("X-Sentry-Auth", PacketBuilder.CreateAuthenticationHeader(dsn));
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
                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);*/

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

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

                // Write the messagebody.
                using (Stream s = request.GetRequestStream())
                {
                    if (Compression)
                        GzipUtil.Write(data, s);
                    else
                    {
                        using (StreamWriter sw = new StreamWriter(s))
                            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 (Exception exception)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("[ERROR] ");
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine(exception);

                WebException webException = exception as WebException;
                if (webException != null && webException.Response != null)
                {
                    string messageBody;
                    using (Stream stream = webException.Response.GetResponseStream())
                    {
                        if (stream == null)
                            return null;

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

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

            return null;
        }
 public EventSourceRavenClient(Dsn dsn)
     : this(dsn, new EventEntryJsonPacketFactory())
 {
 }
 public EventSourceRavenClient(Dsn dsn, IEventEntryJsonPacketFactory eventEntryJsonPacketFactory)
     : base(dsn)
 {
     _packetFactory = eventEntryJsonPacketFactory;
 }
Beispiel #14
0
        /// <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>
        protected virtual string Send(JsonPacket packet, Dsn dsn)
        {
            packet.Logger = Logger;

            var request = (HttpWebRequest) WebRequest.Create(dsn.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(dsn));
            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);*/

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

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

            // Write the messagebody.
            using (Stream s = request.GetRequestStream())
            {
                if (Compression)
                    GzipUtil.Write(data, s);
                else
                {
                    using (StreamWriter sw = new StreamWriter(s))
                        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;
                }
            }
        }