From 59ff50c2738b84191184a336be8af7021985fc0d Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 3 Dec 2026 11:06:41 +1300 Subject: [PATCH 01/10] feat: DataCollection is no longer experimental, and SendDefaultPii is deprecated Mark SentryOptions.SendDefaultPii [Obsolete] in favour of ConfigureDataCollection, with migration notes in its XML docs, and drop [Experimental] from ConfigureDataCollection, DataCollectionOptions, KeyValueCollectionBehavior, KeyValueCollectionMode and HttpBodyTypes. Internal reads that deliberately stay on SendDefaultPii until the next major are wrapped in line-level CS0618 suppressions. Samples move to ConfigureDataCollection, and a sentry-spec-compliance.json manifest records the data collection spec sections we implement. Closes #5437 Co-Authored-By: Claude Opus 5.5 --- .../Sentry.Samples.Android/MainActivity.cs | 2 +- .../appsettings.json | 7 +++- .../appsettings.json | 7 +++- .../appsettings.json | 7 +++- .../Program.cs | 4 +- .../appsettings.json | 6 ++- .../appsettings.json | 4 +- .../Program.cs | 3 +- .../Sentry.Samples.GraphQL.Server/Program.cs | 2 +- .../Sentry.Samples.Hangfire/appsettings.json | 7 +++- samples/Sentry.Samples.NLog/Program.cs | 2 +- .../Program.cs | 2 +- .../Sentry.Samples.Quartz/appsettings.json | 7 +++- samples/Sentry.Samples.Serilog/Program.cs | 2 +- sentry-spec-compliance.json | 17 ++++++++ .../AspNetCoreEnricher.cs | 2 + src/Sentry/BindableSentryOptions.cs | 2 + src/Sentry/DataCollectionOptions.cs | 8 ---- src/Sentry/HttpBodyTypes.cs | 3 -- src/Sentry/Internal/DataCollectionResolver.cs | 2 + .../Internal/MainSentryEventProcessor.cs | 2 + src/Sentry/KeyValueCollectionBehavior.cs | 5 --- src/Sentry/SentryClient.cs | 4 ++ src/Sentry/SentryLog.cs | 2 + src/Sentry/SentryOptions.cs | 40 +++++++++++++++---- .../HttpContextExtensionsTests.cs | 2 + .../SystemWebRequestEventProcessorTests.cs | 2 + .../IntegrationMockedBackgroundWorker.cs | 2 + .../ScopeExtensionsTests.cs | 2 + .../SentryTracingMiddlewareTests.cs | 2 + ...tryWebApplicationBuilderExtensionsTests.cs | 2 + .../SentryAIOptionsTests.cs | 2 + .../SentryAISpanEnricherTests.cs | 2 + .../SentryInstrumentedFunctionTests.cs | 2 + .../SentryHostBuilderExtensionsTests.cs | 2 + .../AspNetCoreEnricherTests.cs | 2 + ...rationTests.Simple.DotNet10_0.verified.txt | 2 +- ...grationTests.Simple.DotNet8_0.verified.txt | 2 +- ...grationTests.Simple.DotNet9_0.verified.txt | 2 +- .../IntegrationTests.verify.cs | 1 + ...iApprovalTests.Run.DotNet10_0.verified.txt | 8 ++-- ...iApprovalTests.Run.DotNet11_0.verified.txt | 8 ++-- ...piApprovalTests.Run.DotNet8_0.verified.txt | 8 ++-- ...piApprovalTests.Run.DotNet9_0.verified.txt | 8 ++-- .../ApiApprovalTests.Run.Net4_8.verified.txt | 3 ++ .../RequestBodyExtractionDispatcherTests.cs | 2 + .../Internals/DataCollectionResolverTests.cs | 2 + .../MainSentryEventProcessorTests.cs | 2 + .../Platforms/Android/SentrySdkTests.cs | 3 +- .../Platforms/iOS/SentrySdkTests.cs | 1 + .../Sentry.Tests/Protocol/SentryEventTests.cs | 2 + .../Protocol/SentryTransactionTests.cs | 2 + test/Sentry.Tests/SentryClientTests.cs | 2 + ...tryGraphQlHttpFailedRequestHandlerTests.cs | 2 + .../SentryHttpFailedRequestHandlerTests.cs | 2 + test/Sentry.Tests/SentryLogTests.cs | 2 + 56 files changed, 166 insertions(+), 69 deletions(-) create mode 100644 sentry-spec-compliance.json diff --git a/samples/Sentry.Samples.Android/MainActivity.cs b/samples/Sentry.Samples.Android/MainActivity.cs index b2bd90ce0a..14f00de12c 100644 --- a/samples/Sentry.Samples.Android/MainActivity.cs +++ b/samples/Sentry.Samples.Android/MainActivity.cs @@ -20,7 +20,7 @@ protected override void OnCreate(Bundle? savedInstanceState) options.Dsn = EnvironmentVariables.Dsn; #endif - options.SendDefaultPii = true; // adds the user's IP address automatically + options.ConfigureDataCollection(_ => { }); // adds the user's IP address automatically // Android specific .NET features are under the Android properties: options.Android.LogCatIntegration = LogCatIntegrationType.Errors; // Get logcat logs for both handled and unhandled errors; default is unhandled only diff --git a/samples/Sentry.Samples.AspNetCore.Grpc/appsettings.json b/samples/Sentry.Samples.AspNetCore.Grpc/appsettings.json index 7b1e482578..5ff24158fe 100644 --- a/samples/Sentry.Samples.AspNetCore.Grpc/appsettings.json +++ b/samples/Sentry.Samples.AspNetCore.Grpc/appsettings.json @@ -6,8 +6,11 @@ //"Dsn": "TODO: Configure your DSN here and uncomment this line", // Opt-in for payload submission "MaxRequestBodySize": "Always", - // Sends Cookies, User Id when one is logged on and user IP address to sentry. It's turned off by default. - "SendDefaultPii": true, + // Opts in to sending cookies, the logged-on user and their IP address, with sensitive values filtered out. + // Restrict any category here, for example "Cookies": { "Mode": "Off" }. + "DataCollection": { + "UserInfo": true + }, // Whether to add System.Diagnostics.Activity data to the event:: // For more: https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.DiagnosticSource/src/ActivityUserGuide.md "IncludeActivityData": true, diff --git a/samples/Sentry.Samples.AspNetCore.Mvc/appsettings.json b/samples/Sentry.Samples.AspNetCore.Mvc/appsettings.json index 535b23fa32..fa466b6c29 100644 --- a/samples/Sentry.Samples.AspNetCore.Mvc/appsettings.json +++ b/samples/Sentry.Samples.AspNetCore.Mvc/appsettings.json @@ -6,8 +6,11 @@ //"Dsn": "TODO: Configure your DSN here and uncomment this line", // Opt-in for payload submission "MaxRequestBodySize": "Always", - // Sends Cookies, User Id when one is logged on and user IP address to sentry. It's turned off by default. - "SendDefaultPii": true, + // Opts in to sending cookies, the logged-on user and their IP address, with sensitive values filtered out. + // Restrict any category here, for example "Cookies": { "Mode": "Off" }. + "DataCollection": { + "UserInfo": true + }, // Whether to add System.Diagnostics.Activity data to the event:: // For more: https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.DiagnosticSource/src/ActivityUserGuide.md "IncludeActivityData": true, diff --git a/samples/Sentry.Samples.AspNetCore.Serilog/appsettings.json b/samples/Sentry.Samples.AspNetCore.Serilog/appsettings.json index 73cae7a365..4fcbf907c0 100644 --- a/samples/Sentry.Samples.AspNetCore.Serilog/appsettings.json +++ b/samples/Sentry.Samples.AspNetCore.Serilog/appsettings.json @@ -7,8 +7,11 @@ "TracesSampleRate": 1.0, // Opt-in for payload submission "MaxRequestBodySize": "Always", - // Sends Cookies, User Id when one is logged on and user IP address to sentry. It's turned off by default. - "SendDefaultPii": true, + // Opts in to sending cookies, the logged-on user and their IP address, with sensitive values filtered out. + // Restrict any category here, for example "Cookies": { "Mode": "Off" }. + "DataCollection": { + "UserInfo": true + }, // Whether to add System.Diagnostics.Activity data to the event:: // For more: https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/ActivityUserGuide.md "IncludeActivityData": true, diff --git a/samples/Sentry.Samples.Console.Customized/Program.cs b/samples/Sentry.Samples.Console.Customized/Program.cs index 3fbc23f7a2..ced2965746 100644 --- a/samples/Sentry.Samples.Console.Customized/Program.cs +++ b/samples/Sentry.Samples.Console.Customized/Program.cs @@ -34,8 +34,8 @@ await SentrySdk.ConfigureScopeAsync(async scope => // Before excluding all prefixed 'LibraryX.', any stack trace from a type namespaced 'LibraryX.Core' will be considered InApp. options.AddInAppInclude("LibraryX.Core"); - // Send personal identifiable information like the username logged on to the computer and machine name - options.SendDefaultPii = true; + // Send personal identifiable information like the username logged on to the computer + options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = true); // To enable event sampling, uncomment: // o.SampleRate = 0.5f; // Randomly drop (don't send to Sentry) half of events diff --git a/samples/Sentry.Samples.GenericHost/appsettings.json b/samples/Sentry.Samples.GenericHost/appsettings.json index d72b9dce5a..2b10486bcf 100644 --- a/samples/Sentry.Samples.GenericHost/appsettings.json +++ b/samples/Sentry.Samples.GenericHost/appsettings.json @@ -14,8 +14,10 @@ }, // Sentry SDK options, read by UseSentry "Sentry": { - // Send user name and machine name - "SendDefaultPii": true, + // Send the user name, with sensitive values filtered out of automatically collected data + "DataCollection": { + "UserInfo": true + }, // Also send ILogger entries to Sentry as structured logs. This is off by default. "EnableLogs": true } diff --git a/samples/Sentry.Samples.Google.Cloud.Functions/appsettings.json b/samples/Sentry.Samples.Google.Cloud.Functions/appsettings.json index 3dd6980118..9cfebe3f99 100644 --- a/samples/Sentry.Samples.Google.Cloud.Functions/appsettings.json +++ b/samples/Sentry.Samples.Google.Cloud.Functions/appsettings.json @@ -12,7 +12,9 @@ "Sentry": { //"Dsn": "TODO: Configure your DSN here and uncomment this line", "MaxRequestBodySize": "Always", - "SendDefaultPii": true, + "DataCollection": { + "UserInfo": true + }, "TracesSampleRate": 1.0, "EnableLogs" : true } diff --git a/samples/Sentry.Samples.GraphQL.Client.Http/Program.cs b/samples/Sentry.Samples.GraphQL.Client.Http/Program.cs index 36a085fcb2..ee28687d0c 100644 --- a/samples/Sentry.Samples.GraphQL.Client.Http/Program.cs +++ b/samples/Sentry.Samples.GraphQL.Client.Http/Program.cs @@ -18,7 +18,8 @@ #endif options.CaptureFailedRequests = true; - options.SendDefaultPii = true; + // Attach GraphQL documents and variables, headers and cookies to failed request events + options.ConfigureDataCollection(_ => { }); options.TracesSampleRate = 1.0; }); diff --git a/samples/Sentry.Samples.GraphQL.Server/Program.cs b/samples/Sentry.Samples.GraphQL.Server/Program.cs index 8a435a12e2..f8eae118b1 100644 --- a/samples/Sentry.Samples.GraphQL.Server/Program.cs +++ b/samples/Sentry.Samples.GraphQL.Server/Program.cs @@ -54,7 +54,7 @@ public static WebApplication BuildWebApplication(string[] args) options.TracesSampleRate = 1.0; options.Debug = true; - options.SendDefaultPii = true; + options.ConfigureDataCollection(_ => { }); options.UseOtlp(); // <-- Configure Sentry to use OpenTelemetry trace information }); diff --git a/samples/Sentry.Samples.Hangfire/appsettings.json b/samples/Sentry.Samples.Hangfire/appsettings.json index d5e353d5b7..8cb7d6b1b8 100644 --- a/samples/Sentry.Samples.Hangfire/appsettings.json +++ b/samples/Sentry.Samples.Hangfire/appsettings.json @@ -6,8 +6,11 @@ // "Dsn": "TODO: Configure your DSN here and uncomment this line", // Opt-in for payload submission "MaxRequestBodySize": "Always", - // Sends Cookies, User Id when one is logged on and user IP address to sentry. It's turned off by default. - "SendDefaultPii": true, + // Opts in to sending cookies, the logged-on user and their IP address, with sensitive values filtered out. + // Restrict any category here, for example "Cookies": { "Mode": "Off" }. + "DataCollection": { + "UserInfo": true + }, // Whether to add System.Diagnostics.Activity data to the event:: // For more: https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.DiagnosticSource/src/ActivityUserGuide.md "IncludeActivityData": true, diff --git a/samples/Sentry.Samples.NLog/Program.cs b/samples/Sentry.Samples.NLog/Program.cs index fff6a48411..ab3fd1bd21 100644 --- a/samples/Sentry.Samples.NLog/Program.cs +++ b/samples/Sentry.Samples.NLog/Program.cs @@ -21,7 +21,7 @@ private static void Main() options.Dsn = SamplesShared.Dsn; #endif options.AttachStacktrace = true; - options.SendDefaultPii = true; // Send Personal Identifiable information like the username of the user logged in to the device + options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = true); // Send Personal Identifiable information like the username of the user logged in to the device }); try diff --git a/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs b/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs index 3b7496a835..c61e6a83ee 100644 --- a/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs +++ b/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs @@ -38,7 +38,7 @@ { options.Dsn = dsn; options.Debug = builder.Environment.IsDevelopment(); - options.SendDefaultPii = true; + options.ConfigureDataCollection(_ => { }); options.TracesSampleRate = 1.0; options.UseOtlp(); // <-- Configure Sentry to use OpenTelemetry trace information }); diff --git a/samples/Sentry.Samples.Quartz/appsettings.json b/samples/Sentry.Samples.Quartz/appsettings.json index 462bf7438f..2e01322d2a 100644 --- a/samples/Sentry.Samples.Quartz/appsettings.json +++ b/samples/Sentry.Samples.Quartz/appsettings.json @@ -6,8 +6,11 @@ // "Dsn": "TODO: Configure your DSN here and uncomment this line", // Opt-in for payload submission "MaxRequestBodySize": "Always", - // Sends Cookies, User Id when one is logged on and user IP address to sentry. It's turned off by default. - "SendDefaultPii": true, + // Opts in to sending cookies, the logged-on user and their IP address, with sensitive values filtered out. + // Restrict any category here, for example "Cookies": { "Mode": "Off" }. + "DataCollection": { + "UserInfo": true + }, // Whether to add System.Diagnostics.Activity data to the event:: // For more: https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.DiagnosticSource/src/ActivityUserGuide.md "IncludeActivityData": true, diff --git a/samples/Sentry.Samples.Serilog/Program.cs b/samples/Sentry.Samples.Serilog/Program.cs index b4c0075c56..5da4975483 100644 --- a/samples/Sentry.Samples.Serilog/Program.cs +++ b/samples/Sentry.Samples.Serilog/Program.cs @@ -19,7 +19,7 @@ private static void Main() options.AttachStacktrace = true; // send PII like the username of the user logged in to the device - options.SendDefaultPii = true; + options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = true); // Apply properties from the Serilog LogContext (like MyTaskId below) to Sentry events options.UseSerilog(); }); diff --git a/sentry-spec-compliance.json b/sentry-spec-compliance.json new file mode 100644 index 0000000000..5387ff5100 --- /dev/null +++ b/sentry-spec-compliance.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://develop.sentry.dev/schemas/spec-compliance.json", + "sdk": "sentry-dotnet", + "last_updated": "2026-12-03", + "specs": { + "sdk/foundations/client/data-collection": { + "version": "0.0.0", + "sections": { + "configuration-surface": "0.19.0", + "integration-overrides": "0.19.0" + }, + "non_applicable": { + "data-sensitivity-levels": "Defines sensitivity categories without requiring SDK behavior." + } + } + } +} diff --git a/src/Sentry.OpenTelemetry/AspNetCoreEnricher.cs b/src/Sentry.OpenTelemetry/AspNetCoreEnricher.cs index 832da26308..45af3ee99c 100644 --- a/src/Sentry.OpenTelemetry/AspNetCoreEnricher.cs +++ b/src/Sentry.OpenTelemetry/AspNetCoreEnricher.cs @@ -8,7 +8,9 @@ internal class AspNetCoreEnricher : IOpenTelemetryEnricher public void Enrich(ISpan span, Activity activity, IHub hub, SentryOptions? options) { +#pragma warning disable CS0618 if (options?.SendDefaultPii is true) +#pragma warning restore CS0618 { hub.ConfigureScope(static (scope, enricher) => { diff --git a/src/Sentry/BindableSentryOptions.cs b/src/Sentry/BindableSentryOptions.cs index ff65251f9e..6979b20567 100644 --- a/src/Sentry/BindableSentryOptions.cs +++ b/src/Sentry/BindableSentryOptions.cs @@ -64,7 +64,9 @@ public void ApplyTo(SentryOptions options) 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; +#pragma warning disable CS0618 options.SendDefaultPii = SendDefaultPii ?? options.SendDefaultPii; +#pragma warning restore CS0618 options.IsEnvironmentUser = IsEnvironmentUser ?? options.IsEnvironmentUser; options.ServerName = ServerName ?? options.ServerName; options.AttachStacktrace = AttachStacktrace ?? options.AttachStacktrace; diff --git a/src/Sentry/DataCollectionOptions.cs b/src/Sentry/DataCollectionOptions.cs index 10a0211d4d..9c0856ff2f 100644 --- a/src/Sentry/DataCollectionOptions.cs +++ b/src/Sentry/DataCollectionOptions.cs @@ -1,27 +1,19 @@ -using Sentry.Infrastructure; - namespace Sentry; /// /// Controls which categories of data the SDK's integrations collect automatically. /// /// -/// The integrations are still being migrated onto these options, and those that haven't moved yet ignore these -/// categories; see . -/// /// Every category starts at the default from the data collection spec, which collects it - including user identity /// and HTTP bodies - with sensitive keys filtered out. Restrict an individual category by setting it. -/// /// /// This only gates data the SDK gathers by itself. Data you provide explicitly - a set on /// the scope, tags, or anything added in /// - is always sent. Where an integration exposes its own data-collection option, that option takes precedence /// over the matching category here. /// -/// This API is experimental, and it may change in the future. /// /// -[Experimental(DiagnosticId.ExperimentalFeature)] public class DataCollectionOptions { internal DataCollectionOptions() diff --git a/src/Sentry/HttpBodyTypes.cs b/src/Sentry/HttpBodyTypes.cs index 1ff52b3ebf..ee68c0e584 100644 --- a/src/Sentry/HttpBodyTypes.cs +++ b/src/Sentry/HttpBodyTypes.cs @@ -1,12 +1,9 @@ -using Sentry.Infrastructure; - namespace Sentry; /// /// The HTTP bodies that may be attached to telemetry. /// [Flags] -[Experimental(DiagnosticId.ExperimentalFeature)] public enum HttpBodyTypes { /// diff --git a/src/Sentry/Internal/DataCollectionResolver.cs b/src/Sentry/Internal/DataCollectionResolver.cs index fc9913823a..194b99fa68 100644 --- a/src/Sentry/Internal/DataCollectionResolver.cs +++ b/src/Sentry/Internal/DataCollectionResolver.cs @@ -17,7 +17,9 @@ internal sealed class DataCollectionResolver(SentryOptions options) private DataCollectionOptions? Configured => options.DataCollection; +#pragma warning disable CS0618 private bool SendDefaultPii => options.SendDefaultPii; +#pragma warning restore CS0618 public bool UserInfo => Configured?.UserInfo ?? SendDefaultPii; diff --git a/src/Sentry/Internal/MainSentryEventProcessor.cs b/src/Sentry/Internal/MainSentryEventProcessor.cs index 5ad49f020b..c1b7f50088 100644 --- a/src/Sentry/Internal/MainSentryEventProcessor.cs +++ b/src/Sentry/Internal/MainSentryEventProcessor.cs @@ -70,10 +70,12 @@ public SentryEvent Process(SentryEvent @event) { @event.ServerName = _options.ServerName; } +#pragma warning disable CS0618 else if (_options.SendDefaultPii) { @event.ServerName = Environment.MachineName; } +#pragma warning restore CS0618 } @event.Level ??= SentryLevel.Error; diff --git a/src/Sentry/KeyValueCollectionBehavior.cs b/src/Sentry/KeyValueCollectionBehavior.cs index a37822b248..42269eba0d 100644 --- a/src/Sentry/KeyValueCollectionBehavior.cs +++ b/src/Sentry/KeyValueCollectionBehavior.cs @@ -1,11 +1,8 @@ -using Sentry.Infrastructure; - namespace Sentry; /// /// How a category of key-value data is collected. /// -[Experimental(DiagnosticId.ExperimentalFeature)] public enum KeyValueCollectionMode { /// @@ -46,9 +43,7 @@ public enum KeyValueCollectionMode /// available in code has no configuration equivalent, so a scalar such as /// Sentry:DataCollection:Cookies=false is ignored. /// -/// This API is experimental, and it may change in the future. /// -[Experimental(DiagnosticId.ExperimentalFeature)] public sealed class KeyValueCollectionBehavior { private KeyValueCollectionBehavior(KeyValueCollectionMode mode, IReadOnlyList? terms) diff --git a/src/Sentry/SentryClient.cs b/src/Sentry/SentryClient.cs index e64a92942b..a6d83e7f68 100644 --- a/src/Sentry/SentryClient.cs +++ b/src/Sentry/SentryClient.cs @@ -243,10 +243,12 @@ public void CaptureTransaction(SentryTransaction transaction, Scope? scope, Sent return; } +#pragma warning disable CS0618 if (!_options.SendDefaultPii) { processedTransaction.Redact(); } +#pragma warning restore CS0618 // Keep null entries so the null-attachment guard in Envelope.FromTransaction handles them // (consistent with the event/feedback capture paths); dereferencing them here would throw. @@ -440,10 +442,12 @@ private SentryId DoSendEvent(SentryEvent @event, SentryHint? hint, Scope? scope) _options.LogDebug("Event sampled in."); } +#pragma warning disable CS0618 if (!_options.SendDefaultPii) { processedEvent.Redact(); } +#pragma warning restore CS0618 CaptureReplay(processedEvent, scope); diff --git a/src/Sentry/SentryLog.cs b/src/Sentry/SentryLog.cs index 589e8a2e7d..780b39aa15 100644 --- a/src/Sentry/SentryLog.cs +++ b/src/Sentry/SentryLog.cs @@ -168,10 +168,12 @@ internal void SetDefaultAttributes(SentryOptions options, Scope? scope, SdkVersi { SetAttribute("server.address", options.ServerName!); } +#pragma warning disable CS0618 else if (options.SendDefaultPii) { SetAttribute("server.address", Environment.MachineName); } +#pragma warning restore CS0618 // User Attributes if (scope?.User is { } user) diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index d95beb7c74..57808ad3f0 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -322,6 +322,10 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// internal List? InAppInclude { get; set; } + internal const string ObsoleteSendDefaultPii = + "Use ConfigureDataCollection instead, which controls each category of automatically collected data separately. " + + "SendDefaultPii will be removed in the next major version."; + /// /// Whether to include default Personal Identifiable information /// @@ -329,7 +333,35 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// By default PII data like Username and Client IP address are not sent to Sentry. /// When this flag is turned on, default PII data like Cookies, Claims in Web applications /// and user data read from the request are sent. + /// + /// Superseded by . Once that has been called, integrations ignore this + /// option. To keep what SendDefaultPii = true collects, call ConfigureDataCollection(_ => { }). + /// The defaults collect every category, with sensitive keys filtered out. + /// + /// + /// The closest equivalent of SendDefaultPii = false is: + /// + /// options.ConfigureDataCollection(dataCollection => + /// { + /// dataCollection.UserInfo = false; + /// dataCollection.Cookies = KeyValueCollectionBehavior.Off; + /// dataCollection.HttpBodies = HttpBodyTypes.IncomingRequest; + /// dataCollection.GraphQL.Document = false; + /// dataCollection.GraphQL.Variables = false; + /// }); + /// + /// This still differs from SendDefaultPii = false in three ways. Failed HTTP request events include + /// headers: sets one behavior for those and for the headers of + /// incoming requests, and SendDefaultPii = false collected only the latter. They also include the URL + /// fragment, which follows . And database statements are + /// sanitized. + /// + /// + /// The machine name is still sent as only when this option is true. Set + /// explicitly to keep sending it without this option. + /// /// + [Obsolete(ObsoleteSendDefaultPii)] public bool SendDefaultPii { get; set; } /// @@ -346,16 +378,11 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// SendDefaultPii = false to suppress user identity needs to set /// to false here as well. /// - /// The integrations are still being migrated onto these options. Those that haven't moved yet still follow - /// and ignore the categories set here. - /// - /// /// On Android, calling this also turns on the native SDK's file path collection for file I/O spans, which has /// no counterpart here. To turn it off, set the io.sentry.data-collection.file-paths metadata in /// AndroidManifest.xml to false. /// /// Repeated calls build on the same options. - /// This API is experimental, and it may change in the future. /// /// /// @@ -367,7 +394,6 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// /// /// - [Experimental(DiagnosticId.ExperimentalFeature)] public void ConfigureDataCollection(Action configure) { ArgumentNullException.ThrowIfNull(configure); @@ -384,7 +410,7 @@ public void ConfigureDataCollection(Action configure) /// Whether to report the as the User affected in the event. /// /// - /// This configuration is only relevant if is set to true. + /// This configuration is only relevant when is enabled. /// In environments like server applications this is set to false in order to not report server account names as user names. /// public bool IsEnvironmentUser { get; set; } = true; diff --git a/test/Sentry.AspNet.Tests/HttpContextExtensionsTests.cs b/test/Sentry.AspNet.Tests/HttpContextExtensionsTests.cs index f7628a3a9f..b184755ef8 100644 --- a/test/Sentry.AspNet.Tests/HttpContextExtensionsTests.cs +++ b/test/Sentry.AspNet.Tests/HttpContextExtensionsTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + using Sentry.Internal.DataCollection; using Sentry.Internal.OpenTelemetry; using HttpCookie = System.Web.HttpCookie; diff --git a/test/Sentry.AspNet.Tests/Internal/SystemWebRequestEventProcessorTests.cs b/test/Sentry.AspNet.Tests/Internal/SystemWebRequestEventProcessorTests.cs index ec054d71ed..7520bac94a 100644 --- a/test/Sentry.AspNet.Tests/Internal/SystemWebRequestEventProcessorTests.cs +++ b/test/Sentry.AspNet.Tests/Internal/SystemWebRequestEventProcessorTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + using Sentry.AspNet.Internal; namespace Sentry.AspNet.Tests.Internal; diff --git a/test/Sentry.AspNetCore.Tests/IntegrationMockedBackgroundWorker.cs b/test/Sentry.AspNetCore.Tests/IntegrationMockedBackgroundWorker.cs index b1285a7e0f..126494aba8 100644 --- a/test/Sentry.AspNetCore.Tests/IntegrationMockedBackgroundWorker.cs +++ b/test/Sentry.AspNetCore.Tests/IntegrationMockedBackgroundWorker.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; diff --git a/test/Sentry.AspNetCore.Tests/ScopeExtensionsTests.cs b/test/Sentry.AspNetCore.Tests/ScopeExtensionsTests.cs index ac1422154e..d5ac0b3c59 100644 --- a/test/Sentry.AspNetCore.Tests/ScopeExtensionsTests.cs +++ b/test/Sentry.AspNetCore.Tests/ScopeExtensionsTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Routing; diff --git a/test/Sentry.AspNetCore.Tests/SentryTracingMiddlewareTests.cs b/test/Sentry.AspNetCore.Tests/SentryTracingMiddlewareTests.cs index 70c669e09c..0fa0142442 100644 --- a/test/Sentry.AspNetCore.Tests/SentryTracingMiddlewareTests.cs +++ b/test/Sentry.AspNetCore.Tests/SentryTracingMiddlewareTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; diff --git a/test/Sentry.AspNetCore.Tests/SentryWebApplicationBuilderExtensionsTests.cs b/test/Sentry.AspNetCore.Tests/SentryWebApplicationBuilderExtensionsTests.cs index abfb4da1fa..c1db7032ba 100644 --- a/test/Sentry.AspNetCore.Tests/SentryWebApplicationBuilderExtensionsTests.cs +++ b/test/Sentry.AspNetCore.Tests/SentryWebApplicationBuilderExtensionsTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; diff --git a/test/Sentry.Extensions.AI.Tests/SentryAIOptionsTests.cs b/test/Sentry.Extensions.AI.Tests/SentryAIOptionsTests.cs index 2ba4e14790..ca7ea2eb64 100644 --- a/test/Sentry.Extensions.AI.Tests/SentryAIOptionsTests.cs +++ b/test/Sentry.Extensions.AI.Tests/SentryAIOptionsTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + namespace Sentry.Extensions.AI.Tests; public class SentryAIOptionsTests diff --git a/test/Sentry.Extensions.AI.Tests/SentryAISpanEnricherTests.cs b/test/Sentry.Extensions.AI.Tests/SentryAISpanEnricherTests.cs index 9dd8d96c2a..159b3603c8 100644 --- a/test/Sentry.Extensions.AI.Tests/SentryAISpanEnricherTests.cs +++ b/test/Sentry.Extensions.AI.Tests/SentryAISpanEnricherTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + using Microsoft.Extensions.AI; namespace Sentry.Extensions.AI.Tests; diff --git a/test/Sentry.Extensions.AI.Tests/SentryInstrumentedFunctionTests.cs b/test/Sentry.Extensions.AI.Tests/SentryInstrumentedFunctionTests.cs index c4df3abe89..b594bf6c0e 100644 --- a/test/Sentry.Extensions.AI.Tests/SentryInstrumentedFunctionTests.cs +++ b/test/Sentry.Extensions.AI.Tests/SentryInstrumentedFunctionTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + using Microsoft.Extensions.AI; using Sentry.Internal; diff --git a/test/Sentry.Extensions.Hosting.Tests/SentryHostBuilderExtensionsTests.cs b/test/Sentry.Extensions.Hosting.Tests/SentryHostBuilderExtensionsTests.cs index 90244659de..1d9ee66099 100644 --- a/test/Sentry.Extensions.Hosting.Tests/SentryHostBuilderExtensionsTests.cs +++ b/test/Sentry.Extensions.Hosting.Tests/SentryHostBuilderExtensionsTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; diff --git a/test/Sentry.OpenTelemetry.Tests/AspNetCoreEnricherTests.cs b/test/Sentry.OpenTelemetry.Tests/AspNetCoreEnricherTests.cs index 430fd2a769..cb3c757da9 100644 --- a/test/Sentry.OpenTelemetry.Tests/AspNetCoreEnricherTests.cs +++ b/test/Sentry.OpenTelemetry.Tests/AspNetCoreEnricherTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + namespace Sentry.OpenTelemetry.Tests; public class AspNetCoreEnricherTests diff --git a/test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet10_0.verified.txt b/test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet10_0.verified.txt index 902ed8c912..e456683826 100644 --- a/test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet10_0.verified.txt +++ b/test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet10_0.verified.txt @@ -215,7 +215,7 @@ FileName: IntegrationTests.verify.cs, Function: Task IntegrationTests.Simple(), Module: null, - LineNumber: 53, + LineNumber: 54, ColumnNumber: 21, AbsolutePath: {ProjectDirectory}IntegrationTests.verify.cs, ContextLine: null, diff --git a/test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet8_0.verified.txt b/test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet8_0.verified.txt index 902ed8c912..e456683826 100644 --- a/test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet8_0.verified.txt +++ b/test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet8_0.verified.txt @@ -215,7 +215,7 @@ FileName: IntegrationTests.verify.cs, Function: Task IntegrationTests.Simple(), Module: null, - LineNumber: 53, + LineNumber: 54, ColumnNumber: 21, AbsolutePath: {ProjectDirectory}IntegrationTests.verify.cs, ContextLine: null, diff --git a/test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet9_0.verified.txt b/test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet9_0.verified.txt index 902ed8c912..e456683826 100644 --- a/test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet9_0.verified.txt +++ b/test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet9_0.verified.txt @@ -215,7 +215,7 @@ FileName: IntegrationTests.verify.cs, Function: Task IntegrationTests.Simple(), Module: null, - LineNumber: 53, + LineNumber: 54, ColumnNumber: 21, AbsolutePath: {ProjectDirectory}IntegrationTests.verify.cs, ContextLine: null, diff --git a/test/Sentry.Serilog.Tests/IntegrationTests.verify.cs b/test/Sentry.Serilog.Tests/IntegrationTests.verify.cs index 614bb8b88b..b4a53f5764 100644 --- a/test/Sentry.Serilog.Tests/IntegrationTests.verify.cs +++ b/test/Sentry.Serilog.Tests/IntegrationTests.verify.cs @@ -1,3 +1,4 @@ +#pragma warning disable CS0618 #if NET6_0_OR_GREATER namespace Sentry.Serilog.Tests; diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt index 86bf7b7b21..81bfef9e2a 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt @@ -69,7 +69,6 @@ namespace Sentry ManagedBackgroundThread = 1, Native = 2, } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public class DataCollectionOptions { public Sentry.KeyValueCollectionBehavior Cookies { get; set; } @@ -154,7 +153,6 @@ namespace Sentry public const string Exception = "exception"; public const string HttpResponseMessage = "http-response-message"; } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] [System.Flags] public enum HttpBodyTypes { @@ -387,7 +385,6 @@ namespace Sentry Sentry = 0, OpenTelemetry = 1, } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public sealed class KeyValueCollectionBehavior { public Sentry.KeyValueCollectionMode Mode { get; } @@ -397,7 +394,6 @@ namespace Sentry public static Sentry.KeyValueCollectionBehavior DenyList(params string[] additionalTerms) { } public static Sentry.KeyValueCollectionBehavior op_Implicit(bool collect) { } } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public enum KeyValueCollectionMode { Off = 0, @@ -951,6 +947,9 @@ namespace Sentry public float? SampleRate { get; set; } protected Sentry.IScopeObserver? ScopeObserver { get; set; } public bool SendClientReports { get; set; } + [System.Obsolete("Use ConfigureDataCollection instead, which controls each category of automaticall" + + "y collected data separately. SendDefaultPii will be removed in the next major ve" + + "rsion.")] public bool SendDefaultPii { get; set; } public Sentry.ISentryScopeStateProcessor SentryScopeStateProcessor { get; set; } public string? ServerName { get; set; } @@ -987,7 +986,6 @@ namespace Sentry public void AddTransactionProcessor(Sentry.Extensibility.ISentryTransactionProcessor processor) { } public void AddTransactionProcessorProvider(System.Func> processorProvider) { } public void AddTransactionProcessors(System.Collections.Generic.IEnumerable processors) { } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public void ConfigureDataCollection(System.Action configure) { } public void DisableAppDomainProcessExitFlush() { } public void DisableAppDomainUnhandledExceptionCapture() { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet11_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet11_0.verified.txt index 86bf7b7b21..81bfef9e2a 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet11_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet11_0.verified.txt @@ -69,7 +69,6 @@ namespace Sentry ManagedBackgroundThread = 1, Native = 2, } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public class DataCollectionOptions { public Sentry.KeyValueCollectionBehavior Cookies { get; set; } @@ -154,7 +153,6 @@ namespace Sentry public const string Exception = "exception"; public const string HttpResponseMessage = "http-response-message"; } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] [System.Flags] public enum HttpBodyTypes { @@ -387,7 +385,6 @@ namespace Sentry Sentry = 0, OpenTelemetry = 1, } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public sealed class KeyValueCollectionBehavior { public Sentry.KeyValueCollectionMode Mode { get; } @@ -397,7 +394,6 @@ namespace Sentry public static Sentry.KeyValueCollectionBehavior DenyList(params string[] additionalTerms) { } public static Sentry.KeyValueCollectionBehavior op_Implicit(bool collect) { } } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public enum KeyValueCollectionMode { Off = 0, @@ -951,6 +947,9 @@ namespace Sentry public float? SampleRate { get; set; } protected Sentry.IScopeObserver? ScopeObserver { get; set; } public bool SendClientReports { get; set; } + [System.Obsolete("Use ConfigureDataCollection instead, which controls each category of automaticall" + + "y collected data separately. SendDefaultPii will be removed in the next major ve" + + "rsion.")] public bool SendDefaultPii { get; set; } public Sentry.ISentryScopeStateProcessor SentryScopeStateProcessor { get; set; } public string? ServerName { get; set; } @@ -987,7 +986,6 @@ namespace Sentry public void AddTransactionProcessor(Sentry.Extensibility.ISentryTransactionProcessor processor) { } public void AddTransactionProcessorProvider(System.Func> processorProvider) { } public void AddTransactionProcessors(System.Collections.Generic.IEnumerable processors) { } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public void ConfigureDataCollection(System.Action configure) { } public void DisableAppDomainProcessExitFlush() { } public void DisableAppDomainUnhandledExceptionCapture() { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt index 86bf7b7b21..81bfef9e2a 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt @@ -69,7 +69,6 @@ namespace Sentry ManagedBackgroundThread = 1, Native = 2, } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public class DataCollectionOptions { public Sentry.KeyValueCollectionBehavior Cookies { get; set; } @@ -154,7 +153,6 @@ namespace Sentry public const string Exception = "exception"; public const string HttpResponseMessage = "http-response-message"; } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] [System.Flags] public enum HttpBodyTypes { @@ -387,7 +385,6 @@ namespace Sentry Sentry = 0, OpenTelemetry = 1, } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public sealed class KeyValueCollectionBehavior { public Sentry.KeyValueCollectionMode Mode { get; } @@ -397,7 +394,6 @@ namespace Sentry public static Sentry.KeyValueCollectionBehavior DenyList(params string[] additionalTerms) { } public static Sentry.KeyValueCollectionBehavior op_Implicit(bool collect) { } } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public enum KeyValueCollectionMode { Off = 0, @@ -951,6 +947,9 @@ namespace Sentry public float? SampleRate { get; set; } protected Sentry.IScopeObserver? ScopeObserver { get; set; } public bool SendClientReports { get; set; } + [System.Obsolete("Use ConfigureDataCollection instead, which controls each category of automaticall" + + "y collected data separately. SendDefaultPii will be removed in the next major ve" + + "rsion.")] public bool SendDefaultPii { get; set; } public Sentry.ISentryScopeStateProcessor SentryScopeStateProcessor { get; set; } public string? ServerName { get; set; } @@ -987,7 +986,6 @@ namespace Sentry public void AddTransactionProcessor(Sentry.Extensibility.ISentryTransactionProcessor processor) { } public void AddTransactionProcessorProvider(System.Func> processorProvider) { } public void AddTransactionProcessors(System.Collections.Generic.IEnumerable processors) { } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public void ConfigureDataCollection(System.Action configure) { } public void DisableAppDomainProcessExitFlush() { } public void DisableAppDomainUnhandledExceptionCapture() { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt index 86bf7b7b21..81bfef9e2a 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt @@ -69,7 +69,6 @@ namespace Sentry ManagedBackgroundThread = 1, Native = 2, } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public class DataCollectionOptions { public Sentry.KeyValueCollectionBehavior Cookies { get; set; } @@ -154,7 +153,6 @@ namespace Sentry public const string Exception = "exception"; public const string HttpResponseMessage = "http-response-message"; } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] [System.Flags] public enum HttpBodyTypes { @@ -387,7 +385,6 @@ namespace Sentry Sentry = 0, OpenTelemetry = 1, } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public sealed class KeyValueCollectionBehavior { public Sentry.KeyValueCollectionMode Mode { get; } @@ -397,7 +394,6 @@ namespace Sentry public static Sentry.KeyValueCollectionBehavior DenyList(params string[] additionalTerms) { } public static Sentry.KeyValueCollectionBehavior op_Implicit(bool collect) { } } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public enum KeyValueCollectionMode { Off = 0, @@ -951,6 +947,9 @@ namespace Sentry public float? SampleRate { get; set; } protected Sentry.IScopeObserver? ScopeObserver { get; set; } public bool SendClientReports { get; set; } + [System.Obsolete("Use ConfigureDataCollection instead, which controls each category of automaticall" + + "y collected data separately. SendDefaultPii will be removed in the next major ve" + + "rsion.")] public bool SendDefaultPii { get; set; } public Sentry.ISentryScopeStateProcessor SentryScopeStateProcessor { get; set; } public string? ServerName { get; set; } @@ -987,7 +986,6 @@ namespace Sentry public void AddTransactionProcessor(Sentry.Extensibility.ISentryTransactionProcessor processor) { } public void AddTransactionProcessorProvider(System.Func> processorProvider) { } public void AddTransactionProcessors(System.Collections.Generic.IEnumerable processors) { } - [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public void ConfigureDataCollection(System.Action configure) { } public void DisableAppDomainProcessExitFlush() { } public void DisableAppDomainUnhandledExceptionCapture() { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt index f73ab02af5..6426c43309 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt @@ -918,6 +918,9 @@ namespace Sentry public float? SampleRate { get; set; } protected Sentry.IScopeObserver? ScopeObserver { get; set; } public bool SendClientReports { get; set; } + [System.Obsolete("Use ConfigureDataCollection instead, which controls each category of automaticall" + + "y collected data separately. SendDefaultPii will be removed in the next major ve" + + "rsion.")] public bool SendDefaultPii { get; set; } public Sentry.ISentryScopeStateProcessor SentryScopeStateProcessor { get; set; } public string? ServerName { get; set; } diff --git a/test/Sentry.Tests/Extensibility/RequestBodyExtractionDispatcherTests.cs b/test/Sentry.Tests/Extensibility/RequestBodyExtractionDispatcherTests.cs index 3e07686332..4d373f7879 100644 --- a/test/Sentry.Tests/Extensibility/RequestBodyExtractionDispatcherTests.cs +++ b/test/Sentry.Tests/Extensibility/RequestBodyExtractionDispatcherTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + namespace Sentry.Tests.Extensibility; public class RequestBodyExtractionDispatcherTests diff --git a/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs b/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs index 9e5b4ae122..eb03772904 100644 --- a/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs +++ b/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + namespace Sentry.Tests.Internals; public class DataCollectionResolverTests diff --git a/test/Sentry.Tests/Internals/MainSentryEventProcessorTests.cs b/test/Sentry.Tests/Internals/MainSentryEventProcessorTests.cs index d752a25451..b317a3f122 100644 --- a/test/Sentry.Tests/Internals/MainSentryEventProcessorTests.cs +++ b/test/Sentry.Tests/Internals/MainSentryEventProcessorTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + namespace Sentry.Tests.Internals; public class MainSentryEventProcessorTests diff --git a/test/Sentry.Tests/Platforms/Android/SentrySdkTests.cs b/test/Sentry.Tests/Platforms/Android/SentrySdkTests.cs index eb0735d942..a4a5d30e93 100644 --- a/test/Sentry.Tests/Platforms/Android/SentrySdkTests.cs +++ b/test/Sentry.Tests/Platforms/Android/SentrySdkTests.cs @@ -1,3 +1,4 @@ +#pragma warning disable CS0618 #if ANDROID namespace Sentry.Tests.Platforms.Android; @@ -82,9 +83,7 @@ public void ApplyDataCollection_NotConfigured_ForwardsOnlySendDefaultPii(bool se SentrySdk.ApplyDataCollection(options, javaOptions); -#pragma warning disable CS0618 javaOptions.SendDefaultPii.Should().Be(sendDefaultPii); -#pragma warning restore CS0618 javaOptions.DataCollection.IsExplicitlyConfigured.Should().BeFalse(); javaOptions.DataCollectionResolver.IsUserInfo.Should().Be(sendDefaultPii); } diff --git a/test/Sentry.Tests/Platforms/iOS/SentrySdkTests.cs b/test/Sentry.Tests/Platforms/iOS/SentrySdkTests.cs index 7bfea6aa57..d1af7156fe 100644 --- a/test/Sentry.Tests/Platforms/iOS/SentrySdkTests.cs +++ b/test/Sentry.Tests/Platforms/iOS/SentrySdkTests.cs @@ -1,3 +1,4 @@ +#pragma warning disable CS0618 #if __IOS__ using Foundation; using Sentry.Cocoa; diff --git a/test/Sentry.Tests/Protocol/SentryEventTests.cs b/test/Sentry.Tests/Protocol/SentryEventTests.cs index 1f4199b948..1b435653cd 100644 --- a/test/Sentry.Tests/Protocol/SentryEventTests.cs +++ b/test/Sentry.Tests/Protocol/SentryEventTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + namespace Sentry.Tests.Protocol; public partial class SentryEventTests diff --git a/test/Sentry.Tests/Protocol/SentryTransactionTests.cs b/test/Sentry.Tests/Protocol/SentryTransactionTests.cs index d9d4de9d18..ad9db89b14 100644 --- a/test/Sentry.Tests/Protocol/SentryTransactionTests.cs +++ b/test/Sentry.Tests/Protocol/SentryTransactionTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + namespace Sentry.Tests.Protocol; public class SentryTransactionTests diff --git a/test/Sentry.Tests/SentryClientTests.cs b/test/Sentry.Tests/SentryClientTests.cs index ffee07f391..a277cadd3a 100644 --- a/test/Sentry.Tests/SentryClientTests.cs +++ b/test/Sentry.Tests/SentryClientTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + using Sentry.Internal.Http; using BackgroundWorker = Sentry.Internal.BackgroundWorker; diff --git a/test/Sentry.Tests/SentryGraphQlHttpFailedRequestHandlerTests.cs b/test/Sentry.Tests/SentryGraphQlHttpFailedRequestHandlerTests.cs index 369d5bf6ac..88e7bed3d0 100644 --- a/test/Sentry.Tests/SentryGraphQlHttpFailedRequestHandlerTests.cs +++ b/test/Sentry.Tests/SentryGraphQlHttpFailedRequestHandlerTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + namespace Sentry.Tests; public class SentryGraphQlHttpFailedRequestHandlerTests diff --git a/test/Sentry.Tests/SentryHttpFailedRequestHandlerTests.cs b/test/Sentry.Tests/SentryHttpFailedRequestHandlerTests.cs index 2f0d3de583..388bd0b79a 100644 --- a/test/Sentry.Tests/SentryHttpFailedRequestHandlerTests.cs +++ b/test/Sentry.Tests/SentryHttpFailedRequestHandlerTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + namespace Sentry.Tests; public class SentryHttpFailedRequestHandlerTests diff --git a/test/Sentry.Tests/SentryLogTests.cs b/test/Sentry.Tests/SentryLogTests.cs index 288be6ec6c..6a5e3a5b5b 100644 --- a/test/Sentry.Tests/SentryLogTests.cs +++ b/test/Sentry.Tests/SentryLogTests.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 + using System.Text.Encodings.Web; using Sentry.PlatformAbstractions; From e11c61b2e89f4aea0b0d77a380471eea8cf4c456 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 3 Dec 2026 11:11:26 +1300 Subject: [PATCH 02/10] docs: list the behaviors that still follow SendDefaultPii Redaction of URL credentials in breadcrumbs and span descriptions, and Sentry.OpenTelemetry's user enricher, still read SendDefaultPii after ConfigureDataCollection has been called, alongside the server name. Co-Authored-By: Claude Opus 5.5 --- src/Sentry/SentryOptions.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index 57808ad3f0..58bc36d3d1 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -335,8 +335,8 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// and user data read from the request are sent. /// /// Superseded by . Once that has been called, integrations ignore this - /// option. To keep what SendDefaultPii = true collects, call ConfigureDataCollection(_ => { }). - /// The defaults collect every category, with sensitive keys filtered out. + /// option, apart from the exceptions below. To keep what SendDefaultPii = true collects, call + /// ConfigureDataCollection(_ => { }). The defaults collect every category, with sensitive keys filtered out. /// /// /// The closest equivalent of SendDefaultPii = false is: @@ -357,8 +357,15 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// sanitized. /// /// - /// The machine name is still sent as only when this option is true. Set - /// explicitly to keep sending it without this option. + /// A few behaviors still follow this option, whether or not has been called: + /// + /// The machine name is sent as only when this option is true. Set + /// explicitly to keep sending it without this option. + /// When this option is false, URL credentials are redacted from breadcrumbs and span descriptions, + /// including ones the application set itself. + /// Sentry.OpenTelemetry's AddSentry sets the user from the HTTP request only when this option + /// is true. + /// /// /// [Obsolete(ObsoleteSendDefaultPii)] From 45b06f7243180294f1b77783a9a1c8d8573d48da Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 3 Dec 2026 11:51:33 +1300 Subject: [PATCH 03/10] feat: add a parameterless ConfigureDataCollection overload ConfigureDataCollection() opts in to the data collection options with their defaults, so callers no longer need ConfigureDataCollection(_ => { }). Tests switch to it, and samples now set the category they rely on (UserInfo, or the GraphQL document and variables) explicitly, so readers can see which setting to change. Co-Authored-By: Claude Opus 5.5 --- .../Sentry.Samples.Android/MainActivity.cs | 2 +- .../Program.cs | 8 ++++++-- .../Sentry.Samples.GraphQL.Server/Program.cs | 2 +- .../Program.cs | 2 +- .../SentryAspNetCoreOptions.cs | 2 +- .../SentryOptionsExtensions.cs | 2 +- .../SentrySpanProcessor.cs | 2 +- .../TracerProviderBuilderExtensions.cs | 2 +- src/Sentry/SentryOptions.cs | 19 +++++++++++++++---- .../HttpContextExtensionsTests.cs | 2 +- .../SystemWebRequestEventProcessorTests.cs | 6 +++--- .../SentryEFCoreListenerTests.cs | 4 ++-- .../SentrySqlListenerTests.cs | 2 +- .../SentryQueryLoggerTests.cs | 4 ++-- .../SentryQueryPerformanceListenerTests.cs | 4 ++-- ...iApprovalTests.Run.DotNet10_0.verified.txt | 1 + ...iApprovalTests.Run.DotNet11_0.verified.txt | 1 + ...piApprovalTests.Run.DotNet8_0.verified.txt | 1 + ...piApprovalTests.Run.DotNet9_0.verified.txt | 1 + .../ApiApprovalTests.Run.Net4_8.verified.txt | 1 + .../DataCollectionOptionsTests.cs | 13 ++++++++++++- .../Internals/DataCollectionResolverTests.cs | 6 +++--- .../Platforms/Android/SentrySdkTests.cs | 4 ++-- ...tryGraphQlHttpFailedRequestHandlerTests.cs | 6 +++--- .../SentryHttpFailedRequestHandlerTests.cs | 6 +++--- 25 files changed, 67 insertions(+), 36 deletions(-) diff --git a/samples/Sentry.Samples.Android/MainActivity.cs b/samples/Sentry.Samples.Android/MainActivity.cs index 14f00de12c..5442cb2c93 100644 --- a/samples/Sentry.Samples.Android/MainActivity.cs +++ b/samples/Sentry.Samples.Android/MainActivity.cs @@ -20,7 +20,7 @@ protected override void OnCreate(Bundle? savedInstanceState) options.Dsn = EnvironmentVariables.Dsn; #endif - options.ConfigureDataCollection(_ => { }); // adds the user's IP address automatically + options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = true); // adds the user's IP address automatically // Android specific .NET features are under the Android properties: options.Android.LogCatIntegration = LogCatIntegrationType.Errors; // Get logcat logs for both handled and unhandled errors; default is unhandled only diff --git a/samples/Sentry.Samples.GraphQL.Client.Http/Program.cs b/samples/Sentry.Samples.GraphQL.Client.Http/Program.cs index ee28687d0c..f4e5720a73 100644 --- a/samples/Sentry.Samples.GraphQL.Client.Http/Program.cs +++ b/samples/Sentry.Samples.GraphQL.Client.Http/Program.cs @@ -18,8 +18,12 @@ #endif options.CaptureFailedRequests = true; - // Attach GraphQL documents and variables, headers and cookies to failed request events - options.ConfigureDataCollection(_ => { }); + // Attach GraphQL documents and variables to failed request events + options.ConfigureDataCollection(dataCollection => + { + dataCollection.GraphQL.Document = true; + dataCollection.GraphQL.Variables = true; + }); options.TracesSampleRate = 1.0; }); diff --git a/samples/Sentry.Samples.GraphQL.Server/Program.cs b/samples/Sentry.Samples.GraphQL.Server/Program.cs index f8eae118b1..dc115add04 100644 --- a/samples/Sentry.Samples.GraphQL.Server/Program.cs +++ b/samples/Sentry.Samples.GraphQL.Server/Program.cs @@ -54,7 +54,7 @@ public static WebApplication BuildWebApplication(string[] args) options.TracesSampleRate = 1.0; options.Debug = true; - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = true); // adds the user's IP address automatically options.UseOtlp(); // <-- Configure Sentry to use OpenTelemetry trace information }); diff --git a/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs b/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs index c61e6a83ee..dfba93739f 100644 --- a/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs +++ b/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs @@ -38,7 +38,7 @@ { options.Dsn = dsn; options.Debug = builder.Environment.IsDevelopment(); - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = true); // adds the signed-in user automatically options.TracesSampleRate = 1.0; options.UseOtlp(); // <-- Configure Sentry to use OpenTelemetry trace information }); diff --git a/src/Sentry.AspNetCore/SentryAspNetCoreOptions.cs b/src/Sentry.AspNetCore/SentryAspNetCoreOptions.cs index e4a5d69786..d8a524191e 100644 --- a/src/Sentry.AspNetCore/SentryAspNetCoreOptions.cs +++ b/src/Sentry.AspNetCore/SentryAspNetCoreOptions.cs @@ -41,7 +41,7 @@ public bool EnableLogs /// No truncation is done by the SDK. /// If the request body is larger than the accepted size, nothing is sent. /// - /// If you call , request bodies are only collected when + /// If you call , request bodies are only collected when /// includes . /// /// diff --git a/src/Sentry.OpenTelemetry/SentryOptionsExtensions.cs b/src/Sentry.OpenTelemetry/SentryOptionsExtensions.cs index 6255cf9216..4957a8e1f7 100644 --- a/src/Sentry.OpenTelemetry/SentryOptionsExtensions.cs +++ b/src/Sentry.OpenTelemetry/SentryOptionsExtensions.cs @@ -34,7 +34,7 @@ public static class SentryOptionsExtensions /// /// /// The user and span attributes this integration collects don't follow - /// . It sets the user from ASP.NET Core only when + /// . It sets the user from ASP.NET Core only when /// is true, replaces sensitive URL query values on spans using the /// default deny list, and sends all other span attributes as they are. /// diff --git a/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs b/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs index c6abd9ff9e..c102589907 100644 --- a/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs +++ b/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs @@ -11,7 +11,7 @@ namespace Sentry.OpenTelemetry; /// Sentry span processor for Open Telemetry. /// /// -/// The span attributes this processor collects don't follow . It +/// The span attributes this processor collects don't follow . It /// replaces sensitive URL query values using the default deny list, and sends all other span attributes as they are. /// public class SentrySpanProcessor : BaseProcessor diff --git a/src/Sentry.OpenTelemetry/TracerProviderBuilderExtensions.cs b/src/Sentry.OpenTelemetry/TracerProviderBuilderExtensions.cs index 8ddb426b41..d28c8f7f12 100644 --- a/src/Sentry.OpenTelemetry/TracerProviderBuilderExtensions.cs +++ b/src/Sentry.OpenTelemetry/TracerProviderBuilderExtensions.cs @@ -41,7 +41,7 @@ public static class TracerProviderBuilderExtensions /// The supplied for chaining. /// /// The user and span attributes this integration collects don't follow - /// . It sets the user from ASP.NET Core only when + /// . It sets the user from ASP.NET Core only when /// is true, replaces sensitive URL query values on spans using the /// default deny list, and sends all other span attributes as they are. /// diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index 58bc36d3d1..db9600d230 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -334,9 +334,10 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// When this flag is turned on, default PII data like Cookies, Claims in Web applications /// and user data read from the request are sent. /// - /// Superseded by . Once that has been called, integrations ignore this - /// option, apart from the exceptions below. To keep what SendDefaultPii = true collects, call - /// ConfigureDataCollection(_ => { }). The defaults collect every category, with sensitive keys filtered out. + /// Superseded by . Once that has been called, + /// integrations ignore this option, apart from the exceptions below. To keep what SendDefaultPii = true + /// collects, call , whose defaults collect every category with sensitive + /// keys filtered out. /// /// /// The closest equivalent of SendDefaultPii = false is: @@ -357,7 +358,7 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// sanitized. /// /// - /// A few behaviors still follow this option, whether or not has been called: + /// A few behaviors still follow this option, whether or not has been called: /// /// The machine name is sent as only when this option is true. Set /// explicitly to keep sending it without this option. @@ -409,6 +410,16 @@ public void ConfigureDataCollection(Action configure) configure(DataCollection); } + /// + /// Opts in to with every category at its + /// default from the data collection spec. + /// + /// + /// Categories set by an earlier call keep their values. + /// + /// + public void ConfigureDataCollection() => DataCollection ??= new DataCollectionOptions(); + internal DataCollectionOptions? DataCollection { get; set; } internal DataCollectionResolver DataCollectionResolver { get; } diff --git a/test/Sentry.AspNet.Tests/HttpContextExtensionsTests.cs b/test/Sentry.AspNet.Tests/HttpContextExtensionsTests.cs index b184755ef8..a538f674d6 100644 --- a/test/Sentry.AspNet.Tests/HttpContextExtensionsTests.cs +++ b/test/Sentry.AspNet.Tests/HttpContextExtensionsTests.cs @@ -176,7 +176,7 @@ public void StartSentryTransaction_DataCollectionCookiesDenyList_FiltersCookiesW TracesSampleRate = 1.0, SendDefaultPii = false }; - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); using var _ = SentrySdk.UseHub(new Hub(options, Substitute.For())); var context = HttpContextBuilder.BuildWithCookies(new[] { diff --git a/test/Sentry.AspNet.Tests/Internal/SystemWebRequestEventProcessorTests.cs b/test/Sentry.AspNet.Tests/Internal/SystemWebRequestEventProcessorTests.cs index 7520bac94a..89b4573db4 100644 --- a/test/Sentry.AspNet.Tests/Internal/SystemWebRequestEventProcessorTests.cs +++ b/test/Sentry.AspNet.Tests/Internal/SystemWebRequestEventProcessorTests.cs @@ -215,7 +215,7 @@ public void Process_DataCollectionUserInfoTrue_SetsUserWithoutSendDefaultPii() { Context.User = CreateClaimsPrincipal(); _fixture.SentryOptions.SendDefaultPii = false; - _fixture.SentryOptions.ConfigureDataCollection(_ => { }); + _fixture.SentryOptions.ConfigureDataCollection(); var evt = new SentryEvent(); _fixture.GetSut().Process(evt); @@ -246,7 +246,7 @@ public void Process_DataCollectionUserInfoFalse_DoesNotSetUser() public void Process_DataCollectionUserInfoTrueWithoutUser_ReturnsEvent() { Context.User = null; - _fixture.SentryOptions.ConfigureDataCollection(_ => { }); + _fixture.SentryOptions.ConfigureDataCollection(); var evt = new SentryEvent(); var processedEvt = _fixture.GetSut().Process(evt); @@ -302,7 +302,7 @@ public void Process_DataCollectionCookiesDenyList_FiltersCookieHeaderValueWithou { Context = HttpContextBuilder.BuildWithHeaders(["Cookie", "name=secret"]); _fixture.SentryOptions.SendDefaultPii = false; - _fixture.SentryOptions.ConfigureDataCollection(_ => { }); + _fixture.SentryOptions.ConfigureDataCollection(); var evt = new SentryEvent(); _fixture.GetSut().Process(evt); diff --git a/test/Sentry.DiagnosticSource.Tests/SentryEFCoreListenerTests.cs b/test/Sentry.DiagnosticSource.Tests/SentryEFCoreListenerTests.cs index 7df1ba940b..23988c48c5 100644 --- a/test/Sentry.DiagnosticSource.Tests/SentryEFCoreListenerTests.cs +++ b/test/Sentry.DiagnosticSource.Tests/SentryEFCoreListenerTests.cs @@ -340,7 +340,7 @@ public void OnNext_CommandExecuting_DataCollectionConfigured_SanitizesForProvide { // Arrange var fixture = new Fixture(); - fixture.Options.ConfigureDataCollection(_ => { }); + fixture.Options.ConfigureDataCollection(); var listener = new SentryEFCoreListener(fixture.Hub, fixture.Options); var connection = new FakeDiagnosticConnectionEventData("connection"); var command = new FakeDiagnosticCommandEventData(connection, $"Executing DbCommand\r\n{sql}"); @@ -400,7 +400,7 @@ public void OnNext_QueryCompiling_DataCollectionConfigured_DescriptionIsDbSystem { // Arrange var fixture = new Fixture(); - fixture.Options.ConfigureDataCollection(_ => { }); + fixture.Options.ConfigureDataCollection(); var listener = new SentryEFCoreListener(fixture.Hub, fixture.Options); var query = new FakeDiagnosticEventData( "Compiling query expression: \n'DbSet().FromSql(SELECT * FROM Items WHERE Email = 'jane@example.com', @p)'"); diff --git a/test/Sentry.DiagnosticSource.Tests/SentrySqlListenerTests.cs b/test/Sentry.DiagnosticSource.Tests/SentrySqlListenerTests.cs index 78d2b9373f..ddf6a0d876 100644 --- a/test/Sentry.DiagnosticSource.Tests/SentrySqlListenerTests.cs +++ b/test/Sentry.DiagnosticSource.Tests/SentrySqlListenerTests.cs @@ -597,7 +597,7 @@ public void OnNext_DataCollection_SanitizesCommandTextOnlyWhenConfigured(bool co var options = new SentryOptions(); if (configureDataCollection) { - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); } var listener = new SentrySqlListener(fixture.Hub, options); var operationId = Guid.NewGuid(); diff --git a/test/Sentry.EntityFramework.Tests/SentryQueryLoggerTests.cs b/test/Sentry.EntityFramework.Tests/SentryQueryLoggerTests.cs index a6d30a51f5..a6c53ee02c 100644 --- a/test/Sentry.EntityFramework.Tests/SentryQueryLoggerTests.cs +++ b/test/Sentry.EntityFramework.Tests/SentryQueryLoggerTests.cs @@ -37,7 +37,7 @@ public void Log_DataCollection_SanitizesOnlyWhenConfigured(bool configureDataCol var options = new SentryOptions(); if (configureDataCollection) { - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); } SentryClientExtensions.SentryOptionsForTestingOnly = options; @@ -55,7 +55,7 @@ public void Log_DataCollection_SanitizesOnlyWhenConfigured(bool configureDataCol public void Log_MySqlCommandThroughInterceptor_UsesMySqlQuoting() { var options = new SentryOptions(); - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); SentryClientExtensions.SentryOptionsForTestingOnly = options; var scope = new Scope(options); diff --git a/test/Sentry.EntityFramework.Tests/SentryQueryPerformanceListenerTests.cs b/test/Sentry.EntityFramework.Tests/SentryQueryPerformanceListenerTests.cs index 6090170478..e542b5fa6a 100644 --- a/test/Sentry.EntityFramework.Tests/SentryQueryPerformanceListenerTests.cs +++ b/test/Sentry.EntityFramework.Tests/SentryQueryPerformanceListenerTests.cs @@ -204,7 +204,7 @@ public void ReaderExecuting_DataCollection_SanitizesOnlyWhenConfigured(bool conf var options = new SentryOptions(); if (configureDataCollection) { - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); } var listener = new SentryQueryPerformanceListener(_fixture.Hub, options); var command = new EffortCommand { CommandText = "SELECT * FROM Users WHERE Email = 'jane@example.com'" }; @@ -218,7 +218,7 @@ public void ReaderExecuting_DataCollection_SanitizesOnlyWhenConfigured(bool conf public void ReaderExecuting_MySqlCommand_UsesMySqlQuoting() { var options = new SentryOptions(); - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); var listener = new SentryQueryPerformanceListener(_fixture.Hub, options); var command = new MySql.Data.MySqlClient.FakeMySqlCommand { CommandText = "SELECT * FROM Users WHERE Name = 'O\\'Brien'" }; diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt index 81bfef9e2a..7295f81d78 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt @@ -986,6 +986,7 @@ namespace Sentry public void AddTransactionProcessor(Sentry.Extensibility.ISentryTransactionProcessor processor) { } public void AddTransactionProcessorProvider(System.Func> processorProvider) { } public void AddTransactionProcessors(System.Collections.Generic.IEnumerable processors) { } + public void ConfigureDataCollection() { } public void ConfigureDataCollection(System.Action configure) { } public void DisableAppDomainProcessExitFlush() { } public void DisableAppDomainUnhandledExceptionCapture() { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet11_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet11_0.verified.txt index 81bfef9e2a..7295f81d78 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet11_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet11_0.verified.txt @@ -986,6 +986,7 @@ namespace Sentry public void AddTransactionProcessor(Sentry.Extensibility.ISentryTransactionProcessor processor) { } public void AddTransactionProcessorProvider(System.Func> processorProvider) { } public void AddTransactionProcessors(System.Collections.Generic.IEnumerable processors) { } + public void ConfigureDataCollection() { } public void ConfigureDataCollection(System.Action configure) { } public void DisableAppDomainProcessExitFlush() { } public void DisableAppDomainUnhandledExceptionCapture() { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt index 81bfef9e2a..7295f81d78 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt @@ -986,6 +986,7 @@ namespace Sentry public void AddTransactionProcessor(Sentry.Extensibility.ISentryTransactionProcessor processor) { } public void AddTransactionProcessorProvider(System.Func> processorProvider) { } public void AddTransactionProcessors(System.Collections.Generic.IEnumerable processors) { } + public void ConfigureDataCollection() { } public void ConfigureDataCollection(System.Action configure) { } public void DisableAppDomainProcessExitFlush() { } public void DisableAppDomainUnhandledExceptionCapture() { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt index 81bfef9e2a..7295f81d78 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt @@ -986,6 +986,7 @@ namespace Sentry public void AddTransactionProcessor(Sentry.Extensibility.ISentryTransactionProcessor processor) { } public void AddTransactionProcessorProvider(System.Func> processorProvider) { } public void AddTransactionProcessors(System.Collections.Generic.IEnumerable processors) { } + public void ConfigureDataCollection() { } public void ConfigureDataCollection(System.Action configure) { } public void DisableAppDomainProcessExitFlush() { } public void DisableAppDomainUnhandledExceptionCapture() { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt index 6426c43309..a865a18ee2 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt @@ -957,6 +957,7 @@ namespace Sentry public void AddTransactionProcessor(Sentry.Extensibility.ISentryTransactionProcessor processor) { } public void AddTransactionProcessorProvider(System.Func> processorProvider) { } public void AddTransactionProcessors(System.Collections.Generic.IEnumerable processors) { } + public void ConfigureDataCollection() { } public void ConfigureDataCollection(System.Action configure) { } public void DisableAppDomainProcessExitFlush() { } public void DisableAppDomainUnhandledExceptionCapture() { } diff --git a/test/Sentry.Tests/DataCollectionOptionsTests.cs b/test/Sentry.Tests/DataCollectionOptionsTests.cs index 77400949e5..2d66615379 100644 --- a/test/Sentry.Tests/DataCollectionOptionsTests.cs +++ b/test/Sentry.Tests/DataCollectionOptionsTests.cs @@ -7,7 +7,7 @@ public void ConfigureDataCollection_StartsAtSpecDefaults() { var options = new SentryOptions(); - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); using (new AssertionScope()) { @@ -45,6 +45,17 @@ public void ConfigureDataCollection_NestedCategories_AreSettableInPlace() } } + [Fact] + public void ConfigureDataCollection_NoArgumentsAfterConfigure_KeepsCategories() + { + var options = new SentryOptions(); + + options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = false); + options.ConfigureDataCollection(); + + options.DataCollection!.UserInfo.Should().BeFalse(); + } + [Fact] public void ConfigureDataCollection_CalledTwice_BuildsOnTheSameOptions() { diff --git a/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs b/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs index eb03772904..c8c1511256 100644 --- a/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs +++ b/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs @@ -114,7 +114,7 @@ public void HeadersWithLegacyPiiGate_ConfiguredDataCollection_IgnoresSendDefault public void HeadersWithLegacyPiiGate_ConfiguredDataCollectionDefaults_AreDenyList() { var options = new SentryOptions(); - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); var resolver = Resolver(options); @@ -199,7 +199,7 @@ public void SanitizeDbStatements_WithoutDataCollection_IsFalseRegardlessOfSendDe public void SanitizeDbStatements_WithDataCollection_IsTrue() { var options = new SentryOptions(); - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); Resolver(options).SanitizeDbStatements.Should().BeTrue(); } @@ -208,7 +208,7 @@ public void SanitizeDbStatements_WithDataCollection_IsTrue() public void ConfiguredDataCollection_WithoutSendDefaultPii_UsesSpecDefaults() { var options = new SentryOptions(); - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); var resolver = Resolver(options); diff --git a/test/Sentry.Tests/Platforms/Android/SentrySdkTests.cs b/test/Sentry.Tests/Platforms/Android/SentrySdkTests.cs index a4a5d30e93..0b19d2adbb 100644 --- a/test/Sentry.Tests/Platforms/Android/SentrySdkTests.cs +++ b/test/Sentry.Tests/Platforms/Android/SentrySdkTests.cs @@ -92,7 +92,7 @@ public void ApplyDataCollection_NotConfigured_ForwardsOnlySendDefaultPii(bool se public void ApplyDataCollection_ConfiguredWithDefaults_SetsEveryMappedCategory() { var options = new SentryOptions(); - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); using var javaOptions = new JavaSdk.SentryOptions(); SentrySdk.ApplyDataCollection(options, javaOptions); @@ -207,7 +207,7 @@ public void ApplyDataCollection_HttpBodies_MapsEachBodyType(HttpBodyTypes bodies public void ApplyDataCollection_Configured_KeepsNativeOnlyCategories() { var options = new SentryOptions(); - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); using var javaOptions = new JavaSdk.SentryOptions(); javaOptions.DataCollection.FilePaths = Java.Lang.Boolean.False; javaOptions.DataCollection.DatabaseQueryData = Java.Lang.Boolean.False; diff --git a/test/Sentry.Tests/SentryGraphQlHttpFailedRequestHandlerTests.cs b/test/Sentry.Tests/SentryGraphQlHttpFailedRequestHandlerTests.cs index 88e7bed3d0..50d4255ed6 100644 --- a/test/Sentry.Tests/SentryGraphQlHttpFailedRequestHandlerTests.cs +++ b/test/Sentry.Tests/SentryGraphQlHttpFailedRequestHandlerTests.cs @@ -244,7 +244,7 @@ public void HandleResponse_UrlWithCredentials_AlwaysStripsCredentialsAndSeparate var options = new SentryOptions { CaptureFailedRequests = true, SendDefaultPii = sendDefaultPii }; if (configureDataCollection) { - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); } var response = PreconditionFailedResponse(); response.RequestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri("http://admin:1234@localhost/test/path?query=string#fragment")); @@ -287,7 +287,7 @@ public void HandleResponse_SensitiveFragmentParameter_FiltersFragment(bool confi var options = new SentryOptions { CaptureFailedRequests = true, SendDefaultPii = true }; if (configureDataCollection) { - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); } var response = PreconditionFailedResponse(); response.RequestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri("https://example.com/callback#access_token=abc123&state=xyz")); @@ -571,7 +571,7 @@ public void HandleResponse_ErrorNoPii_DoesNotCaptureSensitiveHeaders() public void HandleResponse_HeadersConfiguredWithoutSendDefaultPii_CollectsHeaders() { var options = new SentryOptions { CaptureFailedRequests = true, SendDefaultPii = false }; - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); var @event = CaptureEvent(options, ResponseWithSensitiveHeaders()); diff --git a/test/Sentry.Tests/SentryHttpFailedRequestHandlerTests.cs b/test/Sentry.Tests/SentryHttpFailedRequestHandlerTests.cs index 388bd0b79a..cc56bb2123 100644 --- a/test/Sentry.Tests/SentryHttpFailedRequestHandlerTests.cs +++ b/test/Sentry.Tests/SentryHttpFailedRequestHandlerTests.cs @@ -258,7 +258,7 @@ public void HandleResponse_UrlWithCredentials_AlwaysStripsCredentialsAndSeparate var options = new SentryOptions { CaptureFailedRequests = true, SendDefaultPii = sendDefaultPii }; if (configureDataCollection) { - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); } var response = InternalServerErrorResponse(); response.RequestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri("http://admin:1234@localhost/test/path?query=string#fragment")); @@ -320,7 +320,7 @@ public void HandleResponse_SensitiveFragmentParameter_FiltersFragment(bool confi var options = new SentryOptions { CaptureFailedRequests = true, SendDefaultPii = true }; if (configureDataCollection) { - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); } var response = InternalServerErrorResponse(); response.RequestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri("https://example.com/callback#access_token=abc123&state=xyz")); @@ -600,7 +600,7 @@ public void HandleResponse_FailedRequestNoPii_DoesNotCaptureSensitiveHeaders() public void HandleResponse_HeadersConfiguredWithoutSendDefaultPii_CollectsHeaders() { var options = new SentryOptions { CaptureFailedRequests = true, SendDefaultPii = false }; - options.ConfigureDataCollection(_ => { }); + options.ConfigureDataCollection(); var @event = CaptureEvent(options, ResponseWithSensitiveHeaders()); From 669a117bba6f670d04d0e98b4dd7c586bd6eca10 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 3 Dec 2026 13:10:50 +1300 Subject: [PATCH 04/10] fix: stop redacting app-set URLs once ConfigureDataCollection is called The Redact() pass in SentryClient rewrote URL credentials in every breadcrumb and span description whenever SendDefaultPii was false, even after ConfigureDataCollection. Since #5935 the SDK strips credentials where it records URLs, so the pass only touched data the app set, which the data collection spec says the SDK must not modify. It now runs only without ConfigureDataCollection and with SendDefaultPii = false, through a legacy-gate accessor that #5439 removes. Co-Authored-By: Claude Opus 5.5 --- src/Sentry/Internal/DataCollectionResolver.cs | 6 +++++ src/Sentry/SentryClient.cs | 8 ++----- src/Sentry/SentryOptions.cs | 4 +--- .../Internals/DataCollectionResolverTests.cs | 17 +++++++++++++ test/Sentry.Tests/SentryClientTests.cs | 24 ++++++++++++++----- 5 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/Sentry/Internal/DataCollectionResolver.cs b/src/Sentry/Internal/DataCollectionResolver.cs index 194b99fa68..65d7bf9fbc 100644 --- a/src/Sentry/Internal/DataCollectionResolver.cs +++ b/src/Sentry/Internal/DataCollectionResolver.cs @@ -63,6 +63,12 @@ internal sealed class DataCollectionResolver(SentryOptions options) public KeyValueCollectionBehavior UrlFragmentWithLegacyPiiGate => Configured?.UrlQueryParams ?? (SendDefaultPii ? DenyList : Off); + /// + /// Temporary bridge for redacting URL credentials in breadcrumbs and span descriptions without + /// SendDefaultPii; remove with it, see https://github.com/getsentry/sentry-dotnet/issues/5439 + /// + public bool RedactUrlCredentialsWithLegacyPiiGate => Configured is null && !SendDefaultPii; + public bool IncomingRequestBody => CollectsBody(HttpBodyTypes.IncomingRequest, legacyFallback: true); public bool OutgoingRequestBody => CollectsBody(HttpBodyTypes.OutgoingRequest, SendDefaultPii); diff --git a/src/Sentry/SentryClient.cs b/src/Sentry/SentryClient.cs index a6d83e7f68..9ba8030a18 100644 --- a/src/Sentry/SentryClient.cs +++ b/src/Sentry/SentryClient.cs @@ -243,12 +243,10 @@ public void CaptureTransaction(SentryTransaction transaction, Scope? scope, Sent return; } -#pragma warning disable CS0618 - if (!_options.SendDefaultPii) + if (_options.DataCollectionResolver.RedactUrlCredentialsWithLegacyPiiGate) { processedTransaction.Redact(); } -#pragma warning restore CS0618 // Keep null entries so the null-attachment guard in Envelope.FromTransaction handles them // (consistent with the event/feedback capture paths); dereferencing them here would throw. @@ -442,12 +440,10 @@ private SentryId DoSendEvent(SentryEvent @event, SentryHint? hint, Scope? scope) _options.LogDebug("Event sampled in."); } -#pragma warning disable CS0618 - if (!_options.SendDefaultPii) + if (_options.DataCollectionResolver.RedactUrlCredentialsWithLegacyPiiGate) { processedEvent.Redact(); } -#pragma warning restore CS0618 CaptureReplay(processedEvent, scope); diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index db9600d230..dc088931c3 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -358,12 +358,10 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// sanitized. /// /// - /// A few behaviors still follow this option, whether or not has been called: + /// Two behaviors still follow this option, whether or not has been called: /// /// The machine name is sent as only when this option is true. Set /// explicitly to keep sending it without this option. - /// When this option is false, URL credentials are redacted from breadcrumbs and span descriptions, - /// including ones the application set itself. /// Sentry.OpenTelemetry's AddSentry sets the user from the HTTP request only when this option /// is true. /// diff --git a/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs b/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs index c8c1511256..1d3152625c 100644 --- a/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs +++ b/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs @@ -110,6 +110,23 @@ public void HeadersWithLegacyPiiGate_ConfiguredDataCollection_IgnoresSendDefault } } + [Theory] + [InlineData(false, false, true)] + [InlineData(true, false, false)] + [InlineData(false, true, false)] + [InlineData(true, true, false)] + public void RedactUrlCredentialsWithLegacyPiiGate_OnlyWithoutSendDefaultPiiOrDataCollection( + bool sendDefaultPii, bool configureDataCollection, bool expected) + { + var options = new SentryOptions { SendDefaultPii = sendDefaultPii }; + if (configureDataCollection) + { + options.ConfigureDataCollection(); + } + + Resolver(options).RedactUrlCredentialsWithLegacyPiiGate.Should().Be(expected); + } + [Fact] public void HeadersWithLegacyPiiGate_ConfiguredDataCollectionDefaults_AreDenyList() { diff --git a/test/Sentry.Tests/SentryClientTests.cs b/test/Sentry.Tests/SentryClientTests.cs index a277cadd3a..32fe1d84f9 100644 --- a/test/Sentry.Tests/SentryClientTests.cs +++ b/test/Sentry.Tests/SentryClientTests.cs @@ -367,12 +367,18 @@ public void CaptureEvent_UserIsNull_SetsFallbackUserId() } [Theory] - [InlineData(false, "Visited https://[Filtered]@sentry.io in session")] - [InlineData(true, "Visited https://user@sentry.io in session")] - public void CaptureEvent_Redact_Breadcrumbs(bool sendDefaultPii, string expected) + [InlineData(false, false, "Visited https://[Filtered]@sentry.io in session")] + [InlineData(true, false, "Visited https://user@sentry.io in session")] + [InlineData(false, true, "Visited https://user@sentry.io in session")] + [InlineData(true, true, "Visited https://user@sentry.io in session")] + public void CaptureEvent_Redact_Breadcrumbs(bool sendDefaultPii, bool configureDataCollection, string expected) { // Act _fixture.SentryOptions.SendDefaultPii = sendDefaultPii; + if (configureDataCollection) + { + _fixture.SentryOptions.ConfigureDataCollection(); + } var scope = new Scope(_fixture.SentryOptions); scope.AddBreadcrumb("Visited https://user@sentry.io in session"); var @event = new SentryEvent(); @@ -1609,12 +1615,18 @@ public void CaptureTransaction_DisposedClient_DoesNotThrow() } [Theory] - [InlineData(false, "The URL: https://[Filtered]@sentry.io has PII data in it")] - [InlineData(true, "The URL: https://user@sentry.io has PII data in it")] - public void CaptureTransaction_Redact_Description(bool sendDefaultPii, string expected) + [InlineData(false, false, "The URL: https://[Filtered]@sentry.io has PII data in it")] + [InlineData(true, false, "The URL: https://user@sentry.io has PII data in it")] + [InlineData(false, true, "The URL: https://user@sentry.io has PII data in it")] + [InlineData(true, true, "The URL: https://user@sentry.io has PII data in it")] + public void CaptureTransaction_Redact_Description(bool sendDefaultPii, bool configureDataCollection, string expected) { // Arrange _fixture.SentryOptions.SendDefaultPii = sendDefaultPii; + if (configureDataCollection) + { + _fixture.SentryOptions.ConfigureDataCollection(); + } var client = _fixture.GetSut(); var original = new SentryTransaction( "test name", From b7fdf3ce909b00a6648da1f9e036fbbd5386a39b Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 3 Dec 2026 13:34:36 +1300 Subject: [PATCH 05/10] feat: add AttachServerName to control sending the machine name Adds SentryOptions.AttachServerName and its bindable counterpart. It defaults to false on Android, iOS and Mac Catalyst, where the machine name is the user's device name, and true elsewhere. Once ConfigureDataCollection has been called it replaces SendDefaultPii as the switch for the machine name in events and logs. ASP.NET and ASP.NET Core honour it too, and ASP.NET no longer overwrites an explicitly set ServerName. Closes #5957 Co-Authored-By: Claude Opus 5.5 --- .../SystemWebRequestEventProcessor.cs | 5 ++- .../AspNetCoreEventProcessor.cs | 9 ++-- src/Sentry.AspNetCore/ScopeExtensions.cs | 5 ++- src/Sentry/BindableSentryOptions.cs | 2 + src/Sentry/Internal/DataCollectionResolver.cs | 7 ++++ .../Internal/MainSentryEventProcessor.cs | 4 +- src/Sentry/SentryLog.cs | 4 +- src/Sentry/SentryOptions.cs | 29 ++++++++----- .../SystemWebRequestEventProcessorTests.cs | 31 ++++++++++++++ .../AspNetCoreEventProcessorTests.cs | 16 +++++++- .../ScopeExtensionsTests.cs | 10 +++++ ...iApprovalTests.Run.DotNet10_0.verified.txt | 1 + ...iApprovalTests.Run.DotNet11_0.verified.txt | 1 + ...piApprovalTests.Run.DotNet8_0.verified.txt | 1 + ...piApprovalTests.Run.DotNet9_0.verified.txt | 1 + .../ApiApprovalTests.Run.Net4_8.verified.txt | 1 + .../Internals/DataCollectionResolverTests.cs | 18 ++++++++ .../MainSentryEventProcessorTests.cs | 41 +++++++++++++++++++ test/Sentry.Tests/SentryLogTests.cs | 14 ++++++- test/Sentry.Tests/SentryOptionsTests.cs | 11 +++++ 20 files changed, 185 insertions(+), 26 deletions(-) diff --git a/src/Sentry.AspNet/Internal/SystemWebRequestEventProcessor.cs b/src/Sentry.AspNet/Internal/SystemWebRequestEventProcessor.cs index 42cf87214f..bc4e37b52d 100644 --- a/src/Sentry.AspNet/Internal/SystemWebRequestEventProcessor.cs +++ b/src/Sentry.AspNet/Internal/SystemWebRequestEventProcessor.cs @@ -99,7 +99,10 @@ public SystemWebRequestEventProcessor(IRequestPayloadExtractor payloadExtractor, } } - @event.ServerName = Environment.MachineName; + if (_options.AttachServerName) + { + @event.ServerName ??= Environment.MachineName; + } if (dataCollection.IncomingRequestBody && PayloadExtractor.ExtractPayload(new SystemWebHttpRequest(context.Request)) is { } body) diff --git a/src/Sentry.AspNetCore/AspNetCoreEventProcessor.cs b/src/Sentry.AspNetCore/AspNetCoreEventProcessor.cs index 78d41e90e6..be57e8b965 100644 --- a/src/Sentry.AspNetCore/AspNetCoreEventProcessor.cs +++ b/src/Sentry.AspNetCore/AspNetCoreEventProcessor.cs @@ -1,18 +1,15 @@ +using Microsoft.Extensions.Options; using Sentry.Extensibility; using Sentry.Internal; namespace Sentry.AspNetCore; -internal class AspNetCoreEventProcessor : ISentryEventProcessor, ISdkProcessor +internal class AspNetCoreEventProcessor(IOptions options) : ISentryEventProcessor, ISdkProcessor { public SentryEvent Process(SentryEvent @event) { - // Not PII as this is running on a server - if (@event.ServerName == null) + if (@event.ServerName is null && options.Value.AttachServerName) { - // ServerName from the environment machine name is set by the Sentry base package. - // That is guarded by the SendDefaultPii since the SDK can be used in desktop apps. - // For ASP.NET Core apps, we always set the machine name if not explicitly set by the user. @event.ServerName = Environment.MachineName; } diff --git a/src/Sentry.AspNetCore/ScopeExtensions.cs b/src/Sentry.AspNetCore/ScopeExtensions.cs index d7468ec4dc..1b6f8ba09a 100644 --- a/src/Sentry.AspNetCore/ScopeExtensions.cs +++ b/src/Sentry.AspNetCore/ScopeExtensions.cs @@ -141,7 +141,10 @@ private static void SetEnv(Scope scope, HttpContext context, SentryAspNetCoreOpt scope.Request.Env["REMOTE_ADDR"] = ipAddress; } - scope.Request.Env["SERVER_NAME"] = Environment.MachineName; + if (options.AttachServerName) + { + scope.Request.Env["SERVER_NAME"] = Environment.MachineName; + } scope.Request.Env["SERVER_PORT"] = context.Connection.LocalPort.ToString(); if (context.Response.Headers.TryGetValue("Server", out var server)) diff --git a/src/Sentry/BindableSentryOptions.cs b/src/Sentry/BindableSentryOptions.cs index 6979b20567..f59e28c57a 100644 --- a/src/Sentry/BindableSentryOptions.cs +++ b/src/Sentry/BindableSentryOptions.cs @@ -14,6 +14,7 @@ internal partial class BindableSentryOptions public bool? SendDefaultPii { get; set; } public bool? IsEnvironmentUser { get; set; } public string? ServerName { get; set; } + public bool? AttachServerName { get; set; } public bool? AttachStacktrace { get; set; } public int? MaxBreadcrumbs { get; set; } public float? SampleRate { get; set; } @@ -69,6 +70,7 @@ public void ApplyTo(SentryOptions options) #pragma warning restore CS0618 options.IsEnvironmentUser = IsEnvironmentUser ?? options.IsEnvironmentUser; options.ServerName = ServerName ?? options.ServerName; + options.AttachServerName = AttachServerName ?? options.AttachServerName; options.AttachStacktrace = AttachStacktrace ?? options.AttachStacktrace; options.MaxBreadcrumbs = MaxBreadcrumbs ?? options.MaxBreadcrumbs; options.SampleRate = SampleRate ?? options.SampleRate; diff --git a/src/Sentry/Internal/DataCollectionResolver.cs b/src/Sentry/Internal/DataCollectionResolver.cs index 65d7bf9fbc..ba4b7e67fd 100644 --- a/src/Sentry/Internal/DataCollectionResolver.cs +++ b/src/Sentry/Internal/DataCollectionResolver.cs @@ -69,6 +69,13 @@ internal sealed class DataCollectionResolver(SentryOptions options) /// public bool RedactUrlCredentialsWithLegacyPiiGate => Configured is null && !SendDefaultPii; + /// + /// Temporary bridge for call sites that only sent the machine name with SendDefaultPii; remove with it, see + /// https://github.com/getsentry/sentry-dotnet/issues/5439 + /// + public bool AttachServerNameWithLegacyPiiGate => + options.AttachServerName && (Configured is not null || SendDefaultPii); + public bool IncomingRequestBody => CollectsBody(HttpBodyTypes.IncomingRequest, legacyFallback: true); public bool OutgoingRequestBody => CollectsBody(HttpBodyTypes.OutgoingRequest, SendDefaultPii); diff --git a/src/Sentry/Internal/MainSentryEventProcessor.cs b/src/Sentry/Internal/MainSentryEventProcessor.cs index c1b7f50088..38a5b7259f 100644 --- a/src/Sentry/Internal/MainSentryEventProcessor.cs +++ b/src/Sentry/Internal/MainSentryEventProcessor.cs @@ -70,12 +70,10 @@ public SentryEvent Process(SentryEvent @event) { @event.ServerName = _options.ServerName; } -#pragma warning disable CS0618 - else if (_options.SendDefaultPii) + else if (_options.DataCollectionResolver.AttachServerNameWithLegacyPiiGate) { @event.ServerName = Environment.MachineName; } -#pragma warning restore CS0618 } @event.Level ??= SentryLevel.Error; diff --git a/src/Sentry/SentryLog.cs b/src/Sentry/SentryLog.cs index 780b39aa15..597836e293 100644 --- a/src/Sentry/SentryLog.cs +++ b/src/Sentry/SentryLog.cs @@ -168,12 +168,10 @@ internal void SetDefaultAttributes(SentryOptions options, Scope? scope, SdkVersi { SetAttribute("server.address", options.ServerName!); } -#pragma warning disable CS0618 - else if (options.SendDefaultPii) + else if (options.DataCollectionResolver.AttachServerNameWithLegacyPiiGate) { SetAttribute("server.address", Environment.MachineName); } -#pragma warning restore CS0618 // User Attributes if (scope?.User is { } user) diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index dc088931c3..da24a209e7 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -350,6 +350,7 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// dataCollection.GraphQL.Document = false; /// dataCollection.GraphQL.Variables = false; /// }); + /// options.AttachServerName = false; /// /// This still differs from SendDefaultPii = false in three ways. Failed HTTP request events include /// headers: sets one behavior for those and for the headers of @@ -358,13 +359,9 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// sanitized. /// /// - /// Two behaviors still follow this option, whether or not has been called: - /// - /// The machine name is sent as only when this option is true. Set - /// explicitly to keep sending it without this option. - /// Sentry.OpenTelemetry's AddSentry sets the user from the HTTP request only when this option - /// is true. - /// + /// Sentry.OpenTelemetry's AddSentry still follows this option after + /// has been called: it sets the user from the HTTP request only when this + /// option is true. /// /// [Obsolete(ObsoleteSendDefaultPii)] @@ -435,12 +432,24 @@ public void ConfigureDataCollection(Action configure) /// Gets or sets the name of the server running the application. /// /// - /// When is set to true, is - /// automatically set as ServerName. This property can serve as an override. - /// This is relevant only to server applications. + /// Takes precedence over the machine name sent by . /// public string? ServerName { get; set; } + /// + /// Whether to send as the when that isn't set. + /// + /// + /// The default is false on Android, iOS and Mac Catalyst, where the machine name is the name of the user's + /// device, and true elsewhere. Until is called, events and logs only + /// include it when is also true, except in ASP.NET and ASP.NET Core. + /// +#if __MOBILE__ + public bool AttachServerName { get; set; } +#else + public bool AttachServerName { get; set; } = true; +#endif + /// /// Whether to send the stack trace of a event captured without an exception. /// As of version 3.22.0, the default is true. diff --git a/test/Sentry.AspNet.Tests/Internal/SystemWebRequestEventProcessorTests.cs b/test/Sentry.AspNet.Tests/Internal/SystemWebRequestEventProcessorTests.cs index 89b4573db4..1515a5751a 100644 --- a/test/Sentry.AspNet.Tests/Internal/SystemWebRequestEventProcessorTests.cs +++ b/test/Sentry.AspNet.Tests/Internal/SystemWebRequestEventProcessorTests.cs @@ -48,6 +48,37 @@ public void Process_DefaultFixture_ReadsMockBody() Assert.Same(_fixture.MockBody, expected.Request.Data); } + [Fact] + public void Process_DefaultOptions_ServerNameSetToMachineName() + { + var evt = new SentryEvent(); + + _fixture.GetSut().Process(evt); + + Assert.Equal(Environment.MachineName, evt.ServerName); + } + + [Fact] + public void Process_ServerNameOnEvent_NotOverwritten() + { + var evt = new SentryEvent { ServerName = "expected server name" }; + + _fixture.GetSut().Process(evt); + + Assert.Equal("expected server name", evt.ServerName); + } + + [Fact] + public void Process_AttachServerNameFalse_ServerNameNotSet() + { + _fixture.SentryOptions.AttachServerName = false; + var evt = new SentryEvent(); + + _fixture.GetSut().Process(evt); + + Assert.Null(evt.ServerName); + } + [Fact] public void Process_QueryStringWithSensitiveParameter_FiltersValueAndPreservesEncoding() { diff --git a/test/Sentry.AspNetCore.Tests/AspNetCoreEventProcessorTests.cs b/test/Sentry.AspNetCore.Tests/AspNetCoreEventProcessorTests.cs index f9f1487b24..d5850081d9 100644 --- a/test/Sentry.AspNetCore.Tests/AspNetCoreEventProcessorTests.cs +++ b/test/Sentry.AspNetCore.Tests/AspNetCoreEventProcessorTests.cs @@ -1,12 +1,15 @@ +using Microsoft.Extensions.Options; + namespace Sentry.AspNetCore.Tests; public class AspNetCoreEventProcessorTests { + private readonly SentryAspNetCoreOptions _options = new(); private readonly AspNetCoreEventProcessor _sut; public AspNetCoreEventProcessorTests() { - _sut = new AspNetCoreEventProcessor(); + _sut = new AspNetCoreEventProcessor(Options.Create(_options)); } [Fact] @@ -30,4 +33,15 @@ public void Process_ServerName_SetToEnvironmentMachineName() Assert.Equal(Environment.MachineName, target.ServerName); } + + [Fact] + public void Process_AttachServerNameFalse_ServerNameNotSet() + { + _options.AttachServerName = false; + var target = new SentryEvent(); + + _ = _sut.Process(target); + + Assert.Null(target.ServerName); + } } diff --git a/test/Sentry.AspNetCore.Tests/ScopeExtensionsTests.cs b/test/Sentry.AspNetCore.Tests/ScopeExtensionsTests.cs index d5ac0b3c59..480cd5018c 100644 --- a/test/Sentry.AspNetCore.Tests/ScopeExtensionsTests.cs +++ b/test/Sentry.AspNetCore.Tests/ScopeExtensionsTests.cs @@ -534,6 +534,16 @@ public void Populate_MachineName_SetToEnv() Assert.Equal(Environment.MachineName, _sut.Request.Env["SERVER_NAME"]); } + [Fact] + public void Populate_AttachServerNameFalse_MachineNameNotSetToEnv() + { + SentryAspNetCoreOptions.AttachServerName = false; + + _sut.Populate(_httpContext, SentryAspNetCoreOptions); + + Assert.False(_sut.Request.Env.ContainsKey("SERVER_NAME")); + } + [Fact] public void Populate_NoAspNetCoreOptions_NoPayloadExtractors_NoBodyRead() { diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt index 7295f81d78..ea441cf2c6 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt @@ -900,6 +900,7 @@ namespace Sentry public SentryOptions() { } [System.CLSCompliant(false)] public System.Func? AssemblyReader { get; set; } + public bool AttachServerName { get; set; } public bool AttachStacktrace { get; set; } public bool AutoSessionTracking { get; set; } public System.TimeSpan AutoSessionTrackingInterval { get; set; } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet11_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet11_0.verified.txt index 7295f81d78..ea441cf2c6 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet11_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet11_0.verified.txt @@ -900,6 +900,7 @@ namespace Sentry public SentryOptions() { } [System.CLSCompliant(false)] public System.Func? AssemblyReader { get; set; } + public bool AttachServerName { get; set; } public bool AttachStacktrace { get; set; } public bool AutoSessionTracking { get; set; } public System.TimeSpan AutoSessionTrackingInterval { 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 7295f81d78..ea441cf2c6 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt @@ -900,6 +900,7 @@ namespace Sentry public SentryOptions() { } [System.CLSCompliant(false)] public System.Func? AssemblyReader { get; set; } + public bool AttachServerName { get; set; } public bool AttachStacktrace { get; set; } public bool AutoSessionTracking { get; set; } public System.TimeSpan AutoSessionTrackingInterval { 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 7295f81d78..ea441cf2c6 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt @@ -900,6 +900,7 @@ namespace Sentry public SentryOptions() { } [System.CLSCompliant(false)] public System.Func? AssemblyReader { get; set; } + public bool AttachServerName { get; set; } public bool AttachStacktrace { get; set; } public bool AutoSessionTracking { get; set; } public System.TimeSpan AutoSessionTrackingInterval { 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 a865a18ee2..0a045c5e4d 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt @@ -871,6 +871,7 @@ namespace Sentry public SentryOptions() { } [System.CLSCompliant(false)] public System.Func? AssemblyReader { get; set; } + public bool AttachServerName { get; set; } public bool AttachStacktrace { get; set; } public bool AutoSessionTracking { get; set; } public System.TimeSpan AutoSessionTrackingInterval { get; set; } diff --git a/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs b/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs index 1d3152625c..20c0da1247 100644 --- a/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs +++ b/test/Sentry.Tests/Internals/DataCollectionResolverTests.cs @@ -127,6 +127,24 @@ public void RedactUrlCredentialsWithLegacyPiiGate_OnlyWithoutSendDefaultPiiOrDat Resolver(options).RedactUrlCredentialsWithLegacyPiiGate.Should().Be(expected); } + [Theory] + [InlineData(true, false, false, false)] + [InlineData(true, true, false, true)] + [InlineData(true, false, true, true)] + [InlineData(false, true, false, false)] + [InlineData(false, false, true, false)] + public void AttachServerNameWithLegacyPiiGate_RequiresSendDefaultPiiOrDataCollection( + bool attachServerName, bool sendDefaultPii, bool configureDataCollection, bool expected) + { + var options = new SentryOptions { AttachServerName = attachServerName, SendDefaultPii = sendDefaultPii }; + if (configureDataCollection) + { + options.ConfigureDataCollection(); + } + + Resolver(options).AttachServerNameWithLegacyPiiGate.Should().Be(expected); + } + [Fact] public void HeadersWithLegacyPiiGate_ConfiguredDataCollectionDefaults_AreDenyList() { diff --git a/test/Sentry.Tests/Internals/MainSentryEventProcessorTests.cs b/test/Sentry.Tests/Internals/MainSentryEventProcessorTests.cs index b317a3f122..a6a8ba5e5a 100644 --- a/test/Sentry.Tests/Internals/MainSentryEventProcessorTests.cs +++ b/test/Sentry.Tests/Internals/MainSentryEventProcessorTests.cs @@ -258,12 +258,53 @@ public void Process_SendDefaultPiiTrue_ServerNameSet() var sut = _fixture.GetSut(); var evt = new SentryEvent(); + _fixture.SentryOptions.AttachServerName = true; _fixture.SentryOptions.SendDefaultPii = true; _ = sut.Process(evt); Assert.Equal(Environment.MachineName, evt.ServerName); } + [Fact] + public void Process_DataCollectionConfigured_ServerNameSet() + { + _fixture.SentryOptions.AttachServerName = true; + _fixture.SentryOptions.ConfigureDataCollection(); + var sut = _fixture.GetSut(); + var evt = new SentryEvent(); + + _ = sut.Process(evt); + + Assert.Equal(Environment.MachineName, evt.ServerName); + } + + [Fact] + public void Process_AttachServerNameFalse_NoServerNameSet() + { + _fixture.SentryOptions.AttachServerName = false; + _fixture.SentryOptions.SendDefaultPii = true; + _fixture.SentryOptions.ConfigureDataCollection(); + var sut = _fixture.GetSut(); + var evt = new SentryEvent(); + + _ = sut.Process(evt); + + Assert.Null(evt.ServerName); + } + + [Fact] + public void Process_AttachServerNameFalseAndNameOnOption_ServerNameSetToOptionsValue() + { + _fixture.SentryOptions.AttachServerName = false; + _fixture.SentryOptions.ServerName = "expected server name"; + var sut = _fixture.GetSut(); + var evt = new SentryEvent(); + + _ = sut.Process(evt); + + Assert.Equal("expected server name", evt.ServerName); + } + [Fact] public void Process_SendDefaultPiiTrueNameOnOptionAndOnEvent_ServerNameNotOverwritten() { diff --git a/test/Sentry.Tests/SentryLogTests.cs b/test/Sentry.Tests/SentryLogTests.cs index 6a5e3a5b5b..26cbf595ab 100644 --- a/test/Sentry.Tests/SentryLogTests.cs +++ b/test/Sentry.Tests/SentryLogTests.cs @@ -167,7 +167,7 @@ public void SetDefaultAttributes_OptionsServerName_SetsServerAddress() [Fact] public void SetDefaultAttributes_SendDefaultPii_SetsServerAddressToMachineName() { - var options = new SentryOptions { SendDefaultPii = true }; + var options = new SentryOptions { AttachServerName = true, SendDefaultPii = true }; var log = new SentryLog(Timestamp, TraceId, SentryLogLevel.Info, "message"); log.SetDefaultAttributes(options, new Scope(options)); @@ -175,6 +175,18 @@ public void SetDefaultAttributes_SendDefaultPii_SetsServerAddressToMachineName() log.Attributes.ShouldContain("server.address", Environment.MachineName); } + [Fact] + public void SetDefaultAttributes_AttachServerNameFalse_OmitsServerAddress() + { + var options = new SentryOptions { AttachServerName = false, SendDefaultPii = true }; + options.ConfigureDataCollection(); + var log = new SentryLog(Timestamp, TraceId, SentryLogLevel.Info, "message"); + + log.SetDefaultAttributes(options, new Scope(options)); + + log.Attributes.ShouldNotContain("server.address"); + } + [Fact] public void SetDefaultAttributes_NoServerNameNoPii_OmitsServerAddress() { diff --git a/test/Sentry.Tests/SentryOptionsTests.cs b/test/Sentry.Tests/SentryOptionsTests.cs index d7aff990ae..1e0daf5b67 100644 --- a/test/Sentry.Tests/SentryOptionsTests.cs +++ b/test/Sentry.Tests/SentryOptionsTests.cs @@ -13,6 +13,17 @@ public void DecompressionMethods_ByDefault_GZipAndDeflate() Assert.Equal(DecompressionMethods.GZip | DecompressionMethods.Deflate, sut.DecompressionMethods); } + [Fact] + public void AttachServerName_Default_FalseOnlyOnMobile() + { + var sut = new SentryOptions(); +#if __MOBILE__ + Assert.False(sut.AttachServerName); +#else + Assert.True(sut.AttachServerName); +#endif + } + [Fact] public void EnableBackpressureHandling_Default_True() { From bf500fe4a68c36d4c08a5d0f3484eecbc5e0f8f8 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 3 Dec 2026 13:41:13 +1300 Subject: [PATCH 06/10] docs: limit the ASP.NET AttachServerName exception to events Logs in ASP.NET and ASP.NET Core still follow the core SDK's SendDefaultPii gate until ConfigureDataCollection is called. Co-Authored-By: Claude Opus 5.5 --- src/Sentry/SentryOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index da24a209e7..fa1bf1b6c1 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -442,7 +442,7 @@ public void ConfigureDataCollection(Action configure) /// /// The default is false on Android, iOS and Mac Catalyst, where the machine name is the name of the user's /// device, and true elsewhere. Until is called, events and logs only - /// include it when is also true, except in ASP.NET and ASP.NET Core. + /// include it when is also true, except for events in ASP.NET and ASP.NET Core. /// #if __MOBILE__ public bool AttachServerName { get; set; } From e5e21cbcea70ba0539f5040b262da815b866272c Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 3 Dec 2026 14:02:23 +1300 Subject: [PATCH 07/10] test: bind AttachServerName from config in both directions Outside mobile the generic bindable test binds true, which is already the default, so it didn't cover the ApplyTo line. Co-Authored-By: Claude Opus 5.5 --- .../BindableSentryOptionsTests.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/Sentry.Tests/BindableSentryOptionsTests.cs b/test/Sentry.Tests/BindableSentryOptionsTests.cs index 12b3034dad..4eb668cefc 100644 --- a/test/Sentry.Tests/BindableSentryOptionsTests.cs +++ b/test/Sentry.Tests/BindableSentryOptionsTests.cs @@ -27,6 +27,29 @@ public void ApplyTo_SetsOptionsFromConfig() AssertContainsExpectedPropertyValues(actual); } + [Theory] + [InlineData(true)] + [InlineData(false)] + public void ApplyTo_AttachServerNameConfigured_OverridesDefault(bool configured) + { + // Arrange + var actual = new SentryOptions(); + var bindable = new BindableSentryOptions(); + var config = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + ["AttachServerName"] = configured.ToString() + }) + .Build(); + + // Act + config.Bind(bindable); + bindable.ApplyTo(actual); + + // Assert + actual.AttachServerName.Should().Be(configured); + } + [Fact] public void ApplyTo_TraceIgnoreStatusCodesNotConfigured_KeepsDefault() { From 8b7a7f8786ef897dfc38097bb1b77d7dbfd6b1ac Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Fri, 4 Dec 2026 02:47:51 +1300 Subject: [PATCH 08/10] docs(samples): show how to opt out of UserInfo instead of setting it to true UserInfo defaults to true, so the samples now call the parameterless ConfigureDataCollection() and show the UserInfo = false call as a commented-out alternative. Co-Authored-By: Claude Opus 5.5 --- samples/Sentry.Samples.Android/MainActivity.cs | 4 +++- samples/Sentry.Samples.Console.Customized/Program.cs | 4 +++- samples/Sentry.Samples.GraphQL.Server/Program.cs | 4 +++- samples/Sentry.Samples.NLog/Program.cs | 4 +++- samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs | 4 +++- samples/Sentry.Samples.Serilog/Program.cs | 4 +++- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/samples/Sentry.Samples.Android/MainActivity.cs b/samples/Sentry.Samples.Android/MainActivity.cs index 5442cb2c93..97cd59edbc 100644 --- a/samples/Sentry.Samples.Android/MainActivity.cs +++ b/samples/Sentry.Samples.Android/MainActivity.cs @@ -20,7 +20,9 @@ protected override void OnCreate(Bundle? savedInstanceState) options.Dsn = EnvironmentVariables.Dsn; #endif - options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = true); // adds the user's IP address automatically + options.ConfigureDataCollection(); // adds the user's IP address automatically + // To leave out the user's IP address and other user details, use this instead: + // options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = false); // Android specific .NET features are under the Android properties: options.Android.LogCatIntegration = LogCatIntegrationType.Errors; // Get logcat logs for both handled and unhandled errors; default is unhandled only diff --git a/samples/Sentry.Samples.Console.Customized/Program.cs b/samples/Sentry.Samples.Console.Customized/Program.cs index ced2965746..1b10d77474 100644 --- a/samples/Sentry.Samples.Console.Customized/Program.cs +++ b/samples/Sentry.Samples.Console.Customized/Program.cs @@ -35,7 +35,9 @@ await SentrySdk.ConfigureScopeAsync(async scope => options.AddInAppInclude("LibraryX.Core"); // Send personal identifiable information like the username logged on to the computer - options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = true); + options.ConfigureDataCollection(); + // To leave out the username and other user details, use this instead: + // options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = false); // To enable event sampling, uncomment: // o.SampleRate = 0.5f; // Randomly drop (don't send to Sentry) half of events diff --git a/samples/Sentry.Samples.GraphQL.Server/Program.cs b/samples/Sentry.Samples.GraphQL.Server/Program.cs index dc115add04..8830f93f3d 100644 --- a/samples/Sentry.Samples.GraphQL.Server/Program.cs +++ b/samples/Sentry.Samples.GraphQL.Server/Program.cs @@ -54,7 +54,9 @@ public static WebApplication BuildWebApplication(string[] args) options.TracesSampleRate = 1.0; options.Debug = true; - options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = true); // adds the user's IP address automatically + options.ConfigureDataCollection(); // adds the user's IP address automatically + // To leave out the user's IP address and other user details, use this instead: + // options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = false); options.UseOtlp(); // <-- Configure Sentry to use OpenTelemetry trace information }); diff --git a/samples/Sentry.Samples.NLog/Program.cs b/samples/Sentry.Samples.NLog/Program.cs index ab3fd1bd21..99b0a57e92 100644 --- a/samples/Sentry.Samples.NLog/Program.cs +++ b/samples/Sentry.Samples.NLog/Program.cs @@ -21,7 +21,9 @@ private static void Main() options.Dsn = SamplesShared.Dsn; #endif options.AttachStacktrace = true; - options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = true); // Send Personal Identifiable information like the username of the user logged in to the device + options.ConfigureDataCollection(); // Send Personal Identifiable information like the username of the user logged in to the device + // To leave out the username and other user details, use this instead: + // options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = false); }); try diff --git a/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs b/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs index dfba93739f..3ec994a30f 100644 --- a/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs +++ b/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs @@ -38,7 +38,9 @@ { options.Dsn = dsn; options.Debug = builder.Environment.IsDevelopment(); - options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = true); // adds the signed-in user automatically + options.ConfigureDataCollection(); // adds the signed-in user automatically + // To leave out the signed-in user, use this instead: + // options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = false); options.TracesSampleRate = 1.0; options.UseOtlp(); // <-- Configure Sentry to use OpenTelemetry trace information }); diff --git a/samples/Sentry.Samples.Serilog/Program.cs b/samples/Sentry.Samples.Serilog/Program.cs index 5da4975483..55671890a1 100644 --- a/samples/Sentry.Samples.Serilog/Program.cs +++ b/samples/Sentry.Samples.Serilog/Program.cs @@ -19,7 +19,9 @@ private static void Main() options.AttachStacktrace = true; // send PII like the username of the user logged in to the device - options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = true); + options.ConfigureDataCollection(); + // To leave out the username and other user details, use this instead: + // options.ConfigureDataCollection(dataCollection => dataCollection.UserInfo = false); // Apply properties from the Serilog LogContext (like MyTaskId below) to Sentry events options.UseSerilog(); }); From f94b0ee13fd9193a3c22b3ca2a2510455f473eb5 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Fri, 4 Dec 2026 03:22:59 +1300 Subject: [PATCH 09/10] docs: list database sanitizing and app-set URL credentials among SendDefaultPii differences ConfigureDataCollection() sanitizes database statements, which SendDefaultPii = true doesn't, and since 669a117 it leaves credentials in app-set URLs alone, which SendDefaultPii = false replaced. Co-Authored-By: Claude Opus 5.5 --- src/Sentry/SentryOptions.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index dc088931c3..7cbb71f104 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -337,7 +337,7 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// Superseded by . Once that has been called, /// integrations ignore this option, apart from the exceptions below. To keep what SendDefaultPii = true /// collects, call , whose defaults collect every category with sensitive - /// keys filtered out. + /// keys filtered out. Unlike SendDefaultPii = true, it sanitizes database statements. /// /// /// The closest equivalent of SendDefaultPii = false is: @@ -351,11 +351,13 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// dataCollection.GraphQL.Variables = false; /// }); /// - /// This still differs from SendDefaultPii = false in three ways. Failed HTTP request events include + /// This still differs from SendDefaultPii = false in four ways. Failed HTTP request events include /// headers: sets one behavior for those and for the headers of /// incoming requests, and SendDefaultPii = false collected only the latter. They also include the URL - /// fragment, which follows . And database statements are - /// sanitized. + /// fragment, which follows . Database statements are + /// sanitized. And credentials in URLs that the app put in breadcrumbs or span descriptions, such as + /// https://user:password@example.com, are sent as they are. The SDK still removes them from the URLs + /// it records. /// /// /// Two behaviors still follow this option, whether or not has been called: From 6804c327b112f2d16f69bd13b13a49e5eb417e4a Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Sat, 5 Dec 2026 02:00:45 +1300 Subject: [PATCH 10/10] docs: note that ASP.NET apps keep the machine name with SendDefaultPii = false ASP.NET and ASP.NET Core events included the machine name whatever SendDefaultPii was, so the closest equivalent shouldn't set AttachServerName = false there. The log test for an explicit ServerName now also sets AttachServerName = false, so it checks that ServerName wins. Co-Authored-By: Claude Opus 5.5 --- src/Sentry/SentryOptions.cs | 2 ++ test/Sentry.Tests/SentryLogTests.cs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index 8bea04a4c2..0c84e66b02 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -352,6 +352,8 @@ internal HttpRequestMessage CreateHttpRequest(HttpContent content) /// }); /// options.AttachServerName = false; /// + /// Leave out the last line in ASP.NET and ASP.NET Core apps, whose events include the machine name with + /// SendDefaultPii = false too. /// This still differs from SendDefaultPii = false in four ways. Failed HTTP request events include /// headers: sets one behavior for those and for the headers of /// incoming requests, and SendDefaultPii = false collected only the latter. They also include the URL diff --git a/test/Sentry.Tests/SentryLogTests.cs b/test/Sentry.Tests/SentryLogTests.cs index 26cbf595ab..84e7247425 100644 --- a/test/Sentry.Tests/SentryLogTests.cs +++ b/test/Sentry.Tests/SentryLogTests.cs @@ -156,7 +156,7 @@ public void SetDefaultAttributes_ScopeEnvironment_OverridesDefault() [Fact] public void SetDefaultAttributes_OptionsServerName_SetsServerAddress() { - var options = new SentryOptions { ServerName = "my-server" }; + var options = new SentryOptions { ServerName = "my-server", AttachServerName = false }; var log = new SentryLog(Timestamp, TraceId, SentryLogLevel.Info, "message"); log.SetDefaultAttributes(options, new Scope(options));