Skip to content

Commit

Permalink
Add generic usage event used for iOS/macOS workflows + generic `excep…
Browse files Browse the repository at this point in the history
…tion` event (#206)

* Added event for general apple work flow events

* Organize members

* Adding `exception` event + prep for publish

* `label` --> `result` for `appleUsageEvent`
  • Loading branch information
eliasyishak authored Nov 20, 2023
1 parent 938586b commit 9beff70
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pkgs/unified_analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

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.5.0-wip';
const String kPackageVersion = '5.5.0';

/// The minimum length for a session.
const int kSessionDurationMinutes = 30;
Expand Down
10 changes: 10 additions & 0 deletions pkgs/unified_analytics/lib/src/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
27 changes: 27 additions & 0 deletions pkgs/unified_analytics/lib/src/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
///
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.5.0-wip
version: 5.5.0
repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics

environment:
Expand Down
30 changes: 29 additions & 1 deletion pkgs/unified_analytics/test/event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 '
Expand Down

0 comments on commit 9beff70

Please sign in to comment.