|
2 | 2 | // Licensed under the MIT license. See License.txt in the project root for license information.
|
3 | 3 |
|
4 | 4 | using System;
|
5 |
| -using System.Collections.Generic; |
6 | 5 | using System.Collections.Immutable;
|
7 | 6 | using System.Composition;
|
8 | 7 | using Microsoft.Extensions.Logging;
|
9 | 8 | using Microsoft.VisualStudio.Telemetry;
|
| 9 | +using StreamJsonRpc; |
10 | 10 |
|
11 | 11 | namespace Microsoft.AspNetCore.Razor.Telemetry;
|
12 | 12 |
|
13 | 13 | [Shared]
|
14 | 14 | [Export(typeof(ITelemetryReporter))]
|
15 | 15 | internal class VSTelemetryReporter : TelemetryReporter
|
16 | 16 | {
|
17 |
| - private readonly IEnumerable<IFaultExceptionHandler> _faultExceptionHandlers; |
18 | 17 | private readonly ILogger? _logger;
|
19 | 18 |
|
20 | 19 | [ImportingConstructor]
|
21 | 20 | public VSTelemetryReporter(
|
22 |
| - [Import(AllowDefault = true)] ILoggerFactory? loggerFactory = null, |
23 |
| - [ImportMany] IEnumerable<IFaultExceptionHandler>? faultExceptionHandlers = null) |
| 21 | + [Import(AllowDefault = true)] ILoggerFactory? loggerFactory = null) |
24 | 22 | // Get the DefaultSession for telemetry. This is set by VS with
|
25 | 23 | // TelemetryService.SetDefaultSession and provides the correct
|
26 | 24 | // appinsights keys etc
|
27 | 25 | : base(ImmutableArray.Create(TelemetryService.DefaultSession))
|
28 | 26 | {
|
29 |
| - _faultExceptionHandlers = faultExceptionHandlers ?? Array.Empty<IFaultExceptionHandler>(); |
30 | 27 | _logger = loggerFactory?.CreateLogger<VSTelemetryReporter>();
|
31 | 28 | }
|
32 | 29 |
|
33 | 30 | protected override bool HandleException(Exception exception, string? message, params object?[] @params)
|
34 | 31 | {
|
35 |
| - var handled = false; |
36 |
| - foreach (var handler in _faultExceptionHandlers) |
| 32 | + if (exception is RemoteInvocationException remoteInvocationException) |
37 | 33 | {
|
38 |
| - if (handler.HandleException(this, exception, message, @params)) |
39 |
| - { |
40 |
| - // This behavior means that each handler still gets a chance |
41 |
| - // to respond to the exception. There's no real reason for this other |
42 |
| - // than best guess. When it was added, there was only one handler but |
43 |
| - // it was intended to be easy to add more. |
44 |
| - handled = true; |
45 |
| - } |
| 34 | + ReportRemoteInvocationException(remoteInvocationException); |
| 35 | + return true; |
46 | 36 | }
|
47 | 37 |
|
48 |
| - return handled; |
| 38 | + return false; |
| 39 | + } |
| 40 | + |
| 41 | + private void ReportRemoteInvocationException(RemoteInvocationException remoteInvocationException) |
| 42 | + { |
| 43 | + if (remoteInvocationException.InnerException is Exception innerException) |
| 44 | + { |
| 45 | + ReportFault(innerException, "RIE: " + remoteInvocationException.Message); |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + ReportFault( |
| 50 | + remoteInvocationException, |
| 51 | + remoteInvocationException.Message, |
| 52 | + remoteInvocationException.ErrorCode, |
| 53 | + remoteInvocationException.DeserializedErrorData); |
49 | 54 | }
|
50 | 55 |
|
51 | 56 | protected override void LogTrace(string? message, params object?[] args)
|
|
0 commit comments