Skip to content

Commit

Permalink
Merge pull request #445 from Microsoft/develop
Browse files Browse the repository at this point in the history
Merge develop to master for 2.3.0beta3
  • Loading branch information
cijothomas committed Mar 3, 2017
2 parents 794e2d0 + 9470bc7 commit 8cb6da6
Show file tree
Hide file tree
Showing 165 changed files with 1,996 additions and 1,923 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This changelog will be used to generate documentation on [release notes page](http://azure.microsoft.com/en-us/documentation/articles/app-insights-release-notes-dotnet/).

## Version 2.3.0-beta3
- [Added overloads of TelemetryClientExtensions.StartOperation.] (https://github.com/Microsoft/ApplicationInsights-dotnet/issues/163)
- Fire new ETW events for Operation Start/Stop.

## Version 2.3.0-beta2
- Added constructor overloads for TelemetryConfiguration and added creation of a default InMemoryChannel when no channel is specified for a new instance.
TelemetryClient will no longer create an InMemoryChannel on the configuration instance if TelemetryChannel is null, instead the configuration instances will always have a channel when created.
Expand Down
2 changes: 1 addition & 1 deletion GlobalStaticVersion.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<SemanticVersionMajor>2</SemanticVersionMajor>
<SemanticVersionMinor>3</SemanticVersionMinor>
<SemanticVersionPatch>0</SemanticVersionPatch>
<PreReleaseMilestone>beta2</PreReleaseMilestone>
<PreReleaseMilestone>beta3</PreReleaseMilestone>
<!--
Date when Semantic Version was changed.
Update for every public release.
Expand Down
261 changes: 0 additions & 261 deletions Microsoft.ApplicationInsights.Channels.sln

This file was deleted.

245 changes: 166 additions & 79 deletions Microsoft.ApplicationInsights.sln

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Package.targets
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
</Target>
<Target Name="Gitlink" AfterTargets="Build" BeforeTargets="BuildNugetPackage">
<Exec Command='$(PackagesDir)\gitlink.2.2.0\lib\net45\GitLink.exe $(MSBuildThisFileDirectory) -f "Microsoft.ApplicationInsights.sln" -u https://github.com/Microsoft/ApplicationInsights-dotnet -c "$(Configuration)" -p "$(Platform)"' IgnoreExitCode='true' />
<Exec Command='$(PackagesDir)\gitlink.2.2.0\lib\net45\GitLink.exe $(MSBuildThisFileDirectory) -f "Microsoft.ApplicationInsights.Channels.sln" -u https://github.com/Microsoft/ApplicationInsights-dotnet -c "$(Configuration)" -p "$(Platform)"' IgnoreExitCode='true' />
</Target>
<UsingTask TaskName="GetFileVersionInfo" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildFrameworkToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
Expand Down
9 changes: 3 additions & 6 deletions Test/CoreSDK.Test/Net40/Core.Net40.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@
<Project>{4b0bc3b7-c7fc-4333-9e28-5790d9153f07}</Project>
<Name>ApplicationInsightsTypes</Name>
</ProjectReference>
<ProjectReference Include="..\TestFramework\Net40\TestFramework.Net40.csproj">
<Project>{804af8fd-87f5-48ae-90c8-70433018b76e}</Project>
<Name>TestFramework.Net40</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config">
Expand All @@ -78,15 +74,16 @@
<Folder Include="Extensibility\Implementation\Tracing\" />
</ItemGroup>
<Import Project="..\Shared\Core.Shared.Tests.projitems" Label="Shared" />
<Import Project="..\..\TestFramework\Shared\TestFramework.Shared.projitems" Label="Shared" />
<Import Project="..\Operation.CC.Shared.Tests\Operation.CC.Tests.Shared.projitems" Label="Shared" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'Common.targets'))\Common.targets" />
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\..\..\packages\StyleCop.MSBuild.4.7.55.0\build\StyleCop.MSBuild.Targets" Condition="Exists('..\..\..\..\packages\StyleCop.MSBuild.4.7.55.0\build\StyleCop.MSBuild.Targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\..\packages\StyleCop.MSBuild.4.7.50.0\build\StyleCop.MSBuild.Targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\StyleCop.MSBuild.4.7.50.0\build\StyleCop.MSBuild.Targets'))" />
<Error Condition="!Exists('..\..\..\..\packages\StyleCop.MSBuild.4.7.55.0\build\StyleCop.MSBuild.Targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\StyleCop.MSBuild.4.7.55.0\build\StyleCop.MSBuild.Targets'))" />
</Target>
<Import Project="..\..\..\..\packages\StyleCop.MSBuild.4.7.50.0\build\StyleCop.MSBuild.Targets" Condition="Exists('..\..\..\..\packages\StyleCop.MSBuild.4.7.50.0\build\StyleCop.MSBuild.Targets')" />
</Project>
2 changes: 1 addition & 1 deletion Test/CoreSDK.Test/Net40/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<package id="gitlink" version="2.2.0" targetFramework="net45" />
<package id="Microsoft.Diagnostics.Tracing.EventSource.Redist" version="1.1.28" targetFramework="net45" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="StyleCop.MSBuild" version="4.7.50.0" targetFramework="net45" developmentDependency="true" />
<package id="StyleCop.MSBuild" version="4.7.55.0" targetFramework="net45" developmentDependency="true" />
<package id="xunit.assert" version="2.0.0-beta-build2650" targetFramework="net45" />
</packages>
4 changes: 1 addition & 3 deletions Test/CoreSDK.Test/Net45/Core.Net45.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
<Project>{4b0bc3b7-c7fc-4333-9e28-5790d9153f07}</Project>
<Name>ApplicationInsightsTypes</Name>
</ProjectReference>
<ProjectReference Include="..\TestFramework\Net45\TestFramework.Net45.csproj">
<Name>TestFramework.Net45</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand All @@ -68,6 +65,7 @@
<Folder Include="Extensibility\Implementation\Tracing\" />
</ItemGroup>
<Import Project="..\Shared\Core.Shared.Tests.projitems" Label="Shared" />
<Import Project="..\..\TestFramework\Shared\TestFramework.Shared.projitems" Label="Shared" />
<Import Project="..\Operation.CC.Shared.Tests\Operation.CC.Tests.Shared.projitems" Label="Shared" />
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
5 changes: 1 addition & 4 deletions Test/CoreSDK.Test/Net46/Core.Net46.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@
<Project>{4b0bc3b7-c7fc-4333-9e28-5790d9153f07}</Project>
<Name>ApplicationInsightsTypes</Name>
</ProjectReference>
<ProjectReference Include="..\TestFramework\Net46\TestFramework.Net46.csproj">
<Project>{d7d4e3f5-ec0d-47c9-90cc-56f612976122}</Project>
<Name>TestFramework.Net46</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand All @@ -68,6 +64,7 @@
<Folder Include="Extensibility\Implementation\Tracing\" />
</ItemGroup>
<Import Project="..\Shared\Core.Shared.Tests.projitems" Label="Shared" />
<Import Project="..\..\TestFramework\Shared\TestFramework.Shared.projitems" Label="Shared" />
<Import Project="..\Operation.AL.Shared.Tests\Operation.AL.Tests.Shared.projitems" Label="Shared" />
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ public void RichPayloadEventSourceSessionStateSentTest()
#pragma warning restore 618
}

