Skip to content

Commit 4cec133

Browse files
authored
fix(dart): Dont guard user behind sendDefaultPii (#3524)
* Dont guard user attributes with sendDEfaultPii * Update sample * Update CHANGELOG * Update comments
1 parent 3135a81 commit 4cec133

File tree

6 files changed

+37
-53
lines changed

6 files changed

+37
-53
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+
### Fixes
6+
7+
- Dont guard user attributes behind `sendDefaultPii` for logs and metrics ([#3524](https://github.com/getsentry/sentry-dart/pull/3524))
8+
59
### Dependencies
610

711
- Bump Native SDK from v0.12.6 to v0.12.8 ([#3514](https://github.com/getsentry/sentry-dart/pull/3514), [#3520](https://github.com/getsentry/sentry-dart/pull/3520))

packages/dart/lib/src/constants.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,19 @@ abstract class SemanticAttributesConstants {
8989
static const sentryInternalReplayIsBuffering =
9090
'sentry._internal.replay_is_buffering';
9191

92-
/// The user ID (gated by `sendDefaultPii`).
92+
/// The user ID.
93+
/// Users are always manually set and never automatically inferred,
94+
/// therefore this is not gated by `sendDefaultPii`.
9395
static const userId = 'user.id';
9496

95-
/// The user email (gated by `sendDefaultPii`).
97+
/// The user email.
98+
/// Users are always manually set and never automatically inferred,
99+
/// therefore this is not gated by `sendDefaultPii`.
96100
static const userEmail = 'user.email';
97101

98-
/// The user IP address (gated by `sendDefaultPii`).
99-
static const userIpAddress = 'user.ip_address';
100-
101-
/// The user username (gated by `sendDefaultPii`).
102+
/// The user username.
103+
/// Users are always manually set and never automatically inferred,
104+
/// therefore this is not gated by `sendDefaultPii`.
102105
static const userName = 'user.name';
103106

104107
/// The operating system name.

packages/dart/lib/src/telemetry/default_attributes.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ Map<String, SentryAttribute> defaultAttributes(SentryOptions options,
2323
SentryAttribute.string(options.release!);
2424
}
2525

26-
if (options.sendDefaultPii) {
27-
final user = scope?.user;
28-
if (user != null) {
29-
if (user.id != null) {
30-
attributes[SemanticAttributesConstants.userId] =
31-
SentryAttribute.string(user.id!);
32-
}
33-
if (user.name != null) {
34-
attributes[SemanticAttributesConstants.userName] =
35-
SentryAttribute.string(user.name!);
36-
}
37-
if (user.email != null) {
38-
attributes[SemanticAttributesConstants.userEmail] =
39-
SentryAttribute.string(user.email!);
40-
}
26+
// Users are always manually set and never automatically inferred,
27+
// therefore this is not gated by `sendDefaultPii`.
28+
final user = scope?.user;
29+
if (user != null) {
30+
if (user.id != null) {
31+
attributes[SemanticAttributesConstants.userId] =
32+
SentryAttribute.string(user.id!);
33+
}
34+
if (user.name != null) {
35+
attributes[SemanticAttributesConstants.userName] =
36+
SentryAttribute.string(user.name!);
37+
}
38+
if (user.email != null) {
39+
attributes[SemanticAttributesConstants.userEmail] =
40+
SentryAttribute.string(user.email!);
4141
}
4242
}
4343

packages/dart/test/telemetry/log/log_capture_pipeline_test.dart

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,6 @@ void main() {
129129
expect(attributes[SemanticAttributesConstants.sentryEnvironment]?.value,
130130
'callback-env');
131131
});
132-
133-
test('does not add user attributes when sendDefaultPii is false',
134-
() async {
135-
fixture.options.sendDefaultPii = false;
136-
await fixture.scope.setUser(SentryUser(id: 'user-id'));
137-
138-
final log = givenLog();
139-
140-
await fixture.pipeline.captureLog(log, scope: fixture.scope);
141-
142-
expect(
143-
log.attributes.containsKey(SemanticAttributesConstants.userId),
144-
isFalse,
145-
);
146-
});
147132
});
148133

149134
group('when logs are disabled', () {
@@ -239,7 +224,6 @@ class Fixture {
239224
final options = defaultTestOptions()
240225
..environment = 'test-env'
241226
..release = 'test-release'
242-
..sendDefaultPii = true
243227
..enableLogs = true;
244228

245229
final processor = MockTelemetryProcessor();

packages/dart/test/telemetry/metric/metric_capture_pipeline_test.dart

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,6 @@ void main() {
118118
expect(attributes[SemanticAttributesConstants.sentryEnvironment]?.value,
119119
'callback-env');
120120
});
121-
122-
test('does not add user attributes when sendDefaultPii is false',
123-
() async {
124-
fixture.options.sendDefaultPii = false;
125-
await fixture.scope.setUser(SentryUser(id: 'user-id'));
126-
127-
final metric = fixture.createMetric();
128-
129-
await fixture.pipeline.captureMetric(metric, scope: fixture.scope);
130-
131-
expect(
132-
metric.attributes.containsKey(SemanticAttributesConstants.userId),
133-
isFalse,
134-
);
135-
});
136121
});
137122

138123
group('when metrics are disabled', () {
@@ -196,7 +181,6 @@ class Fixture {
196181
final options = defaultTestOptions()
197182
..environment = 'test-env'
198183
..release = 'test-release'
199-
..sendDefaultPii = true
200184
..enableMetrics = true;
201185

202186
final processor = MockTelemetryProcessor();

packages/flutter/example/lib/main.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ Future<void> setupSentry(
114114
// Init your App.
115115
appRunner: appRunner,
116116
);
117+
118+
Sentry.configureScope((scope) {
119+
final user = SentryUser(
120+
id: SentryId.newId().toString(),
121+
name: 'J. Smith',
122+
email: 'j.smith@example.com',
123+
);
124+
scope.setUser(user);
125+
});
117126
}
118127

119128
class MyApp extends StatefulWidget {

0 commit comments

Comments
 (0)