Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/Sentry/BindableSentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/Sentry/GlobalSessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Sentry/Platforms/Android/AndroidScopeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Sentry/Platforms/Android/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Java.Lang.RuntimeException>();

Expand Down
2 changes: 2 additions & 0 deletions src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Sentry/Platforms/Cocoa/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProfilingIntegration>())
Expand Down
4 changes: 4 additions & 0 deletions src/Sentry/Platforms/Native/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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();
Expand Down
52 changes: 12 additions & 40 deletions src/Sentry/Scope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ public SentryContexts Contexts
// Internal for testing.
internal Action<SentryUser?> UserChanged => user =>
{
if (Options.EnableScopeSync &&
Options.ScopeObserver is { } observer)
{
observer.SetUser(user);
}
Options.SyncedScopeObserver?.SetUser(user);
};

private SentryUser? _user;
Expand Down Expand Up @@ -165,10 +161,7 @@ public string? Environment
field = value;
}

if (Options is { EnableScopeSync: true, ScopeObserver: { } observer })
{
observer.SetEnvironment(field);
}
Options.SyncedScopeObserver?.SetEnvironment(field);
}
}

Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}

/// <inheritdoc />
public void SetExtra(string key, object? value)
{
_extra[key] = value;
if (Options.EnableScopeSync)
{
Options.ScopeObserver?.SetExtra(key, value);
}
Options.SyncedScopeObserver?.SetExtra(key, value);
}

/// <inheritdoc />
Expand All @@ -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);
}

/// <inheritdoc />
public void UnsetTag(string key)
{
_tags.TryRemove(key, out _);
if (Options.EnableScopeSync)
{
Options.ScopeObserver?.UnsetTag(key);
}
Options.SyncedScopeObserver?.UnsetTag(key);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand Down Expand Up @@ -448,10 +423,7 @@ public void Clear()
public void ClearAttachments()
{
_attachments.Clear();
if (Options.EnableScopeSync)
{
Options.ScopeObserver?.ClearAttachments();
}
Options.SyncedScopeObserver?.ClearAttachments();
}

/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.";

/// <summary>
/// A scope set outside of Sentry SDK. If set, the global parameters from the SDK's scope will be sent to the observed scope.<br/>
/// NOTE: EnableScopeSync must be set true for the scope to be synced.
/// </summary>
[Obsolete(ObsoleteInternalOption)]
public IScopeObserver? ScopeObserver { get; set; }

/// <summary>
/// If true, the SDK's scope will be synced with the observed scope.
/// </summary>
[Obsolete(ObsoleteInternalOption)]
public bool EnableScopeSync { get; set; }

#pragma warning disable CS0618
internal IScopeObserver? SyncedScopeObserver => EnableScopeSync ? ScopeObserver : null;
#pragma warning restore CS0618

/// <summary>
/// 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.
Expand Down Expand Up @@ -1270,6 +1279,7 @@ public StackTraceMode StackTraceMode
/// <summary>
/// Delegate which is used to check whether the application crashed during last run.
/// </summary>
[Obsolete(ObsoleteInternalOption)]
public Func<bool>? CrashedLastRun { get; set; }

#if IOS || MACCATALYST
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Sentry.Extensions.Logging.Tests;

public class SentryLoggingOptionsSetupTests
{
#pragma warning disable CS0618
[Fact]
public void Configure_BindsConfigurationToOptions()
{
Expand Down Expand Up @@ -168,4 +169,5 @@ public void Configure_BindsConfigurationToOptions()
actual.InitializeSdk.Should().Be(expected.InitializeSdk);
}
}
#pragma warning restore CS0618
}
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ namespace Sentry
public string? CacheDirectoryPath { get; set; }
public bool CaptureFailedRequests { get; set; }
public System.Action<System.Net.Http.HttpClient>? 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<bool>? CrashedLastRun { get; set; }
public System.Func<System.Net.Http.HttpMessageHandler>? CreateHttpMessageHandler { get; set; }
public bool Debug { get; set; }
Expand All @@ -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; }
Expand All @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ namespace Sentry
public string? CacheDirectoryPath { get; set; }
public bool CaptureFailedRequests { get; set; }
public System.Action<System.Net.Http.HttpClient>? 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<bool>? CrashedLastRun { get; set; }
public System.Func<System.Net.Http.HttpMessageHandler>? CreateHttpMessageHandler { get; set; }
public bool Debug { get; set; }
Expand All @@ -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; }
Expand All @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ namespace Sentry
public string? CacheDirectoryPath { get; set; }
public bool CaptureFailedRequests { get; set; }
public System.Action<System.Net.Http.HttpClient>? 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<bool>? CrashedLastRun { get; set; }
public System.Func<System.Net.Http.HttpMessageHandler>? CreateHttpMessageHandler { get; set; }
public bool Debug { get; set; }
Expand All @@ -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; }
Expand All @@ -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; }
Expand Down
6 changes: 6 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,8 @@ namespace Sentry
public string? CacheDirectoryPath { get; set; }
public bool CaptureFailedRequests { get; set; }
public System.Action<System.Net.Http.HttpClient>? 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<bool>? CrashedLastRun { get; set; }
public System.Func<System.Net.Http.HttpMessageHandler>? CreateHttpMessageHandler { get; set; }
public bool Debug { get; set; }
Expand All @@ -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; }
Expand All @@ -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; }
Expand Down
2 changes: 2 additions & 0 deletions test/Sentry.Tests/GlobalSessionManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CS0618

namespace Sentry.Tests;

public class GlobalSessionManagerTests
Expand Down
2 changes: 2 additions & 0 deletions test/Sentry.Tests/ScopeTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CS0618

namespace Sentry.Tests;

public class ScopeTests
Expand Down
Loading
Loading