Skip to content

Commit

Permalink
Enum + event constructors added for doctor events (#178)
Browse files Browse the repository at this point in the history
* Enum + event constructors added for doctor events

* Use flexible field for doctor results

* Clean up dartdoc

* Consolidate doctor events into one event instead of 2

* `timestamp` --> `doctorInvocationId`

* Test for `Event.doctorValidatorResult` constructor

* Additional checks on `eventData` fields

* Bump version to prep for publish

* Bump version

* Prepare for publishing
  • Loading branch information
eliasyishak authored Oct 24, 2023
1 parent e3dd149 commit da6bb18
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pkgs/unified_analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 5.0.0-wip
## 5.0.0

- Update to the latest version of `package:dart_flutter_team_lints`
- Using internal futures list to store send events
- Added the `Event.doctorValidatorResult` constructor

## 4.0.1

Expand Down Expand Up @@ -59,4 +60,4 @@

## 0.1.0

- Initial version.
- Initial version
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.0.0-wip';
const String kPackageVersion = '5.0.0';

/// The minimum length for a session.
const int kSessionDurationMinutes = 30;
Expand Down
9 changes: 8 additions & 1 deletion pkgs/unified_analytics/lib/src/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum DashEvent {
),

// Events for the Dart CLI

dartCliCommandExecuted(
label: 'dart_cli_command_executed',
description: 'Information about the execution of a Dart CLI command',
Expand All @@ -43,7 +44,13 @@ enum DashEvent {
toolOwner: DashTool.dartTool,
),

// Events for flutter_tools
// Events for the Flutter CLI

doctorValidatorResult(
label: 'doctor_validator_result',
description: 'Results from a specific doctor validator',
toolOwner: DashTool.flutterTool,
),
hotReloadTime(
label: 'hot_reload_time',
description: 'Hot reload duration',
Expand Down
30 changes: 30 additions & 0 deletions pkgs/unified_analytics/lib/src/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,36 @@ final class Event {
if (exitCode != null) 'exitCode': exitCode,
};

/// Event that contains the results for a specific doctor validator.
///
/// [validatorName] - the name for the doctor validator.
///
/// [result] - the final result for a specific doctor validator.
///
/// [partOfGroupedValidator] - `true` indicates that this validator belongs
/// to a grouped validator.
///
/// [doctorInvocationId] - epoch formatted timestamp that can be used in
/// combination with the client ID in GA4 to group the validators that
/// ran in one doctor invocation.
///
/// [statusInfo] - optional description of the result from the
/// doctor validator.
Event.doctorValidatorResult({
required String validatorName,
required String result,
required bool partOfGroupedValidator,
required int doctorInvocationId,
String? statusInfo,
}) : eventName = DashEvent.doctorValidatorResult,
eventData = {
'validatorName': validatorName,
'result': result,
'partOfGroupedValidator': partOfGroupedValidator,
'doctorInvocationId': doctorInvocationId,
if (statusInfo != null) 'statusInfo': statusInfo,
};

Event.hotReloadTime({required int timeMs})
: eventName = DashEvent.hotReloadTime,
eventData = {'timeMs': timeMs};
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.0.0-wip
version: 5.0.0
repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics

environment:
Expand Down
30 changes: 30 additions & 0 deletions pkgs/unified_analytics/test/event_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:test/test.dart';

import 'package:unified_analytics/src/enums.dart';
import 'package:unified_analytics/unified_analytics.dart';

void main() {
test('Event.doctorValidatorResult constructed', () {
Event genDoctorValidatorResult() => Event.doctorValidatorResult(
validatorName: 'validatorName',
result: 'success',
partOfGroupedValidator: false,
doctorInvocationId: 123,
statusInfo: 'statusInfo',
);

final constructedEvent = genDoctorValidatorResult();

expect(genDoctorValidatorResult, returnsNormally);
expect(constructedEvent.eventName, DashEvent.doctorValidatorResult);
expect(constructedEvent.eventData['validatorName'], 'validatorName');
expect(constructedEvent.eventData['result'], 'success');
expect(constructedEvent.eventData['partOfGroupedValidator'], false);
expect(constructedEvent.eventData['doctorInvocationId'], 123);
expect(constructedEvent.eventData['statusInfo'], 'statusInfo');
});
}

0 comments on commit da6bb18

Please sign in to comment.