Skip to content

Commit

Permalink
Added enum + event for timing events (#208)
Browse files Browse the repository at this point in the history
* Added enum + event for timing events

* Format fix

* Fix typos in dartdoc
  • Loading branch information
eliasyishak authored Nov 26, 2023
1 parent 6246bc8 commit c63dcb5
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
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.6.0

- Added the `Event.timing` constructor

## 5.5.0

- Edit to the `Event.flutterCommandResult` constructor to add `commandHasTerminal`
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';
const String kPackageVersion = '5.6.0';

/// The minimum length for a session.
const int kSessionDurationMinutes = 30;
Expand Down
4 changes: 4 additions & 0 deletions pkgs/unified_analytics/lib/src/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ enum DashEvent {
label: 'survey_shown',
description: 'Survey shown to the user',
),
timing(
label: 'timing',
description: 'Events for timing how long a process takes',
),

// Events for the Dart CLI

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,33 @@ final class Event {
: eventName = DashEvent.analyticsCollectionEnabled,
eventData = {'status': status};

/// Event that records how long a given process takes to complete.
///
/// [workflow] - the overall process or command being run, for example
/// "build" is a possible value for the flutter tool.
///
/// [variableName] - the specific variable being measured, for example
/// "gradle" would indicate how long it took for a gradle build under the
/// "build" [workflow].
///
/// [elapsedMilliseconds] - how long the process took in milliseconds.
///
/// [label] - an optional field that can be used for further filtering, for
/// example, "success" can indicate how long a successful build in gradle
/// takes to complete.
Event.timing({
required String workflow,
required String variableName,
required int elapsedMilliseconds,
String? label,
}) : eventName = DashEvent.timing,
eventData = {
'workflow': workflow,
'variableName': variableName,
'elapsedMilliseconds': elapsedMilliseconds,
if (label != null) 'label': label,
};

/// This is for various workflows within the flutter tool related
/// to iOS and macOS workflows.
///
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
version: 5.6.0
repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics

environment:
Expand Down
21 changes: 20 additions & 1 deletion pkgs/unified_analytics/test/event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,25 @@ void main() {
expect(constructedEvent.eventData.length, 1);
});

test('Event.timing constructed', () {
Event generateEvent() => Event.timing(
workflow: 'workflow',
variableName: 'variableName',
elapsedMilliseconds: 123,
label: 'label',
);

final constructedEvent = generateEvent();

expect(generateEvent, returnsNormally);
expect(constructedEvent.eventName, DashEvent.timing);
expect(constructedEvent.eventData['workflow'], 'workflow');
expect(constructedEvent.eventData['variableName'], 'variableName');
expect(constructedEvent.eventData['elapsedMilliseconds'], 123);
expect(constructedEvent.eventData['label'], 'label');
expect(constructedEvent.eventData.length, 4);
});

test('Confirm all constructors were checked', () {
var constructorCount = 0;
for (var declaration in reflectClass(Event).declarations.keys) {
Expand All @@ -447,7 +466,7 @@ void main() {

// Change this integer below if your PR either adds or removes
// an Event constructor
final eventsAccountedForInTests = 23;
final eventsAccountedForInTests = 24;
expect(eventsAccountedForInTests, constructorCount,
reason: 'If you added or removed an event constructor, '
'ensure you have updated '
Expand Down

0 comments on commit c63dcb5

Please sign in to comment.