Skip to content

Commit 0a9f87c

Browse files
authored
Rewrite the last_ping key again (#255)
* Rewrite the `last_ping` key again * Apply test fix from #247 * Use timestamp instead of null * Format fix * Update version * Code review comments * Lingering comment
1 parent af09f6d commit 0a9f87c

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

pkgs/unified_analytics/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 5.8.7
2+
3+
- [Bug fix](https://github.com/dart-lang/tools/issues/252) to rewrite the `last_ping` key into the session json file
4+
15
## 5.8.6
26

37
- Refactored session handler class to use the last modified timestamp as the last ping value

pkgs/unified_analytics/lib/src/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const int kLogFileLength = 2500;
8282
const String kLogFileName = 'dart-flutter-telemetry.log';
8383

8484
/// The current version of the package, should be in line with pubspec version.
85-
const String kPackageVersion = '5.8.6';
85+
const String kPackageVersion = '5.8.7';
8686

8787
/// The minimum length for a session.
8888
const int kSessionDurationMinutes = 30;

pkgs/unified_analytics/lib/src/initializer.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ class Initializer {
8484
}) {
8585
final now = sessionIdOverride ?? clock.now();
8686
sessionFile.createSync(recursive: true);
87+
88+
// `last_ping` has been deprecated, remains included for backward
89+
// compatibility
8790
sessionFile
88-
.writeAsStringSync('{"session_id": ${now.millisecondsSinceEpoch}}');
91+
.writeAsStringSync('{"session_id": ${now.millisecondsSinceEpoch}, '
92+
'"last_ping": ${now.millisecondsSinceEpoch}}');
8993
}
9094

9195
/// This will check that there is a client ID populated in

pkgs/unified_analytics/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: >-
44
to Google Analytics.
55
# When updating this, keep the version consistent with the changelog and the
66
# value in lib/src/constants.dart.
7-
version: 5.8.6
7+
version: 5.8.7
88
repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics
99

1010
environment:

pkgs/unified_analytics/test/unified_analytics_test.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ void main() {
143143
final timestamp = clock.now().millisecondsSinceEpoch.toString();
144144
expect(sessionFile.readAsStringSync(), 'contents');
145145
analytics.userProperty.preparePayload();
146-
expect(sessionFile.readAsStringSync(), '{"session_id": $timestamp}');
146+
expect(sessionFile.readAsStringSync(),
147+
'{"session_id": $timestamp, "last_ping": $timestamp}');
147148

148149
// Attempting to fetch the session id when malformed should also
149150
// send an error event while parsing
@@ -199,7 +200,8 @@ void main() {
199200
final timestamp = clock.now().millisecondsSinceEpoch.toString();
200201
expect(sessionFile.existsSync(), false);
201202
analytics.userProperty.preparePayload();
202-
expect(sessionFile.readAsStringSync(), '{"session_id": $timestamp}');
203+
expect(sessionFile.readAsStringSync(),
204+
'{"session_id": $timestamp, "last_ping": $timestamp}');
203205

204206
// Attempting to fetch the session id when malformed should also
205207
// send an error event while parsing
@@ -1031,6 +1033,14 @@ ${initialTool.label}=$dateStamp,$toolsMessageVersion
10311033

10321034
test('Null values for flutter parameters is reflected properly in log file',
10331035
() {
1036+
// Because we are using the `MemoryFileSystem.test` constructor,
1037+
// we don't have a real clock in the filesystem, and because we
1038+
// are checking the last modified timestamp for the session file
1039+
// to determine if we need to update the session id, manually setting
1040+
// that timestamp will ensure we are not updating session id when it
1041+
// first gets created
1042+
sessionFile.setLastModifiedSync(DateTime.now());
1043+
10341044
// Use a for loop two initialize the second analytics instance
10351045
// twice to account for no events being sent on the first instance
10361046
// run for a given tool

0 commit comments

Comments
 (0)