Skip to content

Commit 8337863

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Add the attachment with the content of the file being analyzed.
Change-Id: I75b1c61e2d04cd5e03ef4375e97ef3c9f4add874 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138384 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent bbb449d commit 8337863

29 files changed

+195
-49
lines changed

pkg/analysis_server/lib/src/analysis_server.dart

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import 'package:analysis_server/src/plugin/plugin_manager.dart';
3939
import 'package:analysis_server/src/plugin/plugin_watcher.dart';
4040
import 'package:analysis_server/src/protocol_server.dart' as server;
4141
import 'package:analysis_server/src/search/search_domain.dart';
42+
import 'package:analysis_server/src/server/crash_reporting_attachments.dart';
4243
import 'package:analysis_server/src/server/detachable_filesystem_manager.dart';
4344
import 'package:analysis_server/src/server/diagnostic_server.dart';
4445
import 'package:analysis_server/src/server/error_notifier.dart';
@@ -167,11 +168,13 @@ class AnalysisServer extends AbstractAnalysisServer {
167168
ResourceProvider baseResourceProvider,
168169
AnalysisServerOptions options,
169170
this.sdkManager,
171+
CrashReportingAttachmentsBuilder crashReportingAttachmentsBuilder,
170172
this.instrumentationService, {
171173
this.requestStatistics,
172174
DiagnosticServer diagnosticServer,
173175
this.detachableFileSystemManager,
174-
}) : super(options, diagnosticServer, baseResourceProvider) {
176+
}) : super(options, diagnosticServer, crashReportingAttachmentsBuilder,
177+
baseResourceProvider) {
175178
notificationManager = NotificationManager(channel, resourceProvider);
176179

177180
pluginManager = PluginManager(
@@ -866,15 +869,7 @@ class ServerContextManagerCallbacks extends ContextManagerCallbacks {
866869
// TODO(scheglov) Implement notifications for AnalysisService.IMPLEMENTED.
867870
}
868871
});
869-
analysisDriver.exceptions.listen((nd.ExceptionResult result) {
870-
String message = 'Analysis failed: ${result.path}';
871-
if (result.contextKey != null) {
872-
message += ' context: ${result.contextKey}';
873-
}
874-
// TODO(39284): should this exception be silent?
875-
AnalysisEngine.instance.instrumentationService.logException(
876-
SilentException.wrapInMessage(message, result.exception));
877-
});
872+
analysisDriver.exceptions.listen(analysisServer.logExceptionResult);
878873
analysisServer.driverMap[folder] = analysisDriver;
879874
return analysisDriver;
880875
}

