Skip to content
4 changes: 3 additions & 1 deletion samples/Sentry.Samples.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ 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
// 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
Expand Down
7 changes: 5 additions & 2 deletions samples/Sentry.Samples.AspNetCore.Grpc/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions samples/Sentry.Samples.AspNetCore.Mvc/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions samples/Sentry.Samples.AspNetCore.Serilog/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions samples/Sentry.Samples.Console.Customized/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ 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();
// 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
Expand Down
6 changes: 4 additions & 2 deletions samples/Sentry.Samples.GenericHost/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion samples/Sentry.Samples.GraphQL.Client.Http/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
#endif

options.CaptureFailedRequests = true;
options.SendDefaultPii = true;
// Attach GraphQL documents and variables to failed request events
options.ConfigureDataCollection(dataCollection =>
{
dataCollection.GraphQL.Document = true;
dataCollection.GraphQL.Variables = true;
});
options.TracesSampleRate = 1.0;
});

Expand Down
4 changes: 3 additions & 1 deletion samples/Sentry.Samples.GraphQL.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public static WebApplication BuildWebApplication(string[] args)

options.TracesSampleRate = 1.0;
options.Debug = true;
options.SendDefaultPii = true;
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
});

Expand Down
7 changes: 5 additions & 2 deletions samples/Sentry.Samples.Hangfire/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion samples/Sentry.Samples.NLog/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ 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(); // 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
{
options.Dsn = dsn;
options.Debug = builder.Environment.IsDevelopment();
options.SendDefaultPii = true;
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
});
Expand Down
7 changes: 5 additions & 2 deletions samples/Sentry.Samples.Quartz/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion samples/Sentry.Samples.Serilog/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.SendDefaultPii = 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();
});
Expand Down
17 changes: 17 additions & 0 deletions sentry-spec-compliance.json
Original file line number Diff line number Diff line change
@@ -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."
}
}
}
}
2 changes: 1 addition & 1 deletion src/Sentry.AspNetCore/SentryAspNetCoreOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// <para>
/// If you call <see cref="SentryOptions.ConfigureDataCollection"/>, request bodies are only collected when
/// If you call <see cref="SentryOptions.ConfigureDataCollection()"/>, request bodies are only collected when
/// <see cref="DataCollectionOptions.HttpBodies"/> includes <see cref="HttpBodyTypes.IncomingRequest"/>.
/// </para>
/// </remarks>
Expand Down
2 changes: 2 additions & 0 deletions src/Sentry.OpenTelemetry/AspNetCoreEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

@jamescrosswell jamescrosswell Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although there is an equivalent of this in the new DataCollection options, the OpenTelemetry package is already obsolete... no point in updating it to avoid obsolete members then. We'll remove both of them in version 8.

