From 9beff707bf9ddd8f3c35e1fbbe8e10d6783e6b40 Mon Sep 17 00:00:00 2001 From: Elias Yishak <42216813+eliasyishak@users.noreply.github.com> Date: Mon, 20 Nov 2023 11:05:36 -0500 Subject: [PATCH] Add generic usage event used for iOS/macOS workflows + generic `exception` event (#206) * Added event for general apple work flow events * Organize members * Adding `exception` event + prep for publish * `label` --> `result` for `appleUsageEvent` --- pkgs/unified_analytics/CHANGELOG.md | 4 ++- pkgs/unified_analytics/lib/src/constants.dart | 2 +- pkgs/unified_analytics/lib/src/enums.dart | 10 +++++++ pkgs/unified_analytics/lib/src/event.dart | 27 +++++++++++++++++ pkgs/unified_analytics/pubspec.yaml | 2 +- pkgs/unified_analytics/test/event_test.dart | 30 ++++++++++++++++++- 6 files changed, 71 insertions(+), 4 deletions(-) diff --git a/pkgs/unified_analytics/CHANGELOG.md b/pkgs/unified_analytics/CHANGELOG.md index 65b1c0f4f..728d53e58 100644 --- a/pkgs/unified_analytics/CHANGELOG.md +++ b/pkgs/unified_analytics/CHANGELOG.md @@ -1,7 +1,9 @@ -## 5.5.0-wip +## 5.5.0 - Edit to the `Event.flutterCommandResult` constructor to add `commandHasTerminal` - Added timeout for `Analytics.setTelemetry` to prevent the clients from hanging +- Added the `Event.appleUsageEvent` constructor +- Added the `Event.exception` constructor ## 5.4.0 diff --git a/pkgs/unified_analytics/lib/src/constants.dart b/pkgs/unified_analytics/lib/src/constants.dart index 8e2610dba..efd67f26f 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.5.0-wip'; +const String kPackageVersion = '5.5.0'; /// The minimum length for a session. const int kSessionDurationMinutes = 30; diff --git a/pkgs/unified_analytics/lib/src/enums.dart b/pkgs/unified_analytics/lib/src/enums.dart index 18dc190cc..6f6e99aa4 100644 --- a/pkgs/unified_analytics/lib/src/enums.dart +++ b/pkgs/unified_analytics/lib/src/enums.dart @@ -22,6 +22,10 @@ enum DashEvent { label: 'analytics_collection_enabled', description: 'The opt-in status for analytics collection', ), + exception( + label: 'exception', + description: 'General errors to log', + ), surveyAction( label: 'survey_action', description: 'Actions taken by users when shown survey', @@ -46,6 +50,12 @@ enum DashEvent { // Events for the Flutter CLI + appleUsageEvent( + label: 'apple_usage_event', + description: + 'Events related to iOS/macOS workflows within the flutter tool', + toolOwner: DashTool.flutterTool, + ), codeSizeAnalysis( label: 'code_size_analysis', description: 'Indicates when the "--analyize-size" command is run', diff --git a/pkgs/unified_analytics/lib/src/event.dart b/pkgs/unified_analytics/lib/src/event.dart index f163653ba..6058b68db 100644 --- a/pkgs/unified_analytics/lib/src/event.dart +++ b/pkgs/unified_analytics/lib/src/event.dart @@ -19,6 +19,25 @@ final class Event { : eventName = DashEvent.analyticsCollectionEnabled, eventData = {'status': status}; + /// This is for various workflows within the flutter tool related + /// to iOS and macOS workflows. + /// + /// [workflow] - which workflow is running, such as "assemble". + /// + /// [parameter] - subcategory of the workflow, such as "ios-archive". + /// + /// [result] - usually to indicate success or failure of the workflow. + Event.appleUsageEvent({ + required String workflow, + required String parameter, + String? result, + }) : eventName = DashEvent.appleUsageEvent, + eventData = { + 'workflow': workflow, + 'parameter': parameter, + if (result != null) 'result': result, + }; + /// Event that is emitted periodically to report the performance of the /// analysis server's handling of a specific kind of notification from the /// client. @@ -247,6 +266,14 @@ final class Event { if (statusInfo != null) 'statusInfo': statusInfo, }; + /// Generic event for all dash tools to use when encountering an + /// exception that we want to log. + /// + /// [exception] - string representation of the exception that occured. + Event.exception({required String exception}) + : eventName = DashEvent.exception, + eventData = {'exception': exception}; + /// Event that is emitted from the flutter tool when a build invocation /// has been run by the user. /// diff --git a/pkgs/unified_analytics/pubspec.yaml b/pkgs/unified_analytics/pubspec.yaml index b733158ba..814884b0a 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.5.0-wip +version: 5.5.0 repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics environment: diff --git a/pkgs/unified_analytics/test/event_test.dart b/pkgs/unified_analytics/test/event_test.dart index 4d4c9148e..013a442b2 100644 --- a/pkgs/unified_analytics/test/event_test.dart +++ b/pkgs/unified_analytics/test/event_test.dart @@ -411,6 +411,34 @@ void main() { expect(constructedEvent.eventData.length, 1); }); + test('Event.appleUsageEvent constructed', () { + Event generateEvent() => Event.appleUsageEvent( + workflow: 'workflow', + parameter: 'parameter', + result: 'result', + ); + + final constructedEvent = generateEvent(); + + expect(generateEvent, returnsNormally); + expect(constructedEvent.eventName, DashEvent.appleUsageEvent); + expect(constructedEvent.eventData['workflow'], 'workflow'); + expect(constructedEvent.eventData['parameter'], 'parameter'); + expect(constructedEvent.eventData['result'], 'result'); + expect(constructedEvent.eventData.length, 3); + }); + + test('Event.exception constructed', () { + Event generateEvent() => Event.exception(exception: 'exception'); + + final constructedEvent = generateEvent(); + + expect(generateEvent, returnsNormally); + expect(constructedEvent.eventName, DashEvent.exception); + expect(constructedEvent.eventData['exception'], 'exception'); + expect(constructedEvent.eventData.length, 1); + }); + test('Confirm all constructors were checked', () { var constructorCount = 0; for (var declaration in reflectClass(Event).declarations.keys) { @@ -419,7 +447,7 @@ void main() { // Change this integer below if your PR either adds or removes // an Event constructor - final eventsAccountedForInTests = 21; + final eventsAccountedForInTests = 23; expect(eventsAccountedForInTests, constructorCount, reason: 'If you added or removed an event constructor, ' 'ensure you have updated '