Skip to content

Commit

Permalink
Add parameter for analytics instance
Browse files Browse the repository at this point in the history
[email protected]

Change-Id: I8ef2fe2c757a7625c2e3aa7eba48513e4c2f4e88
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352561
Reviewed-by: Ben Konyi <[email protected]>
Reviewed-by: Kenzie Davisson <[email protected]>
Commit-Queue: Kenzie Davisson <[email protected]>
  • Loading branch information
eliasyishak authored and Commit Queue committed Feb 17, 2024
1 parent 3c13e9f commit 0e55422
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 15 deletions.
4 changes: 2 additions & 2 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ vars = {
"boringssl_gen_rev": "9c7294fd58261a79794f5afaa26598cf1442ad20",
"boringssl_rev": "d24a38200fef19150eef00cad35b138936c08767",
"browser-compat-data_tag": "ac8cae697014da1ff7124fba33b0b4245cc6cd1b", # v1.0.22
"devtools_rev": "1f208c84965e9edddea11485fb73b170dba1cd96",
"devtools_rev": "333b00377c092306534404c68a82e925ee2e23a3",
"icu_rev": "81d656878ec611cb0b42d52c82e9dae93920d9ba",
"jinja2_rev": "2222b31554f03e62600cd7e383376a7c187967a1",
"libcxx_rev": "44079a4cc04cdeffb9cfe8067bfb3c276fb2bab0",
Expand Down Expand Up @@ -184,7 +184,7 @@ vars = {
"test_descriptor_rev": "35f97afacb2b7fe627f6ed0bede722fd48980848",
"test_process_rev": "7fe39afbb6c444f256c1ec0eef008edebcd44644",
"test_reflective_loader_rev": "9862703a3d14848376c8efde271c88022fba91eb",
"tools_rev": "2ef7673ca4c8eb346debe6d628f0196788fc3c66",
"tools_rev": "9f4e6a4a7de6602a5c13109c1fad8d7b36bec55f",
"typed_data_rev": "375efaa02a13dad0785cfbd9bdcb9f09aa8ef529",
"usage_rev": "67ecd7d1328347ec15cbf8d8a46918df75a66af8",
"vector_math_rev": "cb976c731f5f9011f09311cd1c39d5778d4f8f2e",
Expand Down
4 changes: 4 additions & 0 deletions pkg/dds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.2.1
- Adding `unified_analytics` as a dependency and added static method `DevToolsUtils.initializeAnalytics` to create analytics instance for DevTools.
- Updated `devtools_shared` constraint to ^7.0.0.

# 3.2.0
- [DAP] Fixed "Unable to find library" errors when using global evaluation when the context file resolves to a `package:` URI.
- Updated `devtools_shared` to ^6.0.4.
Expand Down
4 changes: 4 additions & 0 deletions pkg/dds/lib/devtools_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:http_multi_server/http_multi_server.dart';
import 'package:path/path.dart' as path;
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as shelf;
import 'package:unified_analytics/unified_analytics.dart';

import 'src/devtools/client.dart';
import 'src/devtools/handler.dart';
Expand Down Expand Up @@ -51,6 +52,7 @@ class DevToolsServer {

MachineModeCommandHandler? _machineModeCommandHandler;
late ClientManager clientManager;
late Analytics analytics;
final bool _isChromeOS = File('/dev/.cros_milestone').existsSync();

/// Builds an arg parser for the DevTools server.
Expand Down Expand Up @@ -273,10 +275,12 @@ class DevToolsServer {
clientManager = ClientManager(
requestNotificationPermissions: enableNotifications,
);
analytics = DevToolsUtils.initializeAnalytics();
handler ??= await defaultHandler(
buildDir: customDevToolsPath!,
clientManager: clientManager,
dtdUri: dtdUri,
analytics: analytics,
);

HttpServer? server;
Expand Down
3 changes: 3 additions & 0 deletions pkg/dds/lib/src/devtools/handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:path/path.dart' as path;
import 'package:shelf/shelf.dart';
import 'package:shelf_static/shelf_static.dart';
import 'package:sse/server/sse_handler.dart';
import 'package:unified_analytics/unified_analytics.dart';

import '../constants.dart';
import '../dds_impl.dart';
Expand All @@ -35,6 +36,7 @@ FutureOr<Handler> defaultHandler({
DartDevelopmentServiceImpl? dds,
required String buildDir,
ClientManager? clientManager,
Analytics? analytics,
Handler? notFoundHandler,
String? dtdUri,
}) {
Expand Down Expand Up @@ -140,6 +142,7 @@ FutureOr<Handler> defaultHandler({
extensionsManager: ExtensionsManager(buildDir: buildDir),
deeplinkManager: DeeplinkManager(),
dtdUri: dtdUri,
analytics: analytics ?? NoOpAnalytics(),
);
}

Expand Down
68 changes: 57 additions & 11 deletions pkg/dds/lib/src/devtools/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,11 @@ import 'dart:convert';
import 'dart:io';

import 'package:path/path.dart' as path;
import 'package:unified_analytics/unified_analytics.dart';
import 'package:vm_service/utils.dart';
import 'package:vm_service/vm_service.dart';

abstract class DevToolsUtils {
static void printOutput(
String? message,
Object json, {
required bool machineMode,
}) {
final output = machineMode ? jsonEncode(json) : message;
if (output != null) {
print(output);
}
}

static Future<VmService?> connectToVmService(Uri theUri) async {
// Fix up the various acceptable URI formats into a WebSocket URI to connect.
final uri = convertToWebSocketUrl(serviceProtocolUrl: theUri);
Expand Down Expand Up @@ -49,6 +39,62 @@ abstract class DevToolsUtils {
return 'unknown';
}
}

/// Provides an instance of [Analytics] with the Dart SDK version and Flutter
/// version and channel if running the dart executable shipped with Flutter.
static Analytics initializeAnalytics() {
// Use helper method from package:unified_analytics to return
// a cleaned dart sdk verison
final dartVersion = parseDartSDKVersion(Platform.version);

// The location for the dart executable in the following path
// /path/to/dart-sdk/bin/dart
final dartExecutableFile = File(Platform.resolvedExecutable);

// The flutter version file can also be found if we are running the
// dart sdk that is shipped with flutter in the following path
// /path/to/flutter/bin/cache/dart-sdk/bin/dart
final flutterVersionFile = File(path.join(
dartExecutableFile.parent.path, '..', '..', 'flutter.version.json'));

// These fields are defined as nullable incase the dart sdk being run
// is not the sdk shipped with flutter
String? flutterChannel;
String? flutterVersion;

// If the dart sdk being used is vendored with the flutter sdk, we can
// expect this file to exist
if (flutterVersionFile.existsSync()) {
try {
final flutterObj = jsonDecode(flutterVersionFile.readAsStringSync())
as Map<String, Object?>;
flutterChannel = flutterObj['channel'] as String?;
flutterVersion = flutterObj['frameworkVersion'] as String?;
} catch (_) {
// Leave the flutter channel and version info null
}
}

return Analytics(
tool: DashTool.devtools,
dartVersion: dartVersion,
// TODO(eliasyishak): pass this information (https://github.com/flutter/devtools/issues/7230)
// clientIde: 'TBD',
flutterChannel: flutterChannel,
flutterVersion: flutterVersion,
);
}

static void printOutput(
String? message,
Object json, {
required bool machineMode,
}) {
final output = machineMode ? jsonEncode(json) : message;
if (output != null) {
print(output);
}
}
}

extension SafeAccessList<T> on List<T> {
Expand Down
5 changes: 3 additions & 2 deletions pkg/dds/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dds
version: 3.2.0
version: 3.2.1
description: >-
A library used to spawn the Dart Developer Service, used to communicate with
a Dart VM Service instance.
Expand All @@ -16,7 +16,7 @@ dependencies:
dds_service_extensions: ^1.6.0
dap: ^1.1.0
extension_discovery: ^2.0.0
devtools_shared: ^6.0.4
devtools_shared: ^7.0.0
http_multi_server: ^3.0.0
json_rpc_2: ^3.0.0
meta: ^1.1.8
Expand All @@ -31,6 +31,7 @@ dependencies:
stream_channel: ^2.0.0
vm_service: ^14.0.0
web_socket_channel: ^2.0.0
unified_analytics: ^5.8.2

# We use 'any' version constraints here as we get our package versions from
# the dart-lang/sdk repo's DEPS file. Note that this is a special case; the
Expand Down

0 comments on commit 0e55422

Please sign in to comment.