#pragma warning restore CS0618
{
hub.ConfigureScope(static (scope, enricher) =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.OpenTelemetry/SentryOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class SentryOptionsExtensions
/// </param>
/// <remarks>
/// The user and span attributes this integration collects don't follow
/// <see cref="SentryOptions.ConfigureDataCollection"/>. It sets the user from ASP.NET Core only when
/// <see cref="SentryOptions.ConfigureDataCollection()"/>. It sets the user from ASP.NET Core only when
/// <see cref="SentryOptions.SendDefaultPii"/> is <c>true</c>, replaces sensitive URL query values on spans using the
/// default deny list, and sends all other span attributes as they are.
/// </remarks>
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.OpenTelemetry/SentrySpanProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Sentry.OpenTelemetry;
/// Sentry span processor for Open Telemetry.
/// </summary>
/// <remarks>
/// The span attributes this processor collects don't follow <see cref="SentryOptions.ConfigureDataCollection"/>. It
/// The span attributes this processor collects don't follow <see cref="SentryOptions.ConfigureDataCollection()"/>. It
/// replaces sensitive URL query values using the default deny list, and sends all other span attributes as they are.
/// </remarks>
public class SentrySpanProcessor : BaseProcessor<Activity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static class TracerProviderBuilderExtensions
/// <returns>The supplied <see cref="TracerProviderBuilder"/> for chaining.</returns>
/// <remarks>
/// The user and span attributes this integration collects don't follow
/// <see cref="SentryOptions.ConfigureDataCollection"/>. It sets the user from ASP.NET Core only when
/// <see cref="SentryOptions.ConfigureDataCollection()"/>. It sets the user from ASP.NET Core only when
/// <see cref="SentryOptions.SendDefaultPii"/> is <c>true</c>, replaces sensitive URL query values on spans using the
/// default deny list, and sends all other span attributes as they are.
/// </remarks>
Expand Down
2 changes: 2 additions & 0 deletions src/Sentry/BindableSentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions src/Sentry/DataCollectionOptions.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
using Sentry.Infrastructure;

namespace Sentry;

/// <summary>
/// Controls which categories of data the SDK's integrations collect automatically.
/// </summary>
/// <remarks>
/// The integrations are still being migrated onto these options, and those that haven't moved yet ignore these
/// categories; see <see cref="SentryOptions.ConfigureDataCollection"/>.
/// <para>
/// 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.
/// </para>
/// <para>
/// This only gates data the SDK gathers by itself. Data you provide explicitly - a <see cref="SentryUser"/> set on
/// the scope, tags, or anything added in <see cref="SentryOptions.SetBeforeSend(System.Func{SentryEvent, SentryHint, SentryEvent})"/>
/// - is always sent. Where an integration exposes its own data-collection option, that option takes precedence
/// over the matching category here.
/// </para>
/// <para>This API is experimental, and it may change in the future.</para>
/// </remarks>
/// <seealso href="https://develop.sentry.dev/sdk/foundations/client/data-collection/"/>
[Experimental(DiagnosticId.ExperimentalFeature)]
public class DataCollectionOptions
{
internal DataCollectionOptions()
Expand Down
3 changes: 0 additions & 3 deletions src/Sentry/HttpBodyTypes.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using Sentry.Infrastructure;

namespace Sentry;

/// <summary>
/// The HTTP bodies that may be attached to telemetry.
/// </summary>
[Flags]
[Experimental(DiagnosticId.ExperimentalFeature)]
public enum HttpBodyTypes
{
/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Sentry/Internal/DataCollectionResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -61,6 +63,12 @@ internal sealed class DataCollectionResolver(SentryOptions options)
public KeyValueCollectionBehavior UrlFragmentWithLegacyPiiGate =>
Configured?.UrlQueryParams ?? (SendDefaultPii ? DenyList : Off);

/// <summary>
/// Temporary bridge for redacting URL credentials in breadcrumbs and span descriptions without
/// <c>SendDefaultPii</c>; remove with it, see https://github.com/getsentry/sentry-dotnet/issues/5439
/// </summary>
public bool RedactUrlCredentialsWithLegacyPiiGate => Configured is null && !SendDefaultPii;

public bool IncomingRequestBody => CollectsBody(HttpBodyTypes.IncomingRequest, legacyFallback: true);

public bool OutgoingRequestBody => CollectsBody(HttpBodyTypes.OutgoingRequest, SendDefaultPii);
Expand Down
2 changes: 2 additions & 0 deletions src/Sentry/Internal/MainSentryEventProcessor.cs

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is covered by:

Will deal with that in a separate PR stacked on this one...

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions src/Sentry/KeyValueCollectionBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using Sentry.Infrastructure;

namespace Sentry;

/// <summary>
/// How a category of key-value data is collected.
/// </summary>
[Experimental(DiagnosticId.ExperimentalFeature)]
public enum KeyValueCollectionMode
{
/// <summary>
Expand Down Expand Up @@ -46,9 +43,7 @@ public enum KeyValueCollectionMode
/// available in code has no configuration equivalent, so a scalar such as
/// <c>Sentry:DataCollection:Cookies=false</c> is ignored.
/// </para>
/// <para>This API is experimental, and it may change in the future.</para>
/// </remarks>
[Experimental(DiagnosticId.ExperimentalFeature)]
public sealed class KeyValueCollectionBehavior
{
private KeyValueCollectionBehavior(KeyValueCollectionMode mode, IReadOnlyList<string>? terms)
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/SentryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void CaptureTransaction(SentryTransaction transaction, Scope? scope, Sent
return;
}

if (!_options.SendDefaultPii)
if (_options.DataCollectionResolver.RedactUrlCredentialsWithLegacyPiiGate)
{
processedTransaction.Redact();
}
Expand Down Expand Up @@ -440,7 +440,7 @@ private SentryId DoSendEvent(SentryEvent @event, SentryHint? hint, Scope? scope)
_options.LogDebug("Event sampled in.");
}

if (!_options.SendDefaultPii)
if (_options.DataCollectionResolver.RedactUrlCredentialsWithLegacyPiiGate)
{
processedEvent.Redact();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Sentry/SentryLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading