Skip to content

Commit

Permalink
Marked EnableTracing as Obsolete (#3381)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescrosswell committed May 23, 2024
1 parent 5bd8c8a commit b0a1996
Show file tree
Hide file tree
Showing 26 changed files with 64 additions and 19 deletions.
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

### API Changes

- SentryOptions.EnableTracing has been marked as Obsolete ([#3381](https://github.com/getsentry/sentry-dotnet/pull/3381))

### Fixes

- P/Invoke warning for GetWindowThreadProcessId no longer shows when using Sentry in UWP applications ([#3372](https://github.com/getsentry/sentry-dotnet/pull/3372))
Expand Down
2 changes: 1 addition & 1 deletion samples/Sentry.Samples.AspNetCore.Basic/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void Main(string[] args)
o.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537";
// Enable Sentry performance monitoring
o.EnableTracing = true;
o.TracesSampleRate = 1.0;
#if DEBUG
// Log debug information about the Sentry SDK
Expand Down
2 changes: 1 addition & 1 deletion samples/Sentry.Samples.AspNetCore.Blazor.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
builder.WebHost.UseSentry(options =>
{
options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537";
options.EnableTracing = true;
options.TracesSampleRate = 1.0;
options.Debug = true;
});

Expand Down
2 changes: 1 addition & 1 deletion samples/Sentry.Samples.AspNetCore.Grpc/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void Main(string[] args)
options.Release =
"e386dfd"; // Could also be any format, such as: 2.0, or however version of your app is
options.EnableTracing = true;
options.TracesSampleRate = 1.0;
options.MaxBreadcrumbs = 200;
Expand Down
2 changes: 1 addition & 1 deletion samples/Sentry.Samples.AspNetCore.Mvc/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
options.MaxBreadcrumbs = 200;
options.EnableTracing = true;
options.TracesSampleRate = 1.0;
// Set a proxy for outgoing HTTP connections
options.HttpProxy = null; // new WebProxy("https://localhost:3128");
Expand Down
2 changes: 1 addition & 1 deletion samples/Sentry.Samples.Azure.Functions.Worker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
builder.UseSentry(host, options =>
{
options.EnableTracing = true;
options.TracesSampleRate = 1.0;
// options.Debug = true;
});
})
Expand Down
4 changes: 2 additions & 2 deletions samples/Sentry.Samples.Console.Basic/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
// If you are writing a background service of any kind, you should remove this.
options.IsGlobalModeEnabled = true;
// This option will enable Sentry's tracing features. You still need to start transactions and spans.
options.EnableTracing = true;
// This option tells Sentry to capture 100% of traces. You still need to start transactions and spans.
options.TracesSampleRate = 1.0;
});

// This starts a new transaction and attaches it to the scope.
Expand Down
2 changes: 1 addition & 1 deletion samples/Sentry.Samples.Console.Profiling/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private static void Main()
options.Debug = true;
// options.AutoSessionTracking = true;
options.IsGlobalModeEnabled = true;
options.EnableTracing = true;
options.TracesSampleRate = 1.0;
// Make sure to reduce the sampling rate in production.
options.ProfilesSampleRate = 1.0;
Expand Down
2 changes: 1 addition & 1 deletion samples/Sentry.Samples.EntityFramework/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
o.Debug = true; // To see SDK logs on the console
o.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537";
o.EnableTracing = true;
o.TracesSampleRate = 1.0;
// Add the EntityFramework integration to the SentryOptions of your app startup code:
o.AddEntityFramework();
Expand Down
1 change: 0 additions & 1 deletion samples/Sentry.Samples.GraphQL.Client.Http/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
options.CaptureFailedRequests = true;
options.SendDefaultPii = true;
options.TracesSampleRate = 1.0;
options.EnableTracing = true;
});

