Skip to content

Commit 66afa68

Browse files
Breaking change: add and remove parameters from the Event.devtoolsEvent constructor (#1193)
1 parent 0482672 commit 66afa68

File tree

6 files changed

+71
-87
lines changed

6 files changed

+71
-87
lines changed

pkgs/unified_analytics/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 7.0.0
2+
- Added a required parameter `screen` to the `Event.devtoolsEvent` constructor.
3+
- Added an optional parameter `additionalMetrics` to the `Event.devtoolsEvent` constructor.
4+
- Added `CustomMetrics` class for unified_analytics clients to define custom event metrics.
5+
- Removed parameters `uiDurationMicros`, `rasterDurationMicros`, `shaderCompilationDurationMicros`,
6+
`traceEventCount`, `cpuSampleCount`, `cpuStackDepth`, `heapDiffObjectsBefore`, `heapDiffObjectsAfter`,
7+
`heapObjectsTotal`, `rootSetCount`, `rowCount`, `inspectorTreeControllerId`, `androidAppId`, `iosBundleId`
8+
from the `Event.devtoolsEvent` constructor.
9+
110
## 6.1.5
211
- Remove any `data` entries with a null value in the `Event.exception` constructor.
312

pkgs/unified_analytics/lib/src/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const int kMaxLogFileSize = 25 * (1 << 20);
8787
const String kLogFileName = 'dart-flutter-telemetry.log';
8888

8989
/// The current version of the package, should be in line with pubspec version.
90-
const String kPackageVersion = '6.1.5';
90+
const String kPackageVersion = '7.0.0';
9191

9292
/// The minimum length for a session.
9393
const int kSessionDurationMinutes = 30;

pkgs/unified_analytics/lib/src/event.dart

Lines changed: 24 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,17 @@ final class Event {
356356
if (exitCode != null) 'exitCode': exitCode,
357357
};
358358

359-
/// Event that is sent from devtools for various different actions as
359+
/// Event that is sent from DevTools for various different actions as
360360
/// indicated by the [eventCategory].
361+
///
362+
/// The optional parameters in the parameter list contain metadata that is
363+
/// sent with each event, when available.
364+
///
365+
/// [additionalMetrics] may contain any additional data for the event being
366+
/// sent. This often looks like metrics that are unique to the event or to a
367+
/// specific screen.
361368
Event.devtoolsEvent({
369+
required String screen,
362370
required String eventCategory,
363371
required String label,
364372
required int value,
@@ -379,32 +387,10 @@ final class Event {
379387
String? isEmbedded,
380388
String? ideLaunchedFeature,
381389
String? isWasm,
382-
383-
// PerformanceScreenMetrics
384-
int? uiDurationMicros,
385-
int? rasterDurationMicros,
386-
int? shaderCompilationDurationMicros,
387-
int? traceEventCount,
388-
389-
// ProfilerScreenMetrics
390-
int? cpuSampleCount,
391-
int? cpuStackDepth,
392-
393-
// MemoryScreenMetrics
394-
int? heapDiffObjectsBefore,
395-
int? heapDiffObjectsAfter,
396-
int? heapObjectsTotal,
397-
398-
// InspectorScreenMetrics
399-
int? rootSetCount,
400-
int? rowCount,
401-
int? inspectorTreeControllerId,
402-
403-
// DeepLinkScreenMetrics
404-
String? androidAppId,
405-
String? iosBundleId,
390+
CustomMetrics? additionalMetrics,
406391
}) : eventName = DashEvent.devtoolsEvent,
407392
eventData = {
393+
'screen': screen,
408394
'eventCategory': eventCategory,
409395
'label': label,
410396
'value': value,
@@ -425,34 +411,7 @@ final class Event {
425411
if (ideLaunchedFeature != null)
426412
'ideLaunchedFeature': ideLaunchedFeature,
427413
if (isWasm != null) 'isWasm': isWasm,
428-
429-
// PerformanceScreenMetrics
430-
if (uiDurationMicros != null) 'uiDurationMicros': uiDurationMicros,
431-
if (rasterDurationMicros != null)
432-
'rasterDurationMicros': rasterDurationMicros,
433-
if (shaderCompilationDurationMicros != null)
434-
'shaderCompilationDurationMicros': shaderCompilationDurationMicros,
435-
if (traceEventCount != null) 'traceEventCount': traceEventCount,
436-
437-
// ProfilerScreenMetrics
438-
if (cpuSampleCount != null) 'cpuSampleCount': cpuSampleCount,
439-
if (cpuStackDepth != null) 'cpuStackDepth': cpuStackDepth,
440-
441-
// MemoryScreenMetrics
442-
if (heapDiffObjectsBefore != null)
443-
'heapDiffObjectsBefore': heapDiffObjectsBefore,
444-
if (heapDiffObjectsAfter != null)
445-
'heapDiffObjectsAfter': heapDiffObjectsAfter,
446-
if (heapObjectsTotal != null) 'heapObjectsTotal': heapObjectsTotal,
447-
448-
// InspectorScreenMetrics
449-
if (rootSetCount != null) 'rootSetCount': rootSetCount,
450-
if (rowCount != null) 'rowCount': rowCount,
451-
if (inspectorTreeControllerId != null)
452-
'inspectorTreeControllerId': inspectorTreeControllerId,
453-
// DeepLinkScreenMetrics
454-
if (androidAppId != null) 'androidAppId': androidAppId,
455-
if (iosBundleId != null) 'iosBundleId': iosBundleId,
414+
if (additionalMetrics != null) ...additionalMetrics.toMap(),
456415
};
457416

458417
/// Event that contains the results for a specific doctor validator.
@@ -887,3 +846,15 @@ final class Event {
887846
}
888847
}
889848
}
849+
850+
/// A base class for custom metrics that will be defined by a unified_analytics
851+
/// client.
852+
///
853+
/// This base type can be used as a parameter in any event constructor that
854+
/// allows custom metrics to be added by a unified_analytics client.
855+
abstract base class CustomMetrics {
856+
/// Converts the custom metrics data to a [Map] object.
857+
///
858+
/// This must be a JSON encodable [Map].
859+
Map<String, Object> toMap();
860+
}

pkgs/unified_analytics/lib/unified_analytics.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
export 'src/analytics.dart' show Analytics, FakeAnalytics, NoOpAnalytics;
66
export 'src/config_handler.dart' show ToolInfo;
77
export 'src/enums.dart' show DashTool;
8-
export 'src/event.dart' show Event;
8+
export 'src/event.dart' show CustomMetrics, Event;
99
export 'src/log_handler.dart' show LogFileStats;
1010
export 'src/survey_handler.dart' show Survey, SurveyButton, SurveyHandler;
1111
export 'src/utils.dart' show parseDartSDKVersion;

pkgs/unified_analytics/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: >-
55
# LINT.IfChange
66
# When updating this, keep the version consistent with the changelog and the
77
# value in lib/src/constants.dart.
8-
version: 6.1.5
8+
version: 7.0.0
99
# LINT.ThenChange(lib/src/constants.dart)
1010
repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics
1111
issue_tracker: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aunified_analytics

pkgs/unified_analytics/test/event_test.dart

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:mirrors';
66

77
import 'package:test/test.dart';
88
import 'package:unified_analytics/src/enums.dart';
9+
import 'package:unified_analytics/src/event.dart';
910
import 'package:unified_analytics/unified_analytics.dart';
1011

1112
void main() {
@@ -559,6 +560,7 @@ void main() {
559560

560561
test('Event.devtoolsEvent constructed', () {
561562
Event generateEvent() => Event.devtoolsEvent(
563+
screen: 'screen',
562564
eventCategory: 'eventCategory',
563565
label: 'label',
564566
value: 1,
@@ -575,25 +577,17 @@ void main() {
575577
isEmbedded: 'isEmbedded',
576578
ideLaunchedFeature: 'ideLaunchedFeature',
577579
isWasm: 'true',
578-
uiDurationMicros: 123,
579-
rasterDurationMicros: 123,
580-
shaderCompilationDurationMicros: 123,
581-
traceEventCount: 123,
582-
cpuSampleCount: 123,
583-
cpuStackDepth: 123,
584-
heapDiffObjectsBefore: 123,
585-
heapDiffObjectsAfter: 123,
586-
heapObjectsTotal: 123,
587-
rootSetCount: 123,
588-
rowCount: 123,
589-
inspectorTreeControllerId: 123,
590-
androidAppId: 'androidAppId',
591-
iosBundleId: 'iosBundleId',
580+
additionalMetrics: _TestMetrics(
581+
stringField: 'test',
582+
intField: 100,
583+
boolField: false,
584+
),
592585
);
593586

594587
final constructedEvent = generateEvent();
595588

596589
expect(generateEvent, returnsNormally);
590+
expect(constructedEvent.eventData['screen'], 'screen');
597591
expect(constructedEvent.eventData['eventCategory'], 'eventCategory');
598592
expect(constructedEvent.eventData['label'], 'label');
599593
expect(constructedEvent.eventData['value'], 1);
@@ -609,24 +603,15 @@ void main() {
609603
expect(constructedEvent.eventData['isExternalBuild'], 'isExternalBuild');
610604
expect(constructedEvent.eventData['isEmbedded'], 'isEmbedded');
611605
expect(
612-
constructedEvent.eventData['ideLaunchedFeature'], 'ideLaunchedFeature');
606+
constructedEvent.eventData['ideLaunchedFeature'],
607+
'ideLaunchedFeature',
608+
);
613609
expect(constructedEvent.eventData['isWasm'], 'true');
614-
615-
expect(constructedEvent.eventData['uiDurationMicros'], 123);
616-
expect(constructedEvent.eventData['rasterDurationMicros'], 123);
617-
expect(constructedEvent.eventData['shaderCompilationDurationMicros'], 123);
618-
expect(constructedEvent.eventData['traceEventCount'], 123);
619-
expect(constructedEvent.eventData['cpuSampleCount'], 123);
620-
expect(constructedEvent.eventData['cpuStackDepth'], 123);
621-
expect(constructedEvent.eventData['heapDiffObjectsBefore'], 123);
622-
expect(constructedEvent.eventData['heapDiffObjectsAfter'], 123);
623-
expect(constructedEvent.eventData['heapObjectsTotal'], 123);
624-
expect(constructedEvent.eventData['rootSetCount'], 123);
625-
expect(constructedEvent.eventData['rowCount'], 123);
626-
expect(constructedEvent.eventData['inspectorTreeControllerId'], 123);
627-
expect(constructedEvent.eventData['androidAppId'], 'androidAppId');
628-
expect(constructedEvent.eventData['iosBundleId'], 'iosBundleId');
629-
expect(constructedEvent.eventData.length, 30);
610+
expect(constructedEvent.eventData['stringField'], 'test');
611+
expect(constructedEvent.eventData['intField'], 100);
612+
expect(constructedEvent.eventData['boolField'], false);
613+
expect(constructedEvent.eventData.containsKey('nullableField'), false);
614+
expect(constructedEvent.eventData.length, 20);
630615
});
631616

632617
test('Confirm all constructors were checked', () {
@@ -700,3 +685,22 @@ void main() {
700685
expect(eventConstructed, isNull);
701686
});
702687
}
688+
689+
final class _TestMetrics extends CustomMetrics {
690+
_TestMetrics({
691+
required this.stringField,
692+
required this.intField,
693+
required this.boolField,
694+
});
695+
696+
final String stringField;
697+
final int intField;
698+
final bool boolField;
699+
700+
@override
701+
Map<String, Object> toMap() => {
702+
'stringField': stringField,
703+
'intField': intField,
704+
'boolField': boolField,
705+
};
706+
}

0 commit comments

Comments
 (0)