Skip to content

Commit c63dcb5

Browse files
authored
Added enum + event for timing events (#208)
* Added enum + event for timing events * Format fix * Fix typos in dartdoc
1 parent 6246bc8 commit c63dcb5

File tree

6 files changed

+57
-3
lines changed

6 files changed

+57
-3
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.6.0
2+
3+
- Added the `Event.timing` constructor
4+
15
## 5.5.0
26

37
- Edit to the `Event.flutterCommandResult` constructor to add `commandHasTerminal`

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.5.0';
85+
const String kPackageVersion = '5.6.0';
8686

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

pkgs/unified_analytics/lib/src/enums.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ enum DashEvent {
3434
label: 'survey_shown',
3535
description: 'Survey shown to the user',
3636
),
37+
timing(
38+
label: 'timing',
39+
description: 'Events for timing how long a process takes',
40+
),
3741

3842
// Events for the Dart CLI
3943

pkgs/unified_analytics/lib/src/event.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,33 @@ final class Event {
1919
: eventName = DashEvent.analyticsCollectionEnabled,
2020
eventData = {'status': status};
2121

22+
/// Event that records how long a given process takes to complete.
23+
///
24+
/// [workflow] - the overall process or command being run, for example
25+
/// "build" is a possible value for the flutter tool.
26+
///
27+
/// [variableName] - the specific variable being measured, for example
28+
/// "gradle" would indicate how long it took for a gradle build under the
29+
/// "build" [workflow].
30+
///
31+
/// [elapsedMilliseconds] - how long the process took in milliseconds.
32+
///
33+
/// [label] - an optional field that can be used for further filtering, for
34+
/// example, "success" can indicate how long a successful build in gradle
35+
/// takes to complete.
36+
Event.timing({
37+
required String workflow,
38+
required String variableName,
39+
required int elapsedMilliseconds,
40+
String? label,
41+
}) : eventName = DashEvent.timing,
42+
eventData = {
43+
'workflow': workflow,
44+
'variableName': variableName,
45+
'elapsedMilliseconds': elapsedMilliseconds,
46+
if (label != null) 'label': label,
47+
};
48+
2249
/// This is for various workflows within the flutter tool related
2350
/// to iOS and macOS workflows.
2451
///

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

1010
environment:

pkgs/unified_analytics/test/event_test.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,25 @@ void main() {
439439
expect(constructedEvent.eventData.length, 1);
440440
});
441441

442+
test('Event.timing constructed', () {
443+
Event generateEvent() => Event.timing(
444+
workflow: 'workflow',
445+
variableName: 'variableName',
446+
elapsedMilliseconds: 123,
447+
label: 'label',
448+
);
449+
450+
final constructedEvent = generateEvent();
451+
452+
expect(generateEvent, returnsNormally);
453+
expect(constructedEvent.eventName, DashEvent.timing);
454+
expect(constructedEvent.eventData['workflow'], 'workflow');
455+
expect(constructedEvent.eventData['variableName'], 'variableName');
456+
expect(constructedEvent.eventData['elapsedMilliseconds'], 123);
457+
expect(constructedEvent.eventData['label'], 'label');
458+
expect(constructedEvent.eventData.length, 4);
459+
});
460+
442461
test('Confirm all constructors were checked', () {
443462
var constructorCount = 0;
444463
for (var declaration in reflectClass(Event).declarations.keys) {
@@ -447,7 +466,7 @@ void main() {
447466

448467
// Change this integer below if your PR either adds or removes
449468
// an Event constructor
450-
final eventsAccountedForInTests = 23;
469+
final eventsAccountedForInTests = 24;
451470
expect(eventsAccountedForInTests, constructorCount,
452471
reason: 'If you added or removed an event constructor, '
453472
'ensure you have updated '

0 commit comments

Comments
 (0)