Skip to content

Rewrite the last_ping key again #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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 pkgs/unified_analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkgs/unified_analytics/lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion pkgs/unified_analytics/lib/src/initializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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}}');
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a comment here that its deprecated?

}

/// This will check that there is a client ID populated in
Expand Down
2 changes: 1 addition & 1 deletion pkgs/unified_analytics/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 12 additions & 2 deletions pkgs/unified_analytics/test/unified_analytics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down