From 0b1be045860e9aa639ee4d7ffb5b28664cdb25bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saulius=20Menkevi=C4=8Dius?= Date: Wed, 7 Mar 2018 07:29:12 +0200 Subject: [PATCH] Add NoOpRavenClient, an empty (no-op) empty implementation of IRavenClient. --- src/app/SharpRaven/NoOpRavenClient.Net45.cs | 113 +++++++++ src/app/SharpRaven/NoOpRavenClient.cs | 239 ++++++++++++++++++++ 2 files changed, 352 insertions(+) create mode 100644 src/app/SharpRaven/NoOpRavenClient.Net45.cs create mode 100644 src/app/SharpRaven/NoOpRavenClient.cs diff --git a/src/app/SharpRaven/NoOpRavenClient.Net45.cs b/src/app/SharpRaven/NoOpRavenClient.Net45.cs new file mode 100644 index 00000000..b73e137f --- /dev/null +++ b/src/app/SharpRaven/NoOpRavenClient.Net45.cs @@ -0,0 +1,113 @@ +#region License + +// Copyright (c) 2014 The Sentry Team and individual contributors. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are permitted +// provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list of +// conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// 3. Neither the name of the Sentry nor the names of its contributors may be used to +// endorse or promote products derived from this software without specific prior written +// permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#endregion + +#if !(net40) && !(net35) + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +using SharpRaven.Data; + +namespace SharpRaven +{ + /// + /// Empty (no-op) implementation for the Raven Client for use in dependency injection + /// and other places when a silent operation is needed. + /// + public partial class NoOpRavenClient + { + /// Captures the event. + /// The event. + /// + /// The of the successfully captured , or null if it fails. + /// + public async Task CaptureAsync(SentryEvent @event) + { + return await Task.FromResult(Guid.NewGuid().ToString("n")); + } + + + /// + /// Captures the . + /// + /// The to capture. + /// The optional message to capture. Default: . + /// The of the captured . Default: . + /// The tags to annotate the captured with. + /// The custom fingerprint to annotate the captured with. + /// The extra metadata to send with the captured . + /// + /// The of the successfully captured , or null if it fails. + /// + [Obsolete("Use CaptureAsync(SentryEvent) instead.")] + public async Task CaptureExceptionAsync(Exception exception, + SentryMessage message = null, + ErrorLevel level = ErrorLevel.Error, + IDictionary tags = null, + string[] fingerprint = null, + object extra = null) + { + return await Task.FromResult(Guid.NewGuid().ToString("n")); + } + + + /// + /// Captures the message. + /// + /// The message to capture. + /// The of the captured . Default . + /// The tags to annotate the captured with. + /// The custom fingerprint to annotate the captured with. + /// The extra metadata to send with the captured . + /// + /// The of the successfully captured , or null if it fails. + /// + [Obsolete("Use CaptureAsync(SentryEvent) instead.")] + public async Task CaptureMessageAsync(SentryMessage message, + ErrorLevel level = ErrorLevel.Info, + IDictionary tags = null, + string[] fingerprint = null, + object extra = null) + { + return await Task.FromResult(Guid.NewGuid().ToString("n")); + } + + /// Sends the specified user feedback to Sentry + /// An empty string if succesful, otherwise the server response + /// The user feedback to send + public async Task SendUserFeedbackAsync(SentryUserFeedback feedback) + { + return await Task.FromResult(string.Empty); + } + } +} + +#endif diff --git a/src/app/SharpRaven/NoOpRavenClient.cs b/src/app/SharpRaven/NoOpRavenClient.cs new file mode 100644 index 00000000..adb90224 --- /dev/null +++ b/src/app/SharpRaven/NoOpRavenClient.cs @@ -0,0 +1,239 @@ +#region License + +// Copyright (c) 2014 The Sentry Team and individual contributors. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are permitted +// provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list of +// conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// 3. Neither the name of the Sentry nor the names of its contributors may be used to +// endorse or promote products derived from this software without specific prior written +// permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#endregion + +using System; +using System.Collections.Generic; +using SharpRaven.Data; +using SharpRaven.Logging; + +namespace SharpRaven +{ + /// + /// Empty (no-op) implementation for the Raven Client for use in dependency injection + /// and other places when a silent operation is needed. + /// + public partial class NoOpRavenClient : IRavenClient + { + private readonly Dsn currentDsn; + private readonly IDictionary defaultTags; + + /// + /// Initializes a new instance of the class. + /// + public NoOpRavenClient() + { + currentDsn = new Dsn("http://sentry-dsn.invalid"); + defaultTags = new Dictionary(); + } + + /// + /// Gets or sets the to execute to manipulate or extract data from + /// the object before it is used in the method. + /// + /// + /// The to execute to manipulate or extract data from the + /// object before it is used in the method. + /// + public Func BeforeSend { get; set; } + + /// + /// Gets or sets the to execute if an error occurs when executing + /// . + /// + /// + /// The to execute if an error occurs when executing . + /// + public Action ErrorOnCapture { get; set; } + + /// + /// Enable Gzip Compression? + /// Defaults to false. + /// + public bool Compression { get; set; } + + /// + /// The Dsn currently being used to log exceptions. + /// + public Dsn CurrentDsn + { + get { return currentDsn; } + } + + /// + /// Interface for providing a 'log scrubber' that removes + /// sensitive information from exceptions sent to sentry. + /// + public IScrubber LogScrubber { get; set; } + + /// + /// The name of the logger. The default logger name is "root". + /// + public string Logger { get; set; } + + /// + /// The version of the application. + /// + public string Release { get; set; } + + /// + /// The environment (e.g. production) + /// + public string Environment { get; set; } + + /// + /// Default tags sent on all events. + /// + public IDictionary Tags + { + get { return this.defaultTags; } + } + + /// + /// Gets or sets the timeout value in milliseconds for the HTTP communication with Sentry. + /// + /// + /// The number of milliseconds to wait before the request times out. The default is 5,000 milliseconds (5 seconds). + /// + public TimeSpan Timeout { get; set; } + + /// + /// Not register the for tracking. + /// + public bool IgnoreBreadcrumbs { get; set; } + + + /// + /// Captures the last 100 . + /// + /// The to capture. + public void AddTrail(Breadcrumb breadcrumb) + { + } + + + /// + /// Restart the capture of the for tracking. + /// + public void RestartTrails() + { + } + + + /// Captures the specified . + /// The event to capture. + /// + /// The of the successfully captured , or null if it fails. + /// + public string Capture(SentryEvent @event) + { + return Guid.NewGuid().ToString("n"); + } + + + /// + /// Captures the event. + /// + /// The to capture. + /// + [Obsolete("Use CaptureException() instead.", true)] + public string CaptureEvent(Exception e) + { + return CaptureException(e); + } + + + /// + /// Captures the event. + /// + /// The to capture. + /// The tags to annotate the captured exception with. + /// + [Obsolete("Use CaptureException() instead.", true)] + public string CaptureEvent(Exception e, Dictionary tags) + { + return CaptureException(e, tags : tags); + } + + + /// + /// Captures the . + /// + /// The to capture. + /// The optional message to capture. Default: . + /// The of the captured . Default: . + /// The tags to annotate the captured with. + /// The custom fingerprint to annotate the captured with. + /// The extra metadata to send with the captured . + /// + /// The of the successfully captured , or null if it fails. + /// + [Obsolete("Use Capture(SentryEvent) instead")] + public string CaptureException(Exception exception, + SentryMessage message = null, + ErrorLevel level = ErrorLevel.Error, + IDictionary tags = null, + string[] fingerprint = null, + object extra = null) + { + return Guid.NewGuid().ToString("n"); + } + + + /// + /// Captures the message. + /// + /// The message to capture. + /// The of the captured . Default . + /// The tags to annotate the captured with. + /// The custom fingerprint to annotate the captured with. + /// The extra metadata to send with the captured . + /// + /// The of the successfully captured , or null if it fails. + /// + [Obsolete("Use Capture(SentryEvent) instead")] + public string CaptureMessage(SentryMessage message, + ErrorLevel level = ErrorLevel.Info, + IDictionary tags = null, + string[] fingerprint = null, + object extra = null) + { + return Guid.NewGuid().ToString("n"); + } + + + /// Sends the specified user feedback to Sentry + /// An empty string if succesful, otherwise the server response + /// The user feedback to send + public string SendUserFeedback(SentryUserFeedback feedback) + { + return string.Empty; + } + } +}