Skip to content
This repository has been archived by the owner on Jul 5, 2020. It is now read-only.

Adds netstandard2.0 target for dependencycollector. #1234

Merged
merged 4 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Version 2.11.0-beta2
- [Add NetStandard2.0 Target for DependencyCollector](https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/1212)

## Version 2.11.0-beta1
- [Add support for Event Counter collection.](https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/1222)
- [Support for Process CPU and Process Memory perf counters in all platforms including Linux.](https://github.com/microsoft/ApplicationInsights-dotnet-server/issues/1189)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
<RootNamespace>Microsoft.ApplicationInsights.DependencyCollector</RootNamespace>
<AssemblyName>Microsoft.AI.DependencyCollector</AssemblyName>
<DocumentationFile>$(OutputPath)\$(AssemblyName).XML</DocumentationFile>
<TargetFrameworks>net45;netstandard1.6</TargetFrameworks>
<TargetFrameworks>net45;netstandard1.6;netstandard2.0</TargetFrameworks>
<Prefer32Bit>false</Prefer32Bit> <!-- net45 -->
<DefineConstants>$(DefineConstants);DEPENDENCY_COLLECTOR;ALLOW_AGGRESSIVE_INLIGNING_ATTRIBUTE;</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard1.6' OR '$(TargetFramework)' == 'netstandard2.0'">
<DefineConstants>$(DefineConstants);NETSTANDARD;</DefineConstants>
</PropertyGroup>

<PropertyGroup>
<!--Nupkg properties-->
<PackageId>Microsoft.ApplicationInsights.DependencyCollector</PackageId>
Expand Down Expand Up @@ -48,7 +52,8 @@
<PackageReference Include="Microsoft.ApplicationInsights.Agent.Intercept" Version="2.4.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.6'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.6' OR '$(TargetFramework)' == 'netstandard2.0'">

<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="System.Diagnostics.StackTrace" Version="4.3.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'Test.props'))\Test.props" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), NetCore.props))\NetCore.props" />

<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Microsoft.ApplicationInsights.DependencyCollector.NetCore.Tests</AssemblyName>
<PackageId>Microsoft.AI.DependencyCollector.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;1705;1591</NoWarn>
<DefineConstants>TRACE;DEBUG;NETCORE;NETCOREAPP1_0</DefineConstants>
<DefineConstants>TRACE;DEBUG;NETCORE;NETCOREAPP2_1</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702;1705;1591</NoWarn>
<DefineConstants>TRACE;RELEASE;NETCORE;NETCOREAPP1_0</DefineConstants>
<DefineConstants>TRACE;RELEASE;NETCORE;NETCOREAPP2_1</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,29 +170,28 @@ public async Task TestDependencyCollectionWithParentActivity()

parent.Stop();

this.ValidateTelemetryForDiagnosticSource(this.sentTelemetry.Single(), url, request, true, "200", false, parent);
this.ValidateTelemetryForDiagnosticSource(this.sentTelemetry.Single(), url, request, true, "200", false, true, parent);

Assert.AreEqual("k=v", request.Headers.GetValues(RequestResponseHeaders.CorrelationContextHeader).Single());
}
}

/// <summary>
/// Tests dependency collection when request procession causes exception (DNS issue).
/// On .netcore1.1 and before, such dependencies are ot collected
/// On .netcore2.0 they are collected, but there is no build infra to support it (https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/572)
/// TODO: add tests for 2.0
/// Tests dependency collection when request procession causes exception (DNS issue).
/// </summary>
[TestMethod]
[Timeout(10000)]

public async Task TestDependencyCollectionDnsIssue()
{
using (var module = new DependencyTrackingTelemetryModule())
{
module.Initialize(this.config);

var request = new HttpRequestMessage(HttpMethod.Get, $"http://{Guid.NewGuid()}");
var url = $"http://{Guid.NewGuid()}:5050";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is port 5050 ?
would this test still work if we used a non-routable IP address? (ex: 10.0.0.0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5050 was just random!
The goal of this test is to simulate a clientside exception - the easiest way to trigger that is to fail in DNS itself. Its not easy to simulate any other network situation in unit tests.

var request = new HttpRequestMessage(HttpMethod.Get, url);
await new HttpClient().SendAsync(request).ContinueWith(t => { });
Assert.IsFalse(this.sentTelemetry.Any());
// As DNS Resolution itself failed, no response expected
this.ValidateTelemetryForDiagnosticSource(this.sentTelemetry.Single(), new Uri(url), request, false, "Faulted", false, responseExpected: false);
}
}

Expand Down Expand Up @@ -346,7 +345,7 @@ public async Task TestDependencyCollectionWithW3CHeadersWithState()
}
}

