Fix #8783 - Remove AppInsights package.

This commit is contained in:
Andrew Peters 2017-06-13 13:37:42 -07:00
Родитель a3dd89ae50
Коммит a9c8ca7e45
7 изменённых файлов: 1 добавлений и 485 удалений

Просмотреть файл

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.9
VisualStudioVersion = 15.0.26430.6
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore", "src\EFCore\EFCore.csproj", "{715C38E9-B2F5-4DB2-8025-0C6492DEBDD4}"
EndProject
@ -69,10 +69,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-ef.Tests", "test\dot
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ef.Tests", "test\ef.Tests\ef.Tests.csproj", "{935B51B9-A9B9-4DA2-93A2-663D3BCEAA83}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.ApplicationInsights.Tests", "test\EFCore.ApplicationInsights.Tests\EFCore.ApplicationInsights.Tests.csproj", "{55B7DC7C-A2B0-4181-9EFF-DECFBE83602D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.ApplicationInsights", "src\EFCore.ApplicationInsights\EFCore.ApplicationInsights.csproj", "{51F53552-AEC3-4CF5-93D3-DB15DEAA39EA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -203,14 +199,6 @@ Global
{935B51B9-A9B9-4DA2-93A2-663D3BCEAA83}.Debug|Any CPU.Build.0 = Debug|Any CPU
{935B51B9-A9B9-4DA2-93A2-663D3BCEAA83}.Release|Any CPU.ActiveCfg = Release|Any CPU
{935B51B9-A9B9-4DA2-93A2-663D3BCEAA83}.Release|Any CPU.Build.0 = Release|Any CPU
{55B7DC7C-A2B0-4181-9EFF-DECFBE83602D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{55B7DC7C-A2B0-4181-9EFF-DECFBE83602D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{55B7DC7C-A2B0-4181-9EFF-DECFBE83602D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{55B7DC7C-A2B0-4181-9EFF-DECFBE83602D}.Release|Any CPU.Build.0 = Release|Any CPU
{51F53552-AEC3-4CF5-93D3-DB15DEAA39EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{51F53552-AEC3-4CF5-93D3-DB15DEAA39EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51F53552-AEC3-4CF5-93D3-DB15DEAA39EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51F53552-AEC3-4CF5-93D3-DB15DEAA39EA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -247,7 +235,5 @@ Global
{31ED3EA7-8270-478D-935D-0067BD7935B7} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
{27018CE2-C235-439C-80F2-C573C8904892} = {258D5057-81B9-40EC-A872-D21E27452749}
{935B51B9-A9B9-4DA2-93A2-663D3BCEAA83} = {258D5057-81B9-40EC-A872-D21E27452749}
{55B7DC7C-A2B0-4181-9EFF-DECFBE83602D} = {258D5057-81B9-40EC-A872-D21E27452749}
{51F53552-AEC3-4CF5-93D3-DB15DEAA39EA} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -1,6 +1,5 @@
<Project>
<PropertyGroup>
<AppInsightsVersion>2.4.0-beta3</AppInsightsVersion>
<AspNetCoreVersion>2.0.0-*</AspNetCoreVersion>
<CoreFxVersion>4.4.0-*</CoreFxVersion>
<DependencyModelVersion>2.0.0-preview1-*</DependencyModelVersion>

Просмотреть файл

@ -1,277 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using JetBrains.Annotations;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Utilities;
namespace Microsoft.EntityFrameworkCore.ApplicationInsights
{
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public class DiagnosticEventForwarder : IObserver<DiagnosticListener>, IDisposable
{
private const string DependencyTypeName = "SQL";
private readonly object _sync = new object();
private readonly TelemetryClient _telemetryClient;
private IDisposable _efSubscription;
private IDisposable _listenerSubscription;
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public DiagnosticEventForwarder([NotNull] TelemetryClient telemetryClient)
{
Check.NotNull(telemetryClient, nameof(telemetryClient));
_telemetryClient = telemetryClient;
}
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual void Dispose()
{
lock (_sync)
{
_efSubscription?.Dispose();
_efSubscription = null;
_listenerSubscription?.Dispose();
_listenerSubscription = null;
}
}
void IObserver<DiagnosticListener>.OnNext(DiagnosticListener diagnosticListener)
{
if (diagnosticListener.Name == DbLoggerCategory.Name)
{
lock (_sync)
{
_efSubscription = diagnosticListener.Subscribe(new EventObserver(_telemetryClient));
}
}
}
void IObserver<DiagnosticListener>.OnCompleted()
{
}
void IObserver<DiagnosticListener>.OnError(Exception exception)
{
}
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual void Start()
{
lock (_sync)
{
if (_listenerSubscription == null)
{
_listenerSubscription = DiagnosticListener.AllListeners.Subscribe(this);
}
}
}
private sealed class EventObserver : IObserver<KeyValuePair<string, object>>
{
private readonly TelemetryClient _telemetryClient;
public EventObserver(TelemetryClient telemetryClient) => _telemetryClient = telemetryClient;
public void OnNext(KeyValuePair<string, object> value)
{
if (!_telemetryClient.IsEnabled())
{
return;
}
var eventName = value.Key;
var eventData = value.Value;
Debug.Assert(eventName.StartsWith(DbLoggerCategory.Name, StringComparison.Ordinal));
Debug.Assert(eventData != null);
switch (eventData)
{
case CommandErrorEventData commandErrorData:
{
TrackCommandDependency(eventName, commandErrorData, false);
break;
}
case CommandExecutedEventData commandExecutedData:
{
TrackCommandDependency(eventName, commandExecutedData, true);
break;
}
case CommandEndEventData commandEndData:
{
TrackCommandDependency(eventName, commandEndData, true);
break;
}
case ConnectionErrorEventData connectionErrorData:
{
TrackConnectionDependency(eventName, connectionErrorData, false);
break;
}
case ConnectionEndEventData connectionEndData:
{
TrackConnectionDependency(eventName, connectionEndData, true);
break;
}
case TransactionErrorEventData transactionErrorData:
{
TrackTransactionDependency(eventName, transactionErrorData, false);
break;
}
case TransactionEndEventData transactionEndData:
{
TrackTransactionDependency(eventName, transactionEndData, true);
break;
}
case DataReaderDisposingEventData dataReaderDisposingData:
{
TrackReaderDependency(eventName, dataReaderDisposingData);
break;
}
}
}
private void TrackCommandDependency(
string eventName, CommandEndEventData commandEndEventData, bool success)
{
var command = commandEndEventData.Command;
var dependencyTelemetry
= new DependencyTelemetry(
DependencyTypeName,
command.Connection.Database,
eventName,
command.CommandText,
commandEndEventData.StartTime,
commandEndEventData.Duration,
success: success,
resultCode: null);
var properties = dependencyTelemetry.Properties;
properties[nameof(commandEndEventData.ConnectionId)] = commandEndEventData.ConnectionId.ToString();
properties[nameof(commandEndEventData.CommandId)] = commandEndEventData.CommandId.ToString();
properties[nameof(commandEndEventData.IsAsync)] = commandEndEventData.IsAsync.ToString();
properties[nameof(commandEndEventData.ExecuteMethod)] = commandEndEventData.ExecuteMethod.ToString();
properties[nameof(command.CommandText)] = command.CommandText;
_telemetryClient.TrackDependency(dependencyTelemetry);
}
private void TrackConnectionDependency(
string eventName, ConnectionEndEventData connectionEndEventData, bool success)
{
var connection = connectionEndEventData.Connection;
var dependencyTelemetry
= new DependencyTelemetry(
DependencyTypeName,
connectionEndEventData.Connection.Database,
eventName,
$"[{nameof(connection.Database)}='{connection.Database}',"
+ $" {nameof(connection.DataSource)}='{connection.DataSource}',"
+ $" {nameof(connection.ConnectionTimeout)}={connection.ConnectionTimeout}]",
connectionEndEventData.StartTime,
connectionEndEventData.Duration,
success: success,
resultCode: null);
var properties = dependencyTelemetry.Properties;
properties[nameof(connectionEndEventData.ConnectionId)] = connectionEndEventData.ConnectionId.ToString();
properties[nameof(connectionEndEventData.IsAsync)] = connectionEndEventData.IsAsync.ToString();
properties[nameof(connection.Database)] = connection.Database;
properties[nameof(connection.DataSource)] = connection.DataSource;
properties[nameof(connection.ConnectionTimeout)] = connection.ConnectionTimeout.ToString();
_telemetryClient.TrackDependency(dependencyTelemetry);
}
private void TrackTransactionDependency(
string eventName, TransactionEndEventData transactionEndEventData, bool success)
{
var transaction = transactionEndEventData.Transaction;
var dependencyTelemetry
= new DependencyTelemetry(
DependencyTypeName,
transaction.Connection.Database,
eventName,
$"{nameof(transactionEndEventData.Transaction.IsolationLevel)}={transaction.IsolationLevel}",
transactionEndEventData.StartTime,
transactionEndEventData.Duration,
success: success,
resultCode: null);
var properties = dependencyTelemetry.Properties;
properties[nameof(transactionEndEventData.ConnectionId)] = transactionEndEventData.ConnectionId.ToString();
properties[nameof(transactionEndEventData.TransactionId)] = transactionEndEventData.TransactionId.ToString();
properties[nameof(transactionEndEventData.Transaction.IsolationLevel)] = transactionEndEventData.Transaction.IsolationLevel.ToString();
_telemetryClient.TrackDependency(dependencyTelemetry);
}
private void TrackReaderDependency(string eventName, DataReaderDisposingEventData dataReaderDisposingEventData)
{
var command = dataReaderDisposingEventData.Command;
var dependencyTelemetry
= new DependencyTelemetry(
DependencyTypeName,
command.Connection.Database,
eventName,
command.CommandText,
dataReaderDisposingEventData.StartTime,
dataReaderDisposingEventData.Duration,
success: true,
resultCode: null);
var properties = dependencyTelemetry.Properties;
properties[nameof(dataReaderDisposingEventData.ConnectionId)] = dataReaderDisposingEventData.ConnectionId.ToString();
properties[nameof(dataReaderDisposingEventData.CommandId)] = dataReaderDisposingEventData.CommandId.ToString();
properties[nameof(dataReaderDisposingEventData.RecordsAffected)] = dataReaderDisposingEventData.RecordsAffected.ToString();
properties[nameof(command.CommandText)] = command.CommandText;
_telemetryClient.TrackDependency(dependencyTelemetry);
}
public void OnCompleted()
{
}
public void OnError(Exception error)
{
}
}
}
}

Просмотреть файл

@ -1,25 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<Description>Entity Framework Core Application Insights integration.</Description>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Microsoft.EntityFrameworkCore.ApplicationInsights</AssemblyName>
<RootNamespace>Microsoft.EntityFrameworkCore.ApplicationInsights</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<CodeAnalysisRuleSet>..\EFCore.ruleset</CodeAnalysisRuleSet>
<EnableApiCheck>false</EnableApiCheck>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Shared\*.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EFCore.Relational\EFCore.Relational.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="$(AppInsightsVersion)" />
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopAnalyzersVersion)" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,17 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.EntityFrameworkCore.ApplicationInsights
{
public class ApiConsistencyTest : ApiConsistencyTestBase
{
protected override void AddServices(ServiceCollection serviceCollection)
{
}
protected override Assembly TargetAssembly => typeof(DiagnosticEventForwarder).GetTypeInfo().Assembly;
}
}

Просмотреть файл

@ -1,124 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.TestUtilities.Xunit;
using Microsoft.EntityFrameworkCore.Utilities;
using Xunit;
using Xunit.Abstractions;
// ReSharper disable NotAccessedField.Local
// ReSharper disable InconsistentNaming
// ReSharper disable ReturnValueOfPureMethodIsNotUsed
// ReSharper disable PrivateFieldCanBeConvertedToLocalVariable
namespace Microsoft.EntityFrameworkCore.ApplicationInsights
{
public class DiagnosticEventForwarderTest : IClassFixture<NorthwindQuerySqlServerFixture>
{
private readonly NorthwindQuerySqlServerFixture _fixture;
private readonly TestTelemetryChannel _testTelemetryChannel = new TestTelemetryChannel();
private readonly TelemetryClient _telemetryClient;
public DiagnosticEventForwarderTest(NorthwindQuerySqlServerFixture fixture, ITestOutputHelper testOutputHelper)
{
_fixture = fixture;
//_testTelemetryChannel.SetTestOutputHelper(testOutputHelper);
_telemetryClient = new TelemetryClient(
new TelemetryConfiguration
{
InstrumentationKey = Guid.NewGuid().ToString(),
TelemetryChannel = _testTelemetryChannel
});
new DiagnosticEventForwarder(_telemetryClient).Start();
Assert.True(_telemetryClient.IsEnabled());
}
[ConditionalFact]
[SqlServerConfiguredCondition]
public void Forwards_events_as_dependencies()
{
using (var context = _fixture.CreateContext())
{
context.Customers.ToList();
}
Assert.Equal(4, _testTelemetryChannel.Items.Count);
Assert.True(_testTelemetryChannel.Items.All(it => it is DependencyTelemetry));
Assert.True(_testTelemetryChannel.Items.All(it => it.Context.Properties.ContainsKey("ConnectionId")));
var dependencyTelemetry = (DependencyTelemetry)_testTelemetryChannel.Items[0];
Assert.Equal("SQL", dependencyTelemetry.Type);
Assert.Equal("Northwind", dependencyTelemetry.Target);
Assert.Equal(RelationalEventId.ConnectionOpened.Name, dependencyTelemetry.Name);
}
#region TestTelemetryChannel
private sealed class TestTelemetryChannel : ITelemetryChannel
{
private ITestOutputHelper _testOutputHelper;
public void SetTestOutputHelper(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}
public List<ITelemetry> Items { get; } = new List<ITelemetry>();
void ITelemetryChannel.Send(ITelemetry item)
{
Items.Add(item);
_testOutputHelper?.WriteLine(PrintTelemetry((dynamic)item));
}
void IDisposable.Dispose()
{
}
private static string PrintTelemetry(OperationTelemetry operationTelemetry)
{
return $"{operationTelemetry.GetType().ShortDisplayName()}: [Id='{operationTelemetry.Id}', Name='{operationTelemetry.Name}']";
}
private static string PrintTelemetry(DependencyTelemetry dependencyTelemetry)
{
return $"{dependencyTelemetry.GetType().ShortDisplayName()}: "
+ $"[Type='{dependencyTelemetry.Type}', "
+ $"Target='{dependencyTelemetry.Target}', "
+ $"Name='{dependencyTelemetry.Name}', "
+ $"Data='{dependencyTelemetry.Data}', "
+ $"Duration='{dependencyTelemetry.Duration.Milliseconds}ms']";
}
private static string PrintTelemetry(ITelemetry item)
{
return item.ToString();
}
void ITelemetryChannel.Flush()
{
}
bool? ITelemetryChannel.DeveloperMode { get; set; }
string ITelemetryChannel.EndpointAddress { get; set; }
}
#endregion
}
}

Просмотреть файл

@ -1,26 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT' OR '$(CoreOnly)' == 'True'">netcoreapp2.0</TargetFrameworks>
<AssemblyName>Microsoft.EntityFrameworkCore.ApplicationInsights.Tests</AssemblyName>
<RootNamespace>Microsoft.EntityFrameworkCore.ApplicationInsights</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\EFCore.ApplicationInsights\EFCore.ApplicationInsights.csproj" />
<ProjectReference Include="..\EFCore.Tests\EFCore.Tests.csproj" />
<ProjectReference Include="..\EFCore.SqlServer.FunctionalTests\EFCore.SqlServer.FunctionalTests.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>