Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- Dont guard user attributes behind `sendDefaultPii` for logs and metrics ([#3524](https://github.com/getsentry/sentry-dart/pull/3524))

### Dependencies

- Bump Native SDK from v0.12.6 to v0.12.7 ([#3514](https://github.com/getsentry/sentry-dart/pull/3514))
Expand Down
15 changes: 9 additions & 6 deletions packages/dart/lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,19 @@ abstract class SemanticAttributesConstants {
static const sentryInternalReplayIsBuffering =
'sentry._internal.replay_is_buffering';

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

/// The user email (gated by `sendDefaultPii`).
/// The user email.
/// Users are always manually set and never automatically inferred,
/// therefore this is not gated by `sendDefaultPii`.
static const userEmail = 'user.email';

/// The user IP address (gated by `sendDefaultPii`).
static const userIpAddress = 'user.ip_address';
Comment on lines -98 to -99
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we dont use this currently so we can remove it


/// The user username (gated by `sendDefaultPii`).
/// The user username.
/// Users are always manually set and never automatically inferred,
/// therefore this is not gated by `sendDefaultPii`.
static const userName = 'user.name';

/// The operating system name.
Expand Down
30 changes: 15 additions & 15 deletions packages/dart/lib/src/telemetry/default_attributes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ Map<String, SentryAttribute> defaultAttributes(SentryOptions options,
SentryAttribute.string(options.release!);
}

if (options.sendDefaultPii) {
final user = scope?.user;
if (user != null) {
if (user.id != null) {
attributes[SemanticAttributesConstants.userId] =
SentryAttribute.string(user.id!);
}
if (user.name != null) {
attributes[SemanticAttributesConstants.userName] =
SentryAttribute.string(user.name!);
}
if (user.email != null) {
attributes[SemanticAttributesConstants.userEmail] =
SentryAttribute.string(user.email!);
}
// Users are always manually set and never automatically inferred,
// therefore this is not gated by `sendDefaultPii`.
final user = scope?.user;
if (user != null) {
if (user.id != null) {
attributes[SemanticAttributesConstants.userId] =
SentryAttribute.string(user.id!);
}
if (user.name != null) {
attributes[SemanticAttributesConstants.userName] =
SentryAttribute.string(user.name!);
}
if (user.email != null) {
attributes[SemanticAttributesConstants.userEmail] =
SentryAttribute.string(user.email!);
}
}

Expand Down
16 changes: 0 additions & 16 deletions packages/dart/test/telemetry/log/log_capture_pipeline_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,6 @@ void main() {
expect(attributes[SemanticAttributesConstants.sentryEnvironment]?.value,
'callback-env');
});

test('does not add user attributes when sendDefaultPii is false',
() async {
fixture.options.sendDefaultPii = false;
await fixture.scope.setUser(SentryUser(id: 'user-id'));

final log = givenLog();

await fixture.pipeline.captureLog(log, scope: fixture.scope);

expect(
log.attributes.containsKey(SemanticAttributesConstants.userId),
isFalse,
);
});
});

group('when logs are disabled', () {
Expand Down Expand Up @@ -239,7 +224,6 @@ class Fixture {
final options = defaultTestOptions()
..environment = 'test-env'
..release = 'test-release'
..sendDefaultPii = true
..enableLogs = true;

final processor = MockTelemetryProcessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,6 @@ void main() {
expect(attributes[SemanticAttributesConstants.sentryEnvironment]?.value,
'callback-env');
});

test('does not add user attributes when sendDefaultPii is false',
() async {
fixture.options.sendDefaultPii = false;
await fixture.scope.setUser(SentryUser(id: 'user-id'));

final metric = fixture.createMetric();

await fixture.pipeline.captureMetric(metric, scope: fixture.scope);

expect(
metric.attributes.containsKey(SemanticAttributesConstants.userId),
isFalse,
);
});
});

group('when metrics are disabled', () {
Expand Down Expand Up @@ -196,7 +181,6 @@ class Fixture {
final options = defaultTestOptions()
..environment = 'test-env'
..release = 'test-release'
..sendDefaultPii = true
..enableMetrics = true;

final processor = MockTelemetryProcessor();
Expand Down
9 changes: 9 additions & 0 deletions packages/flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ Future<void> setupSentry(
// Init your App.
appRunner: appRunner,
);

Sentry.configureScope((scope) {
final user = SentryUser(
id: SentryId.newId().toString(),
name: 'J. Smith',
email: 'j.smith@example.com',
);
scope.setUser(user);
});
}

class MyApp extends StatefulWidget {
Expand Down
Loading