pkg/analysis_server/lib/src/analysis_server_abstract.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:analysis_server/src/analysis_server.dart';
99
import 'package:analysis_server/src/collections.dart';
1010
import 'package:analysis_server/src/context_manager.dart';
1111
import 'package:analysis_server/src/domains/completion/available_suggestions.dart';
12+
import 'package:analysis_server/src/server/crash_reporting_attachments.dart';
1213
import 'package:analysis_server/src/server/diagnostic_server.dart';
1314
import 'package:analysis_server/src/services/correction/namespace.dart';
1415
import 'package:analysis_server/src/services/search/element_visitors.dart';
@@ -39,6 +40,9 @@ abstract class AbstractAnalysisServer {
3940
/// The options of this server instance.
4041
AnalysisServerOptions options;
4142

43+
/// The builder for attachments that should be included into crash reports.
44+
final CrashReportingAttachmentsBuilder crashReportingAttachmentsBuilder;
45+
4246
/// The [ContextManager] that handles the mapping from analysis roots to
4347
/// context directories.
4448
ContextManager contextManager;
@@ -93,7 +97,10 @@ abstract class AbstractAnalysisServer {
9397
/// list is lazily created and should be accessed using [analyzedFilesGlobs].
9498
List<Glob> _analyzedFilesGlobs;
9599

96-
AbstractAnalysisServer(this.options, this.diagnosticServer,
100+
AbstractAnalysisServer(
101+
this.options,
102+
this.diagnosticServer,
103+
this.crashReportingAttachmentsBuilder,
97104
ResourceProvider baseResourceProvider)
98105
: resourceProvider = OverlayResourceProvider(baseResourceProvider) {
99106
performance = performanceDuringStartup;
@@ -287,6 +294,23 @@ abstract class AbstractAnalysisServer {
287294
});
288295
}
289296

297+
void logExceptionResult(nd.ExceptionResult result) {
298+
String message = 'Analysis failed: ${result.filePath}';
299+
if (result.contextKey != null) {
300+
message += ' context: ${result.contextKey}';
301+
}
302+
303+
var attachments =
304+
crashReportingAttachmentsBuilder.forExceptionResult(result);
305+
306+
// TODO(39284): should this exception be silent?
307+
AnalysisEngine.instance.instrumentationService.logException(
308+
SilentException.wrapInMessage(message, result.exception),
309+
null,
310+
attachments,
311+
);
312+
}
313+
290314
/// Notify the declarations tracker that the file with the given [path] was
291315
/// changed - added, updated, or removed. Schedule processing of the file.
292316
void notifyDeclarationsTracker(String path) {

pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import 'package:analysis_server/src/lsp/handlers/handlers.dart';
2727
import 'package:analysis_server/src/lsp/mapping.dart';
2828
import 'package:analysis_server/src/plugin/notification_manager.dart';
2929
import 'package:analysis_server/src/protocol_server.dart' as protocol;
30+
import 'package:analysis_server/src/server/crash_reporting_attachments.dart';
3031
import 'package:analysis_server/src/server/diagnostic_server.dart';
3132
import 'package:analysis_server/src/services/completion/completion_performance.dart'
3233
show CompletionPerformance;
@@ -118,9 +119,11 @@ class LspAnalysisServer extends AbstractAnalysisServer {
118119
ResourceProvider baseResourceProvider,
119120
AnalysisServerOptions options,
120121
this.sdkManager,
122+
CrashReportingAttachmentsBuilder crashReportingAttachmentsBuilder,
121123
this.instrumentationService, {
122124
DiagnosticServer diagnosticServer,
123-
}) : super(options, diagnosticServer, baseResourceProvider) {
125+
}) : super(options, diagnosticServer, crashReportingAttachmentsBuilder,
126+
baseResourceProvider) {
124127
messageHandler = UninitializedStateMessageHandler(this);
125128
// TODO(dantup): This code is almost identical to AnalysisServer, consider
126129
// moving it the base class that already holds many of these fields.
@@ -629,15 +632,7 @@ class LspServerContextManagerCallbacks extends ContextManagerCallbacks {
629632
}
630633
}
631634
});
632-
analysisDriver.exceptions.listen((nd.ExceptionResult result) {
633-
String message = 'Analysis failed: ${result.path}';
634-
if (result.contextKey != null) {
635-
message += ' context: ${result.contextKey}';
636-
}
637-
// TODO(39284): should this exception be silent?
638-
AnalysisEngine.instance.instrumentationService.logException(
639-
SilentException.wrapInMessage(message, result.exception));
640-
});
635+
analysisDriver.exceptions.listen(analysisServer.logExceptionResult);
641636
analysisServer.driverMap[folder] = analysisDriver;
642637
return analysisDriver;
643638
}

pkg/analysis_server/lib/src/lsp/lsp_socket_server.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:analysis_server/src/analysis_server.dart';
88
import 'package:analysis_server/src/lsp/channel/lsp_channel.dart';
99
import 'package:analysis_server/src/lsp/constants.dart';
1010
import 'package:analysis_server/src/lsp/lsp_analysis_server.dart';
11+
import 'package:analysis_server/src/server/crash_reporting_attachments.dart';
1112
import 'package:analysis_server/src/server/diagnostic_server.dart';
1213
import 'package:analysis_server/src/socket_server.dart';
1314
import 'package:analyzer/file_system/physical_file_system.dart';
@@ -75,8 +76,13 @@ class LspSocketServer implements AbstractSocketServer {
7576
'File read mode was set to the unknown mode: $analysisServerOptions.fileReadMode');
7677
}
7778

