Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Obsolete WithScope #2677

Merged
merged 7 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- `WithScope` has been marked Obsolete ([#2677](https://github.com/getsentry/sentry-dotnet/pull/2677))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be more descriptive on why we're doing this

bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

### Dependencies

- Bump CLI from v2.20.7 to v2.21.1 ([#2645](https://github.com/getsentry/sentry-dotnet/pull/2645), [#2647](https://github.com/getsentry/sentry-dotnet/pull/2647))
Expand Down
17 changes: 8 additions & 9 deletions benchmarks/Sentry.Benchmarks/LastActiveSpanBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ public class LastActiveSpanBenchmarks
public void CreateScopedSpans()
{
var transaction = SentrySdk.StartTransaction(Name, Operation);
SentrySdk.WithScope(scope =>
SentrySdk.ConfigureScope(scope => scope.Transaction = transaction);

for (var i = 0; i < SpanCount; i++)
{
scope.Transaction = transaction;
for (var i = 0; i < SpanCount; i++)
{
// Simulates a scenario where TransactionTracer.GetLastActiveSpan will be called frequently
// See: https://github.com/getsentry/sentry-dotnet/blob/c2a31b4ead03da388c2db7fe07f290354aa51b9d/src/Sentry/Scope.cs#L567C1-L567C68
CallOneFunction(i);
}
});
// Simulates a scenario where TransactionTracer.GetLastActiveSpan will be called frequently
// See: https://github.com/getsentry/sentry-dotnet/blob/c2a31b4ead03da388c2db7fe07f290354aa51b9d/src/Sentry/Scope.cs#L567C1-L567C68
CallOneFunction(i);
}

transaction.Finish();
}

Expand Down
8 changes: 8 additions & 0 deletions src/Sentry/Extensibility/HubAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public IDisposable PushScope<TState>(TState 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);
Expand Down Expand Up @@ -289,18 +291,24 @@ public void CaptureUserFeedback(UserFeedback 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);
}
2 changes: 2 additions & 0 deletions src/Sentry/ISentryScopeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ public interface ISentryScopeManager
/// </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);
}
4 changes: 4 additions & 0 deletions src/Sentry/Internal/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,16 @@ public async Task ConfigureScopeAsync(Func<Scope, Task> configureScope)

public IDisposable PushScope<TState>(TState state) => ScopeManager.PushScope(state);

[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);
Expand Down
8 changes: 8 additions & 0 deletions src/Sentry/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ public static void AddBreadcrumb(Breadcrumb breadcrumb, Hint? hint = null)
/// </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);
Expand All @@ -346,6 +348,8 @@ public static void WithScope(Action<Scope> scopeCallback)
/// <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;
Expand All @@ -362,6 +366,8 @@ public static void WithScope(Action<Scope> scopeCallback)
/// <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;
Expand All @@ -378,6 +384,8 @@ public static Task WithScopeAsync(Func<Scope, Task> scopeCallback)
/// <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));
Expand Down
18 changes: 18 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ namespace Sentry
System.Threading.Tasks.Task ConfigureScopeAsync(System.Func<Sentry.Scope, System.Threading.Tasks.Task> configureScope);
System.IDisposable PushScope();
System.IDisposable PushScope<TState>(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<Sentry.Scope> scopeCallback);
}
public interface ISentryScopeStateProcessor
Expand Down Expand Up @@ -784,9 +786,17 @@ namespace Sentry
public static Sentry.ITransaction StartTransaction(string name, string operation) { }
public static Sentry.ITransaction StartTransaction(string name, string operation, Sentry.SentryTraceHeader traceHeader) { }
public static Sentry.ITransaction 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<Sentry.Scope> 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<T>(System.Func<Sentry.Scope, T?> 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<Sentry.Scope, System.Threading.Tasks.Task> 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<T?> WithScopeAsync<T>(System.Func<Sentry.Scope, System.Threading.Tasks.Task<T?>> scopeCallback) { }
}
public sealed class SentryStackFrame : Sentry.IJsonSerializable
Expand Down Expand Up @@ -1293,9 +1303,17 @@ namespace Sentry.Extensibility
public void ResumeSession() { }
public void StartSession() { }
public Sentry.ITransaction StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> 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<Sentry.Scope> 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<T>(System.Func<Sentry.Scope, T?> 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<Sentry.Scope, System.Threading.Tasks.Task> 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<T?> WithScopeAsync<T>(System.Func<Sentry.Scope, System.Threading.Tasks.Task<T?>> scopeCallback) { }
}
public interface IBackgroundWorker
Expand Down
18 changes: 18 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ namespace Sentry
System.Threading.Tasks.Task ConfigureScopeAsync(System.Func<Sentry.Scope, System.Threading.Tasks.Task> configureScope);
System.IDisposable PushScope();
System.IDisposable PushScope<TState>(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<Sentry.Scope> scopeCallback);
}
public interface ISentryScopeStateProcessor
Expand Down Expand Up @@ -785,9 +787,17 @@ namespace Sentry
public static Sentry.ITransaction StartTransaction(string name, string operation) { }
public static Sentry.ITransaction StartTransaction(string name, string operation, Sentry.SentryTraceHeader traceHeader) { }
public static Sentry.ITransaction 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<Sentry.Scope> 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<T>(System.Func<Sentry.Scope, T?> 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<Sentry.Scope, System.Threading.Tasks.Task> 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<T?> WithScopeAsync<T>(System.Func<Sentry.Scope, System.Threading.Tasks.Task<T?>> scopeCallback) { }
}
public sealed class SentryStackFrame : Sentry.IJsonSerializable
Expand Down Expand Up @@ -1294,9 +1304,17 @@ namespace Sentry.Extensibility
public void ResumeSession() { }
public void StartSession() { }
public Sentry.ITransaction StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> 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<Sentry.Scope> 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<T>(System.Func<Sentry.Scope, T?> 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<Sentry.Scope, System.Threading.Tasks.Task> 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<T?> WithScopeAsync<T>(System.Func<Sentry.Scope, System.Threading.Tasks.Task<T?>> scopeCallback) { }
}
public interface IBackgroundWorker
Expand Down
18 changes: 18 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.DotNet7_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ namespace Sentry
System.Threading.Tasks.Task ConfigureScopeAsync(System.Func<Sentry.Scope, System.Threading.Tasks.Task> configureScope);
System.IDisposable PushScope();
System.IDisposable PushScope<TState>(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<Sentry.Scope> scopeCallback);
}
public interface ISentryScopeStateProcessor
Expand Down Expand Up @@ -785,9 +787,17 @@ namespace Sentry
public static Sentry.ITransaction StartTransaction(string name, string operation) { }
public static Sentry.ITransaction StartTransaction(string name, string operation, Sentry.SentryTraceHeader traceHeader) { }
public static Sentry.ITransaction 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<Sentry.Scope> 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<T>(System.Func<Sentry.Scope, T?> 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<Sentry.Scope, System.Threading.Tasks.Task> 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<T?> WithScopeAsync<T>(System.Func<Sentry.Scope, System.Threading.Tasks.Task<T?>> scopeCallback) { }
}
public sealed class SentryStackFrame : Sentry.IJsonSerializable
Expand Down Expand Up @@ -1294,9 +1304,17 @@ namespace Sentry.Extensibility
public void ResumeSession() { }
public void StartSession() { }
public Sentry.ITransaction StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> 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<Sentry.Scope> 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<T>(System.Func<Sentry.Scope, T?> 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<Sentry.Scope, System.Threading.Tasks.Task> 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<T?> WithScopeAsync<T>(System.Func<Sentry.Scope, System.Threading.Tasks.Task<T?>> scopeCallback) { }
}
public interface IBackgroundWorker
Expand Down
Loading