/// <summary>
/// Tests tracking session state telemetry.
/// </summary>
/// <summary>
/// Tests tracking session state telemetry.
/// </summary>
[TestMethod]
public void RichPayloadEventSourceSessionPerformanceCounterTest()
{
Expand All @@ -147,6 +147,79 @@ public void RichPayloadEventSourceSessionPerformanceCounterTest()
#pragma warning restore 618
}

/// <summary>
/// Tests start/stop events for Operations.
/// </summary>
[TestMethod]
public void RichPayloadEventSourceOperationStartStopTest()
{
if (IsRunningOnEnvironmentSupportingRichPayloadEventSource())
{
var client = CreateTelemetryClient();

using (var listener = new TestFramework.TestEventListener())
{
listener.EnableEvents(RichPayloadEventSource.Log.EventSourceInternal, EventLevel.Informational, RichPayloadEventSource.Keywords.Operations);

// Simulate a Start/Stop request operation
var requestTelemetry = new RequestTelemetry { Name = "Request" };
using (client.StartOperation(requestTelemetry))
{
}

// Expect exactly two events (start and stop)
var actualEvents = listener.Messages.Where(m => m.Keywords.HasFlag(RichPayloadEventSource.Keywords.Operations)).Take(2).ToArray();

VerifyOperationEvent(requestTelemetry, RequestTelemetry.TelemetryName, EventOpcode.Start, actualEvents[0]);
VerifyOperationEvent(requestTelemetry, RequestTelemetry.TelemetryName, EventOpcode.Stop, actualEvents[1]);
}
}
else
{
// 4.5 doesn't have RichPayload events
Assert.IsNull(RichPayloadEventSource.Log.EventSourceInternal);
}
}