78-
analysisServer = LspAnalysisServer(serverChannel, resourceProvider,
79-
analysisServerOptions, sdkManager, instrumentationService,
79+
analysisServer = LspAnalysisServer(
80+
serverChannel,
81+
resourceProvider,
82+
analysisServerOptions,
83+
sdkManager,
84+
CrashReportingAttachmentsBuilder.empty,
85+
instrumentationService,
8086
diagnosticServer: diagnosticServer);
8187
}
8288
}

pkg/analysis_server/lib/src/server/crash_reporting.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:analyzer/exception/exception.dart';
66
import 'package:analyzer/instrumentation/noop_service.dart';
77
import 'package:analyzer/instrumentation/plugin_data.dart';
8+
import 'package:analyzer/instrumentation/service.dart';
89
import 'package:telemetry/crash_reporting.dart';
910

1011
class CrashReportingInstrumentation extends NoopInstrumentationService {
@@ -13,19 +14,30 @@ class CrashReportingInstrumentation extends NoopInstrumentationService {
1314
CrashReportingInstrumentation(this.reporter);
1415

1516
@override
16-
void logException(dynamic exception, [StackTrace stackTrace]) {
17+
void logException(dynamic exception,
18+
[StackTrace stackTrace,
19+
List<InstrumentationServiceAttachment> attachments]) {
20+
var crashReportAttachments = (attachments ?? []).map((e) {
21+
return CrashReportAttachment.string(
22+
field: 'attachment_${e.id}',
23+
value: e.stringValue,
24+
);
25+
}).toList();
26+
1727
if (exception is CaughtException) {
1828
// Get the root CaughtException, which matters most for debugging.
1929
CaughtException root = exception.rootCaughtException;
2030

2131
reporter
22-
.sendReport(root.exception, root.stackTrace, comment: root.message)
32+
.sendReport(root.exception, root.stackTrace,
33+
attachments: crashReportAttachments, comment: root.message)
2334
.catchError((error) {
2435
// We silently ignore errors sending crash reports (network issues, ...).
2536
});
2637
} else {
2738
reporter
28-
.sendReport(exception, stackTrace ?? StackTrace.current)
39+
.sendReport(exception, stackTrace ?? StackTrace.current,
40+
attachments: crashReportAttachments)
2941
.catchError((error) {
3042
// We silently ignore errors sending crash reports (network issues, ...).
3143
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/instrumentation/service.dart';
6+
import 'package:analyzer/src/dart/analysis/driver.dart' show ExceptionResult;
7+
8+
/// A builder for attachments to include into crash reports.
9+
class CrashReportingAttachmentsBuilder {
10+
static final CrashReportingAttachmentsBuilder empty =
11+
CrashReportingAttachmentsBuilder();
12+
13+
/// Return attachments with information about the analysis exception.
14+
List<InstrumentationServiceAttachment> forExceptionResult(
15+
ExceptionResult result,
16+
) {
17+
return const [];
18+
}
19+
}

pkg/analysis_server/lib/src/server/driver.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:analysis_server/protocol/protocol_constants.dart'
1212
import 'package:analysis_server/src/analysis_server.dart';
1313
import 'package:analysis_server/src/lsp/lsp_socket_server.dart';
1414
import 'package:analysis_server/src/server/crash_reporting.dart';
15+
import 'package:analysis_server/src/server/crash_reporting_attachments.dart';
1516
import 'package:analysis_server/src/server/detachable_filesystem_manager.dart';
1617
import 'package:analysis_server/src/server/dev_server.dart';
1718
import 'package:analysis_server/src/server/diagnostic_server.dart';
@@ -287,14 +288,17 @@ class Driver implements ServerStarter {
287288
/// should be used to compute relevance scores.
288289
static const String USE_NEW_RELEVANCE = 'use-new-relevance';
289290

290-
/// The instrumentation service that is to be used by the analysis server.
291-
InstrumentationService instrumentationService;
291+
/// The builder for attachments that should be included into crash reports.
292+
CrashReportingAttachmentsBuilder crashReportingAttachmentsBuilder =
293+
CrashReportingAttachmentsBuilder.empty;
292294

293-
/// *
294295
/// An optional manager to handle file systems which may not always be
295296
/// available.
296297
DetachableFileSystemManager detachableFileSystemManager;
297298

299+
/// The instrumentation service that is to be used by the analysis server.
300+
InstrumentationService instrumentationService;
301+
298302
HttpAnalysisServer httpServer;
299303

300304
Driver();
@@ -455,6 +459,7 @@ class Driver implements ServerStarter {
455459
analysisServerOptions,
456460
parser,
457461
dartSdkManager,
462+
crashReportingAttachmentsBuilder,
458463
instrumentationService,
459464
RequestStatisticsHelper(),
460465
analytics,
@@ -468,6 +473,7 @@ class Driver implements ServerStarter {
468473
AnalysisServerOptions analysisServerOptions,
469474
CommandLineParser parser,
470475
DartSdkManager dartSdkManager,
476+
CrashReportingAttachmentsBuilder crashReportingAttachmentsBuilder,
471477
InstrumentationService instrumentationService,
472478
RequestStatisticsHelper requestStatistics,
473479
telemetry.Analytics analytics,
@@ -500,6 +506,7 @@ class Driver implements ServerStarter {
500506
final socketServer = SocketServer(
501507
analysisServerOptions,
502508
dartSdkManager,
509+
crashReportingAttachmentsBuilder,
503510
instrumentationService,
504511
requestStatistics,
505512
diagnosticServer,

pkg/analysis_server/lib/src/server/error_notifier.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ class ErrorNotifier extends NoopInstrumentationService {
88
AbstractAnalysisServer server;
99

1010
@override
11-
void logException(dynamic exception, [StackTrace stackTrace]) {
11+
void logException(dynamic exception,
12+
[StackTrace stackTrace,
13+
List<InstrumentationServiceAttachment> attachments]) {
1214
if (exception is SilentException) {
1315
// Silent exceptions should not be reported to the user.
1416
return;

pkg/analysis_server/lib/src/socket_server.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:analysis_server/protocol/protocol_generated.dart';
77
import 'package:analysis_server/src/analysis_server.dart';
88
import 'package:analysis_server/src/analysis_server_abstract.dart';
99
import 'package:analysis_server/src/channel/channel.dart';
10+
import 'package:analysis_server/src/server/crash_reporting_attachments.dart';
1011
import 'package:analysis_server/src/server/detachable_filesystem_manager.dart';
1112
import 'package:analysis_server/src/server/diagnostic_server.dart';
1213
import 'package:analysis_server/src/utilities/request_statistics.dart';
@@ -31,6 +32,7 @@ class SocketServer implements AbstractSocketServer {
3132
/// The function used to create a new SDK using the default SDK.
3233
final DartSdkManager sdkManager;
3334

35+
final CrashReportingAttachmentsBuilder crashReportingAttachmentsBuilder;
3436
final InstrumentationService instrumentationService;
3537
final RequestStatisticsHelper requestStatistics;
3638
@override
@@ -45,6 +47,7 @@ class SocketServer implements AbstractSocketServer {
4547
SocketServer(
4648
this.analysisServerOptions,
4749
this.sdkManager,
50+
this.crashReportingAttachmentsBuilder,
4851
this.instrumentationService,
4952
this.requestStatistics,
5053
this.diagnosticServer,
@@ -81,6 +84,7 @@ class SocketServer implements AbstractSocketServer {
8184
resourceProvider,
8285
analysisServerOptions,
8386
sdkManager,
87+
crashReportingAttachmentsBuilder,
8488
instrumentationService,
8589
requestStatistics: requestStatistics,
8690
diagnosticServer: diagnosticServer,

pkg/analysis_server/lib/starter.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:analysis_server/src/server/crash_reporting_attachments.dart';
56
import 'package:analysis_server/src/server/detachable_filesystem_manager.dart';
67
import 'package:analysis_server/src/server/driver.dart';
78
import 'package:analyzer/instrumentation/instrumentation.dart';
@@ -14,6 +15,11 @@ abstract class ServerStarter {
1415
/// Initialize a newly created starter to start up an analysis server.
1516
factory ServerStarter() = Driver;
1617

18+
/// Set the new builder for attachments that should be included into crash
19+
/// reports.
20+
set crashReportingAttachmentsBuilder(
21+
CrashReportingAttachmentsBuilder builder);
22+
1723
/// An optional manager to handle file systems which may not always be
1824
/// available.
1925
set detachableFileSystemManager(DetachableFileSystemManager manager);

pkg/analysis_server/test/analysis_abstract.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:analysis_server/protocol/protocol_generated.dart'
1010
hide AnalysisOptions;
1111
import 'package:analysis_server/src/analysis_server.dart';
1212
import 'package:analysis_server/src/domain_analysis.dart';
13+
import 'package:analysis_server/src/server/crash_reporting_attachments.dart';
1314
import 'package:analysis_server/src/utilities/mocks.dart';
1415
import 'package:analyzer/file_system/file_system.dart';
1516
import 'package:analyzer/instrumentation/instrumentation.dart';
@@ -125,6 +126,7 @@ class AbstractAnalysisTest with ResourceProviderMixin {
125126
resourceProvider,
126127
options,
127128
DartSdkManager(resourceProvider.convertPath('/sdk'), true),
129+
CrashReportingAttachmentsBuilder.empty,
128130
InstrumentationService.NULL_SERVICE);
129131
}
130132

pkg/analysis_server/test/analysis_server_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:analysis_server/protocol/protocol_constants.dart';
99
import 'package:analysis_server/protocol/protocol_generated.dart';
1010
import 'package:analysis_server/src/analysis_server.dart';
1111
import 'package:analysis_server/src/domain_server.dart';
12+
import 'package:analysis_server/src/server/crash_reporting_attachments.dart';
1213
import 'package:analysis_server/src/utilities/mocks.dart';
1314
import 'package:analyzer/file_system/file_system.dart';
1415
import 'package:analyzer/instrumentation/instrumentation.dart';
@@ -86,6 +87,7 @@ class AnalysisServerTest with ResourceProviderMixin {
8687
resourceProvider,
8788
AnalysisServerOptions(),
8889
DartSdkManager(convertPath('/sdk'), false),
90+
CrashReportingAttachmentsBuilder.empty,
8991
InstrumentationService.NULL_SERVICE);
9092
}
9193

pkg/analysis_server/test/client/impl/abstract_client.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:analysis_server/protocol/protocol_generated.dart'
1010
import 'package:analysis_server/src/analysis_server.dart';
1111
import 'package:analysis_server/src/domain_analysis.dart';
1212
import 'package:analysis_server/src/domain_completion.dart';
13+
import 'package:analysis_server/src/server/crash_reporting_attachments.dart';
1314
import 'package:analysis_server/src/utilities/mocks.dart';
1415
import 'package:analyzer/file_system/file_system.dart';
1516
import 'package:analyzer/instrumentation/instrumentation.dart';
@@ -104,8 +105,13 @@ abstract class AbstractClient {
104105
AnalysisServer createAnalysisServer(String sdkPath) {
105106
sdk = MockSdk(resourceProvider: resourceProvider);
106107
var options = AnalysisServerOptions();
107-
return AnalysisServer(serverChannel, resourceProvider, options,
108-
DartSdkManager(sdkPath, true), InstrumentationService.NULL_SERVICE);
108+
return AnalysisServer(
109+
serverChannel,
110+
resourceProvider,
111+
options,
112+
DartSdkManager(sdkPath, true),
113+
CrashReportingAttachmentsBuilder.empty,
114+
InstrumentationService.NULL_SERVICE);
109115
}
110116

111117
/// Create a project at [projectPath].

pkg/analysis_server/test/context_manager_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2404,7 +2404,7 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
24042404
driverMap[path] = currentDriver;
24052405
currentDriver.exceptions.listen((ExceptionResult result) {
24062406
AnalysisEngine.instance.instrumentationService.logException(
2407-
CaughtException.withMessage('Analysis failed: ${result.path}',
2407+
CaughtException.withMessage('Analysis failed: ${result.filePath}',
24082408
result.exception.exception, result.exception.stackTrace));
24092409
});
24102410
return currentDriver;

0 commit comments

Comments
 (0)