diff --git a/CHANGELOG.md b/CHANGELOG.md index b7e379496f..1c93fb145e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/packages/dart/lib/src/constants.dart b/packages/dart/lib/src/constants.dart index 94759424df..cfc2f92e2c 100644 --- a/packages/dart/lib/src/constants.dart +++ b/packages/dart/lib/src/constants.dart @@ -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'; - - /// 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. diff --git a/packages/dart/lib/src/telemetry/default_attributes.dart b/packages/dart/lib/src/telemetry/default_attributes.dart index 93facb066a..d71ca991bb 100644 --- a/packages/dart/lib/src/telemetry/default_attributes.dart +++ b/packages/dart/lib/src/telemetry/default_attributes.dart @@ -23,21 +23,21 @@ Map 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!); } } diff --git a/packages/dart/test/telemetry/log/log_capture_pipeline_test.dart b/packages/dart/test/telemetry/log/log_capture_pipeline_test.dart index 5c6179f99e..ffbe119712 100644 --- a/packages/dart/test/telemetry/log/log_capture_pipeline_test.dart +++ b/packages/dart/test/telemetry/log/log_capture_pipeline_test.dart @@ -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', () { @@ -239,7 +224,6 @@ class Fixture { final options = defaultTestOptions() ..environment = 'test-env' ..release = 'test-release' - ..sendDefaultPii = true ..enableLogs = true; final processor = MockTelemetryProcessor(); diff --git a/packages/dart/test/telemetry/metric/metric_capture_pipeline_test.dart b/packages/dart/test/telemetry/metric/metric_capture_pipeline_test.dart index e60f63d0e6..4d235796a3 100644 --- a/packages/dart/test/telemetry/metric/metric_capture_pipeline_test.dart +++ b/packages/dart/test/telemetry/metric/metric_capture_pipeline_test.dart @@ -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', () { @@ -196,7 +181,6 @@ class Fixture { final options = defaultTestOptions() ..environment = 'test-env' ..release = 'test-release' - ..sendDefaultPii = true ..enableMetrics = true; final processor = MockTelemetryProcessor(); diff --git a/packages/flutter/example/lib/main.dart b/packages/flutter/example/lib/main.dart index 7f65a7f9c2..cb0c89ad91 100644 --- a/packages/flutter/example/lib/main.dart +++ b/packages/flutter/example/lib/main.dart @@ -114,6 +114,15 @@ Future 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 {