Skip to content

Commit b31e4db

Browse files
fix: Guard user.IpAddress = "{{ auto }}" by SendDefaultPii (#3893)
Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com>
1 parent aa2caa1 commit b31e4db

File tree

23 files changed

+43
-65
lines changed

23 files changed

+43
-65
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Significant change in behavior
6+
7+
- The User.IpAddress is now only set to `{{auto}}` when `SendDefaultPii` is enabled. This change gives you control over IP address collection directly on the client ([#3893](https://github.com/getsentry/sentry-dotnet/pull/3893))
8+
59
### Features
610

711
- .NET on iOS: Add experimental EnableAppHangTrackingV2 configuration flag to the options binding SDK ([#3877](https://github.com/getsentry/sentry-dotnet/pull/3877))

src/Sentry/Internal/Enricher.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,16 @@ public void Apply(IEventLike eventLike)
7676

7777
// User
7878
// Report local user if opt-in PII, no user was already set to event and feature not opted-out:
79-
if (_options is { SendDefaultPii: true, IsEnvironmentUser: true } && !eventLike.HasUser())
79+
if (_options.SendDefaultPii)
8080
{
81-
eventLike.User.Username = Environment.UserName;
81+
if (_options.IsEnvironmentUser && !eventLike.HasUser())
82+
{
83+
eventLike.User.Username = Environment.UserName;
84+
}
85+
86+
eventLike.User.IpAddress ??= DefaultIpAddress;
8287
}
8388
eventLike.User.Id ??= _options.InstallationId;
84-
eventLike.User.IpAddress ??= DefaultIpAddress;
8589

8690
//Apply App startup and Boot time
8791
eventLike.Contexts.App.StartTime ??= ProcessInfo.Instance?.StartupTime;

test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet8_0.verified.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
}
2727
},
2828
User: {
29-
Id: Guid_1,
30-
IpAddress: {{auto}}
29+
Id: Guid_1
3130
},
3231
Environment: production,
3332
Breadcrumbs: [

test/Sentry.AspNetCore.Tests/WebIntegrationTests.Versioning.DotNet9_0.verified.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
}
2727
},
2828
User: {
29-
Id: Guid_1,
30-
IpAddress: {{auto}}
29+
Id: Guid_1
3130
},
3231
Environment: production,
3332
Breadcrumbs: [

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet8_0.verified.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
}
1919
},
2020
User: {
21-
Id: Guid_1,
22-
IpAddress: {{auto}}
21+
Id: Guid_1
2322
},
2423
Spans: [
2524
{

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.LoggingAsync.DotNet9_0.verified.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
}
1919
},
2020
User: {
21-
Id: Guid_1,
22-
IpAddress: {{auto}}
21+
Id: Guid_1
2322
},
2423
Spans: [
2524
{

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet8_0.verified.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
}
2323
},
2424
User: {
25-
Id: Guid_1,
26-
IpAddress: {{auto}}
25+
Id: Guid_1
2726
}
2827
}
2928
},
@@ -46,8 +45,7 @@
4645
}
4746
},
4847
User: {
49-
Id: Guid_1,
50-
IpAddress: {{auto}}
48+
Id: Guid_1
5149
},
5250
Breadcrumbs: [
5351
{

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet9_0.verified.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
}
2323
},
2424
User: {
25-
Id: Guid_1,
26-
IpAddress: {{auto}}
25+
Id: Guid_1
2726
}
2827
}
2928
},
@@ -46,8 +45,7 @@
4645
}
4746
},
4847
User: {
49-
Id: Guid_1,
50-
IpAddress: {{auto}}
48+
Id: Guid_1
5149
},
5250
Breadcrumbs: [
5351
{

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.Net4_8.verified.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
}
2323
},
2424
User: {
25-
Id: Guid_1,
26-
IpAddress: {{auto}}
25+
Id: Guid_1
2726
}
2827
}
2928
},
@@ -46,8 +45,7 @@
4645
}
4746
},
4847
User: {
49-
Id: Guid_1,
50-
IpAddress: {{auto}}
48+
Id: Guid_1
5149
},
5250
Breadcrumbs: [
5351
{

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsSqlAsync.verified.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
}
2323
},
2424
User: {
25-
Id: Guid_1,
26-
IpAddress: {{auto}}
25+
Id: Guid_1
2726
}
2827
}
2928
},
@@ -46,8 +45,7 @@
4645
}
4746
},
4847
User: {
49-
Id: Guid_1,
50-
IpAddress: {{auto}}
48+
Id: Guid_1
5149
},
5250
Breadcrumbs: [
5351
{

0 commit comments

Comments
 (0)