diff --git a/CHANGELOG.md b/CHANGELOG.md index 993efc93f9..05bbf107b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- Load contexts integration not setting `SentryUser` ([#2089](https://github.com/getsentry/sentry-dart/pull/2089)) - Change app start span description from `Cold start` to `Cold Start` and `Warm start` to `Warm Start` ([#2076](https://github.com/getsentry/sentry-dart/pull/2076)) - Parse `PlatformException` from details instead of message ([#2052](https://github.com/getsentry/sentry-dart/pull/2052)) diff --git a/dart/lib/src/sentry_client.dart b/dart/lib/src/sentry_client.dart index a1f20ded61..63fcbfb421 100644 --- a/dart/lib/src/sentry_client.dart +++ b/dart/lib/src/sentry_client.dart @@ -119,6 +119,8 @@ class SentryClient { return _sentryId; } + preparedEvent = _createUserOrSetDefaultIpAddress(preparedEvent); + preparedEvent = await _runBeforeSend( preparedEvent, hint, @@ -176,8 +178,6 @@ class SentryClient { platform: event.platform ?? sdkPlatform(_options.platformChecker.isWeb), ); - event = _createUserOrSetDefaultIpAddress(event); - if (event is SentryTransaction) { return event; } diff --git a/dart/test/sentry_client_test.dart b/dart/test/sentry_client_test.dart index b10ae154f7..b8c6bee716 100644 --- a/dart/test/sentry_client_test.dart +++ b/dart/test/sentry_client_test.dart @@ -1684,6 +1684,7 @@ class Fixture { class ExceptionWithCause { ExceptionWithCause(this.cause, this.stackTrace); + final dynamic cause; final dynamic stackTrace; } @@ -1698,6 +1699,7 @@ class ExceptionWithCauseExtractor class ExceptionWithStackTrace { ExceptionWithStackTrace(this.stackTrace); + final StackTrace stackTrace; } diff --git a/flutter/test/integrations/load_contexts_integration_test.dart b/flutter/test/integrations/load_contexts_integration_test.dart index 926d8e09b1..a3bbbcbab7 100644 --- a/flutter/test/integrations/load_contexts_integration_test.dart +++ b/flutter/test/integrations/load_contexts_integration_test.dart @@ -128,6 +128,45 @@ void main() { expect(event.breadcrumbs!.length, 1); expect(event.breadcrumbs!.first.message, 'native-mutated-applied'); }); + + test('apply default IP to user during captureEvent after loading context', + () async { + fixture.options.enableScopeSync = true; + + const expectedIp = '{{auto}}'; + String? actualIp; + + const expectedId = '1'; + String? actualId; + + fixture.options.beforeSend = (event, hint) { + actualIp = event.user?.ipAddress; + actualId = event.user?.id; + return event; + }; + + final options = fixture.options; + + final user = SentryUser(id: expectedId); + Map loadContexts = {'user': user.toJson()}; + final future = Future.value(loadContexts); + when(fixture.methodChannel.invokeMethod('loadContexts')) + .thenAnswer((_) => future); + // ignore: deprecated_member_use + _channel.setMockMethodCallHandler((MethodCall methodCall) async {}); + + final integration = LoadContextsIntegration(fixture.methodChannel); + options.addIntegration(integration); + options.integrations.first.call(fixture.hub, options); + + final client = SentryClient(options); + final event = SentryEvent(); + + await client.captureEvent(event); + + expect(expectedIp, actualIp); + expect(expectedId, actualId); + }); }); }