|
| 1 | +#region License |
| 2 | + |
| 3 | +// Copyright (c) 2014 The Sentry Team and individual contributors. |
| 4 | +// All rights reserved. |
| 5 | +// |
| 6 | +// Redistribution and use in source and binary forms, with or without modification, are permitted |
| 7 | +// provided that the following conditions are met: |
| 8 | +// |
| 9 | +// 1. Redistributions of source code must retain the above copyright notice, this list of |
| 10 | +// conditions and the following disclaimer. |
| 11 | +// |
| 12 | +// 2. Redistributions in binary form must reproduce the above copyright notice, this list of |
| 13 | +// conditions and the following disclaimer in the documentation and/or other materials |
| 14 | +// provided with the distribution. |
| 15 | +// |
| 16 | +// 3. Neither the name of the Sentry nor the names of its contributors may be used to |
| 17 | +// endorse or promote products derived from this software without specific prior written |
| 18 | +// permission. |
| 19 | +// |
| 20 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR |
| 21 | +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 22 | +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 23 | +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 | +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 27 | +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | + |
| 29 | +#endregion |
| 30 | + |
| 31 | +using System; |
| 32 | +using System.Collections.Generic; |
| 33 | +using SharpRaven.Data; |
| 34 | +using SharpRaven.Logging; |
| 35 | + |
| 36 | +namespace SharpRaven |
| 37 | +{ |
| 38 | + /// <summary> |
| 39 | + /// Empty (no-op) implementation for the Raven Client for use in dependency injection |
| 40 | + /// and other places when a silent operation is needed. |
| 41 | + /// </summary> |
| 42 | + public partial class NoOpRavenClient : IRavenClient |
| 43 | + { |
| 44 | + private readonly Dsn currentDsn; |
| 45 | + private readonly IDictionary<string, string> defaultTags; |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// Initializes a new instance of the <see cref="NoOpRavenClient" /> class. |
| 49 | + /// </summary> |
| 50 | + public NoOpRavenClient() |
| 51 | + { |
| 52 | + currentDsn = new Dsn("http://sentry-dsn.invalid"); |
| 53 | + defaultTags = new Dictionary<string, string>(); |
| 54 | + } |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// Gets or sets the <see cref="Action"/> to execute to manipulate or extract data from |
| 58 | + /// the <see cref="Requester"/> object before it is used in the <see cref="Send"/> method. |
| 59 | + /// </summary> |
| 60 | + /// <value> |
| 61 | + /// The <see cref="Action"/> to execute to manipulate or extract data from the |
| 62 | + /// <see cref="Requester"/> object before it is used in the <see cref="Send"/> method. |
| 63 | + /// </value> |
| 64 | + public Func<Requester, Requester> BeforeSend { get; set; } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Gets or sets the <see cref="Action"/> to execute if an error occurs when executing |
| 68 | + /// <see cref="Capture"/>. |
| 69 | + /// </summary> |
| 70 | + /// <value> |
| 71 | + /// The <see cref="Action"/> to execute if an error occurs when executing <see cref="Capture"/>. |
| 72 | + /// </value> |
| 73 | + public Action<Exception> ErrorOnCapture { get; set; } |
| 74 | + |
| 75 | + /// <summary> |
| 76 | + /// Enable Gzip Compression? |
| 77 | + /// Defaults to <c>false</c>. |
| 78 | + /// </summary> |
| 79 | + public bool Compression { get; set; } |
| 80 | + |
| 81 | + /// <summary> |
| 82 | + /// The Dsn currently being used to log exceptions. |
| 83 | + /// </summary> |
| 84 | + public Dsn CurrentDsn |
| 85 | + { |
| 86 | + get { return currentDsn; } |
| 87 | + } |
| 88 | + |
| 89 | + /// <summary> |
| 90 | + /// Interface for providing a 'log scrubber' that removes |
| 91 | + /// sensitive information from exceptions sent to sentry. |
| 92 | + /// </summary> |
| 93 | + public IScrubber LogScrubber { get; set; } |
| 94 | + |
| 95 | + /// <summary> |
| 96 | + /// The name of the logger. The default logger name is "root". |
| 97 | + /// </summary> |
| 98 | + public string Logger { get; set; } |
| 99 | + |
| 100 | + /// <summary> |
| 101 | + /// The version of the application. |
| 102 | + /// </summary> |
| 103 | + public string Release { get; set; } |
| 104 | + |
| 105 | + /// <summary> |
| 106 | + /// The environment (e.g. production) |
| 107 | + /// </summary> |
| 108 | + public string Environment { get; set; } |
| 109 | + |
| 110 | + /// <summary> |
| 111 | + /// Default tags sent on all events. |
| 112 | + /// </summary> |
| 113 | + public IDictionary<string, string> Tags |
| 114 | + { |
| 115 | + get { return this.defaultTags; } |
| 116 | + } |
| 117 | + |
| 118 | + /// <summary> |
| 119 | + /// Gets or sets the timeout value in milliseconds for the HTTP communication with Sentry. |
| 120 | + /// </summary> |
| 121 | + /// <value> |
| 122 | + /// The number of milliseconds to wait before the request times out. The default is 5,000 milliseconds (5 seconds). |
| 123 | + /// </value> |
| 124 | + public TimeSpan Timeout { get; set; } |
| 125 | + |
| 126 | + /// <summary> |
| 127 | + /// Not register the <see cref="Breadcrumb"/> for tracking. |
| 128 | + /// </summary> |
| 129 | + public bool IgnoreBreadcrumbs { get; set; } |
| 130 | + |
| 131 | + |
| 132 | + /// <summary> |
| 133 | + /// Captures the last 100 <see cref="Breadcrumb" />. |
| 134 | + /// </summary> |
| 135 | + /// <param name="breadcrumb">The <see cref="Breadcrumb" /> to capture.</param> |
| 136 | + public void AddTrail(Breadcrumb breadcrumb) |
| 137 | + { |
| 138 | + } |
| 139 | + |
| 140 | + |
| 141 | + /// <summary> |
| 142 | + /// Restart the capture of the <see cref="Breadcrumb"/> for tracking. |
| 143 | + /// </summary> |
| 144 | + public void RestartTrails() |
| 145 | + { |
| 146 | + } |
| 147 | + |
| 148 | + |
| 149 | + /// <summary>Captures the specified <paramref name="event"/>.</summary> |
| 150 | + /// <param name="event">The event to capture.</param> |
| 151 | + /// <returns> |
| 152 | + /// The <see cref="JsonPacket.EventID" /> of the successfully captured <paramref name="event" />, or <c>null</c> if it fails. |
| 153 | + /// </returns> |
| 154 | + public string Capture(SentryEvent @event) |
| 155 | + { |
| 156 | + return Guid.NewGuid().ToString("n"); |
| 157 | + } |
| 158 | + |
| 159 | + |
| 160 | + /// <summary> |
| 161 | + /// Captures the event. |
| 162 | + /// </summary> |
| 163 | + /// <param name="e">The <see cref="Exception" /> to capture.</param> |
| 164 | + /// <returns></returns> |
| 165 | + [Obsolete("Use CaptureException() instead.", true)] |
| 166 | + public string CaptureEvent(Exception e) |
| 167 | + { |
| 168 | + return CaptureException(e); |
| 169 | + } |
| 170 | + |
| 171 | + |
| 172 | + /// <summary> |
| 173 | + /// Captures the event. |
| 174 | + /// </summary> |
| 175 | + /// <param name="e">The <see cref="Exception" /> to capture.</param> |
| 176 | + /// <param name="tags">The tags to annotate the captured exception with.</param> |
| 177 | + /// <returns></returns> |
| 178 | + [Obsolete("Use CaptureException() instead.", true)] |
| 179 | + public string CaptureEvent(Exception e, Dictionary<string, string> tags) |
| 180 | + { |
| 181 | + return CaptureException(e, tags : tags); |
| 182 | + } |
| 183 | + |
| 184 | + |
| 185 | + /// <summary> |
| 186 | + /// Captures the <see cref="Exception" />. |
| 187 | + /// </summary> |
| 188 | + /// <param name="exception">The <see cref="Exception" /> to capture.</param> |
| 189 | + /// <param name="message">The optional message to capture. Default: <see cref="Exception.Message" />.</param> |
| 190 | + /// <param name="level">The <see cref="ErrorLevel" /> of the captured <paramref name="exception" />. Default: <see cref="ErrorLevel.Error"/>.</param> |
| 191 | + /// <param name="tags">The tags to annotate the captured <paramref name="exception" /> with.</param> |
| 192 | + /// <param name="fingerprint">The custom fingerprint to annotate the captured <paramref name="message" /> with.</param> |
| 193 | + /// <param name="extra">The extra metadata to send with the captured <paramref name="exception" />.</param> |
| 194 | + /// <returns> |
| 195 | + /// The <see cref="JsonPacket.EventID" /> of the successfully captured <paramref name="exception" />, or <c>null</c> if it fails. |
| 196 | + /// </returns> |
| 197 | + [Obsolete("Use Capture(SentryEvent) instead")] |
| 198 | + public string CaptureException(Exception exception, |
| 199 | + SentryMessage message = null, |
| 200 | + ErrorLevel level = ErrorLevel.Error, |
| 201 | + IDictionary<string, string> tags = null, |
| 202 | + string[] fingerprint = null, |
| 203 | + object extra = null) |
| 204 | + { |
| 205 | + return Guid.NewGuid().ToString("n"); |
| 206 | + } |
| 207 | + |
| 208 | + |
| 209 | + /// <summary> |
| 210 | + /// Captures the message. |
| 211 | + /// </summary> |
| 212 | + /// <param name="message">The message to capture.</param> |
| 213 | + /// <param name="level">The <see cref="ErrorLevel" /> of the captured <paramref name="message"/>. Default <see cref="ErrorLevel.Info"/>.</param> |
| 214 | + /// <param name="tags">The tags to annotate the captured <paramref name="message"/> with.</param> |
| 215 | + /// <param name="fingerprint">The custom fingerprint to annotate the captured <paramref name="message" /> with.</param> |
| 216 | + /// <param name="extra">The extra metadata to send with the captured <paramref name="message"/>.</param> |
| 217 | + /// <returns> |
| 218 | + /// The <see cref="JsonPacket.EventID"/> of the successfully captured <paramref name="message"/>, or <c>null</c> if it fails. |
| 219 | + /// </returns> |
| 220 | + [Obsolete("Use Capture(SentryEvent) instead")] |
| 221 | + public string CaptureMessage(SentryMessage message, |
| 222 | + ErrorLevel level = ErrorLevel.Info, |
| 223 | + IDictionary<string, string> tags = null, |
| 224 | + string[] fingerprint = null, |
| 225 | + object extra = null) |
| 226 | + { |
| 227 | + return Guid.NewGuid().ToString("n"); |
| 228 | + } |
| 229 | + |
| 230 | + |
| 231 | + /// <summary>Sends the specified user feedback to Sentry</summary> |
| 232 | + /// <returns>An empty string if succesful, otherwise the server response</returns> |
| 233 | + /// <param name="feedback">The user feedback to send</param> |
| 234 | + public string SendUserFeedback(SentryUserFeedback feedback) |
| 235 | + { |
| 236 | + return string.Empty; |
| 237 | + } |
| 238 | + } |
| 239 | +} |
0 commit comments