зеркало из https://github.com/dotnet/razor.git
Add telemetry reporting (#6873)
This commit is contained in:
Родитель
7dd08ef1f2
Коммит
109ec4e8e8
|
@ -110,6 +110,7 @@
|
|||
<MicrosoftVisualStudioInteropPackageVersion>$(MicrosoftVisualStudioShellPackagesVersion)</MicrosoftVisualStudioInteropPackageVersion>
|
||||
<MicrosoftInternalVisualStudioInteropPackageVersion>$(MicrosoftVisualStudioShellPackagesVersion)</MicrosoftInternalVisualStudioInteropPackageVersion>
|
||||
<MicrosoftVisualStudioRpcContractsPackageVersion>17.3.3-alpha</MicrosoftVisualStudioRpcContractsPackageVersion>
|
||||
<MicrosoftVisualStudioTelemetryVersion>16.4.137</MicrosoftVisualStudioTelemetryVersion>
|
||||
<MicrosoftVisualStudioTextDataPackageVersion>$(MicrosoftVisualStudioPackagesVersion)</MicrosoftVisualStudioTextDataPackageVersion>
|
||||
<MicrosoftVisualStudioTextImplementationPackageVersion>$(MicrosoftVisualStudioPackagesVersion)</MicrosoftVisualStudioTextImplementationPackageVersion>
|
||||
<MicrosoftVisualStudioTextLogicPackageVersion>$(MicrosoftVisualStudioPackagesVersion)</MicrosoftVisualStudioTextLogicPackageVersion>
|
||||
|
|
|
@ -8,9 +8,10 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions.Tooling.Internal" Version="$(MicrosoftAspNetCoreMvcRazorExtensionsToolingInternalPackageVersion)"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Internal.Transport" Version="$(MicrosoftAspNetCoreMvcRazorExtensionsVersion1_XInternalTransportPackageVersion)"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X.Internal.Transport" Version="$(MicrosoftAspNetCoreMvcRazorExtensionsVersion2_XInternalTransportPackageVersion)"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions.Tooling.Internal" Version="$(MicrosoftAspNetCoreMvcRazorExtensionsToolingInternalPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Internal.Transport" Version="$(MicrosoftAspNetCoreMvcRazorExtensionsVersion1_XInternalTransportPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X.Internal.Transport" Version="$(MicrosoftAspNetCoreMvcRazorExtensionsVersion2_XInternalTransportPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Telemetry" Version="$(MicrosoftVisualStudioTelemetryVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.VisualStudio.Telemetry;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.LanguageServer.Common.Telemetry
|
||||
{
|
||||
internal interface ITelemetryReporter
|
||||
{
|
||||
void ReportEvent(string name, TelemetrySeverity severity);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
@ -10,6 +11,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert;
|
||||
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;
|
||||
using Microsoft.AspNetCore.Razor.LanguageServer.Common;
|
||||
using Microsoft.AspNetCore.Razor.LanguageServer.Common.Telemetry;
|
||||
using Microsoft.AspNetCore.Razor.LanguageServer.Completion;
|
||||
using Microsoft.AspNetCore.Razor.LanguageServer.Completion.Delegation;
|
||||
using Microsoft.AspNetCore.Razor.LanguageServer.Debugging;
|
||||
|
@ -30,6 +32,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Refactoring;
|
|||
using Microsoft.AspNetCore.Razor.LanguageServer.Semantic;
|
||||
using Microsoft.AspNetCore.Razor.LanguageServer.Serialization;
|
||||
using Microsoft.AspNetCore.Razor.LanguageServer.SignatureHelp;
|
||||
using Microsoft.AspNetCore.Razor.LanguageServer.Telemetry;
|
||||
using Microsoft.AspNetCore.Razor.LanguageServer.Tooltip;
|
||||
using Microsoft.AspNetCore.Razor.LanguageServer.WrapWithTag;
|
||||
using Microsoft.CodeAnalysis.Razor;
|
||||
|
@ -41,6 +44,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
|
|||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.VisualStudio.Editor.Razor;
|
||||
using Microsoft.VisualStudio.Telemetry;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OmniSharp.Extensions.JsonRpc;
|
||||
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
|
||||
|
@ -306,6 +310,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
|
|||
|
||||
// Defaults: For when the caller hasn't provided them through the `configure` action.
|
||||
services.TryAddSingleton<HostServicesProvider, DefaultHostServicesProvider>();
|
||||
|
||||
// Get the DefaultSession for telemetry. This is set by VS with
|
||||
// TelemetryService.SetDefaultSession and provides the correct
|
||||
// appinsights keys etc
|
||||
services.AddSingleton<ITelemetryReporter>(provider =>
|
||||
new TelemetryReporter(ImmutableArray.Create(TelemetryService.DefaultSession), provider.GetRequiredService<ILoggerFactory>()));
|
||||
}));
|
||||
|
||||
try
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using Microsoft.AspNetCore.Razor.LanguageServer.Common.Telemetry;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualStudio.Telemetry;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.LanguageServer.Telemetry
|
||||
{
|
||||
internal class TelemetryReporter : ITelemetryReporter
|
||||
{
|
||||
private readonly ImmutableArray<TelemetrySession> _telemetrySessions;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public TelemetryReporter(ImmutableArray<TelemetrySession> telemetrySessions, ILoggerFactory loggerFactory)
|
||||
{
|
||||
_telemetrySessions = telemetrySessions;
|
||||
_logger = loggerFactory.CreateLogger<TelemetryReporter>();
|
||||
}
|
||||
|
||||
public void ReportEvent(string name, TelemetrySeverity severity)
|
||||
{
|
||||
var telemetryEvent = new TelemetryEvent(name, severity);
|
||||
Report(telemetryEvent);
|
||||
}
|
||||
|
||||
private void Report(TelemetryEvent telemetryEvent)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var session in _telemetrySessions)
|
||||
{
|
||||
session.PostEvent(telemetryEvent);
|
||||
}
|
||||
}
|
||||
catch (OutOfMemoryException)
|
||||
{
|
||||
// Do we want to failfast like Roslyn here?
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// No need to do anything here. We failed to report telemetry
|
||||
// which isn't good, but not catastrophic for a user
|
||||
_logger.LogError(e, "Failed logging telemetry event");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче