diff --git a/CHANGELOG.md b/CHANGELOG.md index 9544743c93..dab99e27b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - The `SentryUser.Segment` property has been deprecated. Consider sending this as a tag or additional data instead ([#3563](https://github.com/getsentry/sentry-dotnet/pull/3563)) - The ITraceContext now includes an [Origin](https://develop.sentry.dev/sdk/telemetry/traces/trace-origin/), which is set automatically and is primarily used internally by the Sentry server ([#3564](https://github.com/getsentry/sentry-dotnet/pull/3564)) - `Device.BatteryLevel` and `Device.ProcessorFrequency` are now stored as floats rather than ints, to align with the Cocoa and Java SDKs ([#3567](https://github.com/getsentry/sentry-dotnet/pull/3567)) +- `SentryOptions.EnableTracing` has been removed. Instead, tracing should be enabled or disabled by setting the `SentryOptions.TracesSampleRate` or by using `SentryOptions.TracesSampler` to configure a sampling function ([#3569](https://github.com/getsentry/sentry-dotnet/pull/3569)) ## 4.10.2 diff --git a/src/Sentry/BindableSentryOptions.cs b/src/Sentry/BindableSentryOptions.cs index 4630f053c0..cf3816ef1b 100644 --- a/src/Sentry/BindableSentryOptions.cs +++ b/src/Sentry/BindableSentryOptions.cs @@ -83,9 +83,6 @@ public void ApplyTo(SentryOptions options) options.FailedRequestTargets = FailedRequestTargets?.Select(s => new SubstringOrRegexPattern(s)).ToList() ?? options.FailedRequestTargets; options.InitCacheFlushTimeout = InitCacheFlushTimeout ?? options.InitCacheFlushTimeout; options.DefaultTags = DefaultTags ?? options.DefaultTags; -#pragma warning disable CS0618 // Type or member is obsolete - options.EnableTracing = EnableTracing ?? options.EnableTracing; -#pragma warning restore CS0618 // Type or member is obsolete options.TracesSampleRate = TracesSampleRate ?? options.TracesSampleRate; options.ProfilesSampleRate = ProfilesSampleRate ?? options.ProfilesSampleRate; options.TracePropagationTargets = TracePropagationTargets?.Select(s => new SubstringOrRegexPattern(s)).ToList() ?? options.TracePropagationTargets; diff --git a/src/Sentry/Internal/Hub.cs b/src/Sentry/Internal/Hub.cs index 151150514a..240cc0f60f 100644 --- a/src/Sentry/Internal/Hub.cs +++ b/src/Sentry/Internal/Hub.cs @@ -129,9 +129,7 @@ internal ITransactionTracer StartTransaction( // Additionally, we will always sample out if tracing is explicitly disabled. // Do not invoke the TracesSampler, evaluate the TracesSampleRate, and override any sampling decision // that may have been already set (i.e.: from a sentry-trace header). -#pragma warning disable CS0618 // Type or member is obsolete - if (!IsEnabled || _options.EnableTracing is false) -#pragma warning restore CS0618 // Type or member is obsolete + if (!IsEnabled) { transaction.IsSampled = false; transaction.SampleRate = 0.0; @@ -156,9 +154,7 @@ internal ITransactionTracer StartTransaction( // Random sampling runs only if the sampling decision hasn't been made already. if (transaction.IsSampled == null) { -#pragma warning disable CS0618 // Type or member is obsolete - var sampleRate = _options.TracesSampleRate ?? (_options.EnableTracing is true ? 1.0 : 0.0); -#pragma warning restore CS0618 // Type or member is obsolete + var sampleRate = _options.TracesSampleRate ?? 0.0; transaction.IsSampled = _randomValuesFactory.NextBool(sampleRate); transaction.SampleRate = sampleRate; } diff --git a/src/Sentry/Platforms/Android/SentrySdk.cs b/src/Sentry/Platforms/Android/SentrySdk.cs index a346f581b3..5c12bdaec9 100644 --- a/src/Sentry/Platforms/Android/SentrySdk.cs +++ b/src/Sentry/Platforms/Android/SentrySdk.cs @@ -89,9 +89,7 @@ private static void InitSentryAndroidSdk(SentryOptions options) // These options we have behind feature flags if (options is { IsPerformanceMonitoringEnabled: true, Native.EnableTracing: true }) { -#pragma warning disable CS0618 // Type or member is obsolete - o.EnableTracing = (JavaBoolean?)options.EnableTracing; -#pragma warning restore CS0618 // Type or member is obsolete + o.EnableTracing = null; o.TracesSampleRate = (JavaDouble?)options.TracesSampleRate; if (options.TracesSampler is { } tracesSampler) diff --git a/src/Sentry/Platforms/Cocoa/SentrySdk.cs b/src/Sentry/Platforms/Cocoa/SentrySdk.cs index ac075af7a6..5adc96c249 100644 --- a/src/Sentry/Platforms/Cocoa/SentrySdk.cs +++ b/src/Sentry/Platforms/Cocoa/SentrySdk.cs @@ -75,13 +75,6 @@ private static void InitSentryCocoaSdk(SentryOptions options) // These options we have behind feature flags if (options is { IsPerformanceMonitoringEnabled: true, Native.EnableTracing: true }) { -#pragma warning disable CS0618 // Type or member is obsolete - if (options.EnableTracing != null) - { - nativeOptions.EnableTracing = options.EnableTracing.Value; - } -#pragma warning restore CS0618 // Type or member is obsolete - nativeOptions.TracesSampleRate = options.TracesSampleRate; if (options.TracesSampler is { } tracesSampler) diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index d354d253e3..3480207ab5 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -753,56 +753,16 @@ public Dictionary DefaultTags } /// - /// Indicates whether the performance feature is enabled, via any combination of - /// , , or . + /// Indicates whether the performance feature is enabled, via either + /// or . /// -#pragma warning disable CS0618 // Type or member is obsolete - internal bool IsPerformanceMonitoringEnabled => EnableTracing switch - { - false => false, - null => TracesSampler is not null || TracesSampleRate is > 0.0, - true => TracesSampler is not null || TracesSampleRate is > 0.0 or null - }; -#pragma warning restore CS0618 // Type or member is obsolete + internal bool IsPerformanceMonitoringEnabled => TracesSampler is not null || TracesSampleRate is > 0.0; /// - /// Indicates whether profiling is enabled, via any combination of - /// , , or . + /// Indicates whether profiling is enabled, via , or /// internal bool IsProfilingEnabled => IsPerformanceMonitoringEnabled && ProfilesSampleRate > 0.0; - /// - /// Simplified option for enabling or disabling tracing. - /// - /// - /// Value - /// Effect - /// - /// - /// true - /// - /// Tracing is enabled. or will be used if set, - /// or 100% sample rate will be used otherwise. - /// - /// - /// - /// false - /// - /// Tracing is disabled, regardless of or . - /// - /// - /// - /// null - /// - /// The default setting. - /// Tracing is enabled only if or are set. - /// - /// - /// - /// - [Obsolete("Use TracesSampleRate or TracesSampler instead")] - public bool? EnableTracing { get; set; } - private double? _tracesSampleRate; /// @@ -815,8 +775,7 @@ public Dictionary DefaultTags /// /// >= 0.0 and <=1.0 /// - /// A custom sample rate is used unless is false, - /// or unless overriden by a function. + /// A custom sample rate is used unless overriden by a function. /// Values outside of this range are invalid. /// /// @@ -824,8 +783,7 @@ public Dictionary DefaultTags /// null /// /// The default setting. - /// The tracing sample rate is determined by the property, - /// unless overriden by a function. + /// The tracing sample rate is determined by the function. /// /// /// diff --git a/test/Sentry.Extensions.Logging.Tests/SentryLoggingOptionsSetupTests.cs b/test/Sentry.Extensions.Logging.Tests/SentryLoggingOptionsSetupTests.cs index cb20a8014e..d6ffa6ac1e 100644 --- a/test/Sentry.Extensions.Logging.Tests/SentryLoggingOptionsSetupTests.cs +++ b/test/Sentry.Extensions.Logging.Tests/SentryLoggingOptionsSetupTests.cs @@ -43,9 +43,6 @@ public void Configure_BindsConfigurationToOptions() FailedRequestTargets = new List { "target1", "target2" }, InitCacheFlushTimeout = TimeSpan.FromSeconds(27), // DefaultTags = Dictionary, -#pragma warning disable CS0618 // Type or member is obsolete - EnableTracing = true, -#pragma warning restore CS0618 // Type or member is obsolete TracesSampleRate = 0.8f, TracePropagationTargets = new List { "target3", "target4" }, StackTraceMode = StackTraceMode.Enhanced, @@ -96,9 +93,6 @@ public void Configure_BindsConfigurationToOptions() ["FailedRequestTargets:1"] = expected.FailedRequestTargets.Last().ToString(), ["InitCacheFlushTimeout"] = expected.InitCacheFlushTimeout.ToString(), ["DefaultTags"] = expected.DefaultTags.ToString(), -#pragma warning disable CS0618 // Type or member is obsolete - ["EnableTracing"] = expected.EnableTracing.ToString(), -#pragma warning restore CS0618 // Type or member is obsolete ["TracesSampleRate"] = expected.TracesSampleRate.Value.ToString(CultureInfo.InvariantCulture), ["TracePropagationTargets:0"] = expected.TracePropagationTargets.First().ToString(), ["TracePropagationTargets:1"] = expected.TracePropagationTargets.Last().ToString(), @@ -156,9 +150,6 @@ public void Configure_BindsConfigurationToOptions() actual.CaptureFailedRequests.Should().Be(expected.CaptureFailedRequests); actual.FailedRequestTargets.Should().BeEquivalentTo(expected.FailedRequestTargets); actual.InitCacheFlushTimeout.Should().Be(expected.InitCacheFlushTimeout); -#pragma warning disable CS0618 // Type or member is obsolete - actual.EnableTracing.Should().Be(expected.EnableTracing); -#pragma warning restore CS0618 // Type or member is obsolete actual.TracesSampleRate.Should().Be(expected.TracesSampleRate); actual.TracePropagationTargets.Should().BeEquivalentTo(expected.TracePropagationTargets); actual.StackTraceMode.Should().Be(expected.StackTraceMode); diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt index 95b72d1fb6..2fb50223fa 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt @@ -668,8 +668,6 @@ namespace Sentry public string? Dsn { get; set; } public bool EnableScopeSync { get; set; } public bool EnableSpotlight { get; set; } - [System.Obsolete("Use TracesSampleRate or TracesSampler instead")] - public bool? EnableTracing { get; set; } public string? Environment { get; set; } public Sentry.ExperimentalMetricsOptions? ExperimentalMetrics { get; set; } public System.Collections.Generic.IList FailedRequestStatusCodes { get; set; } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet7_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet7_0.verified.txt index 95b72d1fb6..2fb50223fa 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet7_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet7_0.verified.txt @@ -668,8 +668,6 @@ namespace Sentry public string? Dsn { get; set; } public bool EnableScopeSync { get; set; } public bool EnableSpotlight { get; set; } - [System.Obsolete("Use TracesSampleRate or TracesSampler instead")] - public bool? EnableTracing { get; set; } public string? Environment { get; set; } public Sentry.ExperimentalMetricsOptions? ExperimentalMetrics { get; set; } public System.Collections.Generic.IList FailedRequestStatusCodes { 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 568ebe00f6..f593dedb0a 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt @@ -669,8 +669,6 @@ namespace Sentry public string? Dsn { get; set; } public bool EnableScopeSync { get; set; } public bool EnableSpotlight { get; set; } - [System.Obsolete("Use TracesSampleRate or TracesSampler instead")] - public bool? EnableTracing { get; set; } public string? Environment { get; set; } public Sentry.ExperimentalMetricsOptions? ExperimentalMetrics { get; set; } public System.Collections.Generic.IList FailedRequestStatusCodes { 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 b2873faa6d..84c37bccc2 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt @@ -666,8 +666,6 @@ namespace Sentry public string? Dsn { get; set; } public bool EnableScopeSync { get; set; } public bool EnableSpotlight { get; set; } - [System.Obsolete("Use TracesSampleRate or TracesSampler instead")] - public bool? EnableTracing { get; set; } public string? Environment { get; set; } public Sentry.ExperimentalMetricsOptions? ExperimentalMetrics { get; set; } public System.Collections.Generic.IList FailedRequestStatusCodes { get; set; } diff --git a/test/Sentry.Tests/HubTests.cs b/test/Sentry.Tests/HubTests.cs index f285747a82..0dd5eddda8 100644 --- a/test/Sentry.Tests/HubTests.cs +++ b/test/Sentry.Tests/HubTests.cs @@ -601,23 +601,6 @@ public void StartTransaction_EnableTracing_SampledIn() transaction.IsSampled.Should().BeTrue(); } - [Fact] - public void StartTransaction_DisableTracing_SampledOut() - { - // Arrange - _fixture.Options.TracesSampleRate = 1.0; -#pragma warning disable CS0618 // Type or member is obsolete - _fixture.Options.EnableTracing = false; -#pragma warning restore CS0618 // Type or member is obsolete - var hub = _fixture.GetSut(); - - // Act - var transaction = hub.StartTransaction("name", "operation"); - - // Assert - transaction.IsSampled.Should().BeFalse(); - } - [Fact] public void StartTransaction_SameInstrumenter_SampledIn() { @@ -673,23 +656,6 @@ public void StartTransaction_EnableTracing_Sampler_SampledIn() transaction.IsSampled.Should().BeTrue(); } - [Fact] - public void StartTransaction_DisableTracing_Sampler_SampledOut() - { - // Arrange - _fixture.Options.TracesSampler = _ => 1.0; -#pragma warning disable CS0618 // Type or member is obsolete - _fixture.Options.EnableTracing = false; -#pragma warning restore CS0618 // Type or member is obsolete - var hub = _fixture.GetSut(); - - // Act - var transaction = hub.StartTransaction("name", "operation"); - - // Assert - transaction.IsSampled.Should().BeFalse(); - } - [Theory] [InlineData(0.25f)] [InlineData(0.50f)] diff --git a/test/Sentry.Tests/SentryOptionsTests.cs b/test/Sentry.Tests/SentryOptionsTests.cs index 1f5789f45d..d9e8194039 100644 --- a/test/Sentry.Tests/SentryOptionsTests.cs +++ b/test/Sentry.Tests/SentryOptionsTests.cs @@ -32,15 +32,6 @@ public void AttachStackTrace_ByDefault_True() Assert.True(sut.AttachStacktrace); } - [Fact] - public void EnableTracing_Default_Null() - { - var sut = new SentryOptions(); -#pragma warning disable CS0618 // Type or member is obsolete - Assert.Null(sut.EnableTracing); -#pragma warning restore CS0618 // Type or member is obsolete - } - [Fact] public void TracesSampleRate_Default_Null() { @@ -62,32 +53,6 @@ public void IsPerformanceMonitoringEnabled_Default_False() Assert.False(sut.IsPerformanceMonitoringEnabled); } - [Fact] - public void IsPerformanceMonitoringEnabled_EnableTracing_True() - { - var sut = new SentryOptions - { -#pragma warning disable CS0618 // Type or member is obsolete - EnableTracing = true -#pragma warning restore CS0618 // Type or member is obsolete - }; - - Assert.True(sut.IsPerformanceMonitoringEnabled); - } - - [Fact] - public void IsPerformanceMonitoringEnabled_EnableTracing_False() - { - var sut = new SentryOptions - { -#pragma warning disable CS0618 // Type or member is obsolete - EnableTracing = false -#pragma warning restore CS0618 // Type or member is obsolete - }; - - Assert.False(sut.IsPerformanceMonitoringEnabled); - } - [Fact] public void IsPerformanceMonitoringEnabled_TracesSampleRate_Zero() { @@ -137,57 +102,6 @@ public void IsPerformanceMonitoringEnabled_TracesSampler_Provided() Assert.True(sut.IsPerformanceMonitoringEnabled); } - [Fact] - public void IsPerformanceMonitoringEnabled_EnableTracing_True_TracesSampleRate_Zero() - { - // Edge Case: - // Tracing enabled, but sample rate set to zero, and no sampler function, should be treated as disabled. - - var sut = new SentryOptions - { -#pragma warning disable CS0618 // Type or member is obsolete - EnableTracing = true, -#pragma warning restore CS0618 // Type or member is obsolete - TracesSampleRate = 0.0 - }; - - Assert.False(sut.IsPerformanceMonitoringEnabled); - } - - [Fact] - public void IsPerformanceMonitoringEnabled_EnableTracing_False_TracesSampleRate_One() - { - // Edge Case: - // Tracing disabled should be treated as disabled regardless of sample rate set. - - var sut = new SentryOptions - { -#pragma warning disable CS0618 // Type or member is obsolete - EnableTracing = false, -#pragma warning restore CS0618 // Type or member is obsolete - TracesSampleRate = 1.0 - }; - - Assert.False(sut.IsPerformanceMonitoringEnabled); - } - - [Fact] - public void IsPerformanceMonitoringEnabled_EnableTracing_False_TracesSampler_Provided() - { - // Edge Case: - // Tracing disabled should be treated as disabled regardless of sampler function set. - - var sut = new SentryOptions - { -#pragma warning disable CS0618 // Type or member is obsolete - EnableTracing = false, -#pragma warning restore CS0618 // Type or member is obsolete - TracesSampler = _ => null - }; - - Assert.False(sut.IsPerformanceMonitoringEnabled); - } - [Fact] public void ProfilesSampleRate_Default_Null() { @@ -202,34 +116,6 @@ public void IsProfilingEnabled_Default_False() Assert.False(sut.IsProfilingEnabled); } - [Fact] - public void IsProfilingEnabled_EnableTracing_True() - { - var sut = new SentryOptions - { -#pragma warning disable CS0618 // Type or member is obsolete - EnableTracing = true, -#pragma warning restore CS0618 // Type or member is obsolete - ProfilesSampleRate = double.Epsilon - }; - - Assert.True(sut.IsProfilingEnabled); - } - - [Fact] - public void IsProfilingEnabled_EnableTracing_False() - { - var sut = new SentryOptions - { -#pragma warning disable CS0618 // Type or member is obsolete - EnableTracing = false, -#pragma warning restore CS0618 // Type or member is obsolete - ProfilesSampleRate = double.Epsilon - }; - - Assert.False(sut.IsProfilingEnabled); - } - [Fact] public void IsProfilingEnabled_TracesSampleRate_Zero() {