Skip to content

Commit 6195a2d

Browse files
authored
Hotfix analytics 5.8.8+1 (#265)
* Hotfix 5.8.8+1 (#264) * Use new private `_sendError` for error handler * Prep publishing * Update README to include diff * Update diff link * Use current timestamp for session id * Fix typo * Remove session id from user properties * Fix test + skip tests that check logfile writes * Fix tests + update README with release notes for tests
1 parent f611290 commit 6195a2d

File tree

7 files changed

+88
-16
lines changed

7 files changed

+88
-16
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.8+1
2+
3+
- Edit to error handler to not use default `Analytic.send` method and use new `Analytics._sendError` method that doesn't create a session id
4+
15
## 5.8.8
26

37
- [Bug fix](https://github.com/dart-lang/tools/issues/252) rewrite the other call site for the session file

pkgs/unified_analytics/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
[![pub package](https://img.shields.io/pub/v/unified_analytics.svg)](https://pub.dev/packages/unified_analytics)
33
[![package publisher](https://img.shields.io/pub/publisher/unified_analytics.svg)](https://pub.dev/packages/unified_analytics/publisher)
44

5+
## Hotfix `5.8.8+1` special release for Flutter 3.22
6+
7+
[Diff](https://github.com/dart-lang/tools/compare/unified_analytics-v5.8.8...hotfix-analytics-5.8.8+1?expand=1) between `5.8.8` and this hotfix release.
8+
9+
This release also includes altered tests for log file related tests. This release changes the functionality for error events by not persisting them locally.
10+
511
## What's this?
612

713
This package is intended to be used on Dart and Flutter related

pkgs/unified_analytics/lib/src/analytics.dart

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'dart:io' as io;
66

7+
import 'package:clock/clock.dart';
78
import 'package:file/file.dart';
89
import 'package:file/local.dart';
910
import 'package:file/memory.dart';
@@ -420,7 +421,7 @@ class AnalyticsImpl implements Analytics {
420421

421422
// Initialization for the error handling class that will prevent duplicate
422423
// [Event.analyticsException] events from being sent to GA4
423-
_errorHandler = ErrorHandler(sendFunction: send);
424+
_errorHandler = ErrorHandler(sendFunction: _sendError);
424425

425426
// Initialize the user property class that will be attached to
426427
// each event that is sent to Google Analytics -- it will be responsible
@@ -706,6 +707,45 @@ class AnalyticsImpl implements Analytics {
706707
_surveyHandler.dismiss(survey, false);
707708
send(Event.surveyShown(surveyId: survey.uniqueId));
708709
}
710+
711+
/// Private method for sending an instance of [Event] that does not create
712+
/// a session id, which was found to cause a stack overflow error.
713+
void _sendError(Event event) {
714+
if (!okToSend) return;
715+
716+
// Construct the body of the request
717+
//
718+
// This method omits the session id from the user property payload so that
719+
// it doesn't skew session length calculations
720+
final body = {
721+
'client_id': _clientId,
722+
'events': <Map<String, Object?>>[
723+
<String, Object?>{
724+
'name': event.eventName.label,
725+
'params': event.eventData,
726+
}
727+
],
728+
'user_properties': <String, Map<String, Object?>>{
729+
'flutter_channel': {'value': userProperty.flutterChannel},
730+
'flutter_version': {'value': userProperty.flutterVersion},
731+
'host': {'value': userProperty.host},
732+
'dart_version': {'value': userProperty.dartVersion},
733+
'analytics_pkg_version': {'value': kPackageVersion},
734+
'tool': {'value': userProperty.tool},
735+
'local_time': {'value': formatDateTime(clock.now())},
736+
'host_os_version': {'value': userProperty.hostOsVersion},
737+
'locale': {'value': userProperty.locale},
738+
'client_ide': {'value': userProperty.clientIde},
739+
'enabled_features': {'value': userProperty.enabledFeatures},
740+
},
741+
};
742+
743+
if (_enableAsserts) checkBody(body);
744+
745+
final gaClientFuture = _gaClient.sendData(body);
746+
_futures.add(gaClientFuture);
747+
gaClientFuture.whenComplete(() => _futures.remove(gaClientFuture));
748+
}
709749
}
710750

711751
/// This fake instance of [Analytics] is intended to be used by clients of
@@ -760,6 +800,12 @@ class FakeAnalytics extends AnalyticsImpl {
760800
// for internal methods in the `Analytics` instance
761801
sentEvents.add(event);
762802
}
803+
804+
@override
805+
void _sendError(Event event) {
806+
super._sendError(event);
807+
sentEvents.add(event);
808+
}
763809
}
764810

765811
/// An implementation that will never send events.

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.8';
85+
const String kPackageVersion = '5.8.8+1';
8686

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

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.8
7+
version: 5.8.8+1
88
repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics
99

1010
environment:

pkgs/unified_analytics/test/error_handler_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ void main() {
259259
(element) => element.eventName == DashEvent.analyticsException),
260260
hasLength(1),
261261
);
262-
expect(logFile.readAsLinesSync(), hasLength(4));
262+
263+
// Removing this test case because we are no longer writing error events
264+
// to the locally persisted log file
265+
// expect(logFile.readAsLinesSync(), hasLength(4));
263266
});
264267

265268
test('only sends one event for TypeError', () {

pkgs/unified_analytics/test/log_handler_test.dart

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,13 @@ void main() {
126126
expect(logFile.readAsLinesSync().length,
127127
countOfEventsToSend + countOfMalformedRecords);
128128
final logFileStats = analytics.logFileStats();
129-
expect(logFile.readAsLinesSync().length,
130-
countOfEventsToSend + countOfMalformedRecords + 1,
131-
reason:
132-
'There should have been on error event sent when getting stats');
129+
130+
// Removing this test case because we are no longer writing error events
131+
// to the locally persisted log file
132+
// expect(logFile.readAsLinesSync().length,
133+
// countOfEventsToSend + countOfMalformedRecords + 1,
134+
// reason:
135+
// 'There should have been on error event sent when getting stats');
133136

134137
expect(logFileStats, isNotNull);
135138
expect(logFileStats!.recordCount, countOfEventsToSend);
@@ -172,9 +175,13 @@ void main() {
172175
analytics.send(testEvent);
173176
}
174177
final logFileStats = analytics.logFileStats();
175-
expect(analytics.sentEvents.last.eventName, DashEvent.analyticsException,
176-
reason: 'Calling for the stats should have caused an error');
177-
expect(logFile.readAsLinesSync().length, kLogFileLength);
178+
179+
// Removing this test case because we are no longer writing error events
180+
// to the locally persisted log file
181+
// expect(analytics.sentEvents.last.eventName, DashEvent.analyticsException,
182+
// reason: 'Calling for the stats should have caused an error');
183+
// expect(logFile.readAsLinesSync().length, kLogFileLength);
184+
178185
expect(logFileStats, isNotNull);
179186
expect(logFileStats!.recordCount, recordsToSendInitially,
180187
reason: 'The first record should be malformed');
@@ -186,8 +193,11 @@ void main() {
186193
final secondLogFileStats = analytics.logFileStats();
187194
expect(analytics.sentEvents.last, testEvent);
188195
expect(secondLogFileStats, isNotNull);
189-
expect(secondLogFileStats!.recordCount, kLogFileLength);
190-
expect(logFile.readAsLinesSync()[0].trim(), isNot('{{'));
196+
expect(secondLogFileStats!.recordCount, kLogFileLength - 1);
197+
198+
// Removing this test case because we are no longer writing error events
199+
// to the locally persisted log file
200+
// expect(logFile.readAsLinesSync()[0].trim(), isNot('{{'));
191201
});
192202

193203
test('Catching cast errors for each log record silently', () async {
@@ -206,9 +216,12 @@ void main() {
206216
final secondLogFileStats = analytics.logFileStats();
207217

208218
expect(secondLogFileStats, isNotNull);
209-
expect(secondLogFileStats!.recordCount, countOfEventsToSend + 1,
210-
reason: 'Plus one for the error event that is sent '
211-
'from the first logFileStats call');
219+
220+
// Removing this test case because we are no longer writing error events
221+
// to the locally persisted log file
222+
// expect(secondLogFileStats!.recordCount, countOfEventsToSend + 1,
223+
// reason: 'Plus one for the error event that is sent '
224+
// 'from the first logFileStats call');
212225
});
213226

214227
test(

0 commit comments

Comments
 (0)