diff --git a/pkgs/unified_analytics/CHANGELOG.md b/pkgs/unified_analytics/CHANGELOG.md index cb7ff9301c..6827643e3d 100644 --- a/pkgs/unified_analytics/CHANGELOG.md +++ b/pkgs/unified_analytics/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.8.7 + +- [Bug fix](https://github.com/dart-lang/tools/issues/252) to rewrite the `last_ping` key into the session json file + ## 5.8.6 - Refactored session handler class to use the last modified timestamp as the last ping value diff --git a/pkgs/unified_analytics/lib/src/constants.dart b/pkgs/unified_analytics/lib/src/constants.dart index 2ab6bfe2e8..9b0c72bfe8 100644 --- a/pkgs/unified_analytics/lib/src/constants.dart +++ b/pkgs/unified_analytics/lib/src/constants.dart @@ -82,7 +82,7 @@ const int kLogFileLength = 2500; const String kLogFileName = 'dart-flutter-telemetry.log'; /// The current version of the package, should be in line with pubspec version. -const String kPackageVersion = '5.8.6'; +const String kPackageVersion = '5.8.7'; /// The minimum length for a session. const int kSessionDurationMinutes = 30; diff --git a/pkgs/unified_analytics/lib/src/initializer.dart b/pkgs/unified_analytics/lib/src/initializer.dart index 4f84ef1d5b..a9d78cfc62 100644 --- a/pkgs/unified_analytics/lib/src/initializer.dart +++ b/pkgs/unified_analytics/lib/src/initializer.dart @@ -84,8 +84,12 @@ class Initializer { }) { final now = sessionIdOverride ?? clock.now(); sessionFile.createSync(recursive: true); + + // `last_ping` has been deprecated, remains included for backward + // compatibility sessionFile - .writeAsStringSync('{"session_id": ${now.millisecondsSinceEpoch}}'); + .writeAsStringSync('{"session_id": ${now.millisecondsSinceEpoch}, ' + '"last_ping": ${now.millisecondsSinceEpoch}}'); } /// This will check that there is a client ID populated in diff --git a/pkgs/unified_analytics/pubspec.yaml b/pkgs/unified_analytics/pubspec.yaml index b929cd1837..fa53caafb4 100644 --- a/pkgs/unified_analytics/pubspec.yaml +++ b/pkgs/unified_analytics/pubspec.yaml @@ -4,7 +4,7 @@ description: >- to Google Analytics. # When updating this, keep the version consistent with the changelog and the # value in lib/src/constants.dart. -version: 5.8.6 +version: 5.8.7 repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics environment: diff --git a/pkgs/unified_analytics/test/unified_analytics_test.dart b/pkgs/unified_analytics/test/unified_analytics_test.dart index 8c0849338e..cf6711c874 100644 --- a/pkgs/unified_analytics/test/unified_analytics_test.dart +++ b/pkgs/unified_analytics/test/unified_analytics_test.dart @@ -143,7 +143,8 @@ void main() { final timestamp = clock.now().millisecondsSinceEpoch.toString(); expect(sessionFile.readAsStringSync(), 'contents'); analytics.userProperty.preparePayload(); - expect(sessionFile.readAsStringSync(), '{"session_id": $timestamp}'); + expect(sessionFile.readAsStringSync(), + '{"session_id": $timestamp, "last_ping": $timestamp}'); // Attempting to fetch the session id when malformed should also // send an error event while parsing @@ -199,7 +200,8 @@ void main() { final timestamp = clock.now().millisecondsSinceEpoch.toString(); expect(sessionFile.existsSync(), false); analytics.userProperty.preparePayload(); - expect(sessionFile.readAsStringSync(), '{"session_id": $timestamp}'); + expect(sessionFile.readAsStringSync(), + '{"session_id": $timestamp, "last_ping": $timestamp}'); // Attempting to fetch the session id when malformed should also // send an error event while parsing @@ -1031,6 +1033,14 @@ ${initialTool.label}=$dateStamp,$toolsMessageVersion test('Null values for flutter parameters is reflected properly in log file', () { + // Because we are using the `MemoryFileSystem.test` constructor, + // we don't have a real clock in the filesystem, and because we + // are checking the last modified timestamp for the session file + // to determine if we need to update the session id, manually setting + // that timestamp will ensure we are not updating session id when it + // first gets created + sessionFile.setLastModifiedSync(DateTime.now()); + // Use a for loop two initialize the second analytics instance // twice to account for no events being sent on the first instance // run for a given tool