/// <summary>
/// Tests start/stop events for nested operations.
/// </summary>
[TestMethod]
public void RichPayloadEventSourceNestedOperationStartStopTest()
{
if (IsRunningOnEnvironmentSupportingRichPayloadEventSource())
{
var client = CreateTelemetryClient();

using (var listener = new TestFramework.TestEventListener())
{
listener.EnableEvents(RichPayloadEventSource.Log.EventSourceInternal, EventLevel.Informational, RichPayloadEventSource.Keywords.Operations);

// Simulate a Start/Stop request operation
var requestTelemetry = new RequestTelemetry { Name = "Request" };
var nestedOperation = new DependencyTelemetry { Name = "Dependency" };
using (client.StartOperation(requestTelemetry))
{
using (client.StartOperation(nestedOperation))
{
}
}

// Expect exactly four events (start, start, stop, stop)
var actualEvents = listener.Messages.Where(m=>m.Keywords.HasFlag(RichPayloadEventSource.Keywords.Operations)).Take(4).ToArray();

VerifyOperationEvent(requestTelemetry, RequestTelemetry.TelemetryName, EventOpcode.Start, actualEvents[0]);
VerifyOperationEvent(nestedOperation, OperationTelemetry.TelemetryName, EventOpcode.Start, actualEvents[1]);
VerifyOperationEvent(nestedOperation, OperationTelemetry.TelemetryName, EventOpcode.Stop, actualEvents[2]);
VerifyOperationEvent(requestTelemetry, RequestTelemetry.TelemetryName, EventOpcode.Stop, actualEvents[3]);
}
}
else
{
// 4.5 doesn't have RichPayload events
Assert.IsNull(RichPayloadEventSource.Log.EventSourceInternal);
}
}

/// <summary>
/// Tests sanitizing telemetry event
Expand All @@ -163,8 +236,7 @@ public void RichPayloadEventSourceSanitizeTest()
ResponseCode = "200"
};

var client = new TelemetryClient();
client.InstrumentationKey = Guid.NewGuid().ToString();
var client = CreateTelemetryClient();

using (var listener = new Microsoft.ApplicationInsights.TestFramework.TestEventListener())
{
Expand All @@ -182,6 +254,16 @@ public void RichPayloadEventSourceSanitizeTest()
}


private TelemetryClient CreateTelemetryClient()
{
// The default InMemoryChannel creates a worker thread which, if left running, causes
// System.AppDomainUnloadedException from the test runner.
var channel = new TestFramework.StubTelemetryChannel();
var configuration = new TelemetryConfiguration(Guid.NewGuid().ToString(), channel);
var client = new TelemetryClient(configuration) { InstrumentationKey = configuration.InstrumentationKey };
return client;
}

