diff --git a/CHANGELOG.md b/CHANGELOG.md index 9516008cd1..6931685824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +### Significant change in behavior + +- The User.IpAddress is now set to {{auto}} by default, even when sendDefaultPII is disabled ([#2981](https://github.com/getsentry/sentry-dotnet/pull/2981)) + - The "Prevent Storing of IP Addresses" option in the "Security & Privacy" project settings on sentry.io can be used to control this instead + ### Dependencies - Bump Cocoa SDK from v8.17.1 to v8.17.2 ([#2972](https://github.com/getsentry/sentry-dotnet/pull/2972)) diff --git a/src/Sentry/Internal/Enricher.cs b/src/Sentry/Internal/Enricher.cs index e7acaf0a55..fb5ef24494 100644 --- a/src/Sentry/Internal/Enricher.cs +++ b/src/Sentry/Internal/Enricher.cs @@ -6,6 +6,8 @@ namespace Sentry.Internal; internal class Enricher { + internal const string DefaultIpAddress = "{{auto}}"; + private readonly SentryOptions _options; private readonly Lazy _runtimeLazy = new(() => @@ -74,15 +76,11 @@ public void Apply(IEventLike eventLike) // User // Report local user if opt-in PII, no user was already set to event and feature not opted-out: - if (_options.SendDefaultPii) + if (_options is { SendDefaultPii: true, IsEnvironmentUser: true } && !eventLike.HasUser()) { - if (_options.IsEnvironmentUser && !eventLike.HasUser()) - { - eventLike.User.Username = Environment.UserName; - } - - eventLike.User.IpAddress ??= "{{auto}}"; + eventLike.User.Username = Environment.UserName; } + eventLike.User.IpAddress ??= DefaultIpAddress; //Apply App startup and Boot time eventLike.Contexts.App.StartTime ??= ProcessInfo.Instance?.StartupTime; diff --git a/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet6_0.verified.txt b/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet6_0.verified.txt index b132b2f346..bc945cec2e 100644 --- a/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet6_0.verified.txt +++ b/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet6_0.verified.txt @@ -23,7 +23,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production, Breadcrumbs: [ { diff --git a/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet7_0.verified.txt b/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet7_0.verified.txt index b132b2f346..bc945cec2e 100644 --- a/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet7_0.verified.txt +++ b/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet7_0.verified.txt @@ -23,7 +23,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production, Breadcrumbs: [ { diff --git a/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet8_0.verified.txt b/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet8_0.verified.txt index 2a1ac6c971..467247497d 100644 --- a/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet8_0.verified.txt +++ b/test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet8_0.verified.txt @@ -23,7 +23,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production, Breadcrumbs: [ { diff --git a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet6_0.verified.txt b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet6_0.verified.txt index 1ba9918760..687050119c 100644 --- a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet6_0.verified.txt +++ b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet6_0.verified.txt @@ -21,7 +21,9 @@ WHERE @@ROWCOUNT = 1 AND [Id] = scope_identity(); Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Breadcrumbs: [ { Message: Entity Framework Core initialized 'TestDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:' with options: NoTracking , @@ -66,7 +68,9 @@ WHERE @@ROWCOUNT = 1 AND [Id] = scope_identity();, IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Spans: [ { IsFinished: true, diff --git a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet7_0.verified.txt b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet7_0.verified.txt index 1ba9918760..687050119c 100644 --- a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet7_0.verified.txt +++ b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet7_0.verified.txt @@ -21,7 +21,9 @@ WHERE @@ROWCOUNT = 1 AND [Id] = scope_identity(); Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Breadcrumbs: [ { Message: Entity Framework Core initialized 'TestDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:' with options: NoTracking , @@ -66,7 +68,9 @@ WHERE @@ROWCOUNT = 1 AND [Id] = scope_identity();, IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Spans: [ { IsFinished: true, diff --git a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet8_0.verified.txt b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet8_0.verified.txt index abe305eb4c..b2e69556a7 100644 --- a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet8_0.verified.txt +++ b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet8_0.verified.txt @@ -17,7 +17,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Spans: [ { IsFinished: true, diff --git a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet6_0.verified.txt b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet6_0.verified.txt index 78692f8ffa..fbabc89dff 100644 --- a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet6_0.verified.txt +++ b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet6_0.verified.txt @@ -21,7 +21,9 @@ Operation: } }, - User: {} + User: { + IpAddress: {{auto}} + } } }, { @@ -42,7 +44,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Spans: [ { IsFinished: true, diff --git a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet7_0.verified.txt b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet7_0.verified.txt index 78692f8ffa..fbabc89dff 100644 --- a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet7_0.verified.txt +++ b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet7_0.verified.txt @@ -21,7 +21,9 @@ Operation: } }, - User: {} + User: { + IpAddress: {{auto}} + } } }, { @@ -42,7 +44,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Spans: [ { IsFinished: true, diff --git a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet8_0.verified.txt b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet8_0.verified.txt index 92775423b2..fd290a1521 100644 --- a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet8_0.verified.txt +++ b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet8_0.verified.txt @@ -21,7 +21,9 @@ Operation: } }, - User: {} + User: { + IpAddress: {{auto}} + } } }, { @@ -42,7 +44,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Spans: [ { IsFinished: true, diff --git a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.Net4_8.verified.txt b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.Net4_8.verified.txt index 8b849ac895..40d08c12fc 100644 --- a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.Net4_8.verified.txt +++ b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.Net4_8.verified.txt @@ -21,7 +21,9 @@ Operation: } }, - User: {} + User: { + IpAddress: {{auto}} + } } }, { @@ -42,7 +44,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Spans: [ { IsFinished: true, diff --git a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsSqlAsync.verified.txt b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsSqlAsync.verified.txt index f2bca280f4..c934ddb78c 100644 --- a/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsSqlAsync.verified.txt +++ b/test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsSqlAsync.verified.txt @@ -21,7 +21,9 @@ Operation: } }, - User: {} + User: { + IpAddress: {{auto}} + } } }, { @@ -42,7 +44,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Spans: [ { IsFinished: true, diff --git a/test/Sentry.EntityFramework.Tests/IntegrationTests.Simple.verified.txt b/test/Sentry.EntityFramework.Tests/IntegrationTests.Simple.verified.txt index bf1e0f1d01..8419c2567e 100644 --- a/test/Sentry.EntityFramework.Tests/IntegrationTests.Simple.verified.txt +++ b/test/Sentry.EntityFramework.Tests/IntegrationTests.Simple.verified.txt @@ -21,7 +21,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } }, @@ -43,7 +45,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production, Spans: [ { diff --git a/test/Sentry.Log4Net.Tests/IntegrationTests.LoggingInsideTheContextOfLogging.verified.txt b/test/Sentry.Log4Net.Tests/IntegrationTests.LoggingInsideTheContextOfLogging.verified.txt index 4bfe6a72fe..2bfe72b842 100644 --- a/test/Sentry.Log4Net.Tests/IntegrationTests.LoggingInsideTheContextOfLogging.verified.txt +++ b/test/Sentry.Log4Net.Tests/IntegrationTests.LoggingInsideTheContextOfLogging.verified.txt @@ -32,7 +32,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } @@ -71,7 +73,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } diff --git a/test/Sentry.Log4Net.Tests/IntegrationTests.Simple.verified.txt b/test/Sentry.Log4Net.Tests/IntegrationTests.Simple.verified.txt index 3efadb9332..66f2ebe554 100644 --- a/test/Sentry.Log4Net.Tests/IntegrationTests.Simple.verified.txt +++ b/test/Sentry.Log4Net.Tests/IntegrationTests.Simple.verified.txt @@ -31,7 +31,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } diff --git a/test/Sentry.NLog.Tests/IntegrationTests.LoggingInsideTheContextOfLogging.verified.txt b/test/Sentry.NLog.Tests/IntegrationTests.LoggingInsideTheContextOfLogging.verified.txt index 271399a591..63f250be33 100644 --- a/test/Sentry.NLog.Tests/IntegrationTests.LoggingInsideTheContextOfLogging.verified.txt +++ b/test/Sentry.NLog.Tests/IntegrationTests.LoggingInsideTheContextOfLogging.verified.txt @@ -39,7 +39,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } diff --git a/test/Sentry.Serilog.Tests/IntegrationTests.LoggingInsideTheContextOfLogging.verified.txt b/test/Sentry.Serilog.Tests/IntegrationTests.LoggingInsideTheContextOfLogging.verified.txt index 1a4cd367c2..9c8d8630e4 100644 --- a/test/Sentry.Serilog.Tests/IntegrationTests.LoggingInsideTheContextOfLogging.verified.txt +++ b/test/Sentry.Serilog.Tests/IntegrationTests.LoggingInsideTheContextOfLogging.verified.txt @@ -38,7 +38,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } diff --git a/test/Sentry.Tests/EventProcessorTests.Simple.verified.txt b/test/Sentry.Tests/EventProcessorTests.Simple.verified.txt index 2109bcb4f8..585972e92c 100644 --- a/test/Sentry.Tests/EventProcessorTests.Simple.verified.txt +++ b/test/Sentry.Tests/EventProcessorTests.Simple.verified.txt @@ -31,7 +31,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } diff --git a/test/Sentry.Tests/EventProcessorTests.WithTransaction.verified.txt b/test/Sentry.Tests/EventProcessorTests.WithTransaction.verified.txt index 5a7390c2d0..e50c7d8fc4 100644 --- a/test/Sentry.Tests/EventProcessorTests.WithTransaction.verified.txt +++ b/test/Sentry.Tests/EventProcessorTests.WithTransaction.verified.txt @@ -35,7 +35,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } diff --git a/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.DotNet6_0.verified.txt b/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.DotNet6_0.verified.txt index b2a88282d9..af8d3b06a1 100644 --- a/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.DotNet6_0.verified.txt +++ b/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.DotNet6_0.verified.txt @@ -111,7 +111,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } @@ -173,7 +175,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production, IsFinished: true } diff --git a/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.DotNet7_0.verified.txt b/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.DotNet7_0.verified.txt index 7e4c8954b0..65989515a3 100644 --- a/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.DotNet7_0.verified.txt +++ b/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.DotNet7_0.verified.txt @@ -111,7 +111,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } @@ -173,7 +175,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production, IsFinished: true } diff --git a/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.DotNet8_0.verified.txt b/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.DotNet8_0.verified.txt index 7e4c8954b0..65989515a3 100644 --- a/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.DotNet8_0.verified.txt +++ b/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.DotNet8_0.verified.txt @@ -111,7 +111,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } @@ -173,7 +175,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production, IsFinished: true } diff --git a/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.Mono4_0.verified.txt b/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.Mono4_0.verified.txt index b4ed75b70a..aa7e5001d9 100644 --- a/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.Mono4_0.verified.txt +++ b/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.Mono4_0.verified.txt @@ -111,7 +111,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } @@ -173,7 +175,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production, IsFinished: true } diff --git a/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.Net4_8.verified.txt b/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.Net4_8.verified.txt index 04524791db..603d5b4ae1 100644 --- a/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.Net4_8.verified.txt +++ b/test/Sentry.Tests/HubTests.CaptureEvent_ActiveTransaction_UnhandledExceptionTransactionEndedAsCrashed.Net4_8.verified.txt @@ -111,7 +111,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } @@ -173,7 +175,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production, IsFinished: true } diff --git a/test/Sentry.Tests/Internals/MainSentryEventProcessorTests.cs b/test/Sentry.Tests/Internals/MainSentryEventProcessorTests.cs index 201c041e19..6d9b9d3212 100644 --- a/test/Sentry.Tests/Internals/MainSentryEventProcessorTests.cs +++ b/test/Sentry.Tests/Internals/MainSentryEventProcessorTests.cs @@ -109,7 +109,7 @@ public void Process_SendDefaultPiiTrueAndUserIpNull_UserIpSetServerInferredIp() _ = sut.Process(evt); //Assert - Assert.Equal("{{auto}}", evt.User.IpAddress); + evt.User.IpAddress.Should().Be(Enricher.DefaultIpAddress); } [Fact] @@ -132,7 +132,7 @@ public void Process_SendDefaultPiiTrueAndUserIpSet_UserIpIgnoreServerInferredIp( } [Fact] - public void Process_SendDefaultPiiFalse_UserIpNotSet() + public void Process_SendDefaultPiiFalse_UserIpAuto() { //Arrange var evt = new SentryEvent(); @@ -143,7 +143,7 @@ public void Process_SendDefaultPiiFalse_UserIpNotSet() _ = sut.Process(evt); //Assert - Assert.Null(evt.User.IpAddress); + evt.User.IpAddress.Should().Be(Enricher.DefaultIpAddress); } [Fact] diff --git a/test/Sentry.Tests/TransactionProcessorTests.Discard.verified.txt b/test/Sentry.Tests/TransactionProcessorTests.Discard.verified.txt index 1392e2d68c..8aee2df897 100644 --- a/test/Sentry.Tests/TransactionProcessorTests.Discard.verified.txt +++ b/test/Sentry.Tests/TransactionProcessorTests.Discard.verified.txt @@ -34,7 +34,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } diff --git a/test/Sentry.Tests/TransactionProcessorTests.Simple.verified.txt b/test/Sentry.Tests/TransactionProcessorTests.Simple.verified.txt index 894eb09320..7168a00a25 100644 --- a/test/Sentry.Tests/TransactionProcessorTests.Simple.verified.txt +++ b/test/Sentry.Tests/TransactionProcessorTests.Simple.verified.txt @@ -34,7 +34,9 @@ Operation: } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production } } @@ -81,7 +83,9 @@ IsSampled: true } }, - User: {}, + User: { + IpAddress: {{auto}} + }, Environment: production, IsFinished: true }