Skip to content

Commit

Permalink
Removed WithScope and WithScopeAsync (#2717)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsandfoxes committed Oct 18, 2023
1 parent 6e18dee commit 941d9dc
Show file tree
Hide file tree
Showing 18 changed files with 23 additions and 673 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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<Scope> scopeCallback)`
- `SentrySdk.CaptureMessage(string message, Action<Scope> scopeCallback)`
- `SentrySdk.CaptureException(Exception exception, Action<Scope> 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
Expand Down
7 changes: 0 additions & 7 deletions src/Sentry/Extensibility/DisabledHub.cs
Expand Up @@ -41,13 +41,6 @@ public void ConfigureScope(Action<Scope> configureScope)
/// </summary>
public IDisposable PushScope<TState>(TState state) => this;

/// <summary>
/// No-Op.
/// </summary>
public void WithScope(Action<Scope> scopeCallback)
{
}

/// <summary>
/// Returns a dummy transaction.
/// </summary>
Expand Down
33 changes: 0 additions & 33 deletions src/Sentry/Extensibility/HubAdapter.cs
Expand Up @@ -59,15 +59,6 @@ public IDisposable PushScope()
public IDisposable PushScope<TState>(TState state)
=> SentrySdk.PushScope(state);

/// <summary>
/// Forwards the call to <see cref="SentrySdk"/>.
/// </summary>
[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<Scope> scopeCallback)
=> SentrySdk.WithScope(scopeCallback);

/// <summary>
/// Forwards the call to <see cref="SentrySdk"/>.
/// </summary>
Expand Down Expand Up @@ -287,28 +278,4 @@ public Task FlushAsync(TimeSpan timeout)
[EditorBrowsable(EditorBrowsableState.Never)]
public void CaptureUserFeedback(UserFeedback sentryUserFeedback)
=> SentrySdk.CaptureUserFeedback(sentryUserFeedback);

/// <summary>
/// Forwards the call to <see cref="SentrySdk"/>
/// </summary>
[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<T>(Func<Scope, T?> scopeCallback)
=> SentrySdk.WithScope(scopeCallback);

/// <summary>
/// Forwards the call to <see cref="SentrySdk"/>
/// </summary>
[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<Scope, Task> scopeCallback)
=> SentrySdk.WithScopeAsync(scopeCallback);

/// <summary>
/// Forwards the call to <see cref="SentrySdk"/>
/// </summary>
[Obsolete("This method is deprecated in favor of overloads of CaptureEvent, CaptureMessage and CaptureException " +
"that provide a callback to a configurable scope.")]
public Task<T?> WithScopeAsync<T>(Func<Scope, Task<T?>> scopeCallback)
=> SentrySdk.WithScopeAsync(scopeCallback);
}
14 changes: 0 additions & 14 deletions src/Sentry/ISentryScopeManager.cs
Expand Up @@ -42,18 +42,4 @@ public interface ISentryScopeManager
/// <returns>A disposable which removes the scope
/// from the environment when invoked.</returns>
IDisposable PushScope<TState>(TState state);

/// <summary>
/// Runs the callback within a new scope.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
/// <see href="https://docs.sentry.io/platforms/dotnet/enriching-events/scopes/#local-scopes"/>
/// <param name="scopeCallback">The callback to run with the one time scope.</param>
[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<Scope> scopeCallback);
}
12 changes: 0 additions & 12 deletions src/Sentry/Internal/Hub.cs
Expand Up @@ -100,18 +100,6 @@ public async Task ConfigureScopeAsync(Func<Scope, Task> configureScope)

public void RestoreScope(Scope savedScope) => ScopeManager.RestoreScope(savedScope);

[Obsolete]
public void WithScope(Action<Scope> scopeCallback) => ScopeManager.WithScope(scopeCallback);

[Obsolete]
public T? WithScope<T>(Func<Scope, T?> scopeCallback) => ScopeManager.WithScope(scopeCallback);

[Obsolete]
public Task WithScopeAsync(Func<Scope, Task> scopeCallback) => ScopeManager.WithScopeAsync(scopeCallback);

[Obsolete]
public Task<T?> WithScopeAsync<T>(Func<Scope, Task<T?>> scopeCallback) => ScopeManager.WithScopeAsync(scopeCallback);

public void BindClient(ISentryClient client) => ScopeManager.BindClient(client);

public ITransactionTracer StartTransaction(
Expand Down
4 changes: 0 additions & 4 deletions src/Sentry/Internal/IHubEx.cs
Expand Up @@ -3,8 +3,4 @@ namespace Sentry.Internal;
internal interface IHubEx : IHub
{
SentryId CaptureEventInternal(SentryEvent evt, Hint? hint, Scope? scope = null);

T? WithScope<T>(Func<Scope, T?> scopeCallback);
Task WithScopeAsync(Func<Scope, Task> scopeCallback);
Task<T?> WithScopeAsync<T>(Func<Scope, Task<T?>> scopeCallback);
}
5 changes: 0 additions & 5 deletions src/Sentry/Internal/IInternalScopeManager.cs
Expand Up @@ -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<T>(Func<Scope, T?> scopeCallback);
Task WithScopeAsync(Func<Scope, Task> scopeCallback);
Task<T?> WithScopeAsync<T>(Func<Scope, Task<T?>> scopeCallback);
}
36 changes: 0 additions & 36 deletions src/Sentry/Internal/SentryScopeManager.cs
Expand Up @@ -107,42 +107,6 @@ public void RestoreScope(Scope savedScope)
ScopeAndClientStack = newScopeAndClientStack;
}

public void WithScope(Action<Scope> scopeCallback)
{
using (PushScope())
{
var (scope, _) = GetCurrent();
scopeCallback.Invoke(scope);
}
}

public T? WithScope<T>(Func<Scope, T?> scopeCallback)
{
using (PushScope())
{
var (scope, _) = GetCurrent();
return scopeCallback.Invoke(scope);
}
}

public async Task WithScopeAsync(Func<Scope, Task> scopeCallback)
{
using (PushScope())
{
var (scope, _) = GetCurrent();
await scopeCallback.Invoke(scope).ConfigureAwait(false);
}
}

public async Task<T?> WithScopeAsync<T>(Func<Scope, Task<T?>> 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.");
Expand Down
76 changes: 0 additions & 76 deletions src/Sentry/SentryScopeManagerExtensions.cs

This file was deleted.

69 changes: 0 additions & 69 deletions src/Sentry/SentrySdk.cs
Expand Up @@ -321,75 +321,6 @@ public void Dispose()
public static void AddBreadcrumb(Breadcrumb breadcrumb, Hint? hint = null)
=> CurrentHub.AddBreadcrumb(breadcrumb, hint);

/// <summary>
/// Runs the callback within a new scope.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
/// <see href="https://docs.sentry.io/platforms/dotnet/enriching-events/scopes/#local-scopes"/>
/// <param name="scopeCallback">The callback to run with the one time scope.</param>
[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<Scope> scopeCallback)
=> CurrentHub.WithScope(scopeCallback);

/// <summary>
/// Runs the callback within a new scope.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
/// <see href="https://docs.sentry.io/platforms/dotnet/enriching-events/scopes/#local-scopes"/>
/// <param name="scopeCallback">The callback to run with the one time scope.</param>
/// <returns>The result from the callback.</returns>
[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<T>(Func<Scope, T?> scopeCallback)
=> CurrentHub is IHubEx hub ? hub.WithScope(scopeCallback) : default;

/// <summary>
/// Runs the asynchronous callback within a new scope.
/// </summary>
/// <remarks>
/// Asynchronous version of <see cref="ISentryScopeManager.WithScope"/>.
/// 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.
/// </remarks>
/// <see href="https://docs.sentry.io/platforms/dotnet/enriching-events/scopes/#local-scopes"/>
/// <param name="scopeCallback">The callback to run with the one time scope.</param>
/// <returns>An async task to await the callback.</returns>
[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<Scope, Task> scopeCallback)
=> CurrentHub is IHubEx hub ? hub.WithScopeAsync(scopeCallback) : Task.CompletedTask;

/// <summary>
/// Runs the asynchronous callback within a new scope.
/// </summary>
/// <remarks>
/// Asynchronous version of <see cref="ISentryScopeManager.WithScope"/>.
/// 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.
/// </remarks>
/// <see href="https://docs.sentry.io/platforms/dotnet/enriching-events/scopes/#local-scopes"/>
/// <param name="scopeCallback">The callback to run with the one time scope.</param>
/// <returns>An async task to await the result of the callback.</returns>
[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<T?> WithScopeAsync<T>(Func<Scope, Task<T?>> scopeCallback)
=> CurrentHub is IHubEx hub ? hub.WithScopeAsync(scopeCallback) : Task.FromResult(default(T));

/// <summary>
/// Configures the scope through the callback.
/// </summary>
Expand Down

0 comments on commit 941d9dc

Please sign in to comment.