[Reland] Migration for the sendTiming events for package:unified_analytics (#139299)

Relanding based on this comment:
- https://github.com/flutter/flutter/pull/139278#issuecomment-1832951108

Related to tracker issue:
- https://github.com/flutter/flutter/issues/128251

<img width="278" alt="image" src="https://github.com/flutter/flutter/assets/42216813/cee7b9be-48d6-48e5-8c39-de28d0a1f0de">

The image above shows all of the instances where we have `sendTiming`. All of the call sites have been updated to use the new `Event.timing` event from `package:unified_analytics`.
This commit is contained in:
Elias Yishak
2023-12-04 16:39:18 -05:00
committed by GitHub
parent 7be25c8953
commit 2d60241d61
27 changed files with 806 additions and 274 deletions

View File

@@ -1634,16 +1634,26 @@ abstract class FlutterCommand extends Command<void> {
final String label = labels
.where((String? label) => label != null && !_isBlank(label))
.join('-');
// If the command provides its own end time, use it. Otherwise report
// the duration of the entire execution.
final Duration elapsedDuration = (commandResult.endTimeOverride ?? endTime).difference(startTime);
globals.flutterUsage.sendTiming(
'flutter',
name,
// If the command provides its own end time, use it. Otherwise report
// the duration of the entire execution.
(commandResult.endTimeOverride ?? endTime).difference(startTime),
elapsedDuration,
// Report in the form of `success-[parameter1-parameter2]`, all of which
// can be null if the command doesn't provide a FlutterCommandResult.
label: label == '' ? null : label,
);
analytics.send(Event.timing(
workflow: 'flutter',
variableName: name,
elapsedMilliseconds: elapsedDuration.inMilliseconds,
// Report in the form of `success-[parameter1-parameter2]`, all of which
// can be null if the command doesn't provide a FlutterCommandResult.
label: label == '' ? null : label,
));
}
/// Perform validation then call [runCommand] to execute the command.
@@ -1707,7 +1717,7 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
processManager: globals.processManager,
platform: globals.platform,
usage: globals.flutterUsage,
analytics: globals.analytics,
analytics: analytics,
projectDir: project.directory,
generateDartPluginRegistry: true,
);

View File

@@ -6,6 +6,7 @@ import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:completion/completion.dart';
import 'package:file/file.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../artifacts.dart';
import '../base/common.dart';
@@ -329,6 +330,11 @@ class FlutterCommandRunner extends CommandRunner<void> {
if ((topLevelResults[FlutterGlobalOptions.kVersionFlag] as bool?) ?? false) {
globals.flutterUsage.sendCommand(FlutterGlobalOptions.kVersionFlag);
globals.analytics.send(Event.flutterCommandResult(
commandPath: 'version',
result: 'success',
commandHasTerminal: globals.stdio.hasTerminal,
));
final FlutterVersion version = globals.flutterVersion.fetchTagsAndGetVersion(
clock: globals.systemClock,
);