var transaction = SentrySdk.StartTransaction("Program Main", "function");
Expand Down
2 changes: 1 addition & 1 deletion samples/Sentry.Samples.GraphQL.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static WebApplication BuildWebApplication(string[] args)
{
// A DSN is required. You can set it here, or in configuration, or in an environment variable.
// o.Dsn = "...Your DSN Here...";
o.EnableTracing = true;
o.TracesSampleRate = 1.0;
o.Debug = true;
o.SendDefaultPii = true;
o.UseOpenTelemetry(); // <-- Configure Sentry to use OpenTelemetry trace information
Expand Down
2 changes: 2 additions & 0 deletions src/Sentry/BindableSentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ 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;
Expand Down
4 changes: 4 additions & 0 deletions src/Sentry/Internal/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public async Task ConfigureScopeAsync(Func<Scope, Task> configureScope)
// 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
{
transaction.IsSampled = false;
transaction.SampleRate = 0.0;
Expand All @@ -152,7 +154,9 @@ public async Task ConfigureScopeAsync(Func<Scope, Task> configureScope)
// 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
transaction.IsSampled = _randomValuesFactory.NextBool(sampleRate);
transaction.SampleRate = sampleRate;
}
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 @@ -117,7 +117,9 @@ 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.TracesSampleRate = (JavaDouble?)options.TracesSampleRate;
if (options.TracesSampler is { } tracesSampler)
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 @@ -75,10 +75,12 @@ 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;

Expand Down
3 changes: 3 additions & 0 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -753,12 +753,14 @@ public IList<SubstringOrRegexPattern> FailedRequestTargets
/// Indicates whether the performance feature is enabled, via any combination of
/// <see cref="EnableTracing"/>, <see cref="TracesSampleRate"/>, or <see cref="TracesSampler"/>.
/// </summary>
#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

/// <summary>
/// Indicates whether profiling is enabled, via any combination of
Expand Down Expand Up @@ -795,6 +797,7 @@ public IList<SubstringOrRegexPattern> FailedRequestTargets
/// </item>
/// </list>
/// </summary>
[Obsolete("Use TracesSampleRate or TracesSampler instead")]
public bool? EnableTracing { get; set; }

private double? _tracesSampleRate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Fixture()
var options = new SentryOptions
{
Dsn = ValidDsn,
EnableTracing = true,
TracesSampleRate = 1.0,
};

var client = Substitute.For<ISentryClient>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public void Configure_BindsConfigurationToOptions()
FailedRequestTargets = new List<SubstringOrRegexPattern> { "target1", "target2" },
InitCacheFlushTimeout = TimeSpan.FromSeconds(27),
// DefaultTags = Dictionary<string,string>,
#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<SubstringOrRegexPattern> { "target3", "target4" },
StackTraceMode = StackTraceMode.Enhanced,
Expand Down Expand Up @@ -94,7 +96,9 @@ 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(),
Expand Down Expand Up @@ -152,7 +156,9 @@ 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Fixture()
Options = new SentryOptions
{
Dsn = ValidDsn,
EnableTracing = true,
TracesSampleRate = 1.0,
AutoSessionTracking = false
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ 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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ 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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ 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; }
Expand Down
1 change: 1 addition & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ 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; }
Expand Down
14 changes: 9 additions & 5 deletions test/Sentry.Tests/HubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Fixture()
Options = new SentryOptions
{
Dsn = ValidDsn,
EnableTracing = true,
TracesSampleRate = 1.0,
AutoSessionTracking = false
};

Expand Down Expand Up @@ -591,7 +591,7 @@ public void StartTransaction_StaticSampling_SampledOut()
public void StartTransaction_EnableTracing_SampledIn()
{
// Arrange
_fixture.Options.EnableTracing = true;
_fixture.Options.TracesSampleRate = 1.0;
var hub = _fixture.GetSut();

// Act
Expand All @@ -606,7 +606,9 @@ 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
Expand All @@ -620,7 +622,7 @@ public void StartTransaction_DisableTracing_SampledOut()
public void StartTransaction_SameInstrumenter_SampledIn()
{
// Arrange
_fixture.Options.EnableTracing = true;
_fixture.Options.TracesSampleRate = 1.0;
_fixture.Options.Instrumenter = Instrumenter.Sentry; // The default... making it explicit for this test though
var hub = _fixture.GetSut();

Expand All @@ -640,7 +642,7 @@ public void StartTransaction_SameInstrumenter_SampledIn()
public void StartTransaction_DifferentInstrumenter_SampledIn()
{
// Arrange
_fixture.Options.EnableTracing = true;
_fixture.Options.TracesSampleRate = 1.0;
_fixture.Options.Instrumenter = Instrumenter.OpenTelemetry;
var hub = _fixture.GetSut();

Expand All @@ -661,7 +663,7 @@ public void StartTransaction_EnableTracing_Sampler_SampledIn()
{
// Arrange
_fixture.Options.TracesSampler = _ => 1.0;
_fixture.Options.EnableTracing = true;
_fixture.Options.TracesSampleRate = 1.0;
var hub = _fixture.GetSut();

// Act
Expand All @@ -676,7 +678,9 @@ 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
Expand Down

0 comments on commit b0a1996

Please sign in to comment.