Unverified Commit 9a76efc8 authored by Elias Yishak's avatar Elias Yishak Committed by GitHub

Update analytics constructor to include `FLUTTER_HOST` (#138107)

Fixes issues:
- https://github.com/flutter/flutter/issues/138035

Similar to GA3, we will now record the host running the flutter tool, such as VSCode, stored in the `FLUTTER_HOST` env variable
parent 33c0f274
...@@ -93,6 +93,7 @@ Future<T> runInContext<T>( ...@@ -93,6 +93,7 @@ Future<T> runInContext<T>(
runningOnBot: runningOnBot, runningOnBot: runningOnBot,
flutterVersion: globals.flutterVersion, flutterVersion: globals.flutterVersion,
environment: globals.platform.environment, environment: globals.platform.environment,
clientIde: globals.platform.environment['FLUTTER_HOST'],
), ),
AndroidBuilder: () => AndroidGradleBuilder( AndroidBuilder: () => AndroidGradleBuilder(
java: globals.java, java: globals.java,
......
...@@ -19,6 +19,7 @@ Analytics getAnalytics({ ...@@ -19,6 +19,7 @@ Analytics getAnalytics({
required bool runningOnBot, required bool runningOnBot,
required FlutterVersion flutterVersion, required FlutterVersion flutterVersion,
required Map<String, String> environment, required Map<String, String> environment,
required String? clientIde,
bool enableAsserts = false, bool enableAsserts = false,
FakeAnalytics? analyticsOverride, FakeAnalytics? analyticsOverride,
}) { }) {
...@@ -48,5 +49,6 @@ Analytics getAnalytics({ ...@@ -48,5 +49,6 @@ Analytics getAnalytics({
flutterVersion: flutterVersion.frameworkVersion, flutterVersion: flutterVersion.frameworkVersion,
dartVersion: flutterVersion.dartSdkVersion, dartVersion: flutterVersion.dartSdkVersion,
enableAsserts: enableAsserts, enableAsserts: enableAsserts,
clientIde: clientIde,
); );
} }
...@@ -8,10 +8,12 @@ import 'package:flutter_tools/src/reporting/unified_analytics.dart'; ...@@ -8,10 +8,12 @@ import 'package:flutter_tools/src/reporting/unified_analytics.dart';
import 'package:unified_analytics/unified_analytics.dart'; import 'package:unified_analytics/unified_analytics.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart';
import '../src/fakes.dart'; import '../src/fakes.dart';
void main() { void main() {
const String userBranch = 'abc123'; const String userBranch = 'abc123';
const String clientIde = 'VSCode';
late FileSystem fs; late FileSystem fs;
late FakeAnalytics analyticsOverride; late FakeAnalytics analyticsOverride;
...@@ -24,6 +26,7 @@ void main() { ...@@ -24,6 +26,7 @@ void main() {
fakeFlutterVersion: FakeFlutterVersion( fakeFlutterVersion: FakeFlutterVersion(
branch: userBranch, branch: userBranch,
), ),
clientIde: clientIde,
); );
}); });
...@@ -34,6 +37,7 @@ void main() { ...@@ -34,6 +37,7 @@ void main() {
flutterVersion: FakeFlutterVersion(), flutterVersion: FakeFlutterVersion(),
environment: const <String, String>{}, environment: const <String, String>{},
analyticsOverride: analyticsOverride, analyticsOverride: analyticsOverride,
clientIde: clientIde,
); );
expect(analytics.clientId, isNot(NoOpAnalytics.staticClientId), expect(analytics.clientId, isNot(NoOpAnalytics.staticClientId),
...@@ -50,6 +54,7 @@ void main() { ...@@ -50,6 +54,7 @@ void main() {
), ),
environment: const <String, String>{}, environment: const <String, String>{},
analyticsOverride: analyticsOverride, analyticsOverride: analyticsOverride,
clientIde: clientIde,
); );
expect( expect(
...@@ -68,6 +73,7 @@ void main() { ...@@ -68,6 +73,7 @@ void main() {
), ),
environment: const <String, String>{}, environment: const <String, String>{},
analyticsOverride: analyticsOverride, analyticsOverride: analyticsOverride,
clientIde: clientIde,
); );
expect( expect(
...@@ -84,6 +90,7 @@ void main() { ...@@ -84,6 +90,7 @@ void main() {
flutterVersion: FakeFlutterVersion(), flutterVersion: FakeFlutterVersion(),
environment: const <String, String>{}, environment: const <String, String>{},
analyticsOverride: analyticsOverride, analyticsOverride: analyticsOverride,
clientIde: clientIde,
); );
expect( expect(
...@@ -96,10 +103,11 @@ void main() { ...@@ -96,10 +103,11 @@ void main() {
testWithoutContext('NoOp instance when suppressing via env variable', () { testWithoutContext('NoOp instance when suppressing via env variable', () {
final Analytics analytics = getAnalytics( final Analytics analytics = getAnalytics(
runningOnBot: true, runningOnBot: false,
flutterVersion: FakeFlutterVersion(), flutterVersion: FakeFlutterVersion(),
environment: const <String, String>{'FLUTTER_SUPPRESS_ANALYTICS': 'true'}, environment: const <String, String>{'FLUTTER_SUPPRESS_ANALYTICS': 'true'},
analyticsOverride: analyticsOverride, analyticsOverride: analyticsOverride,
clientIde: clientIde,
); );
expect( expect(
...@@ -121,5 +129,18 @@ void main() { ...@@ -121,5 +129,18 @@ void main() {
expect(analyticsOverride.sentEvents, hasLength(1)); expect(analyticsOverride.sentEvents, hasLength(1));
}); });
testUsingContext('Client IDE is passed and found in events', () {
final Analytics analytics = getAnalytics(
runningOnBot: false,
flutterVersion: FakeFlutterVersion(),
environment: const <String, String>{},
analyticsOverride: analyticsOverride,
clientIde: clientIde,
);
analytics as FakeAnalytics;
expect(analytics.userProperty.clientIde, 'VSCode');
});
}); });
} }
...@@ -320,6 +320,7 @@ class FileExceptionHandler { ...@@ -320,6 +320,7 @@ class FileExceptionHandler {
FakeAnalytics getInitializedFakeAnalyticsInstance({ FakeAnalytics getInitializedFakeAnalyticsInstance({
required FileSystem fs, required FileSystem fs,
required FakeFlutterVersion fakeFlutterVersion, required FakeFlutterVersion fakeFlutterVersion,
String? clientIde,
}) { }) {
final Directory homeDirectory = fs.directory('/'); final Directory homeDirectory = fs.directory('/');
final FakeAnalytics initialAnalytics = FakeAnalytics( final FakeAnalytics initialAnalytics = FakeAnalytics(
...@@ -343,5 +344,6 @@ FakeAnalytics getInitializedFakeAnalyticsInstance({ ...@@ -343,5 +344,6 @@ FakeAnalytics getInitializedFakeAnalyticsInstance({
surveyHandler: SurveyHandler(homeDirectory: homeDirectory, fs: fs), surveyHandler: SurveyHandler(homeDirectory: homeDirectory, fs: fs),
flutterChannel: fakeFlutterVersion.channel, flutterChannel: fakeFlutterVersion.channel,
flutterVersion: fakeFlutterVersion.getVersionString(), flutterVersion: fakeFlutterVersion.getVersionString(),
clientIde: clientIde,
); );
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment