From 941d9dc294312c537401fec6e7ab0bc2520cda63 Mon Sep 17 00:00:00 2001 From: Stefan Jandl Date: Wed, 18 Oct 2023 12:39:46 +0200 Subject: [PATCH] Removed `WithScope` and `WithScopeAsync` (#2717) --- CHANGELOG.md | 23 +++ src/Sentry/Extensibility/DisabledHub.cs | 7 - src/Sentry/Extensibility/HubAdapter.cs | 33 ---- src/Sentry/ISentryScopeManager.cs | 14 -- src/Sentry/Internal/Hub.cs | 12 -- src/Sentry/Internal/IHubEx.cs | 4 - src/Sentry/Internal/IInternalScopeManager.cs | 5 - src/Sentry/Internal/SentryScopeManager.cs | 36 ----- src/Sentry/SentryScopeManagerExtensions.cs | 76 --------- src/Sentry/SentrySdk.cs | 69 -------- .../ApiApprovalTests.Run.Core3_1.verified.txt | 34 ---- ...piApprovalTests.Run.DotNet6_0.verified.txt | 34 ---- ...piApprovalTests.Run.DotNet7_0.verified.txt | 34 ---- .../ApiApprovalTests.Run.Net4_8.verified.txt | 34 ---- .../Extensibility/DisabledHubTests.cs | 12 -- .../Extensibility/HubAdapterTests.cs | 36 ----- test/Sentry.Tests/HubTests.cs | 86 ---------- test/Sentry.Tests/SentrySdkTests.cs | 147 ------------------ 18 files changed, 23 insertions(+), 673 deletions(-) delete mode 100644 src/Sentry/SentryScopeManagerExtensions.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 49dc171c0f..59dbfd549c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,29 @@ API Changes: - Reordered parameters for ther TransactionContext and SpanContext constructors. If you're constructing instances of these classes, you will need to adjust the order in which you pass parameters to these. ([#2696](https://github.com/getsentry/sentry-dotnet/pull/2696)) - The `DiagnosticLogger` signature for `LogError` and `LogFatal` changed to take the `exception` as the first parameter. That way it does no longer get mixed up with the TArgs. The `DiagnosticLogger` now also received an overload for `LogError` and `LogFatal` that accepts a message only. ([#2715](https://github.com/getsentry/sentry-dotnet/pull/2715)) - Integrate `sentry-native` as a static library in Native AOT builds to enable symbolication. ([2704](https://github.com/getsentry/sentry-dotnet/pull/2704)) +- The methods `WithScope` and `WithScopeAsync` have been removed. We discovered that these methods didn't work correctly in certain desktop contexts, especially when using a global scope. ([#2717](https://github.com/getsentry/sentry-dotnet/pull/2717)) + Replace your usage of `WithScope` with the overloads of the `Capture` methods: + - `SentrySdk.CaptureEvent(SentryEvent @event, Action scopeCallback)` + - `SentrySdk.CaptureMessage(string message, Action scopeCallback)` + - `SentrySdk.CaptureException(Exception exception, Action scopeCallback)` + + #### Before + ``` + SentrySdk.WithScope(scope => + { + // Configure your scope here + scope.SetTag("key", "value"); + SentrySdk.CaptureEvent(new SentryEvent()); // Capture the event with the configured scope + }); + ``` + #### After + ``` + SentrySdk.CaptureEvent(new SentryEvent(), scope => + { + // Configure your scope here + scope.SetTag("key", "value"); + }); + ``` - `ISpan` and `ITransaction` have been renamed to `ISpanTracer` and `ITransactionTracer`. You will need to update any references to these interfaces in your code to use the new interface names ([#2731](https://github.com/getsentry/sentry-dotnet/pull/2731)) ## Unreleased diff --git a/src/Sentry/Extensibility/DisabledHub.cs b/src/Sentry/Extensibility/DisabledHub.cs index 69695cdda7..a49397e533 100644 --- a/src/Sentry/Extensibility/DisabledHub.cs +++ b/src/Sentry/Extensibility/DisabledHub.cs @@ -41,13 +41,6 @@ public void ConfigureScope(Action configureScope) /// public IDisposable PushScope(TState state) => this; - /// - /// No-Op. - /// - public void WithScope(Action scopeCallback) - { - } - /// /// Returns a dummy transaction. /// diff --git a/src/Sentry/Extensibility/HubAdapter.cs b/src/Sentry/Extensibility/HubAdapter.cs index c842f14122..844e8231b7 100644 --- a/src/Sentry/Extensibility/HubAdapter.cs +++ b/src/Sentry/Extensibility/HubAdapter.cs @@ -59,15 +59,6 @@ public IDisposable PushScope() public IDisposable PushScope(TState state) => SentrySdk.PushScope(state); - /// - /// Forwards the call to . - /// - [Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage and CaptureException " + - "that provide a callback to a configurable scope.")] - [DebuggerStepThrough] - public void WithScope(Action scopeCallback) - => SentrySdk.WithScope(scopeCallback); - /// /// Forwards the call to . /// @@ -287,28 +278,4 @@ public Task FlushAsync(TimeSpan timeout) [EditorBrowsable(EditorBrowsableState.Never)] public void CaptureUserFeedback(UserFeedback sentryUserFeedback) => SentrySdk.CaptureUserFeedback(sentryUserFeedback); - - /// - /// Forwards the call to - /// - [Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage and CaptureException " + - "that provide a callback to a configurable scope.")] - public T? WithScope(Func scopeCallback) - => SentrySdk.WithScope(scopeCallback); - - /// - /// Forwards the call to - /// - [Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage and CaptureException " + - "that provide a callback to a configurable scope.")] - public Task WithScopeAsync(Func scopeCallback) - => SentrySdk.WithScopeAsync(scopeCallback); - - /// - /// Forwards the call to - /// - [Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage and CaptureException " + - "that provide a callback to a configurable scope.")] - public Task WithScopeAsync(Func> scopeCallback) - => SentrySdk.WithScopeAsync(scopeCallback); } diff --git a/src/Sentry/ISentryScopeManager.cs b/src/Sentry/ISentryScopeManager.cs index 9dce098e41..72456843b1 100644 --- a/src/Sentry/ISentryScopeManager.cs +++ b/src/Sentry/ISentryScopeManager.cs @@ -42,18 +42,4 @@ public interface ISentryScopeManager /// A disposable which removes the scope /// from the environment when invoked. IDisposable PushScope(TState state); - - /// - /// Runs the callback within a new scope. - /// - /// - /// Pushes a new scope, runs the callback, then pops the scope. Use this when you have significant work to - /// perform within an isolated scope. If you just need to configure scope for a single event, use the overloads - /// of CaptureEvent, CaptureMessage and CaptureException that provide a callback to a configurable scope. - /// - /// - /// The callback to run with the one time scope. - [Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage and CaptureException " + - "that provide a callback to a configurable scope.")] - void WithScope(Action scopeCallback); } diff --git a/src/Sentry/Internal/Hub.cs b/src/Sentry/Internal/Hub.cs index cf26404eed..7d34035bde 100644 --- a/src/Sentry/Internal/Hub.cs +++ b/src/Sentry/Internal/Hub.cs @@ -100,18 +100,6 @@ public async Task ConfigureScopeAsync(Func configureScope) public void RestoreScope(Scope savedScope) => ScopeManager.RestoreScope(savedScope); - [Obsolete] - public void WithScope(Action scopeCallback) => ScopeManager.WithScope(scopeCallback); - - [Obsolete] - public T? WithScope(Func scopeCallback) => ScopeManager.WithScope(scopeCallback); - - [Obsolete] - public Task WithScopeAsync(Func scopeCallback) => ScopeManager.WithScopeAsync(scopeCallback); - - [Obsolete] - public Task WithScopeAsync(Func> scopeCallback) => ScopeManager.WithScopeAsync(scopeCallback); - public void BindClient(ISentryClient client) => ScopeManager.BindClient(client); public ITransactionTracer StartTransaction( diff --git a/src/Sentry/Internal/IHubEx.cs b/src/Sentry/Internal/IHubEx.cs index 9a6b200a63..63410606b0 100644 --- a/src/Sentry/Internal/IHubEx.cs +++ b/src/Sentry/Internal/IHubEx.cs @@ -3,8 +3,4 @@ namespace Sentry.Internal; internal interface IHubEx : IHub { SentryId CaptureEventInternal(SentryEvent evt, Hint? hint, Scope? scope = null); - - T? WithScope(Func scopeCallback); - Task WithScopeAsync(Func scopeCallback); - Task WithScopeAsync(Func> scopeCallback); } diff --git a/src/Sentry/Internal/IInternalScopeManager.cs b/src/Sentry/Internal/IInternalScopeManager.cs index 796597b311..81398d1ec4 100644 --- a/src/Sentry/Internal/IInternalScopeManager.cs +++ b/src/Sentry/Internal/IInternalScopeManager.cs @@ -8,9 +8,4 @@ internal interface IInternalScopeManager : ISentryScopeManager, IDisposable void RestoreScope(Scope savedScope); IScopeStackContainer ScopeStackContainer { get; } - - // TODO: Move The following to ISentryScopeManager in a future major version. - T? WithScope(Func scopeCallback); - Task WithScopeAsync(Func scopeCallback); - Task WithScopeAsync(Func> scopeCallback); } diff --git a/src/Sentry/Internal/SentryScopeManager.cs b/src/Sentry/Internal/SentryScopeManager.cs index aab716c867..676c105eb5 100644 --- a/src/Sentry/Internal/SentryScopeManager.cs +++ b/src/Sentry/Internal/SentryScopeManager.cs @@ -107,42 +107,6 @@ public void RestoreScope(Scope savedScope) ScopeAndClientStack = newScopeAndClientStack; } - public void WithScope(Action scopeCallback) - { - using (PushScope()) - { - var (scope, _) = GetCurrent(); - scopeCallback.Invoke(scope); - } - } - - public T? WithScope(Func scopeCallback) - { - using (PushScope()) - { - var (scope, _) = GetCurrent(); - return scopeCallback.Invoke(scope); - } - } - - public async Task WithScopeAsync(Func scopeCallback) - { - using (PushScope()) - { - var (scope, _) = GetCurrent(); - await scopeCallback.Invoke(scope).ConfigureAwait(false); - } - } - - public async Task WithScopeAsync(Func> scopeCallback) - { - using (PushScope()) - { - var (scope, _) = GetCurrent(); - return await scopeCallback.Invoke(scope).ConfigureAwait(false); - } - } - public void BindClient(ISentryClient? client) { _options.LogDebug("Binding a new client to the current scope."); diff --git a/src/Sentry/SentryScopeManagerExtensions.cs b/src/Sentry/SentryScopeManagerExtensions.cs deleted file mode 100644 index 6f801a34d9..0000000000 --- a/src/Sentry/SentryScopeManagerExtensions.cs +++ /dev/null @@ -1,76 +0,0 @@ -using Sentry.Extensibility; -using Sentry.Internal; - -namespace Sentry; - -/// -/// Extension methods for . -/// -[EditorBrowsable(EditorBrowsableState.Never)] -public static class SentryScopeManagerExtensions -{ - /// - /// Runs the callback within a new scope. - /// - /// - /// Pushes a new scope, runs the callback, then pops the scope. Use this when you have significant work to - /// perform within an isolated scope. If you just need to configure scope for a single event, use the overloads - /// of CaptureEvent, CaptureMessage and CaptureException that provide a callback to a configurable scope. - /// - /// - /// The scope manager (usually the hub). - /// The callback to run with the one time scope. - /// The result from the callback. - [DebuggerStepThrough] - public static T? WithScope(this ISentryScopeManager scopeManager, Func scopeCallback) => - scopeManager switch - { - IHubEx hub => hub.WithScope(scopeCallback), - IInternalScopeManager manager => manager.WithScope(scopeCallback), - _ => default - }; - - /// - /// Runs the asynchronous callback within a new scope. - /// - /// - /// Asynchronous version of . - /// Pushes a new scope, runs the callback, then pops the scope. Use this when you have significant work to - /// perform within an isolated scope. If you just need to configure scope for a single event, use the overloads - /// of CaptureEvent, CaptureMessage and CaptureException that provide a callback to a configurable scope. - /// - /// - /// The scope manager (usually the hub). - /// The callback to run with the one time scope. - /// An async task to await the callback. - [DebuggerStepThrough] - public static Task WithScopeAsync(this ISentryScopeManager scopeManager, Func scopeCallback) => - scopeManager switch - { - IHubEx hub => hub.WithScopeAsync(scopeCallback), - IInternalScopeManager manager => manager.WithScopeAsync(scopeCallback), - _ => Task.CompletedTask - }; - - /// - /// Runs the asynchronous callback within a new scope. - /// - /// - /// Asynchronous version of . - /// Pushes a new scope, runs the callback, then pops the scope. Use this when you have significant work to - /// perform within an isolated scope. If you just need to configure scope for a single event, use the overloads - /// of CaptureEvent, CaptureMessage and CaptureException that provide a callback to a configurable scope. - /// - /// - /// The scope manager (usually the hub). - /// The callback to run with the one time scope. - /// An async task to await the result of the callback. - [DebuggerStepThrough] - public static Task WithScopeAsync(this ISentryScopeManager scopeManager, Func> scopeCallback) => - scopeManager switch - { - IHubEx hub => hub.WithScopeAsync(scopeCallback), - IInternalScopeManager manager => manager.WithScopeAsync(scopeCallback), - _ => Task.FromResult(default(T)) - }; -} diff --git a/src/Sentry/SentrySdk.cs b/src/Sentry/SentrySdk.cs index 980ce25231..4236e86943 100644 --- a/src/Sentry/SentrySdk.cs +++ b/src/Sentry/SentrySdk.cs @@ -321,75 +321,6 @@ public void Dispose() public static void AddBreadcrumb(Breadcrumb breadcrumb, Hint? hint = null) => CurrentHub.AddBreadcrumb(breadcrumb, hint); - /// - /// Runs the callback within a new scope. - /// - /// - /// Pushes a new scope, runs the callback, then pops the scope. Use this when you have significant work to - /// perform within an isolated scope. If you just need to configure scope for a single event, use the overloads - /// of CaptureEvent, CaptureMessage and CaptureException that provide a callback to a configurable scope. - /// - /// - /// The callback to run with the one time scope. - [Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage and CaptureException " + - "that provide a callback to a configurable scope.")] - [DebuggerStepThrough] - public static void WithScope(Action scopeCallback) - => CurrentHub.WithScope(scopeCallback); - - /// - /// Runs the callback within a new scope. - /// - /// - /// Pushes a new scope, runs the callback, then pops the scope. Use this when you have significant work to - /// perform within an isolated scope. If you just need to configure scope for a single event, use the overloads - /// of CaptureEvent, CaptureMessage and CaptureException that provide a callback to a configurable scope. - /// - /// - /// The callback to run with the one time scope. - /// The result from the callback. - [Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage and CaptureException " + - "that provide a callback to a configurable scope.")] - [DebuggerStepThrough] - public static T? WithScope(Func scopeCallback) - => CurrentHub is IHubEx hub ? hub.WithScope(scopeCallback) : default; - - /// - /// Runs the asynchronous callback within a new scope. - /// - /// - /// Asynchronous version of . - /// Pushes a new scope, runs the callback, then pops the scope. Use this when you have significant work to - /// perform within an isolated scope. If you just need to configure scope for a single event, use the overloads - /// of CaptureEvent, CaptureMessage and CaptureException that provide a callback to a configurable scope. - /// - /// - /// The callback to run with the one time scope. - /// An async task to await the callback. - [Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage and CaptureException " + - "that provide a callback to a configurable scope.")] - [DebuggerStepThrough] - public static Task WithScopeAsync(Func scopeCallback) - => CurrentHub is IHubEx hub ? hub.WithScopeAsync(scopeCallback) : Task.CompletedTask; - - /// - /// Runs the asynchronous callback within a new scope. - /// - /// - /// Asynchronous version of . - /// Pushes a new scope, runs the callback, then pops the scope. Use this when you have significant work to - /// perform within an isolated scope. If you just need to configure scope for a single event, use the overloads - /// of CaptureEvent, CaptureMessage and CaptureException that provide a callback to a configurable scope. - /// - /// - /// The callback to run with the one time scope. - /// An async task to await the result of the callback. - [Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage and CaptureException " + - "that provide a callback to a configurable scope.")] - [DebuggerStepThrough] - public static Task WithScopeAsync(Func> scopeCallback) - => CurrentHub is IHubEx hub ? hub.WithScopeAsync(scopeCallback) : Task.FromResult(default(T)); - /// /// Configures the scope through the callback. /// diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt index 32d952ff20..67c161dcf4 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt @@ -261,9 +261,6 @@ namespace Sentry System.Threading.Tasks.Task ConfigureScopeAsync(System.Func configureScope); System.IDisposable PushScope(); System.IDisposable PushScope(TState state); - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - void WithScope(System.Action scopeCallback); } public interface ISentryScopeStateProcessor { @@ -718,12 +715,6 @@ namespace Sentry where TProcessor : Sentry.Extensibility.ISentryTransactionProcessor { } public static Sentry.SentryOptions UseStackTraceFactory(this Sentry.SentryOptions options, Sentry.Extensibility.ISentryStackTraceFactory sentryStackTraceFactory) { } } - public static class SentryScopeManagerExtensions - { - public static T? WithScope(this Sentry.ISentryScopeManager scopeManager, System.Func scopeCallback) { } - public static System.Threading.Tasks.Task WithScopeAsync(this Sentry.ISentryScopeManager scopeManager, System.Func scopeCallback) { } - public static System.Threading.Tasks.Task WithScopeAsync(this Sentry.ISentryScopeManager scopeManager, System.Func> scopeCallback) { } - } public static class SentrySdk { public static bool IsEnabled { get; } @@ -776,18 +767,6 @@ namespace Sentry public static Sentry.ITransactionTracer StartTransaction(string name, string operation) { } public static Sentry.ITransactionTracer StartTransaction(string name, string operation, Sentry.SentryTraceHeader traceHeader) { } public static Sentry.ITransactionTracer StartTransaction(string name, string operation, string? description) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static void WithScope(System.Action scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static T? WithScope(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static System.Threading.Tasks.Task WithScopeAsync(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static System.Threading.Tasks.Task WithScopeAsync(System.Func> scopeCallback) { } } public sealed class SentryStackFrame : Sentry.IJsonSerializable { @@ -1256,7 +1235,6 @@ namespace Sentry.Extensibility public void ResumeSession() { } public void StartSession() { } public Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary customSamplingContext) { } - public void WithScope(System.Action scopeCallback) { } } public class FormRequestPayloadExtractor : Sentry.Extensibility.BaseRequestPayloadExtractor { @@ -1297,18 +1275,6 @@ namespace Sentry.Extensibility public void ResumeSession() { } public void StartSession() { } public Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary customSamplingContext) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public void WithScope(System.Action scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public T? WithScope(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public System.Threading.Tasks.Task WithScopeAsync(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public System.Threading.Tasks.Task WithScopeAsync(System.Func> scopeCallback) { } } public interface IBackgroundWorker { diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt index 94e0ca01b6..3c08ffe293 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt @@ -261,9 +261,6 @@ namespace Sentry System.Threading.Tasks.Task ConfigureScopeAsync(System.Func configureScope); System.IDisposable PushScope(); System.IDisposable PushScope(TState state); - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - void WithScope(System.Action scopeCallback); } public interface ISentryScopeStateProcessor { @@ -719,12 +716,6 @@ namespace Sentry where TProcessor : Sentry.Extensibility.ISentryTransactionProcessor { } public static Sentry.SentryOptions UseStackTraceFactory(this Sentry.SentryOptions options, Sentry.Extensibility.ISentryStackTraceFactory sentryStackTraceFactory) { } } - public static class SentryScopeManagerExtensions - { - public static T? WithScope(this Sentry.ISentryScopeManager scopeManager, System.Func scopeCallback) { } - public static System.Threading.Tasks.Task WithScopeAsync(this Sentry.ISentryScopeManager scopeManager, System.Func scopeCallback) { } - public static System.Threading.Tasks.Task WithScopeAsync(this Sentry.ISentryScopeManager scopeManager, System.Func> scopeCallback) { } - } public static class SentrySdk { public static bool IsEnabled { get; } @@ -777,18 +768,6 @@ namespace Sentry public static Sentry.ITransactionTracer StartTransaction(string name, string operation) { } public static Sentry.ITransactionTracer StartTransaction(string name, string operation, Sentry.SentryTraceHeader traceHeader) { } public static Sentry.ITransactionTracer StartTransaction(string name, string operation, string? description) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static void WithScope(System.Action scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static T? WithScope(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static System.Threading.Tasks.Task WithScopeAsync(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static System.Threading.Tasks.Task WithScopeAsync(System.Func> scopeCallback) { } } public sealed class SentryStackFrame : Sentry.IJsonSerializable { @@ -1257,7 +1236,6 @@ namespace Sentry.Extensibility public void ResumeSession() { } public void StartSession() { } public Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary customSamplingContext) { } - public void WithScope(System.Action scopeCallback) { } } public class FormRequestPayloadExtractor : Sentry.Extensibility.BaseRequestPayloadExtractor { @@ -1298,18 +1276,6 @@ namespace Sentry.Extensibility public void ResumeSession() { } public void StartSession() { } public Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary customSamplingContext) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public void WithScope(System.Action scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public T? WithScope(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public System.Threading.Tasks.Task WithScopeAsync(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public System.Threading.Tasks.Task WithScopeAsync(System.Func> scopeCallback) { } } public interface IBackgroundWorker { diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet7_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet7_0.verified.txt index 94e0ca01b6..3c08ffe293 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet7_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet7_0.verified.txt @@ -261,9 +261,6 @@ namespace Sentry System.Threading.Tasks.Task ConfigureScopeAsync(System.Func configureScope); System.IDisposable PushScope(); System.IDisposable PushScope(TState state); - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - void WithScope(System.Action scopeCallback); } public interface ISentryScopeStateProcessor { @@ -719,12 +716,6 @@ namespace Sentry where TProcessor : Sentry.Extensibility.ISentryTransactionProcessor { } public static Sentry.SentryOptions UseStackTraceFactory(this Sentry.SentryOptions options, Sentry.Extensibility.ISentryStackTraceFactory sentryStackTraceFactory) { } } - public static class SentryScopeManagerExtensions - { - public static T? WithScope(this Sentry.ISentryScopeManager scopeManager, System.Func scopeCallback) { } - public static System.Threading.Tasks.Task WithScopeAsync(this Sentry.ISentryScopeManager scopeManager, System.Func scopeCallback) { } - public static System.Threading.Tasks.Task WithScopeAsync(this Sentry.ISentryScopeManager scopeManager, System.Func> scopeCallback) { } - } public static class SentrySdk { public static bool IsEnabled { get; } @@ -777,18 +768,6 @@ namespace Sentry public static Sentry.ITransactionTracer StartTransaction(string name, string operation) { } public static Sentry.ITransactionTracer StartTransaction(string name, string operation, Sentry.SentryTraceHeader traceHeader) { } public static Sentry.ITransactionTracer StartTransaction(string name, string operation, string? description) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static void WithScope(System.Action scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static T? WithScope(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static System.Threading.Tasks.Task WithScopeAsync(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static System.Threading.Tasks.Task WithScopeAsync(System.Func> scopeCallback) { } } public sealed class SentryStackFrame : Sentry.IJsonSerializable { @@ -1257,7 +1236,6 @@ namespace Sentry.Extensibility public void ResumeSession() { } public void StartSession() { } public Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary customSamplingContext) { } - public void WithScope(System.Action scopeCallback) { } } public class FormRequestPayloadExtractor : Sentry.Extensibility.BaseRequestPayloadExtractor { @@ -1298,18 +1276,6 @@ namespace Sentry.Extensibility public void ResumeSession() { } public void StartSession() { } public Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary customSamplingContext) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public void WithScope(System.Action scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public T? WithScope(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public System.Threading.Tasks.Task WithScopeAsync(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public System.Threading.Tasks.Task WithScopeAsync(System.Func> scopeCallback) { } } public interface IBackgroundWorker { diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt index 18d99fcdc4..8dd834a9c4 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt @@ -260,9 +260,6 @@ namespace Sentry System.Threading.Tasks.Task ConfigureScopeAsync(System.Func configureScope); System.IDisposable PushScope(); System.IDisposable PushScope(TState state); - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - void WithScope(System.Action scopeCallback); } public interface ISentryScopeStateProcessor { @@ -717,12 +714,6 @@ namespace Sentry where TProcessor : Sentry.Extensibility.ISentryTransactionProcessor { } public static Sentry.SentryOptions UseStackTraceFactory(this Sentry.SentryOptions options, Sentry.Extensibility.ISentryStackTraceFactory sentryStackTraceFactory) { } } - public static class SentryScopeManagerExtensions - { - public static T? WithScope(this Sentry.ISentryScopeManager scopeManager, System.Func scopeCallback) { } - public static System.Threading.Tasks.Task WithScopeAsync(this Sentry.ISentryScopeManager scopeManager, System.Func scopeCallback) { } - public static System.Threading.Tasks.Task WithScopeAsync(this Sentry.ISentryScopeManager scopeManager, System.Func> scopeCallback) { } - } public static class SentrySdk { public static bool IsEnabled { get; } @@ -775,18 +766,6 @@ namespace Sentry public static Sentry.ITransactionTracer StartTransaction(string name, string operation) { } public static Sentry.ITransactionTracer StartTransaction(string name, string operation, Sentry.SentryTraceHeader traceHeader) { } public static Sentry.ITransactionTracer StartTransaction(string name, string operation, string? description) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static void WithScope(System.Action scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static T? WithScope(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static System.Threading.Tasks.Task WithScopeAsync(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public static System.Threading.Tasks.Task WithScopeAsync(System.Func> scopeCallback) { } } public sealed class SentryStackFrame : Sentry.IJsonSerializable { @@ -1255,7 +1234,6 @@ namespace Sentry.Extensibility public void ResumeSession() { } public void StartSession() { } public Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary customSamplingContext) { } - public void WithScope(System.Action scopeCallback) { } } public class FormRequestPayloadExtractor : Sentry.Extensibility.BaseRequestPayloadExtractor { @@ -1296,18 +1274,6 @@ namespace Sentry.Extensibility public void ResumeSession() { } public void StartSession() { } public Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary customSamplingContext) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public void WithScope(System.Action scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public T? WithScope(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public System.Threading.Tasks.Task WithScopeAsync(System.Func scopeCallback) { } - [System.Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage a" + - "nd CaptureException that provide a callback to a configurable scope.")] - public System.Threading.Tasks.Task WithScopeAsync(System.Func> scopeCallback) { } } public interface IBackgroundWorker { diff --git a/test/Sentry.Tests/Extensibility/DisabledHubTests.cs b/test/Sentry.Tests/Extensibility/DisabledHubTests.cs index 6ec07f6d63..e56ff65370 100644 --- a/test/Sentry.Tests/Extensibility/DisabledHubTests.cs +++ b/test/Sentry.Tests/Extensibility/DisabledHubTests.cs @@ -27,18 +27,6 @@ public void CaptureEvent_EmptyGuid() [Fact] public void ConfigureScope_NoOp() => DisabledHub.Instance.ConfigureScope(null!); - [Fact] - public void WithScope_NoOp() => DisabledHub.Instance.WithScope(null!); - - [Fact] - public void WithScopeT_NoOp() => DisabledHub.Instance.WithScope(null!); - - [Fact] - public Task WithScopeAsync_NoOp() => DisabledHub.Instance.WithScopeAsync(null!); - - [Fact] - public Task WithScopeAsyncT_NoOp() => DisabledHub.Instance.WithScopeAsync(null!); - [Fact] public void BindClient_NoOp() => DisabledHub.Instance.BindClient(null!); diff --git a/test/Sentry.Tests/Extensibility/HubAdapterTests.cs b/test/Sentry.Tests/Extensibility/HubAdapterTests.cs index d0ba4de11a..dbb3b416ab 100644 --- a/test/Sentry.Tests/Extensibility/HubAdapterTests.cs +++ b/test/Sentry.Tests/Extensibility/HubAdapterTests.cs @@ -78,42 +78,6 @@ public void ConfigureScope_MockInvoked() Hub.Received(1).ConfigureScope(Expected); } - [Obsolete] - [Fact] - public void WithScope_MockInvoked() - { - void Expected(Scope _) { } - HubAdapter.Instance.WithScope(Expected); - Hub.Received(1).WithScope(Expected); - } - - [Obsolete] - [Fact] - public void WithScopeT_MockInvoked() - { - object Expected(Scope _) => null; - HubAdapter.Instance.WithScope(Expected); - Hub.Received(1).WithScope(Expected); - } - - [Obsolete] - [Fact] - public async Task WithScopeAsync_MockInvoked() - { - Task Expected(Scope _) => Task.CompletedTask; - await HubAdapter.Instance.WithScopeAsync(Expected); - await Hub.Received(1).WithScopeAsync(Expected); - } - - [Obsolete] - [Fact] - public async Task WithScopeAsyncT_MockInvoked() - { - Task Expected(Scope _) => Task.FromResult(null); - await HubAdapter.Instance.WithScopeAsync(Expected); - await Hub.Received(1).WithScopeAsync(Expected); - } - [Fact] public void PushScope_MockInvoked() { diff --git a/test/Sentry.Tests/HubTests.cs b/test/Sentry.Tests/HubTests.cs index e175eaf694..161545c0b9 100644 --- a/test/Sentry.Tests/HubTests.cs +++ b/test/Sentry.Tests/HubTests.cs @@ -1435,91 +1435,5 @@ await transport.Received(1) .SendEnvelopeAsync(Arg.Any(), Arg.Any()); } - [Obsolete] - [Fact] - public void WithScope_Works() - { - _fixture.Options.IsGlobalModeEnabled = false; - var hub = _fixture.GetSut(); - var originalScope = GetCurrentScope(hub); - - hub.WithScope(scope => - { - var newScope = GetCurrentScope(hub); - Assert.Same(newScope, scope); - Assert.NotSame(originalScope, scope); - }); - - var finalScope = GetCurrentScope(hub); - Assert.Same(originalScope, finalScope); - } - - [Obsolete] - [Fact] - public void WithScopeT_Works() - { - _fixture.Options.IsGlobalModeEnabled = false; - var hub = _fixture.GetSut(); - var originalScope = GetCurrentScope(hub); - - var result = hub.WithScope(scope => - { - var newScope = GetCurrentScope(hub); - Assert.Same(newScope, scope); - Assert.NotSame(originalScope, scope); - - return true; - }); - - Assert.True(result); - - var finalScope = GetCurrentScope(hub); - Assert.Same(originalScope, finalScope); - } - - [Obsolete] - [Fact] - public async Task WithScopeAsync_Works() - { - _fixture.Options.IsGlobalModeEnabled = false; - var hub = _fixture.GetSut(); - var originalScope = GetCurrentScope(hub); - - await hub.WithScopeAsync(scope => - { - var newScope = GetCurrentScope(hub); - Assert.Same(newScope, scope); - Assert.NotSame(originalScope, scope); - - return Task.CompletedTask; - }); - - var finalScope = GetCurrentScope(hub); - Assert.Same(originalScope, finalScope); - } - - [Obsolete] - [Fact] - public async Task WithScopeAsyncT_Works() - { - _fixture.Options.IsGlobalModeEnabled = false; - var hub = _fixture.GetSut(); - var originalScope = GetCurrentScope(hub); - - var result = await hub.WithScopeAsync(scope => - { - var newScope = GetCurrentScope(hub); - Assert.Same(newScope, scope); - Assert.NotSame(originalScope, scope); - - return Task.FromResult(true); - }); - - Assert.True(result); - - var finalScope = GetCurrentScope(hub); - Assert.Same(originalScope, finalScope); - } - private static Scope GetCurrentScope(Hub hub) => hub.ScopeManager.GetCurrent().Key; } diff --git a/test/Sentry.Tests/SentrySdkTests.cs b/test/Sentry.Tests/SentrySdkTests.cs index e9a11ec082..26c9c318d7 100644 --- a/test/Sentry.Tests/SentrySdkTests.cs +++ b/test/Sentry.Tests/SentrySdkTests.cs @@ -469,153 +469,6 @@ async Task ModifyScope() } } - [Obsolete] - [Fact] - public void WithScope_DisabledSdk_CallbackNeverInvoked() - { - var invoked = false; - - // Note: Specifying void in the lambda ensures we are testing WithScope, rather than WithScope. - SentrySdk.WithScope(void (_) => invoked = true); - Assert.False(invoked); - } - - [Obsolete] - [Fact] - public void WithScopeT_DisabledSdk_CallbackNeverInvoked() - { - var invoked = SentrySdk.WithScope(_ => true); - Assert.False(invoked); - } - - [Obsolete] - [Fact] - public async Task WithScopeAsync_DisabledSdk_CallbackNeverInvoked() - { - var invoked = false; - await SentrySdk.WithScopeAsync(_ => - { - invoked = true; - return Task.CompletedTask; - }); - Assert.False(invoked); - } - - [Obsolete] - [Fact] - public async Task WithScopeAsyncT_DisabledSdk_CallbackNeverInvoked() - { - var invoked = await SentrySdk.WithScopeAsync(_ => Task.FromResult(true)); - Assert.False(invoked); - } - - [Obsolete] - [Fact] - public void WithScope_InvokedWithNewScope() - { - var options = new SentryOptions - { - Dsn = ValidDsn, - IsGlobalModeEnabled = false, - AutoSessionTracking = false, - BackgroundWorker = Substitute.For(), - InitNativeSdks = false - }; - - using var _ = SentrySdk.Init(options); - - Scope expected = null; - SentrySdk.ConfigureScope(s => expected = s); - - Scope actual = null; - // Note: Specifying void in the lambda ensures we are testing WithScope, rather than WithScope. - SentrySdk.WithScope(void (s) => actual = s); - - Assert.NotNull(actual); - Assert.NotSame(expected, actual); - SentrySdk.ConfigureScope(s => Assert.Same(expected, s)); - } - - [Obsolete] - [Fact] - public void WithScopeT_InvokedWithNewScope() - { - var options = new SentryOptions - { - Dsn = ValidDsn, - IsGlobalModeEnabled = false, - AutoSessionTracking = false, - BackgroundWorker = Substitute.For(), - InitNativeSdks = false - }; - - using var _ = SentrySdk.Init(options); - - Scope expected = null; - SentrySdk.ConfigureScope(s => expected = s); - - var actual = SentrySdk.WithScope(s => s); - - Assert.NotNull(actual); - Assert.NotSame(expected, actual); - SentrySdk.ConfigureScope(s => Assert.Same(expected, s)); - } - - [Obsolete] - [Fact] - public async Task WithScopeAsync_InvokedWithNewScope() - { - var options = new SentryOptions - { - Dsn = ValidDsn, - IsGlobalModeEnabled = false, - AutoSessionTracking = false, - BackgroundWorker = Substitute.For(), - InitNativeSdks = false - }; - - using var _ = SentrySdk.Init(options); - - Scope expected = null; - SentrySdk.ConfigureScope(s => expected = s); - - Scope actual = null; - await SentrySdk.WithScopeAsync(s => - { - actual = s; - return Task.CompletedTask; - }); - - Assert.NotNull(actual); - Assert.NotSame(expected, actual); - SentrySdk.ConfigureScope(s => Assert.Same(expected, s)); - } - - [Obsolete] - [Fact] - public async Task WithScopeAsyncT_InvokedWithNewScope() - { - var options = new SentryOptions - { - Dsn = ValidDsn, - IsGlobalModeEnabled = false, - AutoSessionTracking = false, - BackgroundWorker = Substitute.For(), - InitNativeSdks = false - }; - - using var _ = SentrySdk.Init(options); - - Scope expected = null; - SentrySdk.ConfigureScope(s => expected = s); - - var actual = await SentrySdk.WithScopeAsync(Task.FromResult); - - Assert.NotNull(actual); - Assert.NotSame(expected, actual); - SentrySdk.ConfigureScope(s => Assert.Same(expected, s)); - } - [Fact] public void CaptureEvent_WithConfiguredScope_ScopeAppliesToEvent() {