private void ValidateTelemetryForDiagnosticSource(DependencyTelemetry item, Uri url, HttpRequestMessage request, bool success, string resultCode, bool expectLegacyHeaders, Activity parent = null)
private void ValidateTelemetryForDiagnosticSource(DependencyTelemetry item, Uri url, HttpRequestMessage request, bool success, string resultCode, bool expectLegacyHeaders, bool responseExpected = true, Activity parent = null)
{
Assert.AreEqual(url, item.Data);
Assert.AreEqual($"{url.Host}:{url.Port}", item.Target);
Expand Down Expand Up @@ -397,7 +396,7 @@ private void ValidateTelemetryForDiagnosticSource(DependencyTelemetry item, Uri
}

// Validate the http request was captured
this.operationDetailsInitializer.ValidateOperationDetailsCore(item);
this.operationDetailsInitializer.ValidateOperationDetailsCore(item, responseExpected);
}

private sealed class LocalServer : IDisposable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Implementation\TelemetryDiagnosticSourceListenerTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)OperationDetailsInitializer.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp1.0' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'NET45' ">
<Compile Include="$(MSBuildThisFileDirectory)DependencyTrackingTelemetryModuleTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HeaderCollectionManipulationTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Implementation\ClientServerDependencyTrackerTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<Compile Include="$(MSBuildThisFileDirectory)SanitizedHostList.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TelemetryDiagnosticSourceListener.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.6' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Compile Include="$(MSBuildThisFileDirectory)Implementation\ClientServerDependencyTracker.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Implementation\DependencyTableStore.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Implementation\FrameworkHttpEventListener.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing;
using Microsoft.ApplicationInsights.W3C;
#if NETSTANDARD1_6
#if NETSTANDARD
using System.Reflection;
using System.Runtime.Versioning;
#else
Expand All @@ -35,7 +35,7 @@ public class DependencyTrackingTelemetryModule : ITelemetryModule, IDisposable
private TelemetryDiagnosticSourceListener telemetryDiagnosticSourceListener;
private SqlClientDiagnosticSourceListener sqlClientDiagnosticSourceListener;

#if !NETSTANDARD1_6
#if !NETSTANDARD
private ProfilerSqlCommandProcessing sqlCommandProcessing;
private ProfilerSqlConnectionProcessing sqlConnectionProcessing;
private ProfilerHttpProcessing httpProcessing;
Expand Down Expand Up @@ -117,7 +117,7 @@ public void Initialize(TelemetryConfiguration configuration)
ClientServerDependencyTracker.IsW3CEnabled = this.EnableW3CHeadersInjection;
#endif

#if !NETSTANDARD1_6
#if !NETSTANDARD
// Net40 only supports runtime instrumentation
// Net45 supports either but not both to avoid duplication
this.InitializeForRuntimeInstrumentationOrFramework();
Expand Down Expand Up @@ -146,7 +146,7 @@ public void Initialize(TelemetryConfiguration configuration)
catch (Exception exc)
{
string clrVersion;
#if NETSTANDARD1_6
#if NETSTANDARD
clrVersion = System.Reflection.Assembly.GetEntryAssembly().GetCustomAttribute<TargetFrameworkAttribute>().FrameworkName;
#else
clrVersion = Environment.Version.ToString();
Expand All @@ -162,7 +162,7 @@ public void Initialize(TelemetryConfiguration configuration)
}
}

#if !NETSTANDARD1_6
#if !NETSTANDARD
internal virtual void InitializeForRuntimeProfiler()
{
// initialize instrumentation extension
Expand Down Expand Up @@ -260,7 +260,7 @@ private static void PrepareFirstActivity()
activity.Stop();
}

#if !NETSTANDARD1_6
#if !NETSTANDARD
/// <summary>
/// Initialize for framework event source (not supported for Net40).
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void GetCollectorReturnsWebAppCollector()
{
try
{
PerformanceCounterUtility.isAzureWebApp = null;
Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", "something");
var actual = PerformanceCounterUtility.GetPerformanceCollector();
Assert.AreEqual("WebAppPerformanceCollector", actual.GetType().Name);
Expand Down