diff --git a/src/Sentry/BindableSentryOptions.cs b/src/Sentry/BindableSentryOptions.cs index 9f2ef5fbe8..a446f57008 100644 --- a/src/Sentry/BindableSentryOptions.cs +++ b/src/Sentry/BindableSentryOptions.cs @@ -63,7 +63,9 @@ internal partial class BindableSentryOptions public void ApplyTo(SentryOptions options) { options.IsGlobalModeEnabled = IsGlobalModeEnabled ?? options.IsGlobalModeEnabled; +#pragma warning disable CS0618 options.EnableScopeSync = EnableScopeSync ?? options.EnableScopeSync; +#pragma warning restore CS0618 options.EnableBackpressureHandling = EnableBackpressureHandling ?? options.EnableBackpressureHandling; options.TagFilters = TagFilters?.Select(s => new StringOrRegex(s)).ToList() ?? options.TagFilters; options.IgnoreTransactions = IgnoreTransactions?.Select(s => new StringOrRegex(s)).ToList() ?? options.IgnoreTransactions; diff --git a/src/Sentry/GlobalSessionManager.cs b/src/Sentry/GlobalSessionManager.cs index 6951fb6293..955d1272a2 100644 --- a/src/Sentry/GlobalSessionManager.cs +++ b/src/Sentry/GlobalSessionManager.cs @@ -164,7 +164,10 @@ private void DeletePersistedSession() SessionEndStatus? status = null; try { - status = _options.CrashedLastRun?.Invoke() switch +#pragma warning disable CS0618 + var crashedLastRun = _options.CrashedLastRun; +#pragma warning restore CS0618 + status = crashedLastRun?.Invoke() switch { // Native crash (if native SDK enabled): // This takes priority - escalate to Crashed even if session had pending unhandled diff --git a/src/Sentry/Platforms/Android/AndroidScopeObserver.cs b/src/Sentry/Platforms/Android/AndroidScopeObserver.cs index c4d3e91640..e20616bd7b 100644 --- a/src/Sentry/Platforms/Android/AndroidScopeObserver.cs +++ b/src/Sentry/Platforms/Android/AndroidScopeObserver.cs @@ -14,7 +14,9 @@ public AndroidScopeObserver(SentryOptions options) _options = options; // Chain any previous observer, but guard against circular reference. +#pragma warning disable CS0618 var observer = options.ScopeObserver; +#pragma warning restore CS0618 _innerObserver = observer is AndroidScopeObserver ? null : observer; } diff --git a/src/Sentry/Platforms/Android/SentrySdk.cs b/src/Sentry/Platforms/Android/SentrySdk.cs index 9afb73dcc8..38efc1046b 100644 --- a/src/Sentry/Platforms/Android/SentrySdk.cs +++ b/src/Sentry/Platforms/Android/SentrySdk.cs @@ -215,9 +215,11 @@ private static void InitSentryAndroidSdk(SentryOptions options) { options.AddEventProcessor(new LogCatAttachmentEventProcessor(options.DiagnosticLogger, options.Android.LogCatIntegration, options.Android.LogCatMaxLines)); } +#pragma warning disable CS0618 options.CrashedLastRun = () => JavaSdk.Sentry.IsCrashedLastRun()?.BooleanValue() is true; options.EnableScopeSync = true; options.ScopeObserver = new AndroidScopeObserver(options); +#pragma warning restore CS0618 // Don't capture Java Runtime exceptions in the managed SDK, since we already capture them in the native SDK options.AddExceptionFilterForType(); diff --git a/src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs b/src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs index 98746e5f15..3ba3c827e5 100644 --- a/src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs +++ b/src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs @@ -14,7 +14,9 @@ public CocoaScopeObserver(SentryOptions options) _options = options; // Chain any previous observer, but guard against circular reference. +#pragma warning disable CS0618 var observer = options.ScopeObserver; +#pragma warning restore CS0618 _innerObserver = observer is CocoaScopeObserver ? null : observer; } diff --git a/src/Sentry/Platforms/Cocoa/SentrySdk.cs b/src/Sentry/Platforms/Cocoa/SentrySdk.cs index b55b44b3bf..b12f5fa64e 100644 --- a/src/Sentry/Platforms/Cocoa/SentrySdk.cs +++ b/src/Sentry/Platforms/Cocoa/SentrySdk.cs @@ -183,9 +183,11 @@ private static void InitSentryCocoaSdk(SentryOptions options) // Set options for the managed SDK that depend on the Cocoa SDK. (The user will not be able to modify these.) options.AddEventProcessor(new CocoaEventProcessor()); +#pragma warning disable CS0618 options.CrashedLastRun = () => SentryCocoaSdk.CrashedLastRun; options.EnableScopeSync = true; options.ScopeObserver = new CocoaScopeObserver(options); +#pragma warning restore CS0618 // Note: don't use AddProfilingIntegration as it would print a warning if user used it too. if (!options.HasIntegration()) diff --git a/src/Sentry/Platforms/Native/SentrySdk.cs b/src/Sentry/Platforms/Native/SentrySdk.cs index 41f0d92175..c7883c7a49 100644 --- a/src/Sentry/Platforms/Native/SentrySdk.cs +++ b/src/Sentry/Platforms/Native/SentrySdk.cs @@ -18,8 +18,10 @@ private static void InitNativeSdk(SentryOptions options) } // Setup future scope updates +#pragma warning disable CS0618 options.ScopeObserver = new NativeScopeObserver(options); options.EnableScopeSync = true; +#pragma warning restore CS0618 // TODO: Do an initial scope sync - we cannot do it now because scope is not propagated until a .NET event is being processed. // options.PostInitCallbacks.Add((IHub hub) => hub.ConfigureScope((scope) => @@ -53,7 +55,9 @@ private static void InitNativeSdk(SentryOptions options) options.DiagnosticLogger?.LogDebug("Native SDK reported: 'crashedLastRun': '{0}'", crashedLastRun); } } +#pragma warning disable CS0618 options.CrashedLastRun = () => crashedLastRun; +#pragma warning restore CS0618 } internal static void CloseNativeSdk() => C.Close(); diff --git a/src/Sentry/Scope.cs b/src/Sentry/Scope.cs index d062290133..fd85744986 100644 --- a/src/Sentry/Scope.cs +++ b/src/Sentry/Scope.cs @@ -107,11 +107,7 @@ public SentryContexts Contexts // Internal for testing. internal Action UserChanged => user => { - if (Options.EnableScopeSync && - Options.ScopeObserver is { } observer) - { - observer.SetUser(user); - } + Options.SyncedScopeObserver?.SetUser(user); }; private SentryUser? _user; @@ -165,10 +161,7 @@ public string? Environment field = value; } - if (Options is { EnableScopeSync: true, ScopeObserver: { } observer }) - { - observer.SetEnvironment(field); - } + Options.SyncedScopeObserver?.SetEnvironment(field); } } @@ -248,17 +241,17 @@ public ITransactionTracer? Transaction { _transaction.Value = value; - if (Options.EnableScopeSync) + if (Options.SyncedScopeObserver is { } observer) { if (_transaction.Value != null) { // If there is a transaction set we propagate the trace to the native layer - Options.ScopeObserver?.SetTrace(_transaction.Value.TraceId, _transaction.Value.SpanId); + observer.SetTrace(_transaction.Value.TraceId, _transaction.Value.SpanId); } else { // If the transaction is being removed from the scope, reset and sync the trace as well - Options.ScopeObserver?.SetTrace(PropagationContext.TraceId, PropagationContext.SpanId); + observer.SetTrace(PropagationContext.TraceId, PropagationContext.SpanId); } } } @@ -358,20 +351,14 @@ public void AddBreadcrumb(Breadcrumb breadcrumb, SentryHint hint) } _breadcrumbs.Enqueue(breadcrumb); - if (Options.EnableScopeSync) - { - Options.ScopeObserver?.AddBreadcrumb(breadcrumb); - } + Options.SyncedScopeObserver?.AddBreadcrumb(breadcrumb); } /// public void SetExtra(string key, object? value) { _extra[key] = value; - if (Options.EnableScopeSync) - { - Options.ScopeObserver?.SetExtra(key, value); - } + Options.SyncedScopeObserver?.SetExtra(key, value); } /// @@ -383,20 +370,14 @@ public void SetTag(string key, string value) } _tags[key] = value; - if (Options.EnableScopeSync) - { - Options.ScopeObserver?.SetTag(key, value); - } + Options.SyncedScopeObserver?.SetTag(key, value); } /// public void UnsetTag(string key) { _tags.TryRemove(key, out _); - if (Options.EnableScopeSync) - { - Options.ScopeObserver?.UnsetTag(key); - } + Options.SyncedScopeObserver?.UnsetTag(key); } /// @@ -405,19 +386,13 @@ public void UnsetTag(string key) public void AddAttachment(SentryAttachment attachment) { _attachments.Add(attachment); - if (Options.EnableScopeSync) - { - Options.ScopeObserver?.AddAttachment(attachment); - } + Options.SyncedScopeObserver?.AddAttachment(attachment); } internal void SetPropagationContext(SentryPropagationContext propagationContext) { PropagationContext = propagationContext; - if (Options.EnableScopeSync) - { - Options.ScopeObserver?.SetTrace(propagationContext.TraceId, propagationContext.SpanId); - } + Options.SyncedScopeObserver?.SetTrace(propagationContext.TraceId, propagationContext.SpanId); } /// @@ -448,10 +423,7 @@ public void Clear() public void ClearAttachments() { _attachments.Clear(); - if (Options.EnableScopeSync) - { - Options.ScopeObserver?.ClearAttachments(); - } + Options.SyncedScopeObserver?.ClearAttachments(); } /// diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index 07f62ca826..ef8945c31e 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -83,17 +83,26 @@ public bool IsGlobalModeEnabled } #endif + internal const string ObsoleteInternalOption = + "This option is intended for use by Sentry SDKs only and will be made internal in version 7.0.0."; + /// /// A scope set outside of Sentry SDK. If set, the global parameters from the SDK's scope will be sent to the observed scope.
/// NOTE: EnableScopeSync must be set true for the scope to be synced. ///
+ [Obsolete(ObsoleteInternalOption)] public IScopeObserver? ScopeObserver { get; set; } /// /// If true, the SDK's scope will be synced with the observed scope. /// + [Obsolete(ObsoleteInternalOption)] public bool EnableScopeSync { get; set; } +#pragma warning disable CS0618 + internal IScopeObserver? SyncedScopeObserver => EnableScopeSync ? ScopeObserver : null; +#pragma warning restore CS0618 + /// /// Enables or disables automatic backpressure handling. When enabled, the SDK will monitor system health and /// reduce the sampling rate of events and transactions when the system is under load. @@ -1270,6 +1279,7 @@ public StackTraceMode StackTraceMode /// /// Delegate which is used to check whether the application crashed during last run. /// + [Obsolete(ObsoleteInternalOption)] public Func? CrashedLastRun { get; set; } #if IOS || MACCATALYST diff --git a/src/Sentry/SentrySdk.cs b/src/Sentry/SentrySdk.cs index 3405cb1069..1d6ab2a6bb 100644 --- a/src/Sentry/SentrySdk.cs +++ b/src/Sentry/SentrySdk.cs @@ -98,7 +98,7 @@ internal static IHub InitHub(SentryOptions options) // but native crashes are captured and uploaded by the native SDK without going through that pipeline. // Forward them to the scope observer so the native layer attaches them to crash reports. // Bypassing the .NET scope keeps scope.Tags identical between native and non-native apps. - if (options is { EnableScopeSync: true, ScopeObserver: { } observer } && options.DefaultTags.Count > 0) + if (options.SyncedScopeObserver is { } observer && options.DefaultTags.Count > 0) { foreach (var tag in options.DefaultTags) { diff --git a/test/Sentry.Extensions.Logging.Tests/SentryLoggingOptionsSetupTests.cs b/test/Sentry.Extensions.Logging.Tests/SentryLoggingOptionsSetupTests.cs index 6417344f91..5edebd1f11 100644 --- a/test/Sentry.Extensions.Logging.Tests/SentryLoggingOptionsSetupTests.cs +++ b/test/Sentry.Extensions.Logging.Tests/SentryLoggingOptionsSetupTests.cs @@ -6,6 +6,7 @@ namespace Sentry.Extensions.Logging.Tests; public class SentryLoggingOptionsSetupTests { +#pragma warning disable CS0618 [Fact] public void Configure_BindsConfigurationToOptions() { @@ -168,4 +169,5 @@ public void Configure_BindsConfigurationToOptions() actual.InitializeSdk.Should().Be(expected.InitializeSdk); } } +#pragma warning restore CS0618 } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt index cfe8324b12..7d91ab2484 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt @@ -825,6 +825,8 @@ namespace Sentry public string? CacheDirectoryPath { get; set; } public bool CaptureFailedRequests { get; set; } public System.Action? ConfigureClient { get; set; } + [System.Obsolete("This option is intended for use by Sentry SDKs only and will be made internal in " + + "version 7.0.0.")] public System.Func? CrashedLastRun { get; set; } public System.Func? CreateHttpMessageHandler { get; set; } public bool Debug { get; set; } @@ -843,6 +845,8 @@ namespace Sentry [System.Obsolete("Metrics are always enabled. This option is ignored and will be removed in version" + " 7.0.0. To drop metrics, use SetBeforeSendMetric and return null.")] public bool EnableMetrics { get; set; } + [System.Obsolete("This option is intended for use by Sentry SDKs only and will be made internal in " + + "version 7.0.0.")] public bool EnableScopeSync { get; set; } public bool EnableSpotlight { get; set; } public string? Environment { get; set; } @@ -868,6 +872,8 @@ namespace Sentry public bool RequestBodyCompressionBuffered { get; set; } public System.IO.Compression.CompressionLevel RequestBodyCompressionLevel { get; set; } public float? SampleRate { get; set; } + [System.Obsolete("This option is intended for use by Sentry SDKs only and will be made internal in " + + "version 7.0.0.")] public Sentry.IScopeObserver? ScopeObserver { get; set; } public bool SendClientReports { get; set; } public bool SendDefaultPii { get; set; } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt index cfe8324b12..7d91ab2484 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt @@ -825,6 +825,8 @@ namespace Sentry public string? CacheDirectoryPath { get; set; } public bool CaptureFailedRequests { get; set; } public System.Action? ConfigureClient { get; set; } + [System.Obsolete("This option is intended for use by Sentry SDKs only and will be made internal in " + + "version 7.0.0.")] public System.Func? CrashedLastRun { get; set; } public System.Func? CreateHttpMessageHandler { get; set; } public bool Debug { get; set; } @@ -843,6 +845,8 @@ namespace Sentry [System.Obsolete("Metrics are always enabled. This option is ignored and will be removed in version" + " 7.0.0. To drop metrics, use SetBeforeSendMetric and return null.")] public bool EnableMetrics { get; set; } + [System.Obsolete("This option is intended for use by Sentry SDKs only and will be made internal in " + + "version 7.0.0.")] public bool EnableScopeSync { get; set; } public bool EnableSpotlight { get; set; } public string? Environment { get; set; } @@ -868,6 +872,8 @@ namespace Sentry public bool RequestBodyCompressionBuffered { get; set; } public System.IO.Compression.CompressionLevel RequestBodyCompressionLevel { get; set; } public float? SampleRate { get; set; } + [System.Obsolete("This option is intended for use by Sentry SDKs only and will be made internal in " + + "version 7.0.0.")] public Sentry.IScopeObserver? ScopeObserver { get; set; } public bool SendClientReports { get; set; } public bool SendDefaultPii { get; set; } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt index cfe8324b12..7d91ab2484 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt @@ -825,6 +825,8 @@ namespace Sentry public string? CacheDirectoryPath { get; set; } public bool CaptureFailedRequests { get; set; } public System.Action? ConfigureClient { get; set; } + [System.Obsolete("This option is intended for use by Sentry SDKs only and will be made internal in " + + "version 7.0.0.")] public System.Func? CrashedLastRun { get; set; } public System.Func? CreateHttpMessageHandler { get; set; } public bool Debug { get; set; } @@ -843,6 +845,8 @@ namespace Sentry [System.Obsolete("Metrics are always enabled. This option is ignored and will be removed in version" + " 7.0.0. To drop metrics, use SetBeforeSendMetric and return null.")] public bool EnableMetrics { get; set; } + [System.Obsolete("This option is intended for use by Sentry SDKs only and will be made internal in " + + "version 7.0.0.")] public bool EnableScopeSync { get; set; } public bool EnableSpotlight { get; set; } public string? Environment { get; set; } @@ -868,6 +872,8 @@ namespace Sentry public bool RequestBodyCompressionBuffered { get; set; } public System.IO.Compression.CompressionLevel RequestBodyCompressionLevel { get; set; } public float? SampleRate { get; set; } + [System.Obsolete("This option is intended for use by Sentry SDKs only and will be made internal in " + + "version 7.0.0.")] public Sentry.IScopeObserver? ScopeObserver { get; set; } public bool SendClientReports { get; set; } public bool SendDefaultPii { get; set; } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt index c26aac91b1..5bd1f5cb03 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt @@ -812,6 +812,8 @@ namespace Sentry public string? CacheDirectoryPath { get; set; } public bool CaptureFailedRequests { get; set; } public System.Action? ConfigureClient { get; set; } + [System.Obsolete("This option is intended for use by Sentry SDKs only and will be made internal in " + + "version 7.0.0.")] public System.Func? CrashedLastRun { get; set; } public System.Func? CreateHttpMessageHandler { get; set; } public bool Debug { get; set; } @@ -830,6 +832,8 @@ namespace Sentry [System.Obsolete("Metrics are always enabled. This option is ignored and will be removed in version" + " 7.0.0. To drop metrics, use SetBeforeSendMetric and return null.")] public bool EnableMetrics { get; set; } + [System.Obsolete("This option is intended for use by Sentry SDKs only and will be made internal in " + + "version 7.0.0.")] public bool EnableScopeSync { get; set; } public bool EnableSpotlight { get; set; } public string? Environment { get; set; } @@ -855,6 +859,8 @@ namespace Sentry public bool RequestBodyCompressionBuffered { get; set; } public System.IO.Compression.CompressionLevel RequestBodyCompressionLevel { get; set; } public float? SampleRate { get; set; } + [System.Obsolete("This option is intended for use by Sentry SDKs only and will be made internal in " + + "version 7.0.0.")] public Sentry.IScopeObserver? ScopeObserver { get; set; } public bool SendClientReports { get; set; } public bool SendDefaultPii { get; set; } diff --git a/test/Sentry.Tests/GlobalSessionManagerTests.cs b/test/Sentry.Tests/GlobalSessionManagerTests.cs index 7365fa1dac..9c79fe73bf 100644 --- a/test/Sentry.Tests/GlobalSessionManagerTests.cs +++ b/test/Sentry.Tests/GlobalSessionManagerTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + namespace Sentry.Tests; public class GlobalSessionManagerTests diff --git a/test/Sentry.Tests/ScopeTests.cs b/test/Sentry.Tests/ScopeTests.cs index 0e04ec4b34..3d5d676b5e 100644 --- a/test/Sentry.Tests/ScopeTests.cs +++ b/test/Sentry.Tests/ScopeTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + namespace Sentry.Tests; public class ScopeTests diff --git a/test/Sentry.Tests/SentrySdkTests.cs b/test/Sentry.Tests/SentrySdkTests.cs index c0dde5651f..0f6df5fb0a 100644 --- a/test/Sentry.Tests/SentrySdkTests.cs +++ b/test/Sentry.Tests/SentrySdkTests.cs @@ -1237,8 +1237,10 @@ public void InitHub_DefaultTagsWithScopeSync_RelayedToScopeObserver() var options = new SentryOptions { Dsn = ValidDsn, +#pragma warning disable CS0618 ScopeObserver = observer, EnableScopeSync = true, +#pragma warning restore CS0618 BackgroundWorker = Substitute.For(), InitNativeSdks = false, }; @@ -1261,8 +1263,10 @@ public void InitHub_DefaultTagsWithoutScopeSync_NotRelayedToScopeObserver() var options = new SentryOptions { Dsn = ValidDsn, +#pragma warning disable CS0618 ScopeObserver = observer, EnableScopeSync = false, +#pragma warning restore CS0618 BackgroundWorker = Substitute.For(), InitNativeSdks = false, };