/// <summary>
/// Helper method to setup shared context and call the desired tracking for testing.
/// </summary>
Expand All @@ -192,8 +274,7 @@ private void DoTracking(EventKeywords keywords, ITelemetry item, Type dataType,
{
if (IsRunningOnEnvironmentSupportingRichPayloadEventSource())
{
var client = new TelemetryClient();
client.InstrumentationKey = Guid.NewGuid().ToString();
var client = CreateTelemetryClient();

using (var listener = new Microsoft.ApplicationInsights.TestFramework.TestEventListener())
{
Expand Down Expand Up @@ -285,6 +366,25 @@ private static void VerifyEventPayload(IEnumerable<PropertyInfo> expectedPropert
}
}

private static void VerifyOperationEvent(OperationTelemetry expectedOperation, string expectedName, EventOpcode expectedOpCode, EventWrittenEventArgs actualEvent)
{
Assert.AreEqual(expectedOpCode, actualEvent.Opcode);
#if !NET45
Assert.AreEqual(expectedName, actualEvent.EventName);
#endif
VerifyOperationPayload(expectedOperation, actualEvent.Payload);
}

private static void VerifyOperationPayload(OperationTelemetry expected, IReadOnlyList<object> actualPayload)
{
Assert.IsNotNull(actualPayload);
Assert.AreEqual(4, actualPayload.Count);
Assert.AreEqual(expected.Context.InstrumentationKey, actualPayload[0]);
Assert.AreEqual(expected.Id, actualPayload[1]);
Assert.AreEqual(expected.Name, actualPayload[2]);
Assert.AreEqual(expected.Context.Operation.Id, actualPayload[3]);
}

private static Type GetEnumerableType(Type type)
{
foreach (Type intType in type.GetInterfaces())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Assert = Xunit.Assert;
using Extensibility.Implementation;
using TestFramework;

/// <summary>
Expand All @@ -30,13 +31,14 @@ public void TestInitialize()
configuration.InstrumentationKey = Guid.NewGuid().ToString();
configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
this.telemetryClient = new TelemetryClient(configuration);
AsyncLocalHelpers.SaveOperationContext(null);
}

/// <summary>
/// Ensure that context being propagated via async/await.
/// </summary>
[TestMethod]
public void ContextPropogatesThruAsyncAwait()
public void ContextPropagatesThroughAsyncAwait()
{
var task = this.TestAsync();
task.Wait();
Expand Down Expand Up @@ -85,24 +87,21 @@ public async Task TestAsync()
/// <summary>
/// Ensure that context being propagated via Begin/End.
/// </summary>
[TestMethod]
public void ContextPropogatesThruBeginEnd()
[TestMethod, Timeout(500)]
public void ContextPropagatesThroughBeginEnd()
{
var op = this.telemetryClient.StartOperation<RequestTelemetry>("request");
var id1 = Thread.CurrentThread.ManagedThreadId;
int id2 = 0;
this.telemetryClient.TrackTrace("trace1");

HttpWebRequest request = WebRequest.Create(new Uri("http://bing.com")) as HttpWebRequest;
var result = request.BeginGetResponse(
var result = Task.Delay(millisecondsDelay: 50).AsAsyncResult(
(r) =>
{
id2 = Thread.CurrentThread.ManagedThreadId;
this.telemetryClient.TrackTrace("trace2");
this.telemetryClient.StopOperation(op);
(r.AsyncState as HttpWebRequest).EndGetResponse(r);
},
null);

Expand All @@ -111,8 +110,6 @@ public void ContextPropogatesThruBeginEnd()
Thread.Sleep(10);
}

Thread.Sleep(100);

Assert.NotEqual(id1, id2);

Assert.Equal(3, this.sendItems.Count);
Expand Down
Loading

0 comments on commit 8cb6da6

Please sign in to comment.